outdated/archer: Post-SVN tidy

- Move source code from `trunk` into root directory.
- Checked ASM include paths.
- Note: Line endings standardised from `CRLF` > `LF`, so best to view diffs with whitespace changes hidden.
This commit is contained in:
2025-06-28 01:08:48 -04:00
parent c4a39efecb
commit 1f9efb9437
10 changed files with 482 additions and 481 deletions

View File

@@ -1,481 +1,482 @@
; @RCHER - Deflate unpacker v2.0 beta ; SPDX-License-Identifier: NOASSERTION
; ;
; Written in pure assembler by Ivushkin Andrey aka Willow
; ; @RCHER - Deflate unpacker v2.0 beta
; Created: May 6, 2005 ;
; ; Written in pure assembler by Ivushkin Andrey aka Willow
; Last changed: August 26, 2006 ;
; ; Created: May 6, 2005
; Compile with FASM ;
; Last changed: August 26, 2006
SYS equ meos ;
OUTBUF equ 4*1024*1024 ; Compile with FASM
png_imag = output+OUTBUF
PARAM_PTR = os_work;png_image SYS equ meos
MEMINIT=next_code;output OUTBUF equ 4*1024*1024
DUMPFILE equ '/hd0/1/out.txt' png_imag = output+OUTBUF
PARAM_PTR = os_work;png_image
SHOW_RBLOCK equ 0;1 MEMINIT=next_code;output
SHOW_PNG_SEC equ 0;1 DUMPFILE equ '/hd0/1/out.txt'
SHOW_METH equ 0;1
FILE_NUM equ 15;8 SHOW_RBLOCK equ 0;1
MEMORY equ 0x800000 SHOW_PNG_SEC equ 0;1
SHOW_METH equ 0;1
BITS equ 16 FILE_NUM equ 15;8
BUFSIZE equ 32 MEMORY equ 0x800000
BUFPTR equ area
BITS equ 16
PASSW_LEN equ 32 BUFSIZE equ 32
NO_STOPS equ 1 BUFPTR equ area
SHOW_CHARS equ 0
BSIZE equ 512 PASSW_LEN equ 32
INBUF equ BUFSIZE*BSIZE*2 NO_STOPS equ 1
IGNORE_DIRS equ 0 SHOW_CHARS equ 0
BSIZE equ 512
MOVE_SLINE_LEV equ 8 INBUF equ BUFSIZE*BSIZE*2
IGNORE_DIRS equ 0
DECRYPT_MODE equ 100b
PNG_MODE equ 10b MOVE_SLINE_LEV equ 8
TAR_MODE equ 1000b
STAY_MODE equ 10000b DECRYPT_MODE equ 100b
IPC_MODE equ 100000b PNG_MODE equ 10b
RAW_MODE equ 1000000b TAR_MODE equ 1000b
THREAD_YES equ 10000000b STAY_MODE equ 10000b
LIST_MODE equ 100000000b IPC_MODE equ 100000b
MEM_MODE equ 1000000000b RAW_MODE equ 1000000b
FIND_MODE equ 10000000000b THREAD_YES equ 10000000b
LIST_MODE equ 100000000b
if SYS eq win MEM_MODE equ 1000000000b
format PE console FIND_MODE equ 10000000000b
entry start
;match =win,SYS if SYS eq win
;{ format PE console
; include 'D:\Ivushkin\projects\fasmw\INCLUDE\win32a.inc' entry start
;} ;match =win,SYS
else ;{
use32 ; include 'D:\Ivushkin\projects\fasmw\INCLUDE\win32a.inc'
;}
org 0x0 else
use32
db 'MENUET01'
dd 0x01 org 0x0
dd start
dd I_END db 'MENUET01'
dd MEMINIT dd 0x01
dd main_stack_top;MEMORY-2048 dd start
if PARAM_PTR eq param dd I_END
dd 0 dd MEMINIT
else dd main_stack_top;MEMORY-2048
dd PARAM_PTR if PARAM_PTR eq param
end if dd 0
dd 0x0 else
dd PARAM_PTR
if PARAM_PTR eq param end if
param db 'N' dd 0x0
db '000015'
db '/hd/1/zip/gz/fasm-1~1.tgz',0 if PARAM_PTR eq param
end if param db 'N'
;match =meos,SYS db '000015'
;{ db '/hd/1/zip/gz/fasm-1~1.tgz',0
include "..\..\..\macros.inc" end if
; purge mov ;match =meos,SYS
include "..\..\..\debug.inc" ;{
include 'dump.inc' include "..\..\..\macros.inc"
;} ; purge mov
end if include "..\..\..\debug.inc"
include 'dump.inc'
include 'lang.inc' ;}
language equ lang end if
if SYS eq win include 'lang.inc'
section '.text' code readable executable writeable language equ lang
end if
if SYS eq win
include "arcmacro.inc" section '.text' code readable executable writeable
include "parser.inc" end if
include "deflate.inc"
include "sys.inc" include "arcmacro.inc"
include "parser.inc"
FileNum dd FILE_NUM include "deflate.inc"
;FNAME equ '/hd/1/zip/pngsuite/s01n3p01.png' include "sys.inc"
start: FileNum dd FILE_NUM
if SYS eq win ;FNAME equ '/hd/1/zip/pngsuite/s01n3p01.png'
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov [cons],eax start:
invoke GetStdHandle, STD_INPUT_HANDLE if SYS eq win
mov [cons_in],eax invoke GetStdHandle, STD_OUTPUT_HANDLE
Msg 0 mov [cons],eax
Msg 1 invoke GetStdHandle, STD_INPUT_HANDLE
else mov [cons_in],eax
Msg 0 Msg 0
Msg 1 Msg 1
mcall 40,1000101b else
; jmp again Msg 0
CmdLine Msg 1
cmdl: mcall 40,1000101b
test [Flags],LIST_MODE ; jmp again
jz red CmdLine
cmdl:
; Dump [lpath],[lpath_len],os_work test [Flags],LIST_MODE
; ud2 jz red
red:
call draw_window ; Dump [lpath],[lpath_len],os_work
mcall 12,2 ; ud2
red:
still: call draw_window
mcall 10 mcall 12,2
cmp eax,1
je red still:
cmp eax,2 mcall 10
jne .nokey cmp eax,1
mcall 2 je red
cmp ah,9 cmp eax,2
jz quit jne .nokey
jmp still mcall 2
.nokey: cmp ah,9
cmp eax,3 jz quit
jne still jmp still
mcall 17 .nokey:
cmp ah,1 cmp eax,3
jne still jne still
mcall 23,30 mcall 17
cmp eax,3 cmp ah,1
jne .noquit jne still
call KillViewer mcall 23,30
mcall -1 cmp eax,3
.noquit: jne .noquit
mcall 17 call KillViewer
mcall 64,1,MEMINIT mcall -1
QueryFile .noquit:
mov [FileNum],FILE_NUM mcall 17
test eax,eax mcall 64,1,MEMINIT
jnz still QueryFile
end if mov [FileNum],FILE_NUM
again: test eax,eax
; Dump Flags,4,os_work jnz still
mov [fat_],fat end if
Newline again:
xor eax,eax ; Dump Flags,4,os_work
; and [Flags],STAY_MODE mov [fat_],fat
and [_CRC32_],eax Newline
and [IDATsize],eax xor eax,eax
mov [Adler32],1 ; and [Flags],STAY_MODE
call OpenFile and [_CRC32_],eax
test ebx,ebx and [IDATsize],eax
jnz .sizeok2 mov [Adler32],1
.sizebad2: call OpenFile
Msg 14 test ebx,ebx
jmp quit jnz .sizeok2
.sizeok2: .sizebad2:
call KillViewer Msg 14
xor eax,eax jmp quit
mov ecx,(child_stack-fat)/4 .sizeok2:
mov edi,fat call KillViewer
rep stosd xor eax,eax
mov [filesize],ebx mov ecx,(child_stack-fat)/4
test [Flags],RAW_MODE mov edi,fat
jz .norawm rep stosd
mov eax,[arc_base] mov [filesize],ebx
xor ebx,ebx test [Flags],RAW_MODE
call FileSeek jz .norawm
jmp .sizeok mov eax,[arc_base]
.norawm: xor ebx,ebx
call SfxParse call FileSeek
jmp .sizeok
call ZipParse .norawm:
cmp edx,52 call SfxParse
je .notzip
mov ecx,[FileNum] call ZipParse
call ZipFindN cmp edx,52
cmp edx,4 je .notzip
je quit mov ecx,[FileNum]
test [Flags],DECRYPT_MODE call ZipFindN
jz .nopass cmp edx,4
call ZipDecrypt je quit
push esi test [Flags],DECRYPT_MODE
mov ecx,31 jz .nopass
._: call ZipDecrypt
mov al,[esi] push esi
push eax mov ecx,31
call decrypt_byte ._:
xor al,byte[esp] mov al,[esi]
add esp,4 push eax
call UKeys call decrypt_byte
mov [esi],al xor al,byte[esp]
inc esi add esp,4
loop ._ call UKeys
pop esi mov [esi],al
ud2 inc esi
.nopass: loop ._
cmp [unp_size],0 pop esi
jne .sizeok ud2
.sizebadq: .nopass:
Msg 13 cmp [unp_size],0
jmp quit jne .sizeok
.notzip: .sizebadq:
call GzipParse Msg 13
test edx,edx jmp quit
jne .notgzip .notzip:
jmp .sizeok call GzipParse
.notgzip: test edx,edx
call PngParse jne .notgzip
test edx,edx jmp .sizeok
jz .sizeok1 .notgzip:
cmp edx,21 call PngParse
je .sizebad test edx,edx
test [Flags],RAW_MODE jz .sizeok1
jne .sizeok cmp edx,21
Msg 40 je .sizebad
jmp exit test [Flags],RAW_MODE
.sizebad: jne .sizeok
Msg 17 Msg 40
jmp exit jmp exit
.sizeok1: .sizebad:
if ~ SYS eq win Msg 17
end if jmp exit
Msg 39 ; unpacking PNG .sizeok1:
mov ecx,[unp_size] if ~ SYS eq win
add ecx,output end if
mov [png_],ecx Msg 39 ; unpacking PNG
mov eax,[PNG_info.Width] mov ecx,[unp_size]
imul eax,[PNG_info.Height] add ecx,output
lea eax,[eax+eax*2] mov [png_],ecx
add ecx,eax mov eax,[PNG_info.Width]
; dps 'Mem=' imul eax,[PNG_info.Height]
; dpd ecx lea eax,[eax+eax*2]
mcall 64,1 add ecx,eax
test eax,eax ; dps 'Mem='
jz .ok ; dpd ecx
Msg 41 mcall 64,1
jmp exit test eax,eax
.ok: jz .ok
mov edi,[outp] Msg 41
call Deflate.blkbegin jmp exit
jmp .defl_end .ok:
.sizeok: mov edi,[outp]
mov ecx,[unp_size] call Deflate.blkbegin
dpd ecx jmp .defl_end
add ecx,output .sizeok:
; mov [png_],ecx mov ecx,[unp_size]
mcall 64,1 dpd ecx
test eax,eax add ecx,output
jz .ok2 ; mov [png_],ecx
Msg 41 mcall 64,1
jmp exit test eax,eax
.ok2: jz .ok2
call Deflate ; <=========== Msg 41
.defl_end: jmp exit
test [bits],7 .ok2:
jnz .esi_ok call Deflate ; <===========
dec esi .defl_end:
.esi_ok: test [bits],7
push dword[esi] ; <- Adler !!! jnz .esi_ok
mov esi,output dec esi
sub edi,esi .esi_ok:
mov ecx,edi push dword[esi] ; <- Adler !!!
mov [outfile.size],ecx mov esi,output
test [Flags],RAW_MODE sub edi,esi
jnz .skipAdler mov ecx,edi
test [Flags],PNG_MODE mov [outfile.size],ecx
jnz .skipCRC test [Flags],RAW_MODE
push esi ecx jnz .skipAdler
call UCRC test [Flags],PNG_MODE
Msg 11 jnz .skipCRC
mov eax,[_CRC32_] push esi ecx
mov edx,36 call UCRC
cmp eax,[CRC_check] Msg 11
je .crcok mov eax,[_CRC32_]
dec edx mov edx,36
.crcok: cmp eax,[CRC_check]
Msg edx je .crcok
if SYS eq win dec edx
else .crcok:
dph eax Msg edx
end if if SYS eq win
pop ecx esi else
jmp .skipAdler dph eax
.skipCRC: end if
; dps 'Out=' pop ecx esi
; dpd ecx jmp .skipAdler
call UAdler .skipCRC:
Msg 10 ; dps 'Out='
mov eax,[Adler32] ; dpd ecx
bswap eax ; <- calculated Adler !!! call UAdler
mov edx,36 Msg 10
cmp eax,[esp] mov eax,[Adler32]
je .adlok bswap eax ; <- calculated Adler !!!
dec edx mov edx,36
.adlok: cmp eax,[esp]
Msg edx je .adlok
if SYS eq win dec edx
else .adlok:
dph eax Msg edx
end if if SYS eq win
.skipAdler: else
pop eax dph eax
Newline end if
.nomoreIDAT: .skipAdler:
mov ebx,output pop eax
if SYS eq win Newline
Msg 37 .nomoreIDAT:
invoke CloseHandle, [hnd] mov ebx,output
if SYS eq win
invoke CreateFile,dumpfile,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, \ Msg 37
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL invoke CloseHandle, [hnd]
mov [hnd],eax
invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL invoke CreateFile,dumpfile,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, \
invoke CloseHandle, [hnd] CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
else mov [hnd],eax
test [Flags],PNG_MODE invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL
jnz .nosave invoke CloseHandle, [hnd]
test [Flags],LIST_MODE else
jnz quit test [Flags],PNG_MODE
jnz .nosave
test [Flags],TAR_MODE test [Flags],LIST_MODE
jnz .nomsg jnz quit
Msg 37
.nomsg: test [Flags],TAR_MODE
mov [outfile.out],ebx jnz .nomsg
mcall 70,outfile Msg 37
; dps 'Before Quit1' .nomsg:
; ud2 mov [outfile.out],ebx
test [Flags],TAR_MODE mcall 70,outfile
jz exit.pad ; dps 'Before Quit1'
; call StartPad ; ud2
.nosave: test [Flags],TAR_MODE
end if jz exit.pad
test [Flags],PNG_MODE ; call StartPad
jz NoPng .nosave:
xor eax,eax end if
mov edi,filters test [Flags],PNG_MODE
mov ecx,6 jz NoPng
rep stosd xor eax,eax
mov edi,[png_] mov edi,filters
mov esi,output mov ecx,6
;// rep stosd
mov [outp],edi mov edi,[png_]
;// mov esi,output
call PngFilter ;//
call FiltStats mov [outp],edi
mov [outfile.size],edi ;//
mov ebx,[outp];png_image call PngFilter
if SYS eq win call FiltStats
exit: mov [outfile.size],edi
Msg 12 mov ebx,[outp];png_image
invoke CreateFile,outfile,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, \ if SYS eq win
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL exit:
mov [hnd],eax Msg 12
invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL invoke CreateFile,outfile,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, \
invoke CloseHandle, [hnd] CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
call RunViewer mov [hnd],eax
and [arc_base],0 invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL
and [Flags],STAY_MODE invoke CloseHandle, [hnd]
; dps 'Before Quit2' call RunViewer
quit: and [arc_base],0
QueryFile and [Flags],STAY_MODE
test eax,eax ; dps 'Before Quit2'
jnz again quit:
invoke ExitProcess,0 QueryFile
else test eax,eax
exit: jnz again
mov [outfile.out],ebx invoke ExitProcess,0
test [Flags],TAR_MODE else
jz .notar exit:
Msg 37 mov [outfile.out],ebx
test [Flags],LIST_MODE test [Flags],TAR_MODE
jne quit jz .notar
mcall 70,outfile Msg 37
.pad: test [Flags],LIST_MODE
call StartPad jne quit
.notar: mcall 70,outfile
Msg 12 .pad:
call RunViewer call StartPad
and [arc_base],0 .notar:
and [Flags],STAY_MODE Msg 12
quit: call RunViewer
test [Flags],STAY_MODE and [arc_base],0
jnz red and [Flags],STAY_MODE
mcall -1 quit:
end if test [Flags],STAY_MODE
jnz red
NoPng: mcall -1
test [Flags],TAR_MODE end if
if SYS eq win
jz quit NoPng:
else test [Flags],TAR_MODE
jz still if SYS eq win
end if jz quit
; Dump output,255,os_work else
; ud2 jz still
; mov ecx,dumpf_len end if
; mov esi,dumpfile ; Dump output,255,os_work
; mov edi,filename ; ud2
; rep movsb ; mov ecx,dumpf_len
; call OpenFile ; mov esi,dumpfile
; test ebx,ebx ; mov edi,filename
; jz again.sizebadq ; rep movsb
call TarParse ; call OpenFile
mov ecx,[FileNum] ; test ebx,ebx
call TarFindN ; jz again.sizebadq
; dpd [outfile.size] call TarParse
cmp [outfile.size],0 mov ecx,[FileNum]
jz again.sizebadq call TarFindN
mov ebx,esi ; dpd [outfile.size]
jmp exit cmp [outfile.size],0
jz again.sizebadq
if ~ SYS eq win mov ebx,esi
draw_window: jmp exit
mcall 12,1
mov ebx,15 if ~ SYS eq win
mov ecx,ebx draw_window:
mov edx,0x0e26830 mcall 12,1
mov edi,edx mov ebx,15
mcall 0,,,,0x1f2a870 mov ecx,ebx
mcall 8,,,1+1 shl 30 mov edx,0x0e26830
mcall 4,<6,5>,0x10d0d0d0,msgs+5,1 mov edi,edx
mcall ,<5,5>,0x10202020 mcall 0,,,,0x1f2a870
ret mcall 8,,,1+1 shl 30
end if mcall 4,<6,5>,0x10d0d0d0,msgs+5,1
mcall ,<5,5>,0x10202020
include 'data.inc' ret
end if
if SYS eq win
section '.idata' import data readable writeable include 'data.inc'
library kernel,'KERNEL32.DLL',\ if SYS eq win
comdlg,'COMDLG32.DLL',\ section '.idata' import data readable writeable
user,'USER32.DLL'
library kernel,'KERNEL32.DLL',\
import kernel,\ comdlg,'COMDLG32.DLL',\
CreateFile,'CreateFileA',\ user,'USER32.DLL'
GetFileSize,'GetFileSize',\
ReadFile,'ReadFile',\ import kernel,\
WriteFile,'WriteFile',\ CreateFile,'CreateFileA',\
SetFilePointer,'SetFilePointer',\ GetFileSize,'GetFileSize',\
CloseHandle,'CloseHandle',\ ReadFile,'ReadFile',\
GetStdHandle,'GetStdHandle',\ WriteFile,'WriteFile',\
WriteConsole,'WriteConsoleA',\ SetFilePointer,'SetFilePointer',\
ReadConsole,'ReadConsoleA',\ CloseHandle,'CloseHandle',\
CreateProcess,'CreateProcessA',\ GetStdHandle,'GetStdHandle',\
WritePrivateProfileString,'WritePrivateProfileStringA',\ WriteConsole,'WriteConsoleA',\
ExitProcess,'ExitProcess' ReadConsole,'ReadConsoleA',\
CreateProcess,'CreateProcessA',\
import comdlg,\ WritePrivateProfileString,'WritePrivateProfileStringA',\
GetOpenFileName,'GetOpenFileNameA' ExitProcess,'ExitProcess'
import user,\ import comdlg,\
wsprintf,'wsprintfA',\ GetOpenFileName,'GetOpenFileNameA'
SendMessage,'SendMessageA',\
FindWindowEx,'FindWindowExA',\ import user,\
WaitForInputIdle,'WaitForInputIdle' wsprintf,'wsprintfA',\
SendMessage,'SendMessageA',\
FindWindowEx,'FindWindowExA',\
section '.reloc' fixups data readable discardable WaitForInputIdle,'WaitForInputIdle'
end if
if ~ SYS in <meos,win> section '.reloc' fixups data readable discardable
error "Please specify SYS: meos OR win" end if
end if
if ~ SYS in <meos,win>
error "Please specify SYS: meos OR win"
end if