Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 10th, 2012  |  syntax: ASM (NASM)  |  size: 4.30 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ; lzarchivator.inc
  2. ;################# Created by Bearchik http://crazyasm.blogspot.com ###############################
  3. include         windows.inc
  4. include         kernel32.inc
  5. include         user32.inc
  6. include         Comctl32.inc
  7. include         shell32.inc
  8.  
  9. includelib      kernel32.lib
  10. includelib      user32.lib
  11. includelib      Comctl32.lib
  12. includelib      shell32.lib
  13.  
  14. compress        PROTO:DWORD,:DWORD,:DWORD,:DWORD
  15. decompress      PROTO:DWORD,:DWORD,:DWORD,:DWORD
  16. writeStr        PROTO:DWORD,:DWORD,:DWORD
  17. addDictStr      PROTO:DWORD,:DWORD,:DWORD
  18. findStr         PROTO:DWORD,:DWORD
  19. getStr          PROTO:DWORD,:DWORD
  20. clearDict       PROTO
  21.  
  22. dict    struc
  23.         pos             dd                      ?
  24.         string  db 0Ch  dup(?)
  25. dict    ends
  26. sdict           equ     sizeof dict
  27.  
  28. .const
  29. DICTSIZE        equ             200h
  30.  
  31. ;#########################################################################
  32.  
  33. .data
  34. src                     db      "KARL_KARAL_KAR!",0
  35. countDict       dd      1
  36.  
  37. ;#########################################################################
  38.  
  39. .data?
  40. dst                     db      100h dup(?)
  41. decstr          db      100h dup(?)
  42. myDict          dict DICTSIZE dup (<>)
  43. buf                     db      0Ch     dup(?)
  44. bufcount        dd      ?
  45.  
  46. ;#########################################################################
  47.  
  48.  
  49.  
  50.  
  51. ; lzarchivator.asm
  52. .386
  53. .model flat, stdcall  ;32 bit memory model
  54. option casemap :none  ;case sensitive
  55.  
  56. include lzarchivator.inc
  57.  
  58. .code
  59.  
  60. start:
  61.         invoke  compress, offset src, sizeof src, offset dst, sizeof dst
  62.         invoke  clearDict
  63.         invoke  decompress, offset dst, sizeof dst, offset decstr, sizeof decstr
  64.         invoke  ExitProcess,0
  65.        
  66. decompress      proc    pSrcString:DWORD, lSrcString:DWORD, pDstString:DWORD, lDstString:DWORD
  67. LOCAL   curDstPos:DWORD
  68.         mov             edi, pSrcString
  69.         xor             ecx, ecx
  70.         mov             eax, pDstString
  71.         mov             curDstPos, eax
  72. nextcode:
  73.         xor             eax, eax
  74.         mov             al, BYTE PTR [edi]
  75.         push    eax
  76.         invoke  getStr, eax , edi
  77.         pop             eax
  78.         lea             esi, buf
  79.         invoke  addDictStr, esi, eax, ebx
  80.         invoke  writeStr, curDstPos, esi, ebx
  81.         mov             curDstPos, eax
  82.         add             edi, 2
  83.         .if     BYTE PTR [edi] == 0
  84.                 jmp             decodeend
  85.         .endif
  86.         jmp             nextcode
  87. decodeend:
  88.        
  89.         ret
  90. decompress endp
  91.  
  92. writeStr proc   uses ecx edi esi pdstString:DWORD, pBuf:DWORD, num:DWORD
  93.         mov             ecx, num
  94.         mov             edi, pdstString
  95.         mov             esi, pBuf
  96.         rep             movsb
  97.         mov             eax, edi
  98.         ret
  99. writeStr endp
  100.  
  101. getStr  proc    uses ecx edi edx        num:DWORD, codeStr:DWORD
  102.         mov             eax, num
  103.         .if     eax == 1
  104.                 mov             eax, codeStr
  105.                 mov             al, BYTE PTR [eax+1]
  106.                 mov             BYTE PTR [buf], al
  107.                 mov             ebx, 1
  108.                 jmp             endGetStr
  109.         .endif
  110.        
  111.         mov             edi, offset buf
  112.         dec             eax
  113.         imul    edx, eax, sdict
  114.         xor             ecx, ecx
  115. nextDictChr:
  116.         mov             al, myDict.string[edx+ecx]
  117.         mov             BYTE PTR [edi+ecx], al
  118.         inc             ecx
  119.         .if     al == 0
  120.                 mov             eax, codeStr
  121.                 mov             al, BYTE PTR [eax+1]
  122.                 mov             BYTE PTR [edi+ecx-1], al
  123.                 mov             ebx, ecx
  124.                 jmp             endGetStr
  125.         .endif
  126.         jmp             nextDictChr
  127. endGetStr:
  128.  
  129.         ret
  130. getStr endp
  131.  
  132. clearDict       proc uses ecx edi
  133.         mov             countDict, 1h
  134.         mov             ecx, sdict
  135.         imul    ecx, ecx, DICTSIZE
  136.         lea             edi, myDict
  137. nextclr:
  138.         mov             BYTE PTR [edi],0h
  139.         inc             edi
  140.         loop    nextclr
  141.         ret
  142. clearDict endp
  143.  
  144. compress        proc    pSrcString:DWORD, lSrcString:DWORD, pDstString:DWORD, lDstString:DWORD
  145. LOCAL   prevPos:DWORD
  146.         mov             prevPos, 1
  147.         mov             edi, pSrcString
  148.         mov             ebx, 1
  149.         xor             ecx, ecx
  150. compnext:
  151.         invoke  findStr, edi, ebx
  152.         .if     eax     == 1
  153.                 invoke  addDictStr, edi, prevPos, ebx
  154.                 jmp     strnotfound
  155.         .endif
  156.         mov             prevPos,eax
  157.         inc             ebx
  158.         jmp             compnext
  159. strnotfound:
  160.         mov             edx, pDstString
  161.         mov             eax, prevPos
  162.         mov             BYTE PTR [edx], al
  163.         mov             al, BYTE PTR [edi+ebx-1]
  164.         mov             BYTE PTR [edx+1], al
  165.         add             pDstString, 2h
  166.         mov             prevPos, 1
  167.         .if             ecx >= lSrcString
  168.                 jmp             compend
  169.         .endif
  170.         add             edi, ebx
  171.         add             ecx, ebx
  172.         mov             ebx, 1
  173.         jmp             compnext
  174. compend:
  175.         ret
  176. compress endp
  177.  
  178. addDictStr      proc    uses ecx ebx edi esi    string:DWORD, num:DWORD, lenght:DWORD
  179.         mov             ebx, num
  180.         mov             eax, countDict
  181.         imul    eax, eax, sdict
  182.         mov             myDict.pos[eax], ebx
  183.         mov             esi, string
  184.         lea             edi, myDict.string[eax]
  185.         xor             ecx, ecx
  186.         mov             ecx, lenght
  187.         rep             movsb
  188.         mov             BYTE PTR [edi], 0h
  189.         inc             countDict
  190.         ret
  191. addDictStr endp
  192.  
  193. findStr proc    uses ecx edx edi        string:DWORD, num:DWORD
  194. LOCAL   count:DWORD
  195.         mov             count, 1h
  196.  
  197. nextserach:
  198.         imul    eax, count, sdict
  199.         lea             edi, myDict.string[eax]
  200.         .if     BYTE PTR [edi] == 0
  201.                 jmp             notfound
  202.         .endif
  203.         mov             esi, string
  204.         mov             ecx, num
  205.         inc             count
  206.         repe    cmpsb
  207.         jz              found
  208.         jmp             nextserach
  209. found:
  210.         .if     BYTE PTR [edi] != 0
  211.                 jmp             nextserach
  212.         .endif
  213.         mov             eax, count
  214.         jmp             endsearch
  215. notfound:
  216.         mov             eax, 1
  217. endsearch:     
  218.         ret
  219. findStr endp
  220.  
  221. end start