KFar 0.4 + KFar_Arc 0.1

git-svn-id: svn://kolibrios.org@589 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2007-07-26 12:45:49 +00:00
parent 379dd4d36d
commit 1d9fff9e92
18 changed files with 9730 additions and 205 deletions

View File

@ -0,0 +1,137 @@
<EFBFBD>« £¨­ ¯à¥¤áâ ¢«ï¥â ᮡ®© áâ ­¤ àâ­ãî ¤«ï Š®«¨¡à¨ ¤¨­ ¬¨ç¥áªãî ¡¨¡«¨®â¥ªã (ä®à¬ â  COFF),
íªá¯®àâ¨àãîéãî á«¥¤ãî騥 ä㭪樨 ¨ ¯¥à¥¬¥­­ë¥ (­¥ª®â®àë¥ ä㭪樨 ¬®£ãâ ®âáãâá⢮¢ âì).
”㭪樨 ¬®£ãâ à §àãè âì «î¡ë¥ ॣ¨áâàë. kfar £ à ­â¨àã¥â á¡à®è¥­­ë© ä« £ ­ ¯à ¢«¥­¨ï DF
¯à¨ ¢ë§®¢¥ íªá¯®àâ¨à㥬ëå ä㭪権 ¨ ®¦¨¤ ¥â ⮣® ¦¥ ¤«ï callback-ä㭪権.
int version;
‚¥àá¨ï ¨­â¥àä¥©á  kfar, ­  ª®â®àãî à ááç¨â ­ ¯« £¨­. ‘¥©ç á ¤®«¦­  ¡ëâì 1.
int __stdcall plugin_load(kfar_info* info);
‚ë§ë¢ ¥âáï ¯à¨ § £à㧪¥ ¯« £¨­ .
typedef struct
{
int StructSize; // = sizeof(kfar_info)
int kfar_ver; // 10000h*major + minor
/* ‚ᥠcallback-ä㭪樨 á®åà ­ïî⠢ᥠॣ¨áâàë, §  ¨áª«î祭¨¥¬ eax. */
/* ”㭪樨 à ¡®âë á ä ©« ¬¨: */
void* open; // HANDLE __stdcall open(const char* name, int mode);
// mode - ª®¬¡¨­ æ¨ï ¡¨â®¢ëå ä« £®¢
// O_READ = 1 - ¤®áâ㯠¤«ï ç⥭¨ï
// O_WRITE = 2 - ¤®áâ㯠¤«ï § ¯¨á¨
// O_CREATE = 4 - ¥á«¨ ä ©« ­¥ áãé¥áâ¢ã¥â, ᮧ¤ âì ¥£®
// O_TRUNCATE = 8 - ãá¥çì ä ©« ¤® ­ã«¥¢®© ¤«¨­ë
void* read; // unsigned __stdcall read(HANDLE hFile, void* buf, unsigned size);
void* write; // ¥éñ ­¥ ॠ«¨§®¢ ­®
void* seek; // void __stdcall seek(HANDLE hFile, int method, __int64 newpos);
void* flush; // ¥éñ ­¥ ॠ«¨§®¢ ­®
void* filesize; // __int64 __stdcall filesize(HANDLE hFile);
void* close; // void __stdcall close(HANDLE hFile);
/* ”㭪樨 à ¡®âë á ¯ ¬ïâìî (¯®áâà ­¨ç­®): */
void* pgalloc; // in: ecx=size, out: eax=pointer or NULL
// ¯à¨ ­¥å¢ âª¥ ¯ ¬ï⨠ᮮ¡é ¥â ¯®«ì§®¢ â¥«î ¨ ¢®§¢à é ¥â NULL
void* pgrealloc; // in: edx=pointer, ecx=new size, out: eax=pointer or NULL
// ¯à¨ ­¥å¢ âª¥ ¯ ¬ï⨠ᮮ¡é ¥â ¯®«ì§®¢ â¥«î ¨ ¢®§¢à é ¥â NULL
void* pgfree; // in: ecx=pointer
void* getfreemem; // unsigned __stdcall getfreemem(void);
// ¢®§¢à é ¥â à §¬¥à ᢮¡®¤­®© ®¯¥à â¨¢­®© ¯ ¬ï⨠¢ Š¡
void* pgalloc2; // void* __stdcall pgalloc2(unsigned size);
void* pgrealloc2; // void* __stdcall pgrealloc2(void* pointer, unsigned size);
void* pgfree2; // void __stdcall pgfree2(void* pointer);
/* ”㭪樨 à ¡®âë á ¤¨ «®£ ¬¨: */
void* menu; // int __stdcall menu(void* variants, const char* title, unsigned flags);
// variants 㪠§ë¢ ¥â ­  ⥪ã騩 í«¥¬¥­â ¢ ¤¢ãá¢ï§­®¬ ᯨ᪥
void* menu_centered_in; // int __stdcall menu_centered_in(unsigned left, unsigned top,
// unsigned width, unsigned height,
// void* variants, const char* title, unsigned flags);
void* DialogBox; // int __stdcall DialogBox(DLGDATA* dlg);
void* SayErr; // int __stdcall SayErr(int num_strings, const char** strings,
// int num_buttons, const char** buttons);
void* Message; // int __stdcall Message(const char* title,
// int num_strings, const char** strings,
// int num_buttons, const char** buttons);
// may be x=-1 and/or y=-1
struct {unsigned width;unsigned height;}* cur_console_size;
} kfar_info;
‚®§¢à é ¥¬®¥ §­ ç¥­¨¥:
0 = ãá¯¥è­ ï ¨­¨æ¨ «¨§ æ¨ï
1 = ®è¨¡ª  ¨­¨æ¨ «¨§ æ¨¨ (kfar ¢ë¤ áâ á®®¡é¥­¨¥ ¯®«ì§®¢ â¥«î)
2 = ®è¨¡ª  ¨­¨æ¨ «¨§ æ¨¨ (kfar ¯à®¤®«¦¨â ¡¥§ á®®¡é¥­¨©)
void __stdcall plugin_unload(void);
‚ë§ë¢ ¥âáï ¯à¨ ¢ë£à㧪¥ ¯« £¨­  (¢ ¯à®æ¥áᥠ§ ¢¥à襭¨ï à ¡®âë kfar).
HANDLE __stdcall OpenFilePlugin(HANDLE basefile, const char* name,
const void* attr, const void* data, int datasize);
Žâªà뢠¥â ¯« £¨­, í¬ã«¨àãî騩 ä ©«®¢ãî á¨á⥬㠭  ¡ §¥ ä ©«  (­ ¯à¨¬¥à,  à娢 ).
basefile - åí­¤« ä ©«  (ª ª®â®à®¬ã ¯à¨¬¥­¨¬ë ä㭪樨 read ¨ seek ¨§ kfar_info)
name - ¨¬ï ä ©«  (¢® ¢à¥¬¥­­®¬ ¡ãä¥à¥)
attr - 㪠§ â¥«ì ­  áâàãªâãàã á  âਡãâ ¬¨ ä ©«  ¢ ä®à¬ â¥ á¨á⥬­®© ä㭪樨 70.1
data - ¡ãä¥à, ᮤ¥à¦ é¨© ¤ ­­ë¥ ¨§ ­ ç «  ä ©«  (¬®¦¥â ¨á¯®«ì§®¢ âìáï ¤«ï ®¯à¥¤¥«¥­¨ï ⨯  ä ©« )
datasize - à §¬¥à ¤ ­­ëå ¢ data. ⥪ã饩 ॠ«¨§ æ¨¨ min(1024,à §¬¥à ä ©« )
…᫨ ¯« £¨­ ®¡à ¡ â뢠¥â ¯¥à¥¤ ­­ë© ä ©«, â® ®­ ¤®«¦¥­ ¢¥à­ãâì ­®¢ë© ®¯¨á â¥«ì,
ª®â®àë© ¢ ¤ «ì­¥©è¥¬ ¡ã¤¥â ¨á¯®«ì§®¢ âì kfar ¤«ï ®¡à é¥­¨ï ª ¯« £¨­ã. í⮬ á«ãç ¥
¯« £¨­ ¤®«¦¥­ á ¬®áâ®ï⥫쭮 § ªàëâì basefile ä㭪樥© close ¨§ kfar_info (­ ¯à¨¬¥à,
¯à¨ § ªàë⨨ ®¯¨á â¥«ï ¯« £¨­  ¢ ClosePlugin ¨«¨ ­¥¯®á।á⢥­­® ¢ OpenFilePlugin,
¥á«¨ basefile ¢®®¡é¥ ¢¯®á«¥¤á⢨¨ ­¥ ­ã¦¥­).
…᫨ ¯« £¨­ ­¥ ®¡à ¡ â뢠¥â ¯¥à¥¤ ­­ë© ä ©«, ¤®«¦¥­ ¢®§¢à é âìáï 0.
…᫨ ®¯¥à æ¨ï ¯à¥à¢ ­  ¯®«ì§®¢ â¥«¥¬, ¤®«¦­® ¢®§¢à é âìáï §­ ç¥­¨¥ -1.
void __stdcall ClosePlugin(HANDLE hPlugin);
‡ ªà뢠¥â ᮧ¤ ­­ë© ¢ OpenFilePlugin ®¯¨á â¥«ì.
void __stdcall GetOpenPluginInfo(HANDLE hPlugin, OpenPluginInfo* Info);
<EFBFBD>®«ãç¨âì ¨­ä®à¬ æ¨î ®¡ ®âªàë⮬ íª§¥¬¯«ïॠ¯« £¨­ .
typedef struct
{
unsigned flags; // ¡¨â 0: ¤®¡ ¢«ïâì í«¥¬¥­â '..', ¥á«¨ ®­ ®âáãâáâ¢ã¥â
// ¡¨â 1: ª®¯¨à®¢ ­¨¥ ®¡à ¡ â뢠¥âáï ä㭪樥© GetFiles
} OpenPluginInfo;
void __stdcall GetPanelTitle(HANDLE hPlugin, char title[1024],
const char* host_file, const char* curdir);
<EFBFBD>®«ãç¨âì § £®«®¢®ª ¯ ­¥«¨ ¯« £¨­ . <20> à ¬¥âà host_file ᮢ¯ ¤ ¥â á ¨¬¥­¥¬ ä ©« , ¯¥à¥¤ ­­ë¬
¢ OpenFilePlugin. <20> à ¬¥âà curdir ᮢ¯ ¤ ¥â á ⥪ã饩 ¯ ¯ª®©, ãáâ ­ ¢«¨¢ ¥¬®© ¢ SetFolder.
int __stdcall ReadFolder(HANDLE hPlugin, unsigned dirinfo_start,
unsigned dirinfo_size, void* dirdata);
—¨â ¥â ⥪ãéãî ¯ ¯ªã. hPlugin - ¢®§¢à éñ­­ë© ¨§ OpenFilePlugin ®¯¨á â¥«ì.
dirinfo_start - á ª ª®£® ä ©«  ç¨â âì, dirinfo_size - ᪮«ìª® ä ©«®¢ ç¨â âì.
‚®§¢à é ¥¬®¥ §­ ç¥­¨¥ ¨ ¢®§¢à é ¥¬ë¥ ¢ dirdata ¤ ­­ë¥ ¤®«¦­ë ᮮ⢥âá⢮¢ âì ä㭪樨 70.1.
bool __stdcall SetFolder(HANDLE hPlugin, const char* relative_path, const char* absolute_path);
“áâ ­®¢¨âì ⥪ãéãî ¯ ¯ªã. relative_path - ®â­®á¨â¥«ì­ë© ¯ãâì (".." ¨«¨ ¨¬ï ¯®¤¯ ¯ª¨),
absolute_path -  ¡á®«îâ­ë© ¯ãâì (¯ ¯ª  í¬ã«¨à㥬®© ¯« £¨­®¬ ä ©«®¢®© á¨á⥬ë).
void __stdcall GetFiles(HANDLE hPlugin, int NumItems, void* items[], void* addfile, void* adddir);
bool __stdcall addfile(const char* name, void* bdfe_info, HANDLE hFile);
bool __stdcall adddir(const char* name, void* bdfe_info);
‚ë§ë¢ ¥âáï ¤«ï ª®¯¨à®¢ ­¨ï, ¥á«¨ ¢® ä« £ å, ¢®§¢à é ¥¬ëå GetOpenPluginInfo, ãáâ ­®¢«¥­ ¡¨â 1.
<EFBFBD>âã äã­ªæ¨î ४®¬¥­¤ã¥âáï ॠ«¨§®¢ë¢ âì ¢ á«ãç ¥, ¥á«¨ áâ ­¤ àâ­ë© ४ãàᨢ­ë© ®¡å®¤ ¯ ¯®ª
­¥ã¤®¡¥­.
hPlugin - ®¯¨á â¥«ì, ᮧ¤ ­­ë© ¢ OpenFilePlugin.
NumItems - ç¨á«® ª®¯¨à㥬ëå í«¥¬¥­â®¢.
items - ¬ áᨢ ª®¯¨à㥬ëå í«¥¬¥­â®¢, ª ¦¤ë© ¨§ ª®â®àëå § ¤ ñâáï 㪠§ â¥«¥¬ ­  áâàãªâãàã BDFE.
‘¯¥æ¨ «ì­ë© á«ãç © NumItems=-1, items=NULL ®§­ ç ¥â "¢á¥ ä ©«ë" (¢ ⥪ã饩 ¯ ¯ª¥ ¨ ¯®¤¯ ¯ª å).
addfile, adddir - callback-ä㭪樨 kfar' . ‚®§¢à â false ®§­ ç ¥â "¯à¥à¢ âì ª®¯¨à®¢ ­¨¥".
<EFBFBD> à ¬¥âà name ¤®«¦¥­ § ¤ ¢ âì ¨¬ï ®â­®á¨â¥«ì­® ⥪ã饩 ¯ ¯ª¨. <20> à ¬¥âà bdfe_info -
㪠§ â¥«ì ­  ᮪à éñ­­ãî (40 ¡ ©â) § ¯¨áì ¢ ä®à¬ â¥ ä㭪樨 70.5.
Žâªàë⨥¬ ¨ § ªàë⨥¬ ®¯¨á â¥«ï hFile ¤®«¦¥­ § ­¨¬ âìáï ¯« £¨­. ”ã­ªæ¨ï addfile ¡ã¤¥â
¢ë§ë¢ âì ⮫쪮 äã­ªæ¨î read.
int __stdcall getattr(HANDLE hPlugin, const char* filename, void* info);
<EFBFBD>®«ãç¨âì ¨­ä®à¬ æ¨î ® ä ©«¥. ‚®§¢à é ¥¬®¥ §­ ç¥­¨¥ ¨ ¤ ­­ë¥ ¢ info ¤®«¦­ë ᮮ⢥âá⢮¢ âì
ä㭪樨 70.5.
HANDLE __stdcall open(HANDLE hPlugin, const char* filename, int mode);
Žâªàëâì ä ©« filename. <20> à ¬¥âà mode § à¥§¥à¢¨à®¢ ­ ¨ ¢ ⥪ã饩 ¢¥àᨨ kfar ¢á¥£¤  à ¢¥­ 1.
unsigned __stdcall read(HANDLE hFile, void* buf, unsigned size);
—⥭¨¥ size ¡ ©â ¢ ¡ãä¥à buf ¨§ ä ©«  hFile, à ­¥¥ ®âªàë⮣® ç¥à¥§ open.
kfar £ à ­â¨àã¥â, çâ® size ªà â¥­ 512 ¡ ©â.
‚®§¢à é ¥¬®¥ §­ ç¥­¨¥: ç¨á«® ¯à®ç¨â ­­ëå ¡ ©â, -1 ¯à¨ ®è¨¡ª¥.
void __stdcall setpos(HANDLE hFile, __int64 pos);
“áâ ­®¢¨âì ⥪ãéãî ¯®§¨æ¨î ¢ ä ©«¥ hFile, à ­¥¥ ®âªàë⮣® ç¥à¥§ open, ¢ pos.
ƒ à ­â¨àã¥âáï, çâ® pos ªà â­® 512 ¡ ©â.
void __stdcall close(HANDLE hFile);

View File

@ -320,8 +320,7 @@ GenericBox:
jz .redraw
dec eax
jz .key
or eax, -1
int 40h
jmp exit
.redraw:
push ebx ebp
call draw_window
@ -772,6 +771,10 @@ MenuDlgProc:
jz .pgdn
cmp al, 0x49
jz .pgup
cmp al, 0x52
jz .ins
cmp al, 0x53
jz .del
mov edx, [ebx+36]
@@:
cmp dword [edx+4], 0
@ -858,6 +861,28 @@ MenuDlgProc:
.enter:
mov eax, [ebx+36]
ret 16
.ins:
push 5
pop edx
jmp @f
.del:
push 4
pop edx
@@:
mov eax, [ebx+36]
cmp byte [eax+8], '/'
jnz @f
cmp word [eax+9], 'cd'
jnz @f
movzx ecx, byte [eax+11]
sub ecx, '0'
push 24
pop eax
mov ebx, edx
int 40h
@@:
xor eax, eax
ret 16
.line_prev:
cmp eax, [ebx+44]
@ -1016,6 +1041,7 @@ dlgitemtemplate:
; 8 = í«¥¬¥­â ¬®¦¥â ¨¬¥âì 䮪ãá ¢¢®¤ 
; 10h: ¤«ï ª­®¯ª¨ = ª­®¯ª  ¯® 㬮«ç ­¨î (Enter ­  ­¥-ª­®¯ª¥)
; ¤«ï ¯®«ï ¢¢®¤  = ¤ ­­ë¥ ¡ë«¨ ¬®¤¨ä¨æ¨à®¢ ­ë
; 20h: ¤«ï ¯®«ï ¢¢®¤  = ­¥ ®â®¡à ¦ âì ¢¢®¤¨¬ë¥ ¤ ­­ë¥ (¯®ª §ë¢ âì '*')
.size = $
end virtual
; struct DLGDATA
@ -1309,7 +1335,8 @@ draw_text:
draw_text_esi:
test esi, esi
jz .ret
or ecx, -1
push -1
pop ecx
@@:
inc ecx
cmp byte [ecx+esi], 0
@ -1372,6 +1399,14 @@ draw_text_esi:
sub esi, ecx
.text_copy:
jecxz .ret
; check for password editboxes
cmp [ebx+dlgitemtemplate.type], 3
jnz @f
test [ebx+dlgitemtemplate.flags], 20h
jz @f
mov al, '*'
rep stosw
jmp .ret
@@:
lodsb
stosw
@ -1441,31 +1476,30 @@ SayNoMem:
call DialogBox
ret
; int __stdcall SayErr(const char* title, int x, int y,
; int num_strings, const char* strings[],
; int num_buttons, const char* buttons[]);
; may be x=-1 and/or y=-1
; int __stdcall SayErr(int num_strings, const char* strings[],
; int num_buttons, const char* buttons[]);
SayErr:
pop eax
push aError
push eax
push 2
jmp @f
; int __stdcall Message(const char* title, int x, int y,
; int __stdcall Message(const char* title,
; int num_strings, const char* strings[],
; int num_buttons, const char* buttons[]);
Message:
push 1
@@:
; [esp+4] = title
; [esp+8] = x
; [esp+12] = y
; [esp+16] = num_strings
; [esp+20] = strings
; [esp+24] = num_buttons
; [esp+28] = buttons
pop eax
; [esp+4] = title
; [esp+8] = num_strings
; [esp+12] = strings
; [esp+16] = num_buttons
; [esp+20] = buttons
pushad
mov ecx, [esp+4+16]
add ecx, [esp+4+24]
mov ecx, [esp+32+8]
add ecx, [esp+32+16]
imul ecx, dlgitemtemplate.size
add ecx, dlgtemplate.size+12
call xpgalloc
@ -1479,13 +1513,12 @@ Message:
mov edi, eax
mov eax, [esp+28]
stosd ; dlgtemplate.flags
mov eax, [esp+32+8]
or eax, -1
stosd ; dlgtemplate.x
mov eax, [esp+32+12]
stosd ; dlgtemplate.y
; calculate width
mov ecx, [esp+32+16]
mov esi, [esp+32+20]
mov ecx, [esp+32+8]
mov esi, [esp+32+12]
xor edx, edx
.calcwidth:
lodsd
@ -1500,8 +1533,8 @@ Message:
mov edx, eax
@@:
loop .calcwidth
mov ecx, [esp+32+24]
mov esi, [esp+32+28]
mov ecx, [esp+32+16]
mov esi, [esp+32+20]
xor ebp, ebp
.calcwidth2:
lodsd
@ -1527,7 +1560,7 @@ Message:
@@:
mov eax, edx
stosd ; dlgtemplate.width
mov eax, [esp+32+16]
mov eax, [esp+32+8]
inc eax
stosd ; dlgtemplate.height
mov eax, 3
@ -1540,12 +1573,12 @@ Message:
stosd ; (ignored)
stosd ; DlgProc
stosd ; userdata
mov eax, [esp+32+16]
add eax, [esp+32+24]
mov eax, [esp+32+8]
add eax, [esp+32+16]
stosd ; num_items
; fill strings
xor ecx, ecx
mov esi, [esp+32+20]
mov esi, [esp+32+12]
@@:
mov eax, 1
stosd ; dlgitemtemplate.type
@ -1561,11 +1594,11 @@ Message:
mov eax, 1
stosd ; dlgitemtemplate.flags
inc ecx
cmp ecx, [esp+32+16]
cmp ecx, [esp+32+8]
jb @b
; fill buttons
mov ecx, [esp+32+24]
mov esi, [esp+32+28]
mov ecx, [esp+32+16]
mov esi, [esp+32+20]
sub edx, ebp
jc .big
shr edx, 1
@ -1596,7 +1629,7 @@ Message:
mov eax, [esi-4]
stosd ; dlgitemtemplate.data
mov eax, 9
cmp ecx, [esp+32+24]
cmp ecx, [esp+32+16]
jnz @f
or al, 4
@@:
@ -1611,10 +1644,10 @@ Message:
xor edx, edx
mov ecx, dlgitemtemplate.size
div ecx
sub eax, [esp+32+16]
sub eax, [esp+32+8]
@@:
mov [esp+28], eax
mov ecx, ebx
call pgfree
popad
ret 28
ret 20

View File

@ -29,9 +29,6 @@ delete_file_worker:
push 4
push eax
push 3
push -1
push -1
push aError
call SayErr
add esp, 3*4
cmp al, -1
@ -66,6 +63,8 @@ delete_file:
mov esi, [esp+28]
mov ecx, esi
add esi, 40
cmp byte [edi-1], '/'
jz .l1
mov al, '/'
stosb
.l1:
@ -239,9 +238,6 @@ makedir:
push dword [eax+16]
push eax
push 3
push -1
push -1
push dword aError
call SayErr
add esp, 3*4
test eax, eax
@ -253,6 +249,9 @@ copy_file_worker:
; in: execdata = source name, CopyDestEditBuf+12 = destination name, edx = BDFE block for source
; out: CF and ZF not set <=> cancel job ("ja cancel_label")
; destroys eax,esi,edi
lea edi, [edx+40]
and [source_hFile], 0
copy_file_worker2:
push CopyDestEditBuf+12+513
cmp [bDestIsFolder], 0
jz .noaddtoname
@ -261,11 +260,15 @@ copy_file_worker:
lodsb
test al, al
jnz @b
mov byte [esi-1], '/'
pop edi
pop eax
dec esi
push esi
mov edi, esi
lea esi, [edx+40]
cmp byte [esi-1], '/'
jz @f
mov byte [esi], '/'
inc esi
@@:
xchg esi, edi
@@:
cmp edi, CopyDestEditBuf+12+513
jae .overflow
@ -277,12 +280,14 @@ copy_file_worker:
.overflow:
.ret_zf:
pop esi
and byte [esi-1], 0 ; ZF=1
and byte [esi], 0 ; ZF=1
ret
.noaddtoname:
; Íåëüçÿ ñêîïèðîâàòü ôàéë ïîâåðõ ñàìîãî ñåáÿ!
; <EFBFBD>¥«ì§ï ᪮¯¨à®¢ âì ä ©« ¯®¢¥àå á ¬®£® ᥡï!
mov esi, execdata
mov edi, CopyDestEditBuf+12
cmp [source_hModule], 0
jnz @f
push esi edi
call strcmpi
pop edi esi
@ -294,15 +299,12 @@ copy_file_worker:
push 1
push eax
push 2
push -1
push -1
push aError
call SayErr
pop eax
pop eax
jmp .ret_zf
@@:
; Ñîáñòâåííî, êîïèðóåì
; ‘®¡á⢥­­®, ª®¯¨à㥬
; esi->source name, edi->destination name
push ebx
mov [writeinfo.code], 2
@ -316,8 +318,40 @@ copy_file_worker:
mov [ebx+readinfo.size-readinfo], copy_buffer_size
mov [ebx+readinfo.data-readinfo], copy_buffer
mov [ebx+readinfo.name-readinfo], esi
mov eax, [source_hFile]
push eax
test eax, eax
jnz .copyloop
.source_reopen:
mov eax, [source_hModule]
test eax, eax
jz .copyloop
pushad
push O_READ+O_SEQUENTIAL_ONLY
push esi
push [source_hPlugin]
call [eax+PluginInfo.open]
mov [source_hFile], eax
popad
.copyloop:
mov ebx, readinfo
mov eax, [source_hModule]
test eax, eax
jz .native
mov ecx, [source_hFile]
jecxz .readerr
pushad
push [ebx+readinfo.size-readinfo]
push [ebx+readinfo.data-readinfo]
push ecx
call [eax+PluginInfo.read]
mov [esp+28], eax
popad
cmp eax, -1
jz .readerr
mov ebx, eax
jmp .copyreadok
.native:
push 70
pop eax
int 0x40
@ -325,6 +359,7 @@ copy_file_worker:
jz .copyreadok
cmp eax, 6
jz .copyreadok
.readerr:
cmp [copy_bSkipAll2], 0
jnz .copyfailed_del2
push esi
@ -336,14 +371,15 @@ copy_file_worker:
push 4
push eax
push 3
push -1
push -1
push dword aError
call SayErr
add esp, 3*4
test eax, eax
jnz .copyfailed_parseuser
cmp [source_hModule], 0
jz .copyloop
jmp .copyfailed_parseuser
cmp [source_hFile], 0
jz .source_reopen
jmp .copyloop
.copyreadok:
add dword [readinfo.first], ebx
adc dword [readinfo.first+4], 0
@ -370,9 +406,6 @@ copy_file_worker:
push 4
push eax
push 3
push -1
push -1
push dword aError
call SayErr
add esp, 3*4
test eax, eax
@ -394,12 +427,48 @@ copy_file_worker:
cmp ecx, copy_buffer_size
jz .copyloop
.copydone:
pop ecx
test ecx, ecx
jnz @f
mov eax, [source_hModule]
test eax, eax
jz @f
mov ecx, [source_hFile]
jecxz @f
push edx
push ecx
call [eax+PluginInfo.close]
pop edx
@@:
; now try to set attributes from source, ignore errors
mov edi, attrinfo.attr
mov esi, edx
push 8
pop ecx
rep movsd
; replace zero dates with default values
mov eax, [default_attr]
cmp dword [edi-32+8], 0
jnz @f
mov ecx, [eax+8]
mov [edi-32+8], ecx
mov ecx, [eax+12]
mov [edi-32+12], ecx
@@:
cmp dword [edi-32+16], 0
jnz @f
mov ecx, [eax+16]
mov [edi-32+16], ecx
mov ecx, [eax+20]
mov [edi-32+20], ecx
@@:
cmp dword [edi-32+24], 0
jnz @f
mov ecx, [eax+24]
mov [edi-32+24], ecx
mov ecx, [eax+28]
mov [edi-32+28], ecx
@@:
mov ebx, attrinfo
mov [ebx+attrinfo.name-attrinfo], CopyDestEditBuf+12
inc dword [ebx]
@ -413,12 +482,23 @@ copy_file_worker:
.ret:
pop ebx
pop esi
mov byte [esi-1], 0
mov byte [esi], 0
ret
.copydone2:
popf
jmp .ret
.copyfailed:
pop ecx
test ecx, ecx
jnz @f
mov eax, [source_hModule]
test eax, eax
jz @f
mov ecx, [source_hFile]
jecxz @f
push ecx
call [eax+PluginInfo.close]
@@:
cmp [bConfirmDeleteIncomplete], 0
jz .copyfailed_del
cmp [writeinfo.code], 2
@ -429,10 +509,8 @@ copy_file_worker:
push 2
push eax
push 1
push -1
push -1
push dword aCopyCaption
call SayErr
call Message
add esp, 4
test eax, eax
jnz .copydone2
@ -468,6 +546,8 @@ copy_file:
@@:
mov esi, [esp+28]
add esi, 40
cmp byte [edi-1], '/'
jz .l1
mov al, '/'
stosb
.l1:
@ -475,6 +555,7 @@ copy_file:
cmp edi, execdataend
jb @f
call panels_OnKey.bigfilename
stc
popad
ret
@@:
@ -504,7 +585,12 @@ copy_file:
lodsb
test al, al
jnz @b
mov byte [esi-1], '/'
dec esi
cmp byte [esi-1], '/'
jz @f
mov byte [esi], '/'
inc esi
@@:
mov edi, esi
lea esi, [edx+40]
@@:
@ -527,8 +613,44 @@ copy_file:
@@:
cmp al, 1
jz .copy_dir_entry_done
jmp .cancel
jmp .cancel2
.target_created:
mov edx, [source_hModule]
test edx, edx
jz .nosetdir
mov esi, execdata
push esi ; absolute_path
@@:
lodsb
test al, al
jnz @b
@@:
dec esi
cmp byte [esi-1], '/'
jnz @b
push esi ; relative_path
push [source_hPlugin] ; hPlugin
call [edx+PluginInfo.SetFolder]
test al, al
jnz .nosetdir
cmp [copy_bSkipAll3], 0
jz .skip2
push execdata
push aCannotSetFolder
mov eax, esp
push DeleteErrorBtn
push 4
push eax
push 2
call SayErr
pop ecx ecx
test al, al
jz .target_created
cmp al, 2
setz [copy_bSkipAll3]
ja .cancel2
jmp .skip2
.nosetdir:
xor ebp, ebp ; ebp will contain number of copied items
.return_from_recursion:
.read_retry:
@ -537,16 +659,30 @@ copy_file:
mov [ebx+dirinfo.size-dirinfo], copy_dir_query_size
mov [ebx+dirinfo.dirdata-dirinfo], copy_dir_query_area
mov [ebx+dirinfo.name-dirinfo], execdata
mov eax, [source_hModule]
test eax, eax
jz .readfolder_native
push ebp
push [ebx+dirinfo.dirdata-dirinfo]
push [ebx+dirinfo.size-dirinfo]
push [ebx+dirinfo.first-dirinfo]
push [source_hPlugin]
call [eax+PluginInfo.ReadFolder]
pop ebp
mov ebx, dword [copy_dir_query_area+4]
jmp @f
.readfolder_native:
push 70
pop eax
int 0x40
@@:
test eax, eax
jz .readok
cmp eax, 6
jz .readok
; read error
cmp [copy_bSkipAll], 0
jz .skip1
jnz .skip1
push execdata
push aCannotReadFolder
call get_error_msg
@ -556,9 +692,6 @@ copy_file:
push 4
push eax
push 3
push -1
push -1
push aError
call SayErr
add esp, 3*4
test al, al
@ -597,7 +730,12 @@ copy_file:
lodsb
test al, al
jnz @b
mov byte [esi-1], '/'
dec esi
cmp byte [esi-1], '/'
jz @f
mov byte [esi], '/'
inc esi
@@:
mov edi, esi
lea esi, [edx+40]
@@:
@ -612,7 +750,12 @@ copy_file:
lodsb
test al, al
jnz @b
mov byte [esi-1], '/'
dec esi
cmp byte [esi-1], '/'
jz @f
mov byte [esi], '/'
inc esi
@@:
mov edi, esi
lea esi, [edx+40]
@@:
@ -625,7 +768,7 @@ copy_file:
test byte [edx], 10h
jnz .entry_is_folder
call copy_file_worker
ja .cancel
ja .cancel3
jmp .restore_name
.entry_is_folder:
; allocate new item in directory stack
@ -642,7 +785,6 @@ copy_file:
.fullname2_big:
mov esi, CopyDestEditBuf+12+512
jmp .restore_name2
.skip1:
.restore_name:
mov esi, CopyDestEditBuf+12
@@:
@ -665,8 +807,23 @@ copy_file:
.copy_dir_entry_continue:
add edx, 304
jmp .copy_dir_entry_loop
.skip1:
.copy_dir_entry_done:
; return to previous directory
mov esi, execdata
call delete_last_name_from_end
mov eax, [source_hModule]
test eax, eax
jz @f
push execdata
push aDotDot
push [source_hPlugin]
call [eax+PluginInfo.SetFolder]
jmp @f
.skip2:
mov esi, execdata
call delete_last_name_from_end
@@:
; pop item from directory stack
mov ecx, [copy_dir_stack_ptr]
cmp ecx, copy_dir_stack
@ -675,16 +832,34 @@ copy_file:
mov [copy_dir_stack_ptr], ecx
mov ebp, [ecx]
; restore prev directory name
mov esi, execdata
call delete_last_name_from_end
mov esi, CopyDestEditBuf+12
call delete_last_name_from_end
jmp .return_from_recursion
.done:
.cancel:
mov [dirinfo.first], 0 ; do not destroys flags
popad
ret
.cancel2:
sub [copy_dir_stack_ptr], 4
.cancel3:
mov esi, execdata
call delete_last_name_from_end
.cancel:
mov eax, [source_hModule]
test eax, eax
jz .cancel.ret
cmp [copy_dir_stack_ptr], copy_dir_stack
jb .cancel.ret
push execdata
push aDotDot
push [source_hPlugin]
call [eax+PluginInfo.SetFolder]
jmp .cancel2
.cancel.ret:
xor eax, eax
inc eax
popad
ret
delete_last_name_from_end:
lodsb
@ -699,5 +874,403 @@ delete_last_name:
cmp al, '/'
jnz @b
cld
inc esi
cmp esi, execdata
jz @f
cmp esi, CopyDestEditBuf+12
jz @f
dec esi
@@:
mov byte [esi+1], 0
ret
copy_AddDir:
push 1
pop eax ; for "return true"
pushad
mov esi, CopyDestEditBuf+12
@@:
lodsb
test al, al
jnz @b
cmp byte [esi-2], '/'
jnz @f
dec esi
@@:
push dword [esi-1]
push esi
mov byte [esi-1], '/'
mov edi, esi
mov esi, [esp+28h+4]
.0:
lodsb
stosb
cmp edi, CopyDestEditBuf+12+512
jae .done
test al, al
jnz .0
push RetryOrCancelBtn
push 2
call makedir
jz .done
and dword [esp+8+1Ch], 0
.done:
pop esi
pop dword [esi-1]
popad
ret 8
copy_AddFile:
pushad
mov eax, [esp+20h+12]
mov [source_hFile], eax
mov edx, [esp+20h+8]
mov edi, [esp+20h+4]
call copy_file_worker2
popad
setna al
ret 12
virtual at 0
_FILE:
.pos dq ?
.bufpos dq ?
.bufsize dd ?
.mode dd ?
.hPlugin dd ?
.hFile dd ?
.fileinfo:
.fimode dd ?
.fioffset dq ?
.fisize dd ?
.fibuf dd ?
.finame rb 1024
.attr rb 40
align 512
.buf rb 2048
.size = $
end virtual
O_READ = 1 ; allows read from file
O_WRITE = 2 ; allows write to file
O_CREATE = 4 ; if file does not exist and this flag is set, create file;
; if file does not exist and this flag is not set, fail
O_TRUNCATE = 8 ; truncate file if it exists
O_SEQUENTIAL_ONLY = 10h ; there will be no 'seek'/'setpos' calls
; HANDLE __stdcall open(const char* name, int mode);
; Opens physical file
open:
pushad
mov ecx, _FILE.size
call xpgalloc
test eax, eax
jz .ret0z
mov [esp+28], eax
mov ecx, eax
mov esi, [esp+36]
lea edi, [eax+_FILE.finame]
lea edx, [eax+_FILE.finame+1024]
@@:
lodsb
stosb
test al, al
jz @f
cmp edi, edx
jb @b
.ret0:
call pgfree
.ret0z:
popad
xor eax, eax
ret 8
@@:
mov eax, [esp+40]
mov [ecx+_FILE.mode], eax
.getattr:
lea edi, [ecx+_FILE.fileinfo]
mov ebx, edi
push 5
pop eax
stosd
xor eax, eax
stosd
stosd
stosd
lea eax, [ecx+_FILE.attr]
stosd
push 70
pop eax
int 0x40
test eax, eax
jz .found
cmp eax, 5
jnz .ret0
; file does not exist
test [ecx+_FILE.mode], O_CREATE
jz .ret0z
.truncate:
lea ebx, [ecx+_FILE.fileinfo]
mov byte [ebx], 2
push 70
pop eax
int 0x40
test eax, eax
jz .getattr
jmp .ret0
.found:
test [ecx+_FILE.mode], O_TRUNCATE
jz @f
cmp dword [ecx+_FILE.attr+36], eax
jnz .truncate
cmp dword [ecx+_FILE.attr+32], eax
jnz .truncate
@@:
mov dword [ecx+_FILE.pos], eax
mov dword [ecx+_FILE.pos+4], eax
mov dword [ecx+_FILE.bufpos], eax
mov dword [ecx+_FILE.bufpos+4], eax
mov [ecx+_FILE.bufsize], eax
mov [ecx+_FILE.hPlugin], eax
mov [ecx+_FILE.hFile], eax
mov dword [ecx+_FILE.fioffset], eax
mov dword [ecx+_FILE.fioffset+4], eax
mov [esp+28], ecx
popad
ret 8
; unsigned __stdcall read(HANDLE hFile, void* buf, unsigned size);
read:
xor eax, eax
pushad
mov ecx, [esp+36]
test [ecx+_FILE.mode], O_READ
jnz @f
.ret:
popad
ret 12
@@:
cmp dword [esp+44], eax
jz .ret
mov [ecx+_FILE.fimode], eax
mov ebx, [ecx+_FILE.bufsize]
mov eax, dword [ecx+_FILE.pos]
and eax, 2047
sub ebx, eax
jbe .nobuf0
cmp ebx, [esp+44]
jbe @f
mov ebx, [esp+44]
@@:
push ecx
lea esi, [ecx+eax+_FILE.buf]
mov ecx, ebx
mov edi, [esp+44]
rep movsb
pop ecx
mov [esp+40], edi
add [esp+28], ebx
add dword [ecx+_FILE.pos], ebx
adc dword [ecx+_FILE.pos+4], 0
sub [esp+44], ebx
jz .ret
.nobuf0:
test dword [ecx+_FILE.pos], 2047
jz .aligned
cmp dword [ecx+_FILE.bufsize], 0
jnz .ret
lea ebx, [ecx+_FILE.fileinfo]
mov dword [ebx+12], 2048
lea eax, [ecx+_FILE.buf]
mov dword [ebx+16], eax
mov eax, dword [ecx+_FILE.fioffset]
mov dword [ecx+_FILE.bufpos], eax
mov eax, dword [ecx+_FILE.fioffset+4]
mov dword [ecx+_FILE.bufpos+4], eax
call .doread
test eax, eax
jnz .ret
mov [ecx+_FILE.bufsize], ebx
mov eax, dword [ecx+_FILE.pos]
and eax, 2047
sub ebx, eax
jbe .ret
cmp ebx, [esp+44]
jbe @f
mov ebx, [esp+44]
@@:
push ecx
lea esi, [ecx+eax+_FILE.buf]
mov ecx, ebx
mov edi, [esp+44]
rep movsb
pop ecx
add dword [ecx+_FILE.pos], ebx
adc dword [ecx+_FILE.pos+4], 0
mov [esp+40], edi
add [esp+28], ebx
sub [esp+44], ebx
jz .ret
test dword [ecx+_FILE.pos], 2047
jnz .ret
.aligned:
lea ebx, [ecx+_FILE.fileinfo]
mov eax, [esp+44]
and eax, not 2047
jz .finish
and [ecx+_FILE.bufsize], 0
mov [ebx+12], eax
mov eax, [esp+40]
mov [ebx+16], eax
call .doread
test eax, eax
jnz .ret
add dword [ecx+_FILE.pos], ebx
adc dword [ecx+_FILE.pos+4], 0
add [esp+28], ebx
add [esp+40], ebx
sub [esp+44], ebx
jz .ret
cmp ebx, [ecx+_FILE.fisize]
jb .ret
.finish:
lea ebx, [ecx+_FILE.fileinfo]
mov dword [ebx+12], 2048
lea eax, [ecx+_FILE.buf]
mov [ebx+16], eax
and [ecx+_FILE.bufsize], 0
mov eax, dword [ecx+_FILE.fioffset]
mov dword [ecx+_FILE.bufpos], eax
mov eax, dword [ecx+_FILE.fioffset+4]
mov dword [ecx+_FILE.bufpos+4], eax
call .doread
test eax, eax
jnz .ret
mov [ecx+_FILE.bufsize], ebx
cmp ebx, [esp+44]
jb @f
mov ebx, [esp+44]
@@:
add [esp+28], ebx
add dword [ecx+_FILE.pos], ebx
adc dword [ecx+_FILE.pos+4], 0
lea esi, [ecx+_FILE.buf]
mov edi, [esp+40]
mov ecx, ebx
rep movsb
popad
ret 12
.doread:
mov eax, [ecx+_FILE.hPlugin]
test eax, eax
jz .native
push ecx
push [ecx+_FILE.fisize]
push [ecx+_FILE.fibuf]
push [ecx+_FILE.hFile]
call [eax+PluginInfo.read]
pop ecx
cmp eax, -1
jz @f
mov ebx, eax
xor eax, eax
jmp .addpos
@@:
ret
.native:
push 70
pop eax
int 0x40
test eax, eax
jz .addpos
cmp eax, 6
jnz @b
xor eax, eax
.addpos:
add dword [ecx+_FILE.fioffset], ebx
adc dword [ecx+_FILE.fioffset+4], 0
ret
; void __stdcall seek(HANDLE hFile, int method, __int64 newpos);
seek:
pushad
mov ecx, [esp+36]
mov eax, [esp+44]
mov edx, [esp+48]
cmp dword [esp+40], 1
jb .set
ja .end
add eax, dword [ecx+_FILE.pos]
adc edx, dword [ecx+_FILE.pos+4]
jmp .set
.end:
add eax, dword [ecx+_FILE.attr+32]
adc edx, dword [ecx+_FILE.attr+36]
.set:
mov dword [ecx+_FILE.pos], eax
mov dword [ecx+_FILE.pos+4], edx
and eax, not 2047
cmp eax, dword [ecx+_FILE.bufpos]
jnz @f
cmp edx, dword [ecx+_FILE.bufpos+4]
jz .bufposok
@@:
and [ecx+_FILE.bufsize], 0
mov dword [ecx+_FILE.bufpos], eax
mov dword [ecx+_FILE.bufpos+4], edx
.bufposok:
cmp [ecx+_FILE.bufsize], 0
jnz .ret
cmp eax, dword [ecx+_FILE.fioffset]
jnz @f
cmp edx, dword [ecx+_FILE.fioffset+4]
jz .ret
@@:
mov dword [ecx+_FILE.fioffset], eax
mov dword [ecx+_FILE.fioffset+4], edx
mov eax, [ecx+_FILE.hPlugin]
test eax, eax
jz @f
push dword [ecx+_FILE.fioffset+4]
push dword [ecx+_FILE.fioffset]
push [ecx+_FILE.hFile]
call [eax+PluginInfo.setpos]
@@:
.ret:
popad
ret 16
setpos_default:
push dword [esp+12]
push dword [esp+12]
push 0
push dword [esp+16]
call seek
ret 12
; __int64 __stdcall filesize(HANDLE hFile);
filesize:
mov eax, [esp+4]
mov edx, dword [eax+_FILE.attr+36]
mov eax, dword [eax+_FILE.attr+32]
ret 4
; void __stdcall close(HANDLE hFile);
close:
pushad
mov ecx, [esp+24h]
mov eax, [ecx+_FILE.hPlugin]
test eax, eax
jz @f
push ecx
push [ecx+_FILE.hFile]
call [eax+PluginInfo.close]
pop ecx
@@:
call pgfree
popad
ret 4
getattr_default:
mov eax, 2
ret 12

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
[Associations]
asm=/rd/1/TinyPad; AsmMenu1,AsmMenu2
inc=/rd/1/TinyPad
ini=/rd/1/TinyPad
txt=/rd/1/TinyPad
jpg=/rd/1/JpegView
jpeg=/rd/1/JpegView
gif=/rd/1/GIFVIEW; GifMenu1,MenuAnimage
wav=/rd/1/AC97SND
mp3=/rd/1/AC97SND
mid=/rd/1/MIDAMP
bmp=/rd/1/MV; BmpMenu1,MenuAnimage
png=/rd/1/@rcher
rtf=/rd/1/RtfRead
3ds=/rd/1/3d/view3ds
lif=/rd/1/demos/life2
skn=/rd/1/desktop
[Menu]
AsmMenu1=&<26>¥¤ ªâ®à,/rd/1/TinyPad
AsmMenu2=&Š®¬¯¨«¨à®¢ âì,/rd/1/develop/fasm
GifMenu1=&<26>à®á¬®âà,/rd/1/GIFVIEW
BmpMenu1=&<26>à®á¬®âà,/rd/1/MV
MenuAnimage=&<26>¥¤ ªâ®à,/rd/1/animage
[Panels]
LeftViewMode=2
RightViewMode=2
[FolderShortcuts]
# Œ®¦­® ®¯à¥¤¥«¨âì ¤® ¤¥áï⨠ááë«®ª ­  ¯ ¯ª¨ Shortcut0...Shortcut9,
# ­  â ª¨¥ ¯ ¯ª¨ ¬®¦­® ᤥ« âì ¡ëáâàë© ¯¥à¥å®¤ ¯® RCtrl+<æ¨äà >
Shortcut0=/rd/1
[Confirmations]
Delete=1
DeleteIncomplete=0
# ‘«¥¢  ®â §­ ª  à ¢¥­á⢠ ¬®¦­® áâ ¢¨âì «î¡®¥ ®á¬ëá«¥­­®¥ ¨«¨ ¡¥áá¬ëá«¥­­®¥
# ¨¬ï; á¯à ¢  - ¯ãâì ª ¯« £¨­ã.
# …᫨ ¯ãâì ­¥  ¡á®«î⥭, â® ®­ ®âáç¨â뢠¥âáï ®â ¯ ¯ª¨ á ¡¨­ à­¨ª®¬ kfar.
[Plugins]
ArchiveReader=kfar_arc.obj

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,216 @@
; Password handling in 7-Zip: "7zAES" filter (SHA256 + AES256).
; Ported from C++ sources of 7-Zip (c) Igor Pavlov.
aes7z_decoder:
virtual at 0
.outStream rb streamInfo.size
.inStream dd ?
.inLen dd ?
.inPtr dd ?
.bufRest dd ?
; key data
.NumCyclesPower dd ?
.SaltSize dd ?
.Salt rb 16
; AES data
.iv rb 16
.Key rb 32
.nr dd ?
.KeyExpanded rb 32*15
.size = $
end virtual
.fillBuf:
mov esi, [eax+.inPtr]
mov ebp, eax
add edi, [eax+.bufRest]
sub ecx, [eax+.bufRest]
js .rest1
and [eax+.bufRest], 0
.mainloop:
test ecx, ecx
jz .done
sub [ebp+.inLen], 16
js .refill
.refilled:
push esi edi ecx
mov ebx, edi
lea edi, [ebp+.nr]
call aes_decode
pop ecx edi esi
mov eax, dword [ebp+.iv]
xor [edi], eax
lodsd
mov dword [ebp+.iv], eax
mov eax, dword [ebp+.iv+4]
xor [edi+4], eax
lodsd
mov dword [ebp+.iv+4], eax
mov eax, dword [ebp+.iv+8]
xor [edi+8], eax
lodsd
mov dword [ebp+.iv+8], eax
mov eax, dword [ebp+.iv+12]
xor [edi+12], eax
lodsd
mov dword [ebp+.iv+12], eax
add edi, 16
sub ecx, 16
jns .mainloop
.rest1:
neg ecx
mov [ebp+.bufRest], ecx
.done:
mov [ebp+.inPtr], esi
popad
ret
.refill:
mov edx, [ebp+.inLen]
add edx, 16
jnz .rest
js return.err
mov eax, [ebp+.inStream]
call fillBuf
mov edx, [eax+streamInfo.bufDataLen]
test edx, edx
jz return.err
mov esi, [eax+streamInfo.bufPtr]
mov [ebp+.inLen], edx
sub [ebp+.inLen], 16
jns .refilled
.rest:
; ASSERT([eax+streamInfo.fullSize] == 0);
sub edx, ecx
jb return.err
add ecx, edx
rep movsb
mov [ebp+.bufRest], edx
jmp .done
aes7z_get_buf_size:
mov eax, aes7z_decoder.size
mov edx, 0x4000
ret
aes7z_init_decoder:
; zero all
xor eax, eax
mov [ebp+aes7z_decoder.inLen], eax
mov [ebp+aes7z_decoder.bufRest], eax
mov [ebp+aes7z_decoder.NumCyclesPower], eax
mov [ebp+aes7z_decoder.SaltSize], eax
lea edi, [ebp+aes7z_decoder.Salt]
push 8
pop ecx
rep stosd ; zero .Salt and .iv
mov [ebp+streamInfo.fillBuf], aes7z_decoder.fillBuf
; parse parameters
cmp dword [esi-4], eax
jz .parok ; no parameters - OK
lodsb
mov cl, al
and al, 0x3F
mov byte [ebp+aes7z_decoder.NumCyclesPower], al
test cl, 0xC0
jz .parok
test cl, 0x80
setnz byte [ebp+aes7z_decoder.SaltSize]
shr cl, 6
and ecx, 1
cmp dword [esi-1-4], 2
jb return.err
lodsb
mov dl, al
shr al, 4
add byte [ebp+aes7z_decoder.SaltSize], al
and edx, 0xF
add ecx, edx
lea edx, [ecx+2]
push ecx
mov ecx, [ebp+aes7z_decoder.SaltSize]
add edx, ecx
cmp dword [esi-2-4], edx
jb return.err
lea edi, [ebp+aes7z_decoder.Salt]
rep movsb
pop ecx
lea edi, [ebp+aes7z_decoder.iv]
rep movsb
.parok:
test bl, bl
jnz .ret ; if reinitializing - all calculations have been already done
call query_password
jz return.clear
;.CalculateDigest:
mov cl, byte [ebp+aes7z_decoder.NumCyclesPower]
cmp cl, 0x3F
jnz .sha
lea edi, [ebp+aes7z_decoder.Key]
mov ecx, [ebp+aes7z_decoder.SaltSize]
push 32
pop edx
sub edx, ecx
lea esi, [ebp+aes7z_decoder.Salt]
rep movsb
mov ecx, [password_size]
add ecx, ecx
cmp ecx, edx
jbe @f
mov ecx, edx
@@:
sub edx, ecx
mov esi, password_unicode
rep movsb
mov ecx, edx
xor eax, eax
rep stosb
jmp .setkey
.sha:
cmp cl, 32
jb .normal
push 1
shl dword [esp], cl
push 0
jmp @f
.normal:
push 0
push 1
shl dword [esp], cl
@@:
push 0
push 0
call sha256_init
.loop:
lea esi, [ebp+aes7z_decoder.Salt]
mov edx, [ebp+aes7z_decoder.SaltSize]
call sha256_update
mov esi, password_unicode
mov edx, [password_size]
add edx, edx
call sha256_update
mov esi, esp
push 8
pop edx
call sha256_update
mov esi, esp
dec esi
@@:
inc esi
inc byte [esi]
jz @b
sub dword [esp+8], 1
sbb dword [esp+12], 0
mov eax, [esp+8]
or eax, [esp+12]
jnz .loop
lea edi, [ebp+aes7z_decoder.Key]
call sha256_final
add esp, 16
.setkey:
lea esi, [ebp+aes7z_decoder.Key]
push 8
pop edx ; 7z uses 256-bit keys
lea edi, [ebp+aes7z_decoder.nr]
call aes_setkey
.ret:
ret

View File

@ -0,0 +1,469 @@
; Branch filters for 7-Zip archives: BCJ and BCJ2.
; Ported from C++ sources of 7-Zip (c) Igor Pavlov.
virtual at 0
bcj_decoder:
.outStream rb streamInfo.size
.inStream dd ?
.inPtr dd ?
.inSize dd ?
.nowPos dd ? ; offset in stream
.prevPos dd ? ; pointer in buffer
.prevMask db ?
.numRest db ?
rw 1
.dwordRest dd ?
.tempSize dd ?
.tempDword dd ?
.size = $
end virtual
bcj_get_buf_size:
mov eax, bcj_decoder.size
mov edx, 0x4000
ret
bcj_init_decoder:
mov [ebp+streamInfo.fillBuf], bcj_fillBuf
xor edx, edx
mov [ebp+bcj_decoder.inPtr], edx
mov [ebp+bcj_decoder.inSize], edx
mov [ebp+bcj_decoder.prevPos], edx
mov [ebp+bcj_decoder.nowPos], edx
mov [ebp+bcj_decoder.numRest], dl
ret
bcj_fillBuf:
add [eax+bcj_decoder.nowPos], ecx
mov ebp, ecx ; save output size
mov esi, [eax+bcj_decoder.inPtr]
mov ebx, [eax+bcj_decoder.inStream]
mov ecx, [eax+bcj_decoder.inSize]
add esi, [ebx+streamInfo.bufPtr]
mov ebx, eax
cmp [eax+bcj_decoder.prevPos], 0
jz @f
add [eax+bcj_decoder.prevPos], edi
@@:
cmp [ebx+bcj_decoder.numRest], 0
jz .mainloop
sub ebp, 1
js .mainloopdone
dec [ebx+bcj_decoder.numRest]
mov eax, [ebx+bcj_decoder.dwordRest]
stosb
shr eax, 8
mov [ebx+bcj_decoder.dwordRest], eax
jmp @b
.mainloop:
sub ebp, 1
js .mainloopdone
sub ecx, 1
js .refill1
.filled1:
lodsb
.filled2:
stosb
cmp al, 0xE8
jz .filter
cmp al, 0xE9
jnz .mainloop
.filter:
and [ebx+bcj_decoder.tempSize], 0
sub ecx, 4
jb .nopos
js .nopos2
lodsd
push eax
.posok:
xor edx, edx
mov eax, edi
sub eax, [ebx+bcj_decoder.prevPos]
cmp eax, 5
ja .maskok
movzx edx, [ebx+bcj_decoder.prevMask]
@@:
and edx, 0x77
add edx, edx
sub eax, 1
jnz @b
.maskok:
mov [ebx+bcj_decoder.prevMask], dl
mov [ebx+bcj_decoder.prevPos], edi
mov al, [esp+3]
add al, 1
cmp al, 2
jae .miss
cmp dl, 0x20
jae .miss2
lea eax, [edx-1]
test eax, edx
jnz .miss2
pop eax
shr edx, 1
push ecx
mov cl, [bcj_kMaskToBitNumber+edx]
iglobal
bcj_kMaskToBitNumber db 24,16,8,8,0,0,0,0
endg
@@:
sub eax, [ebx+bcj_decoder.nowPos]
add eax, [ebx+streamInfo.bufDataLen]
sub eax, edi
sub eax, 4
add eax, [ebx+streamInfo.bufPtr]
cmp cl, 24
jz @f
push eax
shr eax, cl
add al, 1
cmp al, 2
pop eax
jae @f
mov edx, 0x100
shl edx, cl
sub edx, 1
xor eax, edx
jmp @b
@@:
pop ecx
shl eax, 7
sar eax, 7
sub ebp, 4
jb .finalize_dword
stosd
jmp .mainloop
.miss2:
or [ebx+bcj_decoder.prevMask], 10h
.miss:
or [ebx+bcj_decoder.prevMask], 1
cmp [ebx+bcj_decoder.tempSize], 0
jz @f
lea esi, [ebx+bcj_decoder.tempDword]
pop dword [esi]
mov ecx, [ebx+bcj_decoder.tempSize]
jmp .mainloop
@@:
pop eax
sub esi, 4
add ecx, 4
jmp .mainloop
.finalize_dword:
add ebp, 4
mov [ebx+bcj_decoder.numRest], 4
@@:
dec ebp
js .save_dword
stosb
dec [ebx+bcj_decoder.numRest]
shr eax, 8
jmp @b
.save_dword:
mov [ebx+bcj_decoder.dwordRest], eax
.mainloopdone:
mov eax, [ebx+bcj_decoder.prevPos]
test eax, eax
jz .noprev
sub eax, edi
mov [ebx+bcj_decoder.prevPos], eax
.noprev:
mov eax, [ebx+bcj_decoder.inStream]
sub esi, [eax+streamInfo.bufPtr]
mov [ebx+bcj_decoder.inPtr], esi
mov [ebx+bcj_decoder.inSize], ecx
popad
ret
.refill1:
cmp ecx, -1
jz .refill0
lodsb
cmp ecx, -4
jnz @f
mov ecx, [ebx+bcj_decoder.inStream]
mov esi, [ecx+streamInfo.bufPtr]
mov ecx, [ecx+streamInfo.bufDataLen]
@@:
jmp .filled2
.refill0:
mov eax, [ebx+bcj_decoder.inStream]
call fillBuf
mov esi, [eax+streamInfo.bufPtr]
mov ecx, [eax+streamInfo.bufDataLen]
sub ecx, 1
js return.err
jmp .filled1
.nopos:
mov eax, [ebx+bcj_decoder.inStream]
cmp dword [eax+streamInfo.fullSize+4], 0
jnz .hasdata
push ecx
add ecx, dword [eax+streamInfo.fullSize]
pop ecx
jc .hasdata
add ecx, 4
jmp .mainloop
.hasdata:
mov [ebx+bcj_decoder.tempSize], ecx
push 0
push edi
lea edi, [esp+4]
add ecx, 4
rep movsb
sub esi, ebx
sub esi, 1
cmp esi, bcj_decoder.tempDword+4
jbe @f
call fillBuf
@@:
mov esi, [eax+streamInfo.bufPtr]
mov ecx, [ebx+bcj_decoder.tempSize]
neg ecx
rep movsb
pop edi
mov ecx, [eax+streamInfo.bufDataLen]
add ecx, [ebx+bcj_decoder.tempSize]
cmp [ebx+bcj_decoder.tempSize], -4
jnz .posok
and [ebx+bcj_decoder.tempSize], 0
jmp .posok
.nopos2:
mov eax, [ebx+bcj_decoder.inStream]
add ecx, 4
jmp .hasdata
virtual at 0
bcj2_decoder:
.outStream rb streamInfo.size
.mainInStream dd ?
.callStream dd ?
.jumpStream dd ?
.rangeDecoder dd ?
.dwordRest dd ?
.prevByte db ?
.numRest db ?
.bInited db ?
rb 1
.inPtr dd ?
.inSize dd ?
.callPtr dd ?
.jumpPtr dd ?
.callSize dd ?
.jumpSize dd ?
.rangeDecPtr dd ?
.rangeDecSize dd ?
.nowPos dd ?
.range dd ?
.code dd ?
.statusE9Decoder dd ?
.statusJccDecoder dd ?
.statusE8Decoder rd 256
.size = $
end virtual
bcj2_get_buf_size:
mov eax, bcj2_decoder.size
mov edx, 0x4000
ret
bcj2_init_decoder:
mov [ebp+streamInfo.fillBuf], bcj2_fillBuf
mov eax, lzma_decoder.kBitModelTotal/2
mov ecx, 256+1+1
lea edi, [ebp+bcj2_decoder.statusE9Decoder]
rep stosd
mov dword [ebp+bcj2_decoder.prevByte], ecx
mov [ebp+bcj2_decoder.inSize], ecx
mov [ebp+bcj2_decoder.callSize], ecx
mov [ebp+bcj2_decoder.jumpSize], ecx
mov [ebp+bcj2_decoder.rangeDecSize], ecx
mov [ebp+bcj2_decoder.nowPos], ecx
ret
bcj2_fillBuf.init:
mov eax, [eax+bcj2_decoder.rangeDecoder]
call fillBuf
mov edx, [eax+streamInfo.bufDataLen]
sub edx, 5
jb return.err
mov [ebp+bcj2_decoder.rangeDecSize], edx
mov edx, [eax+streamInfo.bufPtr]
add edx, 5
mov [ebp+bcj2_decoder.rangeDecPtr], edx
mov edx, [edx-4]
bswap edx
mov [ebp+bcj2_decoder.code], edx
or [ebp+bcj2_decoder.range], -1
mov [ebp+bcj2_decoder.bInited], 1
mov eax, ebp
jmp bcj2_fillBuf.inited
bcj2_fillBuf:
mov ebp, eax
cmp [eax+bcj2_decoder.bInited], 0
jz .init
.inited:
add [eax+bcj2_decoder.nowPos], ecx
mov esi, [eax+bcj2_decoder.inPtr]
@@:
cmp [ebp+bcj2_decoder.numRest], 0
jz .mainloop
sub ecx, 1
js .mainloopdone
dec [ebp+bcj2_decoder.numRest]
mov eax, [ebp+bcj2_decoder.dwordRest]
stosb
mov [ebp+bcj2_decoder.prevByte], al
shr eax, 8
mov [ebp+bcj2_decoder.dwordRest], eax
jmp @b
.mainloop:
sub ecx, 1
js .mainloopdone
sub [ebp+bcj2_decoder.inSize], 1
js .refill1
.filled1:
lodsb
stosb
cmp al, 0xE8
jz .e8
cmp al, 0xE9
jz .e9
cmp [ebp+bcj2_decoder.prevByte], 0xF
mov [ebp+bcj2_decoder.prevByte], al
jnz .mainloop
and al, 0xF0
cmp al, 0x80
jnz .mainloop
.jcc:
lea eax, [ebp+bcj2_decoder.statusJccDecoder]
call .RangeDecoderBitDecode
jnc .mainloop
jmp .getptrj
.e8:
movzx eax, al
xchg al, [ebp+bcj2_decoder.prevByte]
lea eax, [ebp+bcj2_decoder.statusE8Decoder+eax*4]
call .RangeDecoderBitDecode
jnc .mainloop
lea eax, [ebp+bcj2_decoder.callPtr]
jmp .getptr
.e9:
mov [ebp+bcj2_decoder.prevByte], al
lea eax, [ebp+bcj2_decoder.statusE9Decoder]
call .RangeDecoderBitDecode
jnc .mainloop
.getptrj:
lea eax, [ebp+bcj2_decoder.jumpPtr]
.getptr:
sub dword [eax+8], 4
js .refill2
.filled2:
add dword [eax], 4
mov eax, [eax]
mov eax, [eax-4]
bswap eax
sub eax, [ebp+bcj2_decoder.nowPos]
add eax, [ebp+streamInfo.bufDataLen]
sub eax, edi
sub eax, 4
add eax, [ebp+streamInfo.bufPtr]
sub ecx, 4
jb .finalize_dword
stosd
shr eax, 24
mov [ebp+bcj2_decoder.prevByte], al
jmp .mainloop
.finalize_dword:
add ecx, 4
mov [ebp+bcj2_decoder.numRest], 4
@@:
dec ecx
js .save_dword
stosb
dec [ebp+bcj2_decoder.numRest]
shr eax, 8
jmp @b
.save_dword:
mov [ebp+bcj2_decoder.dwordRest], eax
.mainloopdone:
mov [ebp+bcj2_decoder.inPtr], esi
popad
ret
.refill1:
mov eax, [ebp+bcj2_decoder.mainInStream]
call fillBuf
mov edx, [eax+streamInfo.bufDataLen]
dec edx
js return.err
mov [ebp+bcj2_decoder.inSize], edx
mov esi, [eax+streamInfo.bufPtr]
jmp .filled1
.refill2:
push eax
mov eax, [eax-bcj2_decoder.callPtr+bcj2_decoder.callStream]
call fillBuf
mov edx, [eax+streamInfo.bufDataLen]
sub edx, 4
js return.err
push [eax+streamInfo.bufPtr]
mov eax, [esp+4]
pop dword [eax]
pop eax
mov [eax+8], edx
jmp .filled2
.refill3:
push eax
mov eax, [ebp+bcj2_decoder.rangeDecoder]
call fillBuf
mov edx, [eax+streamInfo.bufDataLen]
dec edx
js return.err
mov [ebp+bcj2_decoder.rangeDecSize], edx
mov edx, [eax+streamInfo.bufPtr]
mov [ebp+bcj2_decoder.rangeDecPtr], edx
pop eax
jmp .filled3
.RangeDecoderBitDecode:
; in: eax->prob
; out: CF=bit; destroys eax,edx
mov edx, [ebp+bcj2_decoder.range]
shr edx, lzma_decoder.kNumBitModelTotalBits
imul edx, [eax]
cmp [ebp+bcj2_decoder.code], edx
jae .ae
mov [ebp+bcj2_decoder.range], edx
mov edx, lzma_decoder.kBitModelTotal
sub edx, [eax]
shr edx, lzma_decoder.kNumMoveBits
add [eax], edx
clc
.n:
lahf
cmp [ebp+bcj2_decoder.range], lzma_decoder.kTopValue
jae @f
shl [ebp+bcj2_decoder.range], 8
shl [ebp+bcj2_decoder.code], 8
dec [ebp+bcj2_decoder.rangeDecSize]
js .refill3
.filled3:
mov edx, [ebp+bcj2_decoder.rangeDecPtr]
mov al, [edx]
add edx, 1
mov [ebp+bcj2_decoder.rangeDecPtr], edx
mov byte [ebp+bcj2_decoder.code], al
@@:
sahf
ret
.ae:
sub [ebp+bcj2_decoder.range], edx
sub [ebp+bcj2_decoder.code], edx
mov edx, [eax]
shr edx, lzma_decoder.kNumMoveBits
sub [eax], edx
stc
jmp .n

View File

@ -0,0 +1,274 @@
; Implementation of AES crypto algorithm.
; Buffer size is 0x10 bytes (128 bits), key size is not fixed.
; Written by diamond in 2007.
uglobal
aes.pow_table rb 256 ; pow[a] = 3^a
aes.log_table rb 256 ; log[3^a] = a
aes.sbox rb 256 ; ShiftBytes(a)
aes.sbox_rev rb 256 ; ShiftBytes^{-1}(a)
aes.mctable rd 256 ; MixColumns(ShiftBytes(a,0,0,0))
aes.mcrtable rd 256 ; MixColumns^{-1}(a,0,0,0)
endg
init_aes:
; Byte values in SubBytes transform are interpreted as items of
; GF(2^8) \cong F_2[x]/(x^8+x^4+x^3+x+1)F_2[x].
; x+1 is primitive item in this field.
xor ebx, ebx
push 1
pop eax
.1:
mov [aes.pow_table+ebx], al
mov [aes.log_table+eax], bl
; Multiplication by x+1...
mov cl, al ; save value
; ...multiply by x with mod (x^8+x^4+x^3+x+1) = 0x11B...
add al, al
jnc @f
xor al, 0x1B
@@:
; ...and add operand
xor al, cl
inc bl
jnz .1
; generate table for SubBytes transform
mov [aes.sbox+0], 0x63
mov [aes.sbox_rev+0x63], bl
inc ebx
.2:
; calculate inverse in GF(2^8)
mov al, [aes.log_table+ebx]
xor al, 0xFF ; equivalent to "al = 0xFF - al"
mov cl, [aes.pow_table+eax]
; linear transform of byte as vector over F_2
mov al, cl
rol cl, 1
xor al, cl
rol cl, 1
xor al, cl
rol cl, 1
xor al, cl
rol cl, 1
xor al, cl
xor al, 0x63
mov [aes.sbox+ebx], al
mov [aes.sbox_rev+eax], bl
inc bl
jnz .2
; generate table for SubBytes + MixColumn transforms
.3:
mov al, [aes.sbox+ebx] ; SubBytes transform
mov cl, al
add cl, cl
jnc @f
xor cl, 0x1B
@@:
mov byte [aes.mctable+ebx*4], cl ; low byte of MixColumn(a,0,0,0)
mov byte [aes.mctable+ebx*4+1], al
mov byte [aes.mctable+ebx*4+2], al
xor cl, al
mov byte [aes.mctable+ebx*4+3], cl ; high byte of MixColumn(a,0,0,0)
inc bl
jnz .3
; generate table for reverse MixColumn transform
mov dword [aes.mcrtable+0], ebx
inc ebx
.4:
; log_table[9]=0xC7, log_table[0xB]=0x68, log_table[0xD]=0xEE, log_table[0xE]=0xDF
mov cl, [aes.log_table+ebx]
mov al, cl
add al, 0xDF
adc al, 0
mov al, [aes.pow_table+eax]
mov byte [aes.mcrtable+ebx*4], al
mov al, cl
add al, 0xC7
adc al, 0
mov al, [aes.pow_table+eax]
mov byte [aes.mcrtable+ebx*4+1], al
mov al, cl
add al, 0xEE
adc al, 0
mov al, [aes.pow_table+eax]
mov byte [aes.mcrtable+ebx*4+2], al
mov al, cl
add al, 0x68
adc al, 0
mov al, [aes.pow_table+eax]
mov byte [aes.mcrtable+ebx*4+3], al
inc bl
jnz .4
ret
aes_setkey:
; in: esi->key, edx=key size in dwords, edi->AES data struc
lea eax, [edx+6] ; calc number of rounds (buffer size=4)
stosd
shl eax, 4
lea ebx, [edi+eax+16]
mov ecx, edx
rep movsd
push ebx
mov bl, 1
.0:
push 4
pop ecx
@@:
movzx esi, byte [edi-5+ecx]
mov al, [aes.sbox+esi]
rol eax, 8
loop @b
ror eax, 16
mov esi, edx
neg esi
xor eax, [edi+esi*4]
xor al, bl
add bl, bl
jnc @f
xor bl, 0x1B
@@:
stosd
lea ecx, [edx-1]
.1:
cmp edi, [esp]
jz .ret
cmp edx, 8
jnz @f
cmp ecx, 4
jnz @f
push eax
movzx eax, al
mov al, [aes.sbox+eax]
mov [esp], al
mov al, byte [esp+1]
mov al, [aes.sbox+eax]
mov [esp+1], al
mov al, byte [esp+2]
mov al, [aes.sbox+eax]
mov [esp+2], al
mov al, byte [esp+3]
mov al, [aes.sbox+eax]
mov [esp+3], al
pop eax
@@:
xor eax, [edi+esi*4]
stosd
loop .1
cmp edi, [esp]
jnz .0
.ret:
pop eax
ret
aes_decode:
; in: esi->in, ebx->out, edi->AES state
push ebx ebp
push dword [esi+12]
push dword [esi+8]
push dword [esi+4]
push dword [esi]
mov esi, esp
; reverse final round
mov ebp, [edi] ; number of rounds
mov ecx, ebp
shl ecx, 4
lea edi, [edi+ecx+4] ; edi->last round key
; load buffer into registers
mov eax, [esi]
mov ebx, [esi+4]
mov ecx, [esi+8]
mov edx, [esi+12]
; (AddRoundKey)
xor eax, [edi]
xor ebx, [edi+4]
xor ecx, [edi+8]
xor edx, [edi+12]
; (ShiftRows)
.loop0:
xchg ch, dh
xchg bh, ch
xchg ah, bh
rol eax, 16
rol ebx, 16
rol ecx, 16
rol edx, 16
xchg al, cl
xchg bl, dl
xchg ah, bh
xchg bh, ch
xchg ch, dh
rol eax, 16
rol ebx, 16
rol ecx, 16
rol edx, 16
; (SubBytes)
mov [esi], eax
mov [esi+4], ebx
mov [esi+8], ecx
mov [esi+12], edx
mov ecx, 16
@@:
movzx eax, byte [esi]
mov al, [aes.sbox_rev+eax]
mov byte [esi], al
add esi, 1
sub ecx, 1
jnz @b
sub esi, 16
sub edi, 16
; reverse normal rounds
sub ebp, 1
jz .done
mov eax, [esi]
mov ebx, [esi+4]
mov ecx, [esi+8]
mov edx, [esi+12]
push esi edi
; (AddRoundKey)
xor eax, [edi]
xor ebx, [edi+4]
xor ecx, [edi+8]
xor edx, [edi+12]
; (MixColumns)
macro mix_reg reg {
movzx esi, reg#l
mov edi, [aes.mcrtable+esi*4]
movzx esi, reg#h
rol e#reg#x, 16
mov esi, [aes.mcrtable+esi*4]
rol esi, 8
xor edi, esi
movzx esi, reg#l
mov esi, [aes.mcrtable+esi*4]
rol esi, 16
xor edi, esi
movzx esi, reg#h
mov esi, [aes.mcrtable+esi*4]
ror esi, 8
xor edi, esi
mov e#reg#x, edi
}
mix_reg a
mix_reg b
mix_reg c
mix_reg d
purge mix_reg
pop edi esi
jmp .loop0
.done:
; (AddRoundKey)
mov esi, [esp+20]
pop eax
xor eax, [edi]
mov [esi], eax
pop eax
xor eax, [edi+4]
mov [esi+4], eax
pop eax
xor eax, [edi+8]
mov [esi+8], eax
pop eax
xor eax, [edi+12]
mov [esi+12], eax
pop ebp ebx
ret

View File

@ -0,0 +1,32 @@
init_crc_table:
xor edx, edx
mov edi, crc_table
.1:
mov ecx, 8
mov eax, edx
.2:
shr eax, 1
jnc @f
xor eax, 0xEDB88320
@@:
loop .2
stosd
inc dl
jnz .1
ret
crc:
; in: ecx=size, esi->buffer
; out: eax=crc
or eax, -1
jecxz .end
.loop:
movzx edx, al
xor dl, byte [esi]
inc esi
shr eax, 8
xor eax, [crc_table+edx*4]
loop .loop
.end:
xor eax, -1
ret

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
;------------------------------------------------------------------
; use "iglobal" for inserting initialized global data definitions.
;------------------------------------------------------------------
macro iglobal {
IGlobals equ IGlobals,
macro __IGlobalBlock { }
;-------------------------------------------------------------
; use 'uglobal' for inserting uninitialized global definitions.
; even when you define some data values, these variables
; will be stored as uninitialized data.
;-------------------------------------------------------------
macro uglobal {
UGlobals equ UGlobals,
macro __UGlobalBlock { }
endg fix } ; Use endg for ending iglobal and uglobal blocks.
macro IncludeIGlobals{
macro IGlobals dummy,[n] \{ __IGlobalBlock
purge __IGlobalBlock \}
match I, IGlobals \{ I \} }
macro IncludeUGlobals{
macro UGlobals dummy,[n] \{
\common
\local begin, size
begin = $
virtual at $
\forward
__UGlobalBlock
purge __UGlobalBlock
\common
size = $ - begin
end virtual
rb size
\}
match U, UGlobals \{ U \} }
macro IncludeAllGlobals {
IncludeIGlobals
IncludeUGlobals
}
iglobal
endg
uglobal
endg

View File

@ -0,0 +1 @@
lang fix ru

View File

@ -0,0 +1,581 @@
; LZMA decoder for *.7z archives.
; Based on C decoder in LZMA SDK (c) Igor Pavlov.
; Portions by Diamond, 2006, 2007.
lzma_decoder:
virtual at 0
.outStream rb streamInfo.size
.inStream dd ?
; RangeDecoder data
.inLen dd ?
.inPtr dd ?
.code dd ?
.range dd ?
; parameters
.pb db ? ; pos state bits (0 - 4)
.lp db ? ; literal pos state bits (0 - 4)
.lc db ? ; literal context bits (0 - 8)
.previousByte db ?
.posStateMask dd ? ; (1 shl .pb)-1
.literalPosMask dd ? ; (1 shl .lp)-1
; constants
.kNumPosBitsMax = 4
.kNumPosStatesMax = (1 shl .kNumPosBitsMax)
.kLenNumLowBits = 3
.kLenNumLowSymbols = (1 shl .kLenNumLowBits)
.kLenNumMidBits = 3
.kLenNumMidSymbols = (1 shl .kLenNumMidBits)
.kLenNumHighBits = 8
.kLenNumHighSymbols = (1 shl .kLenNumHighBits)
.LenChoice = 0
.LenChoice2 = 1
.LenLow = 2
.LenMid = (.LenLow + (.kNumPosStatesMax shl .kLenNumLowBits))
.LenHigh = (.LenMid + (.kNumPosStatesMax shl .kLenNumMidBits))
.kNumLenProbs = (.LenHigh + .kLenNumHighSymbols)
.kNumStates = 12
.kNumLitStates = 7
.kStartPosModelIndex = 4
.kEndPosModelIndex = 14
.kNumFullDistances = (1 shl (.kEndPosModelIndex/2))
.kNumPosSlotBits = 6
.kNumLenToPosStates = 4
.kNumAlignBits = 4
.kAlignTableSize = (1 shl .kNumAlignBits)
.kMatchMinLen = 2
.IsMatch = 0
.IsRep = (.IsMatch + (.kNumStates shl .kNumPosBitsMax))
.IsRepG0 = (.IsRep + .kNumStates)
.IsRepG1 = (.IsRepG0 + .kNumStates)
.IsRepG2 = (.IsRepG1 + .kNumStates)
.IsRep0Long = (.IsRepG2 + .kNumStates)
.PosSlot = (.IsRep0Long + (.kNumStates shl .kNumPosBitsMax))
.SpecPos = (.PosSlot + (.kNumLenToPosStates shl .kNumPosSlotBits))
.Align_ = (.SpecPos + .kNumFullDistances - .kEndPosModelIndex)
.Lencoder = (.Align_ + .kAlignTableSize)
.RepLencoder = (.Lencoder + .kNumLenProbs)
.Literal = (.RepLencoder + .kNumLenProbs)
LZMA_BASE_SIZE = 1846 ; must be ==Literal
LZMA_LIT_SIZE = 768
.kNumTopBits = 24
.kTopValue = (1 shl .kNumTopBits)
.kNumBitModelTotalBits = 11
.kBitModelTotal = (1 shl .kNumBitModelTotalBits)
.kNumMoveBits = 5
; variables
.continue dd ?
.ecx dd ?
.outEnd dd ?
.dictSize dd ?
.state dd ?
.rep0 dd ?
.rep1 dd ?
.rep2 dd ?
.rep3 dd ?
.p rd LZMA_BASE_SIZE
.basesize = $
; rd LZMA_LIT_SIZE shl (.lc+.lp)
end virtual
.fillBuf:
mov ebp, eax
mov ebx, [ebp+.state]
jecxz .nodata
add ecx, edi
mov [ebp+.outEnd], ecx
mov esi, [ebp+.inPtr]
jmp [ebp+.continue]
.nodata:
popad
ret
.start:
mov eax, [ebp+.inStream]
call fillBuf
mov esi, [eax+streamInfo.bufPtr]
mov eax, [eax+streamInfo.bufDataLen]
sub eax, 5
jb return.err
mov [ebp+.inLen], eax
inc esi
lodsd
bswap eax
mov [ebp+.code], eax
or [ebp+.range], -1
.main_loop:
cmp edi, [ebp+.outEnd]
jae .main_loop_done
mov edx, edi
and edx, [ebp+.posStateMask]
mov eax, ebx
shl eax, .kNumPosBitsMax
add eax, edx
lea eax, [ebp + .p + .IsMatch*4 + eax*4]
call .RangeDecoderBitDecode
jc .1
movzx eax, [ebp+.previousByte]
mov ah, dl
and ah, byte [ebp+.literalPosMask]
mov cl, 8
sub cl, [ebp+.lc]
shr eax, cl
imul eax, LZMA_LIT_SIZE*4
lea eax, [ebp + eax + .p+.Literal*4]
cmp ebx, .kNumLitStates
jb .literal
xor edx, edx
sub edx, [ebp+.rep0]
mov dl, [edi + edx]
call .LzmaLiteralDecodeMatch
jmp @f
.literal:
call .LzmaLiteralDecode
@@:
mov [ebp+.previousByte], al
stosb
mov al, bl
cmp bl, 4
jb @f
mov al, 3
cmp bl, 10
jb @f
mov al, 6
@@: sub bl, al
jmp .main_loop
.1:
lea eax, [ebp + .p + .IsRep*4 + ebx*4]
call .RangeDecoderBitDecode
jnc .10
lea eax, [ebp + .p + .IsRepG0*4 + ebx*4]
call .RangeDecoderBitDecode
jc .111
mov eax, ebx
shl eax, .kNumPosBitsMax
add eax, edx
lea eax, [ebp + .p + .IsRep0Long*4 + eax*4]
call .RangeDecoderBitDecode
jc .1101
cmp bl, 7
setae bl
lea ebx, [9 + ebx + ebx]
xor edx, edx
sub edx, [ebp+.rep0]
mov al, [edi + edx]
stosb
mov [ebp+.previousByte], al
jmp .main_loop
.111:
lea eax, [ebp + .p + .IsRepG1*4 + ebx*4]
call .RangeDecoderBitDecode
mov eax, [ebp+.rep1]
jnc .l3
.l1:
lea eax, [ebp + .p + .IsRepG2*4 + ebx*4]
call .RangeDecoderBitDecode
mov eax, [ebp+.rep2]
jnc .l2
xchg [ebp+.rep3], eax
.l2:
push [ebp+.rep1]
pop [ebp+.rep2]
.l3:
xchg eax, [ebp+.rep0]
mov [ebp+.rep1], eax
.1101:
lea eax, [ebp + .p + .RepLencoder*4]
call .LzmaLenDecode
cmp bl, 7
setc bl
adc bl, bl
xor bl, 3
add bl, 8
jmp .repmovsb
.10:
mov eax, [ebp+.rep0]
xchg eax, [ebp+.rep1]
xchg eax, [ebp+.rep2]
xchg eax, [ebp+.rep3]
cmp bl, 7
setc bl
adc bl, bl
xor bl, 3
add bl, 7
lea eax, [ebp + .p + .Lencoder*4]
call .LzmaLenDecode
mov eax, .kNumLenToPosStates-1
cmp eax, ecx
jb @f
mov eax, ecx
@@:
push ecx
mov ecx, .kNumPosSlotBits
shl eax, cl
lea eax, [ebp + .p+.PosSlot*4 + eax*4]
call .RangeDecoderBitTreeDecode
mov [ebp+.rep0], ecx
cmp ecx, .kStartPosModelIndex
jb .l6
push ecx
mov eax, ecx
and eax, 1
shr ecx, 1
or eax, 2
dec ecx
shl eax, cl
mov [ebp+.rep0], eax
pop edx
cmp edx, .kEndPosModelIndex
jae .l5
sub eax, edx
lea eax, [ebp + .p + (.SpecPos - 1)*4 + eax*4]
call .RangeDecoderReverseBitTreeDecode
add [ebp+.rep0], ecx
jmp .l6
.l5:
sub ecx, .kNumAlignBits
call .RangeDecoderDecodeDirectBits
mov ecx, .kNumAlignBits
shl eax, cl
add [ebp+.rep0], eax
lea eax, [ebp+.p+.Align_*4]
call .RangeDecoderReverseBitTreeDecode
add [ebp+.rep0], ecx
.l6:
pop ecx
inc [ebp+.rep0]
jz .main_loop_done
.repmovsb:
add ecx, .kMatchMinLen
.repmovsbz:
push esi
.repmovsbr:
mov eax, [ebp+.rep0]
cmp eax, [ebp+.dictSize]
jae return.err
mov esi, edi
sub esi, eax
mov eax, [ebp+streamInfo.bufPtr]
sub eax, esi
ja .repmovsb0
mov eax, [ebp+.outEnd]
sub eax, edi
push ecx
cmp ecx, eax
jb @f
mov ecx, eax
@@:
sub [esp], ecx
rep movsb
pop ecx
jz .repmovsb1
pop [ebp+.inPtr]
mov [ebp+.state], ebx
mov [ebp+.ecx], ecx
mov [ebp+.continue], .restart_repmovsb
popad
ret
.repmovsb0:
mov edx, [ebp+.dictSize]
cmp edx, [ebp+streamInfo.bufSize]
jnz return.err
add esi, edx
push ecx
cmp ecx, eax
jb @f
mov ecx, eax
@@:
mov eax, [ebp+.outEnd]
sub eax, edi
cmp ecx, eax
jb @f
mov ecx, eax
@@:
sub [esp], ecx
rep movsb
pop ecx
jnz .repmovsbr
.repmovsb1:
pop esi
mov al, [edi-1]
mov [ebp+.previousByte], al
jmp .main_loop
.main_loop_done:
mov [ebp+.state], ebx
mov [ebp+.continue], .main_loop
mov [ebp+.inPtr], esi
popad
ret
.restart_repmovsb:
mov ecx, [ebp+.ecx]
jmp .repmovsbz
.RangeDecoderBitDecode:
; in: eax->prob
; out: CF=bit; destroys eax
push edx
mov edx, [ebp+.range]
shr edx, .kNumBitModelTotalBits
imul edx, [eax]
cmp [ebp+.code], edx
jae .ae
mov [ebp+.range], edx
mov edx, .kBitModelTotal
sub edx, [eax]
shr edx, .kNumMoveBits
add [eax], edx
clc
.n:
lahf
cmp [ebp+.range], .kTopValue
jae @f
shl [ebp+.range], 8
shl [ebp+.code], 8
sub [ebp+.inLen], 1
js .refill1
.refilled1:
lodsb
mov byte [ebp+.code], al
@@:
sahf
pop edx
ret
.ae:
sub [ebp+.range], edx
sub [ebp+.code], edx
mov edx, [eax]
shr edx, .kNumMoveBits
sub [eax], edx
stc
jmp .n
.refill1:
push eax
call .refill
pop eax
jmp .refilled1
.refill:
mov eax, [ebp+.inStream]
cmp dword [eax+streamInfo.fullSize+4], 0
jnz @f
cmp dword [eax+streamInfo.fullSize], 0
jz return.err
@@:
call fillBuf
mov esi, [eax+streamInfo.bufPtr]
mov eax, [eax+streamInfo.bufDataLen]
dec eax
js return.err
mov [ebp+.inLen], eax
ret
.refill2:
call .refill
jmp .refilled2
.RangeDecoderDecodeDirectBits:
; in: ecx=numTotalBits
; out: eax=result; destroys edx
xor eax, eax
.l:
shr [ebp+.range], 1
shl eax, 1
mov edx, [ebp+.code]
sub edx, [ebp+.range]
jb @f
mov [ebp+.code], edx
or eax, 1
@@:
cmp [ebp+.range], .kTopValue
jae @f
shl [ebp+.range], 8
shl [ebp+.code], 8
push eax
dec [ebp+.inLen]
js .refill2
.refilled2:
lodsb
mov byte [ebp+.code], al
pop eax
@@:
loop .l
ret
.LzmaLiteralDecode:
; in: eax->probs
; out: al=byte; destroys edx
push ecx
mov ecx, 1
@@:
push eax
lea eax, [eax+ecx*4]
call .RangeDecoderBitDecode
pop eax
adc cl, cl
jnc @b
.LzmaLiteralDecode.ret:
mov al, cl
pop ecx
ret
.LzmaLiteralDecodeMatch:
; in: eax->probs, dl=matchByte
; out: al=byte; destroys edx
push ecx
mov ecx, 1
.LzmaLiteralDecodeMatch.1:
add dl, dl
setc ch
push eax
lea eax, [eax+ecx*4+0x100*4]
call .RangeDecoderBitDecode
pop eax
adc cl, cl
jc .LzmaLiteralDecode.ret
xor ch, cl
test ch, 1
mov ch, 0
jnz @b
jmp .LzmaLiteralDecodeMatch.1
.LzmaLenDecode:
; in: eax->prob, edx=posState
; out: ecx=len
push eax
add eax, .LenChoice*4
call .RangeDecoderBitDecode
pop eax
jnc .0
push eax
add eax, .LenChoice2*4
call .RangeDecoderBitDecode
pop eax
jc @f
mov ecx, .kLenNumMidBits
shl edx, cl
lea eax, [eax + .LenMid*4 + edx*4]
call .RangeDecoderBitTreeDecode
add ecx, .kLenNumLowSymbols
ret
@@:
add eax, .LenHigh*4
mov ecx, .kLenNumHighBits
call .RangeDecoderBitTreeDecode
add ecx, .kLenNumLowSymbols + .kLenNumMidSymbols
ret
.0:
mov ecx, .kLenNumLowBits
shl edx, cl
lea eax, [eax + .LenLow*4 + edx*4]
.RangeDecoderBitTreeDecode:
; in: eax->probs,ecx=numLevels
; out: ecx=length; destroys edx
push ebx
mov edx, 1
mov ebx, edx
@@:
push eax
lea eax, [eax+edx*4]
call .RangeDecoderBitDecode
pop eax
adc dl, dl
add bl, bl
loop @b
sub dl, bl
pop ebx
mov ecx, edx
ret
.RangeDecoderReverseBitTreeDecode:
; in: eax->probs,ecx=numLevels
; out: ecx=length; destroys edx
push ebx ecx
mov edx, 1
xor ebx, ebx
@@:
push eax
lea eax, [eax+edx*4]
call .RangeDecoderBitDecode
lahf
adc edx, edx
sahf
rcr ebx, 1
pop eax
loop @b
pop ecx
rol ebx, cl
mov ecx, ebx
pop ebx
ret
; LZMA parameters:
; db lc + 9 * (lp + 5 * pb)
; dd dictionarySize
lzma_get_buf_size:
cmp dword [esi-4], 5
jb return.err
push ecx
lodsb
aam 9
mov cl, al
mov al, ah
aam 5
add cl, al
mov eax, LZMA_LIT_SIZE
shl eax, cl
lea eax, [lzma_decoder.basesize+eax*4]
pop ecx
mov edx, [esi]
ret
lzma_init_decoder:
lodsb
aam 9
mov [ebp+lzma_decoder.lc], al
mov al, ah
aam 5
mov [ebp+lzma_decoder.lp], al
mov [ebp+lzma_decoder.pb], ah
cmp ah, lzma_decoder.kNumPosBitsMax
ja return.err
mov cl, ah
lodsd
mov [ebp+lzma_decoder.dictSize], eax
push 1
pop eax
shl eax, cl
dec eax
mov [ebp+lzma_decoder.posStateMask], eax
mov cl, [ebp+lzma_decoder.lp]
push 1
pop eax
shl eax, cl
dec eax
mov [ebp+lzma_decoder.literalPosMask], eax
mov [ebp+streamInfo.fillBuf], lzma_decoder.fillBuf
mov [ebp+lzma_decoder.continue], lzma_decoder.start
xor eax, eax
mov [ebp+lzma_decoder.previousByte], al
mov [ebp+lzma_decoder.state], eax
inc eax
lea edi, [ebp+lzma_decoder.rep0]
stosd
stosd
stosd
mov eax, LZMA_LIT_SIZE
mov cl, [ebp+lzma_decoder.lc]
add cl, [ebp+lzma_decoder.lp]
shl eax, cl
lea ecx, [eax+lzma_decoder.Literal]
mov eax, lzma_decoder.kBitModelTotal/2
lea edi, [ebp+lzma_decoder.p]
rep stosd
ret

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,238 @@
; Implementation of SHA-256 hash algorithm.
; Written by diamond in 2007.
iglobal
align 4
sha256_start_digest:
dd 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A
dd 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
sha256_const:
dd 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5
dd 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5
dd 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3
dd 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174
dd 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC
dd 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA
dd 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7
dd 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967
dd 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13
dd 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85
dd 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3
dd 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070
dd 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5
dd 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3
dd 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208
dd 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
endg
uglobal
align 4
sha256_buf rb 64
sha256_digest rd 8
sha256_count dd ?
sha256_size dq ?
endg
sha256_init:
mov edi, sha256_digest
mov esi, sha256_start_digest
push 8
pop ecx
rep movsd
xor eax, eax
stosd ; 0 bytes in buffer
stosd
stosd ; 0 bytes processed
ret
; Core of SHA-256: transform 64-byte 'sha256_buf' to updated 'sha256_digest'
sha256_transform:
mov esi, sha256_buf
mov edi, esi
rept 16
{
lodsd
bswap eax
stosd
}
push ebp
mov ebp, [esi+7*4]
mov edi, [esi+6*4]
push dword [esi+5*4]
push dword [esi+4*4]
push dword [esi+3*4]
push dword [esi+2*4]
push dword [esi+1*4]
push dword [esi+0*4]
xor ecx, ecx
.loop:
macro cmd1 cmd,a,b
{
if (b and 7) = 7
cmd a, ebp
else if (b and 7) = 6
cmd a, edi
else
cmd a, [esp+(b and 7)*4]
end if
}
macro cmd2 cmd,a,b
{
if (a and 7) = 7
cmd ebp, b
else if (a and 7) = 6
cmd edi, b
else
cmd [esp+(a and 7)*4], b
end if
}
rept 16 counter
{
cmd1 mov, eax, (5-counter)
ror eax, 6
mov edx, eax
ror eax, 5
xor edx, eax
ror eax, 14
xor edx, eax
cmd1 mov, eax, (6-counter)
cmd1 mov, esi, (7-counter)
xor eax, esi
cmd1 and, eax, (5-counter)
xor eax, esi
add edx, eax
add edx, [sha256_const+ecx+(counter-1)*4]
add edx, dword [sha256_buf+(counter-1)*4]
test ecx, ecx
jz @f
mov eax, dword [sha256_buf+((counter-3) and 15)*4]
mov esi, eax
ror eax, 17
shr esi, 10
xor esi, eax
ror eax, 2
xor esi, eax
add esi, dword [sha256_buf+((counter-8) and 15)*4]
mov eax, dword [sha256_buf+(counter and 15)*4]
mov ebx, eax
ror eax, 7
shr ebx, 3
xor ebx, eax
ror eax, 11
xor ebx, eax
add esi, ebx
add dword [sha256_buf+(counter-1)*4], esi
add edx, esi
@@:
cmd1 add, edx, (8-counter)
cmd2 mov, (8-counter), edx
cmd2 add, (4-counter), edx
cmd1 mov, ebx, (1-counter)
mov eax, ebx
cmd1 mov, edx, (2-counter)
mov esi, ebx
ror eax, 2
or esi, edx
and ebx, edx
cmd1 and, esi, (3-counter)
mov edx, eax
or esi, ebx
ror eax, 11
xor edx, eax
ror eax, 9
xor edx, eax
add esi, edx
cmd2 add, (8-counter), esi
}
purge cmd1,cmd2
add cl, 64
jnz .loop
mov esi, sha256_digest
pop eax
add [esi+0*4], eax
pop eax
add [esi+1*4], eax
pop eax
add [esi+2*4], eax
pop eax
add [esi+3*4], eax
pop eax
add [esi+4*4], eax
pop eax
add [esi+5*4], eax
add [esi+6*4], edi
add [esi+7*4], ebp
pop ebp
ret
sha256_update.transform:
push esi edx
call sha256_transform
pop edx esi
mov [sha256_count], ecx
sha256_update:
; in: esi->data, edx=size
mov eax, 64
sub eax, [sha256_count]
sub eax, edx
sbb ecx, ecx
and ecx, eax
add ecx, edx
sub edx, ecx
mov edi, sha256_buf
add edi, [sha256_count]
add [sha256_count], ecx
add dword [sha256_size], ecx
adc dword [sha256_size+4], 0
rep movsb
cmp edi, sha256_buf+64
jz .transform
.ret:
ret
sha256_final:
; out: edi->digest
push edi
mov eax, [sha256_count]
mov [sha256_buf+eax], 0x80
inc eax
cmp al, 64-8
jbe @f
lea edi, [sha256_buf+eax]
push 64
pop ecx
sub ecx, eax
xor eax, eax
rep stosb
push edx
call sha256_transform
pop edx
xor eax, eax
@@:
push 64-8
pop ecx
sub ecx, eax
lea edi, [sha256_buf+eax]
xor eax, eax
rep stosb
mov eax, dword [sha256_size]
mov edx, dword [sha256_size+4]
shld edx, eax, 3
shl eax, 3
bswap edx
bswap eax
xchg eax, edx
stosd
xchg eax, edx
stosd
call sha256_transform
mov esi, sha256_digest
mov cl, 8
pop edi
@@:
lodsd
bswap eax
stosd
loop @b
ret

View File

@ -1,3 +1,12 @@
CHECK_FOR_LEAKS = 0
if CHECK_FOR_LEAKS
uglobal
allocatedregions rd 1024
endg
iglobal
numallocatedregions dd 0
endg
end if
pgalloc:
; in: ecx=size
; out: eax=pointer or NULL
@ -7,12 +16,50 @@ pgalloc:
push 12
pop ebx
int 0x40
if CHECK_FOR_LEAKS
test eax, eax
jz .no
.b:
mov ebx, [numallocatedregions]
cmp ebx, 1024
jb @f
int3
jmp $
@@:
mov [allocatedregions+ebx*4], eax
inc [numallocatedregions]
.no:
end if
pop ebx
ret
pgfree:
; in: ecx=pointer
; destroys eax
if CHECK_FOR_LEAKS
jecxz .no
mov eax, [numallocatedregions]
@@:
dec eax
js .a
cmp [allocatedregions+eax*4], ecx
jnz @b
jmp @f
.a:
int3
jmp $
@@:
dec [numallocatedregions]
@@:
cmp eax, [numallocatedregions]
jae @f
push [allocatedregions+eax*4+4]
pop [allocatedregions+eax*4]
inc eax
jmp @b
@@:
.no:
end if
push ebx
push 68
pop eax
@ -31,6 +78,29 @@ pgrealloc:
push 20
pop ebx
int 0x40
if CHECK_FOR_LEAKS
test edx, edx
jz pgalloc.b
test eax, eax
jz .no
cmp eax, edx
jz .no
xor ebx, ebx
@@:
cmp ebx, [numallocatedregions]
jae .a
cmp [allocatedregions+ebx*4], edx
jz @f
inc ebx
jmp @b
@@:
mov [allocatedregions+ebx*4], eax
jmp .no
.a:
int3
jmp $
.no:
end if
pop ebx
ret
@ -52,6 +122,17 @@ xpgrealloc:
call pgrealloc
jmp xpgalloc.common
getfreemem:
; out: eax=size of free RAM in Kb
push ebx
push 18
pop eax
push 16
pop ebx
int 0x40
pop ebx
ret
get_error_msg:
; in: eax=error code
; out: eax=pointer to message (in static buffer)
@ -85,6 +166,7 @@ get_error_msg:
test al, al
jnz @b
pop eax
dec edi
push edx ecx
test eax, eax
jns @f
@ -162,7 +244,8 @@ load_dll_and_import:
pop eax
pop esi
jz .do
push eax
.big:
push esi
mov edi, aFileNameTooBig
.sayerr:
push dword aCannotLoadDLL
@ -173,9 +256,6 @@ load_dll_and_import:
push 1
push eax
push 3
push -1
push -1
push dword aError
call SayErr
add esp, 16
xor eax, eax
@ -192,9 +272,15 @@ load_dll_and_import:
mov edi, aInvalidDLL
test eax, eax
jz .sayerr
mov edx, eax
cmp ebp, -1
jnz @f
pop eax
xor eax, eax
ret
@@:
; initialize import
mov edi, aMissingExport
mov edx, eax
.import_loop:
lodsd
test eax, eax

View File

@ -6,6 +6,9 @@ viewer_data:
.buf_pos dd ?
.buf_size dd ?
.col dq ?
.hPlugin dd ?
.hFile dd ?
.hWorkFile dd ?
.encoding db ?
.bEofReached db ?
.flags db ? ; & 1: hex mode
@ -13,6 +16,7 @@ viewer_data:
; & 4: big-endian unicode
rb 1
.filename rb 1024
.hostname rb 1024
.buf rb 16384
.size = $
end virtual
@ -34,6 +38,30 @@ view_file:
jnz @f
ret
@@:
mov eax, dword [esi+panel1_hPlugin-panel1_dir]
mov [ebp+viewer_data.hPlugin], eax
test eax, eax
jz .nocopyhostname
lea edi, [ebp+viewer_data.hostname]
push esi
mov eax, dword [esi+panel1_parents-panel1_dir]
mov esi, dword [esi+panel1_parents_sz-panel1_dir]
add esi, eax
@@:
dec esi
cmp byte [esi-1], 0
jz @f
cmp byte [esi-1], '/'
jnz @b
@@:
lodsb
stosb
test al, al
jnz @b
pop esi
.nocopyhostname:
mov eax, dword [esi+panel1_hFile-panel1_dir]
mov [ebp+viewer_data.hFile], eax
mov [ebp+viewer_data.encoding], encodings.cp866
mov [ebp+viewer_data.flags], 0
and dword [ebp+viewer_data.col], 0
@ -48,6 +76,8 @@ view_file:
jmp @b
@@:
lea esi, [ecx+40]
cmp byte [edi-1], '/'
jz @f
mov al, '/'
stosb
@@:
@ -60,9 +90,21 @@ view_file:
mov ebx, attrinfo
mov [ebx+21], eax
.attr_retry:
mov edx, [ebp+viewer_data.hPlugin]
test edx, edx
jz .attr_native
push ebp
push dword [ebx+16]
push eax
push [ebp+viewer_data.hFile]
call [edx+PluginInfo.getattr]
pop ebp
jmp .attr_common
.attr_native:
push 70
pop eax
int 40h
.attr_common:
test eax, eax
jz @f
lea ebx, [ebp+viewer_data.filename]
@ -75,14 +117,12 @@ view_file:
push 2
push eax
push 3
push -1
push -1
push aError
call SayErr
add esp, 3*4
mov ebx, attrinfo
test eax, eax
jz .attr_retry
pop eax
jmp delete_active_screen
@@:
mov eax, dword [attrinfo.attr+32]
@ -102,7 +142,40 @@ view_file:
mov [readinfo.data], eax
mov [ebp+viewer_data.buf_pos], eax
pop dword [readinfo.name]
mov eax, [ebp+viewer_data.hPlugin]
test eax, eax
jz .retry
push ebx ebp
push O_READ
push dword [readinfo.name]
push [ebp+viewer_data.hFile]
call [eax+PluginInfo.open]
pop ebp ebx
mov [ebp+viewer_data.hWorkFile], eax
test eax, eax
jnz .retry
push ContinueBtn
push 1
push aCannotOpenFile_ptr
push 1
call SayErr
jmp delete_active_screen
.retry:
mov eax, [ebp+viewer_data.hPlugin]
test eax, eax
jz .read_native
push ebp
push 16384
push [ebx+readinfo.data-readinfo]
push [ebp+viewer_data.hWorkFile]
call [eax+PluginInfo.read]
pop ebp
cmp eax, -1
jz .readok ; let's hope that plugin says error itself
mov [ebp+viewer_data.buf_size], eax
mov ebx, eax
jmp .readok
.read_native:
push 70
pop eax
int 40h
@ -111,6 +184,7 @@ view_file:
jz .readok
cmp eax, 6
jz .readok
.readerr:
lea ebx, [ebp+viewer_data.filename]
push ebx
push aCannotReadFile
@ -121,9 +195,6 @@ view_file:
push 2
push eax
push 3
push -1
push -1
push aError
call SayErr
add esp, 3*4
mov ebx, readinfo
@ -194,6 +265,21 @@ viewer_get_next_char:
mov [readinfo.name], eax
.readretry:
mov ebx, readinfo
mov eax, [ebp+viewer_data.hPlugin]
test eax, eax
jz .native
push ecx ebp
push 8192
push [ebx+readinfo.data-readinfo]
push [ebp+viewer_data.hWorkFile]
call [eax+PluginInfo.read]
pop ebp ecx
mov ebx, eax
cmp eax, -1
jnz .readok
xor ebx, ebx
jmp .readok
.native:
push 70
pop eax
int 40h
@ -201,6 +287,7 @@ viewer_get_next_char:
jz .readok
cmp eax, 6
jz .readok
.readerr:
call ask_retry_ignore
jz .readretry
.readok:
@ -976,16 +1063,7 @@ viewer_seek:
mov [ebx+16], eax
lea eax, [ebp+viewer_data.filename]
mov [ebx+21], eax
push 70
pop eax
int 40h
test eax, eax
jz .readok
cmp eax, 6
jz .readok
call ask_retry_ignore
jz .doread
.readok:
call .q
cmp ebx, [readinfo.size]
jnz @f
add ebx, [ebp+viewer_data.buf_size]
@ -1027,22 +1105,47 @@ viewer_seek:
mov [ebx+12], eax
lea eax, [ebp+viewer_data.filename]
mov [ebx+21], eax
call .q
sub ebx, [readinfo.size]
add ebx, 16384
jmp .ret
.q:
mov ebx, readinfo
mov eax, [ebp+viewer_data.hPlugin]
test eax, eax
jz .native
push ebp
push dword [ebx+12]
push dword [ebx+16]
push [ebp+viewer_data.hWorkFile]
push eax
push dword [ebx+8]
push dword [ebx+4]
push [ebp+viewer_data.hWorkFile]
call [eax+PluginInfo.setpos]
pop eax
call [eax+PluginInfo.read]
pop ebp
mov ebx, eax
cmp eax, -1
jnz @f
xor ebx, ebx
@@:
ret
.native:
push 70
pop eax
int 40h
test eax, eax
jz @f
jz .readok
cmp eax, 6
jz @f
jz .readok
.readerr:
call ask_retry_ignore
jnz @f
mov ebx, readinfo
jmp @b
@@:
sub ebx, [readinfo.size]
add ebx, 16384
jmp .ret
jz .q
.readok:
ret
ask_retry_ignore:
push esi
@ -1056,9 +1159,6 @@ ask_retry_ignore:
push 2
push eax
push 3
push -1
push -1
push aError
call SayErr
add esp, 3*4
pop esi
@ -1268,12 +1368,33 @@ viewer_OnRedraw:
call viewer_draw_text
ret
viewer_OnExit:
mov edx, [ebp+viewer_data.hPlugin]
test edx, edx
jz @f
and [ebp+viewer_data.hPlugin], 0
push edx ebp
push [ebp+viewer_data.hWorkFile]
call [edx+PluginInfo.close]
pop ebp edx
mov ebx, [ebp+viewer_data.hFile]
call close_handle_if_unused
@@:
ret
viewer_IsHandleUsed:
cmp edx, [ebp+viewer_data.hPlugin]
jnz @f
cmp ebx, [ebp+viewer_data.hFile]
@@:
ret
viewer_OnKey:
mov esi, viewer_ctrlkeys
jmp process_ctrl_keys
.exit:
call delete_active_screen
ret
call viewer_OnExit
jmp delete_active_screen
.down:
cmp [ebp+viewer_data.bEofReached], 0
jnz .ret
@ -1459,6 +1580,25 @@ else
stosb
end if
sub ecx, 13
cmp [ebp+viewer_data.hPlugin], 0
jz .native
lea esi, [ebp+viewer_data.hostname]
push ecx edi
shr ecx, 1
@@:
lodsb
test al, al
jz @f
stosb
loop @b
@@:
sub edi, [esp]
sub [esp+4], edi
add [esp], edi
pop edi ecx
lea esi, [ebp+viewer_data.filename]
jmp .main
.native:
lea esi, [ebp+viewer_data.filename]
push 3
pop edx
@ -1466,10 +1606,13 @@ end if
lodsb
stosb
dec ecx
test al, al
jz .ret
cmp al, '/'
jnz @b
dec edx
jnz @b
.main:
push esi
@@:
lodsb
@ -1493,4 +1636,5 @@ end if
stosb
test al, al
jnz @b
.ret:
ret