Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; lzarchivator.inc
- ;################# Created by Bearchik http://crazyasm.blogspot.com ###############################
- include windows.inc
- include kernel32.inc
- include user32.inc
- include Comctl32.inc
- include shell32.inc
- includelib kernel32.lib
- includelib user32.lib
- includelib Comctl32.lib
- includelib shell32.lib
- compress PROTO:DWORD,:DWORD,:DWORD,:DWORD
- decompress PROTO:DWORD,:DWORD,:DWORD,:DWORD
- writeStr PROTO:DWORD,:DWORD,:DWORD
- addDictStr PROTO:DWORD,:DWORD,:DWORD
- findStr PROTO:DWORD,:DWORD
- getStr PROTO:DWORD,:DWORD
- clearDict PROTO
- dict struc
- pos dd ?
- string db 0Ch dup(?)
- dict ends
- sdict equ sizeof dict
- .const
- DICTSIZE equ 200h
- ;#########################################################################
- .data
- src db "KARL_KARAL_KAR!",0
- countDict dd 1
- ;#########################################################################
- .data?
- dst db 100h dup(?)
- decstr db 100h dup(?)
- myDict dict DICTSIZE dup (<>)
- buf db 0Ch dup(?)
- bufcount dd ?
- ;#########################################################################
- ; lzarchivator.asm
- .386
- .model flat, stdcall ;32 bit memory model
- option casemap :none ;case sensitive
- include lzarchivator.inc
- .code
- start:
- invoke compress, offset src, sizeof src, offset dst, sizeof dst
- invoke clearDict
- invoke decompress, offset dst, sizeof dst, offset decstr, sizeof decstr
- invoke ExitProcess,0
- decompress proc pSrcString:DWORD, lSrcString:DWORD, pDstString:DWORD, lDstString:DWORD
- LOCAL curDstPos:DWORD
- mov edi, pSrcString
- xor ecx, ecx
- mov eax, pDstString
- mov curDstPos, eax
- nextcode:
- xor eax, eax
- mov al, BYTE PTR [edi]
- push eax
- invoke getStr, eax , edi
- pop eax
- lea esi, buf
- invoke addDictStr, esi, eax, ebx
- invoke writeStr, curDstPos, esi, ebx
- mov curDstPos, eax
- add edi, 2
- .if BYTE PTR [edi] == 0
- jmp decodeend
- .endif
- jmp nextcode
- decodeend:
- ret
- decompress endp
- writeStr proc uses ecx edi esi pdstString:DWORD, pBuf:DWORD, num:DWORD
- mov ecx, num
- mov edi, pdstString
- mov esi, pBuf
- rep movsb
- mov eax, edi
- ret
- writeStr endp
- getStr proc uses ecx edi edx num:DWORD, codeStr:DWORD
- mov eax, num
- .if eax == 1
- mov eax, codeStr
- mov al, BYTE PTR [eax+1]
- mov BYTE PTR [buf], al
- mov ebx, 1
- jmp endGetStr
- .endif
- mov edi, offset buf
- dec eax
- imul edx, eax, sdict
- xor ecx, ecx
- nextDictChr:
- mov al, myDict.string[edx+ecx]
- mov BYTE PTR [edi+ecx], al
- inc ecx
- .if al == 0
- mov eax, codeStr
- mov al, BYTE PTR [eax+1]
- mov BYTE PTR [edi+ecx-1], al
- mov ebx, ecx
- jmp endGetStr
- .endif
- jmp nextDictChr
- endGetStr:
- ret
- getStr endp
- clearDict proc uses ecx edi
- mov countDict, 1h
- mov ecx, sdict
- imul ecx, ecx, DICTSIZE
- lea edi, myDict
- nextclr:
- mov BYTE PTR [edi],0h
- inc edi
- loop nextclr
- ret
- clearDict endp
- compress proc pSrcString:DWORD, lSrcString:DWORD, pDstString:DWORD, lDstString:DWORD
- LOCAL prevPos:DWORD
- mov prevPos, 1
- mov edi, pSrcString
- mov ebx, 1
- xor ecx, ecx
- compnext:
- invoke findStr, edi, ebx
- .if eax == 1
- invoke addDictStr, edi, prevPos, ebx
- jmp strnotfound
- .endif
- mov prevPos,eax
- inc ebx
- jmp compnext
- strnotfound:
- mov edx, pDstString
- mov eax, prevPos
- mov BYTE PTR [edx], al
- mov al, BYTE PTR [edi+ebx-1]
- mov BYTE PTR [edx+1], al
- add pDstString, 2h
- mov prevPos, 1
- .if ecx >= lSrcString
- jmp compend
- .endif
- add edi, ebx
- add ecx, ebx
- mov ebx, 1
- jmp compnext
- compend:
- ret
- compress endp
- addDictStr proc uses ecx ebx edi esi string:DWORD, num:DWORD, lenght:DWORD
- mov ebx, num
- mov eax, countDict
- imul eax, eax, sdict
- mov myDict.pos[eax], ebx
- mov esi, string
- lea edi, myDict.string[eax]
- xor ecx, ecx
- mov ecx, lenght
- rep movsb
- mov BYTE PTR [edi], 0h
- inc countDict
- ret
- addDictStr endp
- findStr proc uses ecx edx edi string:DWORD, num:DWORD
- LOCAL count:DWORD
- mov count, 1h
- nextserach:
- imul eax, count, sdict
- lea edi, myDict.string[eax]
- .if BYTE PTR [edi] == 0
- jmp notfound
- .endif
- mov esi, string
- mov ecx, num
- inc count
- repe cmpsb
- jz found
- jmp nextserach
- found:
- .if BYTE PTR [edi] != 0
- jmp nextserach
- .endif
- mov eax, count
- jmp endsearch
- notfound:
- mov eax, 1
- endsearch:
- ret
- findStr endp
- end start
Advertisement
Add Comment
Please, Sign In to add comment