Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; @RCHER - DEflate unpacker v1.0
  2. ;
  3. ; Written in pure assembler by Ivushkin Andrey aka Willow
  4. ;
  5. ; Created: May 6, 2005
  6. ;
  7. ; Last changed: July 14, 2005
  8. ;
  9. ; Compile with FASM
  10.  
  11.  
  12. SYS equ meos
  13. PARAM_PTR equ png_image
  14. DUMPFILE equ '/hd/1/out.txt'
  15.  
  16. SHOW_RBLOCK equ 0;1
  17. SHOW_PNG_SEC equ 0;1
  18. SHOW_METH equ 0;1
  19. FILE_NUM equ 0
  20. MEMORY equ 0x800000
  21.  
  22. BITS equ 16
  23. BUFSIZE equ 32
  24. BUFPTR equ area
  25.  
  26. PASSW_LEN equ 32
  27. NO_STOPS equ 1
  28. SHOW_CHARS equ 0
  29. BSIZE equ 512
  30. INBUF equ BUFSIZE*BSIZE*2
  31. OUTBUF equ 4*1024*1024
  32. IGNORE_DIRS equ 0
  33.  
  34. MOVE_SLINE_LEV equ 8
  35.  
  36. DECRYPT_MODE equ 100b
  37. PNG_MODE equ 10b
  38. TAR_MODE equ 1000b
  39. STAY_MODE equ 10000b
  40. IPC_MODE equ 100000b
  41. RAW_MODE equ 1000000b
  42. THREAD_YES equ 10000000b
  43.  
  44. if SYS eq win
  45. format PE console
  46. entry start
  47. ;match =win,SYS
  48. ;{
  49. ;    include 'D:\Ivushkin\projects\fasmw\INCLUDE\win32a.inc'
  50. ;}
  51. else
  52. use32
  53.  
  54.   org    0x0
  55.  
  56.   db     'MENUET01'
  57.   dd     0x01
  58.   dd     start
  59.   dd     I_END
  60.   dd     MEMORY
  61.   dd     MEMORY-2048
  62. if  PARAM_PTR eq param
  63.   dd     0
  64. else
  65.   dd     PARAM_PTR
  66. end if
  67.   dd     0x0
  68. include "lang.inc"
  69.  
  70. if  PARAM_PTR eq param
  71.   param db 'RQ'
  72.   db '000037'
  73.   db '/hd/1/zip/png.zip',0
  74. end if
  75. ;match =meos,SYS
  76. ;{
  77.     include "macros.inc"
  78. ;    purge mov
  79.     include "debug.inc"
  80. ;}
  81. end if
  82.  
  83. language equ en
  84.  
  85. if SYS eq win
  86. section '.text' code readable executable writeable
  87. end if
  88. include "arcmacro.inc"
  89. include "parser.inc"
  90. include "deflate.inc"
  91. include "sys.inc"
  92.  
  93. FileNum dd FILE_NUM
  94. ;FNAME equ '/hd/1/zip/pngsuite/s01n3p01.png'
  95.  
  96. start:
  97. if SYS eq win
  98.     invoke GetStdHandle, STD_OUTPUT_HANDLE
  99.     mov  [cons],eax
  100.     invoke GetStdHandle, STD_INPUT_HANDLE
  101.     mov  [cons_in],eax
  102.     Msg  0
  103.     Msg  1
  104. else
  105.     Msg  0
  106.     Msg  1
  107.     mcall 40,10000101b
  108. ;    jmp again
  109.     CmdLine
  110.  red:
  111.     call draw_window
  112.     mcall 12,2
  113.  
  114.  still:
  115.     mcall 10
  116.     cmp  eax,1
  117.     je   red
  118.     cmp  eax,2
  119.     jne  .nokey
  120.     mcall 2
  121.     cmp  ah,9
  122.     jz   quit
  123.     jmp  still
  124.   .nokey:
  125.     cmp  eax,3
  126.     jne  still
  127.     mcall 17
  128.     cmp  ah,1
  129.     jne  still
  130.     mcall 23,30
  131.     cmp  eax,3
  132.     jne  .noquit
  133.     call KillViewer
  134.     mcall -1
  135.   .noquit:
  136.     mcall 17
  137.     QueryFile
  138.     and  [FileNum],0
  139.     test eax,eax
  140.     jnz  still
  141. end if
  142. again:
  143.     Newline
  144.     xor  eax,eax
  145. ;    and  [Flags],STAY_MODE
  146.     and  [CRC32],eax
  147.     and  [IDATsize],eax
  148.     mov  [Adler32],1
  149.     call OpenFile
  150.     test ebx,ebx
  151.     jnz   .sizeok2
  152.   .sizebad2:
  153.     Msg  14
  154.     jmp  quit
  155.   .sizeok2:
  156.     mov  [filesize],ebx
  157.     test [Flags],RAW_MODE
  158.     jz   .norawm
  159.     mov  eax,[arc_base]
  160.     xor  ebx,ebx
  161.     call FileSeek
  162.     jmp  .sizeok
  163.   .norawm:
  164.     call SfxParse
  165.  
  166.     call ZipParse
  167.     cmp  edx,52
  168.     je   .notzip
  169.     mov  ecx,[FileNum]
  170.     call ZipFindN
  171.     cmp  edx,4
  172.     je   quit
  173.     test [Flags],DECRYPT_MODE
  174.     jz   .nopass
  175.     call ZipDecrypt
  176.     push esi
  177.     mov  ecx,31
  178.   ._:
  179.     mov  al,[esi]
  180.     push eax
  181.     call decrypt_byte
  182.     xor  al,byte[esp]
  183.     add  esp,4
  184.     call UKeys
  185.     mov  [esi],al
  186.     inc  esi
  187.     loop ._
  188.     pop  esi
  189.     ud2
  190.   .nopass:
  191.     cmp  [unp_size],0
  192.     jne  .sizeok
  193.   .sizebadq:
  194.     Msg  13
  195.     jmp  quit
  196.   .notzip:
  197.     call GzipParse
  198.     test edx,edx
  199.     jne   .notgzip
  200.     jmp  .sizeok
  201.   .notgzip:
  202.     call PngParse
  203.     test edx,edx
  204.     jz  .sizeok1
  205.     cmp  edx,21
  206.     je   .sizebad
  207.     test [Flags],RAW_MODE
  208.     jne  .sizeok
  209.     Msg  40
  210.     jmp  exit
  211.   .sizebad:
  212.     Msg  17
  213.     jmp  exit
  214.   .sizeok1:
  215.   if ~ SYS eq win
  216.     call KillViewer
  217.   end if
  218.     Msg  39
  219.     mov  edi,[outp]
  220.     call Deflate.blkbegin
  221.     jmp  .defl_end
  222.   .sizeok:
  223.     call Deflate                ; <===========
  224.   .defl_end:
  225.     test [bits],7
  226.     jnz  .esi_ok
  227.     dec  esi
  228.   .esi_ok:
  229.     push dword[esi] ; <- Adler !!!
  230.     mov  esi,output
  231.     sub  edi,esi
  232.     mov  ecx,edi
  233.     mov  [outfile.size],ecx
  234.     test [Flags],RAW_MODE
  235.     jnz  .skipAdler
  236.     test [Flags],PNG_MODE
  237.     jnz  .skipCRC
  238.     push esi ecx
  239.     call UCRC
  240.     Msg  11
  241.     mov  eax,[CRC32]
  242.     mov  edx,36
  243.     cmp  eax,[CRC_check]
  244.     je   .crcok
  245.     dec  edx
  246.   .crcok:
  247.     Msg  edx
  248.   if  SYS eq win
  249.   else
  250.     dph  eax
  251.   end if
  252.     pop  ecx esi
  253.     jmp  .skipAdler
  254.   .skipCRC:
  255.     call UAdler
  256.     Msg  10
  257.     mov  eax,[Adler32]
  258.     bswap eax   ; <- calculated Adler !!!
  259.     mov  edx,36
  260.     cmp  eax,[esp]
  261.     je   .adlok
  262.     dec  edx
  263.   .adlok:
  264.     Msg  edx
  265.   if  SYS eq win
  266.   else
  267.     dph  eax
  268.   end if
  269.   .skipAdler:
  270.     pop  eax
  271.     Newline
  272.   .nomoreIDAT:
  273.     mov  ebx,output
  274. if SYS eq win
  275.     Msg 37
  276.     invoke CloseHandle, [hnd]
  277.  
  278.     invoke CreateFile,dumpfile,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, \
  279.     CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
  280.     mov  [hnd],eax
  281.     invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL
  282.     invoke CloseHandle, [hnd]
  283. else
  284.     test [Flags],PNG_MODE
  285.     jnz  .nosave
  286.     test [Flags],TAR_MODE
  287.     jnz  .nomsg
  288.     Msg 37
  289.   .nomsg:
  290.     mov  [outfile.out],ebx
  291.     mcall 58,outfile
  292.     test [Flags],TAR_MODE
  293.     jnz  .nosave
  294.     call StartPad
  295.   .nosave:
  296. end if
  297.     test  [Flags],PNG_MODE
  298.     jz   NoPng
  299.       xor  eax,eax
  300.       mov  edi,filters
  301.       mov  ecx,6
  302.       rep  stosd
  303.       mov  edi,png_image
  304.       mov  esi,output
  305. ;//
  306.       mov  [outp],edi
  307. ;//
  308.       call PngFilter
  309.       call FiltStats
  310.       mov  [outfile.size],edi
  311.       mov  ebx,[outp];png_image
  312. if  SYS eq win
  313. exit:
  314.     Msg  12
  315.     invoke CreateFile,outfile,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, \
  316.     CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
  317.     mov  [hnd],eax
  318.     invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL
  319.     invoke CloseHandle, [hnd]
  320.         call  RunViewer
  321.         and  [arc_base],0
  322.     and  [Flags],STAY_MODE
  323.        
  324. quit:  
  325.     QueryFile
  326.     test eax,eax
  327.     jnz  again
  328.     invoke ExitProcess,0
  329. else
  330. exit:
  331.     mov  [outfile.out],ebx
  332.     test [Flags],TAR_MODE
  333.     jz   .notar
  334.     Msg  37
  335.     mcall 58,outfile
  336.     call StartPad
  337.  .notar:
  338.     Msg  12
  339.         call  RunViewer
  340.         and  [arc_base],0
  341.     and  [Flags],STAY_MODE
  342. quit:
  343.     test [Flags],STAY_MODE
  344.     jnz  red
  345.     mcall -1
  346. end if
  347.  
  348. NoPng:
  349.     test  [Flags],TAR_MODE
  350.   if SYS eq win
  351.     jz  quit
  352.   else
  353.     jz    still
  354.   end if
  355.     mov   ecx,dumpf_len
  356.     mov   esi,dumpfile
  357.     mov   edi,filename
  358.     rep   movsb
  359.     call  OpenFile
  360.     test  ebx,ebx
  361.     jz    again.sizebadq
  362.     call  TarParse
  363.     mov   ecx,[FileNum]
  364.     call  TarFindN
  365.     cmp   [outfile.size],0
  366.     jz    again.sizebadq
  367.     mov   ebx,esi
  368.     jmp   exit
  369.  
  370. if ~ SYS eq win
  371. draw_window:
  372.     mcall 12,1
  373.     mov  ebx,15
  374.     mov  ecx,ebx
  375.     mov  edx,0x0e26830
  376.     mov  edi,edx
  377.     mcall 0,,,,0x1f2a870
  378.     mcall 8,,,1+1 shl 30
  379.     mcall 4,<6,5>,0x10d0d0d0,msgs+5,1
  380.     mcall ,<5,5>,0x10202020
  381.     ret
  382. end if
  383.  
  384. include 'data.inc'
  385.  
  386. if SYS eq win
  387. section '.idata' import data readable writeable
  388.  
  389.   library kernel,'KERNEL32.DLL',\
  390.           comdlg,'COMDLG32.DLL',\
  391.           user,'USER32.DLL'
  392.  
  393.   import kernel,\
  394.      CreateFile,'CreateFileA',\
  395.      GetFileSize,'GetFileSize',\
  396.      ReadFile,'ReadFile',\
  397.      WriteFile,'WriteFile',\
  398.      SetFilePointer,'SetFilePointer',\
  399.      CloseHandle,'CloseHandle',\
  400.          GetStdHandle,'GetStdHandle',\
  401.          WriteConsole,'WriteConsoleA',\
  402.          ReadConsole,'ReadConsoleA',\
  403.          CreateProcess,'CreateProcessA',\
  404.          WritePrivateProfileString,'WritePrivateProfileStringA',\      
  405.          ExitProcess,'ExitProcess'
  406.  
  407.   import comdlg,\
  408.      GetOpenFileName,'GetOpenFileNameA'
  409.  
  410.   import user,\
  411.          wsprintf,'wsprintfA',\
  412.          SendMessage,'SendMessageA',\
  413.          FindWindowEx,'FindWindowExA',\
  414.           WaitForInputIdle,'WaitForInputIdle'
  415.        
  416.  
  417. section '.reloc' fixups data readable discardable
  418. end if
  419.  
  420. if ~ SYS in <meos,win>
  421.     error "Please specify SYS: meos OR win"
  422. end if
  423.  
  424.  
  425.