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