Subversion Repositories Kolibri OS

Rev

Rev 1671 | Rev 1686 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; kpack = Kolibri Packer
  2. ; Kolibri version
  3. ; Written by diamond in 2006, 2007 specially for KolibriOS
  4. ;
  5. ; Disassemled and corrected in 2010 specially for FASM
  6. ;            by Marat Zakiyanov aka Mario79, aka Mario
  7. ;
  8. ; Uses LZMA compression library by Igor Pavlov
  9. ; (for more information on LZMA and 7-Zip visit http://www.7-zip.org)
  10. ; (plain-C packer and ASM unpacker are ported by diamond)
  11. ;---------------------------------------------------------------------
  12. use32
  13.         org     0
  14.  
  15.         db 'MENUET01'
  16.         dd 1
  17.         dd START
  18.         dd IM_END
  19. memf    dd I_END
  20.         dd stacktop
  21.         dd params
  22.         dd 0            ;cur_dir_path
  23. ;---------------------------------------------------------------------
  24. include '..\..\..\macros.inc'
  25.  
  26. START:
  27.         call    clear_messages
  28. ; set default path = /RD/1/
  29.         mov     esi,defpath
  30.         mov     edi,path
  31.         mov     [edi-4],dword 6
  32.         movsw
  33.         movsd
  34. ; get system window info
  35.         mcall   48,3,color_table,40
  36.         inc     ebx
  37.         mcall
  38.         mov     [skinheight],eax
  39. ; check command line
  40.         mov     esi,params
  41.         mov     [esi+100h],byte 0
  42. ;--------------------------------------
  43. parse_opt:
  44.         call    skip_spaces
  45.         test    al,al
  46.         jz      default
  47.  
  48.         mov     edi,inname
  49.         call    copy_name
  50.         test    al,al
  51.         jz      outeqin
  52.  
  53.         mov     edi,outname
  54.         call    copy_name
  55.         test    al,al
  56.         jnz     default
  57. ;--------------------------------------
  58. doit:
  59.         call    draw_window
  60.         call    pack
  61.         jmp     waitevent
  62. ;---------------------------------------------------------------------
  63. clear_messages:
  64.         xor     eax,eax
  65.         mov     ecx,80*20/4+1
  66.         mov     edi,message_mem
  67.         rep     stosd
  68.         ret
  69. ;---------------------------------------------------------------------
  70. exit:
  71.         xor     eax,eax
  72.         dec     eax
  73.         mcall
  74. ;--------------------------------------
  75. outeqin:
  76.         mov     ecx,48/4+1
  77.         mov     esi,inname-4
  78.         mov     edi,outname-4
  79.         rep     movsd
  80.         jmp     doit
  81. ;---------------------------------------------------------------------
  82. default:
  83.         mov     [curedit],inname
  84.         mov     ecx,[skinheight]
  85.         add     ecx,5
  86.         mov     [curedit_y],ecx
  87.         mov     esi,definoutname
  88.         mov     edi,esi
  89.         xor     ecx,ecx
  90.         xor     eax,eax
  91.         dec     ecx
  92.         repnz   scasb
  93.         not     ecx
  94.         dec     ecx
  95.         mov     [innamelen],ecx
  96.         push    ecx
  97.         push    esi
  98.         mov     edi,inname
  99.         rep     movsb
  100.         pop     esi
  101.         pop     ecx
  102.         mov     [outnamelen],ecx
  103.         mov     edi,outname
  104.         rep     movsb
  105. ;---------------------------------------------------------------------
  106. dodraw:
  107.         call    draw_window
  108. ;--------------------------------------
  109. waitevent:
  110.         mcall   10
  111.         dec     eax
  112.         jz      dodraw
  113.  
  114.         dec     eax
  115.         jz      keypressed
  116.  
  117.         dec     eax
  118.         jnz     waitevent
  119. ; button pressed
  120.         mcall   17
  121.         xchg    al,ah
  122.         cmp     al,7
  123.         jz      but7
  124.  
  125.         dec     eax
  126.         jz      exit
  127.  
  128.         dec     eax
  129.         jnz     nopack
  130.  
  131.         call    pack
  132.         jmp     waitevent
  133. ;---------------------------------------------------------------------
  134. nopack:
  135.         dec     eax
  136.         jnz     nounpack
  137.  
  138.         call    unpack
  139.         jmp     waitevent
  140. ;---------------------------------------------------------------------
  141. but7:
  142.         call    clear_messages
  143. ; display logo
  144.         mov     esi,info_str
  145.         push    info_len
  146.         pop     ecx
  147.         call    write_string
  148. ; display info
  149.         mov     esi,usage_str
  150.         mov     ecx,usage_len
  151.         call    write_string
  152.         jmp     waitevent
  153. ;---------------------------------------------------------------------
  154. nounpack:
  155. ; this is infile/outfile/path button
  156.         call    clear_edit_points
  157.         mov     esi,inname
  158.         mov     ecx,[skinheight]
  159.         add     ecx,5
  160.         dec     eax
  161.         jz      edit
  162.  
  163.         mov     esi,outname
  164.         add     ecx,0Ch
  165.         dec     eax
  166.         jz      edit
  167.  
  168.         mov     esi,path
  169.         add     ecx,0Ch
  170. ;--------------------------------------
  171. edit:
  172.         cmp     esi,[curedit]
  173.         mov     [curedit],0
  174.         jz      waitevent
  175.  
  176.         mov     [curedit],esi
  177.         mov     [curedit_y],ecx
  178.         mov     al,1
  179.         mov     ebx,[esi-4]
  180.         mov     edi,ebx
  181.         imul    ebx,6
  182.         add     ebx,42h
  183.         add     ecx,4
  184.         xor     edx,edx
  185. ;--------------------------------------
  186. @@:
  187.         cmp     edi,48
  188.         jz      waitevent
  189.  
  190.         mcall
  191.         add     ebx,6
  192.         inc     edi
  193.         jmp     @b
  194. ;---------------------------------------------------------------------
  195. keypressed:
  196.         mcall   2
  197.         xchg    al,ah
  198.         mov     edi,[curedit]
  199.         test    edi,edi
  200.         jz      waitevent
  201.  
  202.         mov     ebx,[edi-4]
  203.         cmp     al,8
  204.         jz      backspace
  205.  
  206.         cmp     al,13
  207.         jz      onenter
  208.  
  209.         cmp     al,20h
  210.         jb      waitevent
  211.  
  212.         cmp     ebx,48
  213.         jz      waitevent
  214.  
  215.         mov     [edi+ebx],al
  216.         inc     ebx
  217.         mov     [edi-4],ebx
  218. ; clear point and draw symbol
  219.         lea     edi,[edi+ebx-1]
  220.         imul    ebx,6
  221.         add     ebx,40h-6
  222.         shl     ebx,16
  223.         mov     bl,6
  224.         mov     ecx,[curedit_y]
  225.         push    ecx
  226.         shl     ecx,16
  227.         mov     cl,9
  228.         mcall   13,,,[color_table+20]
  229.         pop     ecx
  230.         mov     bx,cx
  231.         mcall   4,,[color_table+32],edi,1
  232.         jmp     waitevent
  233. ;---------------------------------------------------------------------
  234. backspace:
  235.         test    ebx,ebx
  236.         jz      waitevent
  237.  
  238.         dec     ebx
  239.         mov     [edi-4],ebx
  240. ; clear symbol and set point
  241.         imul    ebx,6
  242.         add     ebx,40h
  243.         shl     ebx,16
  244.         mov     bl,6
  245.         mov     ecx,[curedit_y]
  246.         push    ecx
  247.         shl     ecx,16
  248.         mov     cl,9
  249.         mcall   13,,,[color_table+20]
  250.         xor     edx,edx
  251.         shr     ebx,16
  252.         inc     ebx
  253.         inc     ebx
  254.         pop     ecx
  255.         add     ecx,4
  256.         mcall   1
  257.         jmp     waitevent
  258. ;---------------------------------------------------------------------
  259. onenter:
  260.         cmp     [curedit],inname
  261.         jnz     @f
  262.  
  263.         push    2
  264.         pop     eax
  265.         jmp     nounpack
  266. ;---------------------------------------------------------------------
  267. @@:
  268.         cmp     [curedit],outname
  269.         jnz     @f
  270.  
  271.         call    pack
  272.         jmp     waitevent
  273. ;---------------------------------------------------------------------
  274. @@:
  275.         call    clear_edit_points
  276.         jmp     waitevent
  277. ;---------------------------------------------------------------------
  278. pack:
  279.         call    clear_edit_points
  280.         and     [curedit],0
  281. ; clear messages
  282.         call    clear_messages
  283. ; display logo
  284.         mov     esi,info_str
  285.         push    info_len
  286.         pop     ecx
  287.         call    write_string
  288. ; load input file
  289.         mov     esi,inname
  290.         call    get_full_name
  291.         mov     ebx,fn70block
  292.         mov     [ebx],dword 5
  293.         and     [ebx+4],dword 0
  294.         and     [ebx+8],dword 0
  295.         and     [ebx+12],dword 0
  296.         mov     [ebx+16],dword  file_attr
  297.         mcall   70
  298.         test    eax,eax
  299.         jz      inopened
  300. ;---------------------------------------------------------------------
  301. infileerr:
  302.         mov     esi,errload_str
  303.         push    errload_len
  304.         pop     ecx
  305.         jmp     write_string
  306. ;---------------------------------------------------------------------
  307. inopened:
  308.         mov     ebx,[insize]
  309.         test    ebx,ebx
  310.         jz      infileerr
  311. ; maximum memory requests: 2*insize + 2*(maxoutsize+400h) + worksize
  312.         mov     esi,[memf]
  313.         mov     [infile],esi
  314.         add     esi,ebx
  315.         mov     [inbuftmp],esi
  316.         add     esi,ebx
  317.         mov     [outfile],esi
  318.         mov     [outfile1],esi
  319.         mov     [outfilebest],esi
  320.         mov     ecx,ebx
  321.         shr     ecx,3
  322.         add     ecx,ebx
  323.         add     ecx,400h
  324.         add     esi,ecx
  325.         mov     [outfile2],esi
  326.         add     esi,ecx
  327.         mov     [workmem],esi
  328.         add     ecx,ebx
  329.         add     ecx,ecx
  330.         add     ecx,[memf]
  331. ; LZMA requires 0x448000 + dictsize*9.5 bytes for workmem,
  332.         and     [lzma_dictsize],0
  333.         push    ecx
  334.         mov     eax,ebx
  335.         dec     eax
  336.         bsr     ecx,eax
  337.         inc     ecx
  338.         cmp     ecx,28
  339.         jb      @f
  340.  
  341.         mov     cl,28
  342. ;--------------------------------------
  343. @@:
  344.         mov     edx,ecx
  345.         xor     eax,eax
  346.         inc     eax
  347.         shl     eax,cl
  348.         imul    eax,19
  349.         shr     eax,1
  350.         add     eax,448000h
  351.         pop     ecx
  352.         add     ecx,eax
  353.         mcall   64,1
  354.         test    eax,eax
  355.         jz      mem_ok
  356. ;--------------------------------------
  357. ; try to use smaller dictionary
  358. meml0:
  359.         cmp     edx,4
  360.         jbe     memf1
  361.  
  362.         dec     edx
  363.         xor     eax,eax
  364.         inc     eax
  365.         mov     ecx,edx
  366.         shl     eax,cl
  367.         imul    eax,19
  368.         shr     eax,1
  369.         add     eax,509000h
  370.         pop     ecx
  371.         push    ecx
  372.         add     ecx,eax
  373.         mcall   64
  374.         test    eax,eax
  375.         jnz     meml0
  376. ;--------------------------------------
  377. ; ok, say warning and continue
  378.         mov     [lzma_dictsize],edx
  379.         mov     esi,lzma_memsmall_str
  380.         push    lzma_memsmall_len
  381.         pop     ecx
  382.         call    write_string
  383.         jmp     mem_ok
  384. ;---------------------------------------------------------------------
  385. memf1:
  386.         mov     esi,nomem_str
  387.         push    nomem_len
  388.         pop     ecx
  389.         jmp     write_string
  390. ;---------------------------------------------------------------------
  391. mem_ok:
  392.         mov     eax,[insize]
  393.         mov     ebx,fn70block
  394.         mov     [ebx],byte 0
  395.         mov     [ebx+12],eax
  396.         mov     esi,[infile]
  397.         mov     [ebx+16],esi
  398.         mcall   70
  399.         test    eax,eax
  400.         jnz     infileerr
  401.  
  402.         mov     eax,[outfile]
  403.         mov     [eax],dword 'KPCK'      ;'KCPK'
  404.         mov     ecx,[insize]
  405.         mov     [eax+4],dword ecx
  406.         mov     edi,eax
  407. ; set LZMA dictionary size
  408.         mov     eax,[lzma_dictsize]
  409.         test    eax,eax
  410.         js      no_lzma_setds
  411.         jnz     lzma_setds
  412.  
  413.         mov     ecx,[insize]
  414.         dec     ecx
  415.         bsr     eax,ecx
  416.         inc     eax
  417.         cmp     eax,28
  418.         jb      lzma_setds
  419.  
  420.         mov     eax,28
  421. ;--------------------------------------
  422. lzma_setds:
  423.         push    eax
  424.         call    lzma_set_dict_size
  425. ;--------------------------------------
  426. no_lzma_setds:
  427.         push    compressing_len
  428.         pop     ecx
  429.         mov     esi,compressing_str
  430.         call    write_string
  431.         mov     esi,[outfile1]
  432.         mov     edi,[outfile2]
  433.         movsd
  434.         movsd
  435.         movsd
  436.         call    pack_lzma
  437.         mov     [outsize],eax
  438.         mov     eax,[outfile]
  439.         mov     [outfilebest],eax
  440.         mov     [method],use_lzma
  441. ;--------------------------------------
  442. @@:
  443.         call    preprocess_calltrick
  444.         test    eax,eax
  445.         jz      noct1
  446.  
  447.         call    set_outfile
  448.         call    pack_lzma
  449.         add     eax,5
  450.         cmp     eax,[outsize]
  451.         jae     @f
  452.  
  453.         mov     [outsize],eax
  454.         mov     eax,[outfile]
  455.         mov     [outfilebest],eax
  456.         mov     [method],use_lzma or use_calltrick1
  457. ;--------------------------------------
  458. @@:
  459. noct1:
  460.         call    set_outfile
  461.         push    [ctn]
  462.         mov     al,[cti]
  463.         push    eax
  464.         call    preprocess_calltrick2
  465.         test    eax,eax
  466.         jz      noct2
  467.  
  468.         call    set_outfile
  469.         call    pack_lzma
  470.         add     eax,5
  471.         cmp     eax,[outsize]
  472.         jae     @f
  473.  
  474.         mov     [outsize],eax
  475.         mov     eax,[outfile]
  476.         mov     [outfilebest],eax
  477.         mov     [method],use_lzma or use_calltrick2
  478.         pop     ecx
  479.         pop     ecx
  480.         push    [ctn]
  481.         mov     al,[cti]
  482.         push    eax
  483. ;--------------------------------------
  484. @@:
  485. noct2:
  486.         pop     eax
  487.         mov     [cti],al
  488.         pop     [ctn]
  489.         add     [outsize],12
  490.         mov     eax,[outsize]
  491.         cmp     eax,[insize]
  492.         jb      packed_ok
  493.  
  494.         mov     esi,too_big_str
  495.         push    too_big_len
  496.         pop     ecx
  497.         jmp     write_string
  498. ;---------------------------------------------------------------------
  499. packed_ok:
  500. ; set header
  501.         movzx   eax,[method]
  502.         mov     edi,[outfilebest]
  503.         mov     [edi+8],eax
  504.         test    al,use_calltrick1 or use_calltrick2
  505.         jz      @f
  506.  
  507.         mov     ecx,[outsize]
  508.         add     ecx,edi
  509.         mov     eax,[ctn]
  510.         mov     [ecx-5],eax
  511.         mov     al,[cti]
  512.         mov     [ecx-1],al
  513. ;--------------------------------------
  514. @@:
  515.         mov     eax,[outsize]
  516.         mov     ecx,100
  517.         mul     ecx
  518.         div     [insize]
  519.         aam
  520.         xchg    al,ah
  521.         add     ax,'00'
  522.         mov     [ratio],ax
  523.         mov     esi,done_str
  524.         push    done_len
  525.         pop     ecx
  526.         call    write_string
  527. ;--------------------------------------
  528. ; save output file
  529. saveout:
  530.         mov     esi,outname
  531.         call    get_full_name
  532.         mov     ebx,fn70block
  533.         mov     [ebx],byte 2
  534.         mov     eax,[outfilebest]
  535.         mov     ecx,[outsize]
  536.         mov     [ebx+12],ecx
  537.         mov     [ebx+16],eax
  538.         mcall   70
  539.         test    eax,eax
  540.         jz      @f
  541. ;--------------------------------------
  542. outerr:
  543.         mov     esi,outfileerr_str
  544.         push    outfileerr_len
  545.         pop     ecx
  546.         jmp     write_string
  547. ;---------------------------------------------------------------------
  548. @@:
  549.         xor     eax,eax
  550.         mov     ebx,fn70block
  551.         mov     [ebx],byte 6
  552.         mov     [ebx+4],eax
  553.         mov     [ebx+8],eax
  554.         mov     [ebx+12],eax
  555.         mov     [ebx+16],dword file_attr
  556.         mcall   70
  557.         ret
  558. ;---------------------------------------------------------------------
  559. set_outfile:
  560.         mov     eax,[outfilebest]
  561.         xor     eax,[outfile1]
  562.         xor     eax,[outfile2]
  563.         mov     [outfile],eax
  564.         ret
  565. ;---------------------------------------------------------------------
  566. pack_calltrick_fail:
  567.         xor     eax,eax
  568.         mov     [ctn],0
  569.         ret
  570. ;---------------------------------------------------------------------
  571. preprocess_calltrick:
  572. ; input preprocessing
  573.         xor     eax,eax
  574.         mov     edi,ct1
  575.         mov     ecx,256/4
  576.         push    edi
  577.         rep     stosd
  578.         pop     edi
  579.         mov     ecx,[insize]
  580.         mov     esi,[infile]
  581.         xchg    eax,edx
  582.         mov     ebx,[inbuftmp]
  583. ;--------------------------------------
  584. input_pre:
  585.         lodsb
  586.         sub     al,0E8h
  587.         cmp     al,1
  588.         ja      input_pre_cont
  589.  
  590.         cmp     ecx,5
  591.         jb      input_pre_done
  592.  
  593.         lodsd
  594.         add     eax,esi
  595.         sub     eax,[infile]
  596.         cmp     eax,[insize]
  597.         jae     xxx
  598.  
  599.         cmp     eax,1000000h
  600.         jae     xxx
  601.  
  602.         sub     ecx,4
  603. ; bswap is not supported on i386
  604.         xchg    al,ah
  605.         ror     eax,16
  606.         xchg    al,ah
  607.         mov     [esi-4],eax
  608.         inc     edx
  609.         mov     [ebx],esi
  610.         add     ebx,4
  611.         jmp     input_pre_cont
  612. ;---------------------------------------------------------------------
  613. xxx:
  614.         sub     esi,4
  615.         movzx   eax,byte [esi]
  616.         mov     [eax+edi],byte 1
  617. ;--------------------------------------
  618. input_pre_cont:
  619.         loop    input_pre
  620. ;--------------------------------------
  621. input_pre_done:
  622.         mov     [ctn],edx
  623.         xor     eax,eax
  624.         mov     ecx,256
  625.         repnz   scasb
  626.         jnz     pack_calltrick_fail
  627.  
  628.         not     cl
  629.         mov     [cti],cl
  630. @@:
  631.         cmp     ebx,[inbuftmp]
  632.         jz      @f
  633.  
  634.         sub     ebx,4
  635.         mov     eax,[ebx]
  636.         mov     [eax-4],cl
  637.         jmp     @b
  638. ;---------------------------------------------------------------------
  639. @@:
  640.         mov     al,1
  641.         ret
  642. ;---------------------------------------------------------------------
  643. pack_lzma:
  644.         mov     eax,[outfile]
  645.         add     eax,11
  646.         push    [workmem]       ;workmem
  647.         push    [insize]        ;length
  648.         push    eax             ;destination
  649.         push    [infile]        ;source
  650.         call    lzma_compress
  651.         mov     ecx,[outfile]
  652.         mov     edx,[ecx+12]
  653.         xchg    dl,dh
  654.         ror     edx,16
  655.         xchg    dl,dh
  656.         mov     [ecx+12],edx
  657.         dec     eax
  658.         ret
  659. ;---------------------------------------------------------------------
  660. preprocess_calltrick2:
  661. ; restore input
  662.         mov     esi,[infile]
  663.         mov     ecx,[ctn]
  664.         jecxz   pc2l2
  665. ;--------------------------------------
  666. pc2l1:
  667.         lodsb
  668.         sub     al,0E8h
  669.         cmp     al,1
  670.         ja      pc2l1
  671.  
  672.         mov     al,[cti]
  673.         cmp     [esi],al
  674.         jnz     pc2l1
  675.  
  676.         lodsd
  677.         shr     ax,8
  678.         ror     eax,16
  679.         xchg    al,ah
  680.         sub     eax,esi
  681.         add     eax,[infile]
  682.         mov     [esi-4],eax
  683.         loop    pc2l1
  684. ;--------------------------------------
  685. pc2l2:
  686. ; input preprocessing
  687.         mov     edi,ct1
  688.         xor     eax,eax
  689.         push    edi
  690.         mov     ecx,256/4
  691.         rep     stosd
  692.         pop     edi
  693.         mov     ecx,[insize]
  694.         mov     esi,[infile]
  695.         mov     ebx,[inbuftmp]
  696.         xchg    eax,edx
  697. ;--------------------------------------
  698. input_pre2:
  699.         lodsb
  700. ;--------------------------------------
  701. @@:
  702.         cmp     al,0Fh
  703.         jnz     ip1
  704.  
  705.         dec     ecx
  706.         jz      input_pre_done2
  707.  
  708.         lodsb
  709.         cmp     al,80h
  710.         jb      @b
  711.  
  712.         cmp     al,90h
  713.         jb      @f
  714. ;--------------------------------------
  715. ip1:
  716.         sub     al,0E8h
  717.         cmp     al,1
  718.         ja      input_pre_cont2
  719. ;--------------------------------------
  720. @@:
  721.         cmp     ecx,5
  722.         jb      input_pre_done2
  723.  
  724.         lodsd
  725.         add     eax,esi
  726.         sub     eax,[infile]
  727.         cmp     eax,[insize]
  728.         jae     xxx2
  729.  
  730.         cmp     eax,1000000h
  731.         jae     xxx2
  732.  
  733.         sub     ecx,4
  734.         xchg    al,ah
  735.         rol     eax,16
  736.         xchg    al,ah
  737.         mov     [esi-4],eax
  738.         inc     edx
  739.         mov     [ebx],esi
  740.         add     ebx,4
  741.         jmp     input_pre_cont2
  742. ;---------------------------------------------------------------------
  743. xxx2:   sub     esi,4
  744.         movzx   eax,byte [esi]
  745.         mov     [eax+edi],byte 1
  746. ;--------------------------------------
  747. input_pre_cont2:
  748.         loop    input_pre2
  749. ;--------------------------------------
  750. input_pre_done2:
  751.         mov     [ctn],edx
  752.         xor     eax,eax
  753.         mov     ecx,256
  754.         repnz   scasb
  755.         jnz     pack_calltrick_fail
  756.  
  757.         not     cl
  758.         mov     [cti],cl
  759. ;--------------------------------------
  760. @@:
  761.         cmp     ebx,[inbuftmp]
  762.         jz      @f
  763.  
  764.         sub     ebx,4
  765.         mov     eax,[ebx]
  766.         mov     [eax-4],cl
  767.         jmp     @b
  768. ;---------------------------------------------------------------------
  769. @@:
  770.         mov     al,1
  771.         ret
  772. ;---------------------------------------------------------------------
  773. unpack:
  774.         call    clear_edit_points
  775.         and     [curedit],0
  776. ; clear messages
  777.         call    clear_messages
  778. ; display logo
  779.         mov     esi,info_str
  780.         push    info_len
  781.         pop     ecx
  782.         call    write_string
  783. ; load input file
  784.         mov     esi,inname
  785.         call    get_full_name
  786.         mov     ebx,fn70block
  787.         mov     [ebx],dword 5
  788.         and     [ebx+4],dword 0
  789.         and     [ebx+8],dword 0
  790.         and     [ebx+12],dword 0
  791.         mov     [ebx+16],dword file_attr
  792.         mcall   70
  793.         test    eax,eax
  794.         jnz     infileerr
  795.  
  796.         mov     eax,[insize]
  797.         test    eax,eax
  798.         jz      infileerr
  799.  
  800.         mov     ecx,[memf]
  801.         mov     [infile],ecx
  802.         add     ecx,eax
  803.         mov     [outfile],ecx
  804.         mov     [outfilebest],ecx
  805.         mcall   64,1
  806.         test    eax,eax
  807.         jnz     memf1
  808.  
  809.         mov     ebx,fn70block
  810.         mov     [ebx],byte 0
  811.         mov     eax,[insize]
  812.         mov     [ebx+12],eax
  813.         mov     esi,[infile]
  814.         mov     [ebx+16],esi
  815.         mcall   70
  816.         test    eax,eax
  817.         jnz     infileerr
  818.  
  819.         mov     eax,[infile]
  820.         cmp     [eax],dword 'KPCK'
  821.         jz      @f
  822. ;--------------------------------------
  823. unpack_err:
  824.         mov     esi,notpacked_str
  825.         push    notpacked_len
  826.         pop     ecx
  827.         jmp     write_string
  828. ;---------------------------------------------------------------------
  829. @@:
  830.         mov     ecx,[outfile]
  831.         add     ecx,dword [eax+4]
  832.         mcall   64,1
  833.         test    eax,eax
  834.         jnz     memf1
  835.  
  836.         mov     esi,[infile]
  837.         mov     eax,[esi+8]
  838.         push    eax
  839.         and     al,0C0h
  840.         cmp     al,0C0h
  841.         pop     eax
  842.         jz      unpack_err
  843.  
  844.         and     al,not 0C0h
  845.         dec     eax
  846.         jnz     unpack_err
  847.  
  848.         mov     eax,[esi+4]
  849.         mov     [outsize],eax
  850.         push    eax
  851.         push    [outfile]
  852.         add     esi,11
  853.         push    esi
  854.         mov     eax,[esi+1]
  855.         xchg    al,ah
  856.         ror     eax,16
  857.         xchg    al,ah
  858.         mov     [esi+1],eax
  859.         call    lzma_decompress
  860.         mov     esi,[infile]
  861.         test    [esi+8],byte 80h
  862.         jnz     uctr1
  863.  
  864.         test    [esi+8],byte 40h
  865.         jz      udone
  866.  
  867.         add     esi,[insize]
  868.         sub     esi,5
  869.         lodsd
  870.         mov     ecx,eax
  871.         jecxz   udone
  872.  
  873.         mov     dl,[esi]
  874.         mov     esi,[outfile]
  875. ;--------------------------------------
  876. uc1:
  877.         lodsb
  878.         sub     al,0E8h
  879.         cmp     al,1
  880.         ja      uc1
  881.  
  882.         cmp     [esi],dl
  883.         jnz     uc1
  884.  
  885.         lodsd
  886.         shr     ax,8
  887.         ror     eax,16
  888.         xchg    al,ah
  889.         sub     eax,esi
  890.         add     eax,[outfile]
  891.         mov     [esi-4],eax
  892.         loop    uc1
  893.         jmp     udone
  894. ;---------------------------------------------------------------------
  895. uctr1:
  896.         add     esi,[insize]
  897.         sub     esi,5
  898.         lodsd
  899.         mov     ecx,eax
  900.         jecxz   udone
  901.  
  902.         mov     dl,[esi]
  903.         mov     esi,[outfile]
  904. ;--------------------------------------
  905. uc2:
  906.         lodsb
  907. ;--------------------------------------
  908. @@:
  909.         cmp     al,15
  910.         jnz     uf
  911.  
  912.         lodsb
  913.         cmp     al,80h
  914.         jb      @b
  915.  
  916.         cmp     al,90h
  917.         jb      @f
  918. ;--------------------------------------
  919. uf:
  920.         sub     al,0E8h
  921.         cmp     al,1
  922.         ja      uc2
  923. ;--------------------------------------
  924. @@:
  925.         cmp     [esi],dl
  926.         jnz     uc2
  927.  
  928.         lodsd
  929.         shr     ax,8
  930.         ror     eax,16
  931.         xchg    al,ah
  932.         sub     eax,esi
  933.         add     eax,[outfile]
  934.         mov     [esi-4],eax
  935.         loop    uc2
  936. ;--------------------------------------
  937. udone:
  938.         mov     esi,unpacked_ok
  939.         push    unpacked_len
  940.         pop     ecx
  941.         call    write_string
  942.         jmp     saveout
  943.  
  944. ;---------------------------------------------------------------------
  945. get_full_name:
  946.         push    esi
  947.         mov     esi,path
  948.         mov     ecx,[esi-4]
  949.         mov     edi,fullname
  950.         rep     movsb
  951.         mov     al,'/'
  952.         cmp     [edi-1],al
  953.         jz      @f
  954.  
  955.         stosb
  956. ;--------------------------------------
  957. @@:
  958.         pop     esi
  959.         cmp     [esi],al
  960.         jnz     @f
  961.  
  962.         mov     edi,fullname
  963. ;--------------------------------------
  964. @@:
  965.         mov     ecx,[esi-4]
  966.         rep     movsb
  967.         xor     eax,eax
  968.         stosb
  969.         ret
  970. ;---------------------------------------------------------------------
  971. wsret:
  972.         ret
  973. ;---------------------------------------------------------------------
  974. write_string:
  975. ; in: esi=pointer, ecx=length
  976.         mov     edx,[message_cur_pos]
  977. ;--------------------------------------
  978. x1:
  979.         lea     edi,[message_mem+edx]
  980. ;--------------------------------------
  981. do_write_char:
  982.         lodsb
  983.         cmp     al,10
  984.         jz      newline
  985.  
  986.         stosb
  987.         inc     edx
  988.         loop    do_write_char
  989.         jmp     x2
  990. ;---------------------------------------------------------------------
  991. newline:
  992.         xor     eax,eax
  993.         stosb
  994.         xchg    eax,edx
  995.         push    ecx
  996.         push    eax
  997.         mov     ecx,80
  998.         div     ecx
  999.         pop     eax
  1000.         xchg    eax,edx
  1001.         sub     edx,eax
  1002.         add     edx,ecx
  1003.         pop     ecx
  1004.         loop    x1
  1005. ;--------------------------------------
  1006. x2:
  1007.         mov     [message_cur_pos],edx
  1008. ; update window
  1009.         mov     ecx,[skinheight]
  1010.         shl     ecx,16
  1011.         add     ecx,3700DEh
  1012.         mcall   13,<9,417>,,[color_table+20]
  1013. ;--------------------------------------
  1014. draw_messages:
  1015.         mov     ebx,[skinheight]
  1016.         add     ebx,3Ch+12*10000h
  1017.         mov     edi,message_mem
  1018. ;--------------------------------------
  1019. @@:
  1020.         push    edi
  1021.         xor     eax,eax
  1022.         push    80
  1023.         pop     ecx
  1024.         repnz   scasb
  1025.         sub     ecx,79
  1026.         neg     ecx
  1027.         mov     esi,ecx
  1028.         pop     edi
  1029.         mcall   4,,[color_table+32],edi
  1030.         add     ebx,10
  1031.         add     edi,80
  1032.         cmp     edi,message_cur_pos
  1033.         jb      @b
  1034.  
  1035.         ret
  1036. ;---------------------------------------------------------------------
  1037. draw_window:
  1038. ; start redraw
  1039.         mcall   12,1
  1040.         mov     edi,[skinheight]
  1041. ; define window
  1042.         xor     eax,eax
  1043.         mov     ecx,100 shl 16+286
  1044.         add     ecx,edi
  1045.         mov     edx,[color_table+20]
  1046.         add     edx,13000000h
  1047.         push    edi
  1048.         xor     esi,esi
  1049.         mcall   ,<100,435>,,,,caption_str
  1050.         pop     edi
  1051. ; lines - horizontal
  1052.         mov     ebx,8 shl 16+352
  1053.         mov     ecx,edi
  1054.         shl     ecx,16
  1055.         or      ecx,edi
  1056.         add     ecx,2 shl 16+2
  1057.         mcall   38,,,[color_table+36]
  1058.         add     ecx,12 shl 16+12
  1059.         mcall
  1060.         add     ecx,12 shl 16+12
  1061.         mcall
  1062.         add     ecx,12 shl 16+12
  1063.         mcall
  1064. ; lines - vertical
  1065.         sub     ecx,36 shl 16
  1066.         mcall   ,<8,8>
  1067.         add     ebx,52 shl 16+52
  1068.         mcall
  1069.         add     ebx,292 shl 16+292
  1070.         mcall
  1071. ; draw frame for messages data
  1072.         push    ecx
  1073.         add     ecx,52 shl 16+16
  1074.         mcall   ,<8,425>
  1075.         add     ecx,224*(1 shl 16+1)
  1076.         mcall
  1077.         sub     cx,224
  1078.         mcall   ,<8,8>
  1079.         mcall   ,<426,426>
  1080.         pop     ecx
  1081. ; define compress button
  1082.         mov     cx,18
  1083.         mcall   8,<354,72>,,2,[color_table+36]
  1084. ; uncompress button
  1085.         add     ecx,18 shl 16
  1086.         inc     edx
  1087.         mcall
  1088.         add     ecx,-12h+0Ah+140000h
  1089. ; question button
  1090.         push    esi
  1091.         mov     dl,7
  1092.         mcall   ,<417,9>
  1093.         shr     ecx,16
  1094.         lea     ebx,[ecx+1A40002h]
  1095.         mcall   4,,[color_table+28],aQuestion,1
  1096.         mov     al,8
  1097.         pop     esi
  1098. ; define settings buttons
  1099.         mov     ebx,9 shl 16+50
  1100.         lea     ecx,[edi+2]
  1101.         shl     ecx,16
  1102.         mov     cx,11
  1103.         push    4
  1104.         pop     edx
  1105. ;--------------------------------------
  1106. @@:
  1107.         mcall
  1108.         add     ecx,12 shl 16
  1109.         inc     edx
  1110.         cmp     edx,6
  1111.         jbe     @b
  1112. ; text on settings buttons
  1113.         lea     ebx,[edi+5+0C0000h]
  1114.         mov     al,4
  1115.         mov     ecx,[color_table+28]
  1116.         push    buttons1names
  1117.         pop     edx
  1118.         push    8
  1119.         pop     esi
  1120. ;--------------------------------------
  1121. @@:
  1122.         mcall
  1123.         add     edx,esi
  1124.         add     ebx,12
  1125.         cmp     [edx-6],byte ' '
  1126.         jnz     @b
  1127. ; text on compress and decompress buttons
  1128.         lea     ebx,[edi+8+1720000h]
  1129.         or      ecx,80000000h
  1130.         mcall   ,,,aCompress
  1131.         lea     ebx,[edi+1Ah+16A0000h]
  1132.         mcall   ,,,aDecompress
  1133. ; infile, outfile, path strings
  1134.         mov     edx,inname
  1135.         lea     ebx,[edi+400005h]
  1136. ;--------------------------------------
  1137. editdraw:
  1138.         mcall   4,,[color_table+32],,[edx-4]
  1139.         cmp     edx,[curedit]
  1140.         jnz     cont
  1141.  
  1142.         mov     al,1
  1143.         push    ebx
  1144.         push    edx
  1145.         movzx   ecx,bx
  1146.         shr     ebx,16
  1147.         lea     edx,[esi*2]
  1148.         lea     edx,[edx+edx*2]
  1149.         lea     ebx,[ebx+edx+2]
  1150.         add     ecx,4
  1151.         xor     edx,edx
  1152. ;--------------------------------------
  1153. @@:
  1154.         cmp     esi,48
  1155.         jz      @f
  1156.  
  1157.         mcall
  1158.         add     ebx,6
  1159.         inc     esi
  1160.         jmp     @b
  1161. ;---------------------------------------------------------------------
  1162. @@:
  1163.         pop     edx
  1164.         pop     ebx
  1165. ;--------------------------------------
  1166. cont:
  1167.         add     edx,52
  1168.         add     ebx,0Ch
  1169.         cmp     edx,path+52
  1170.         jb      editdraw
  1171. ; draw messages
  1172.         call    draw_messages
  1173. ; end redraw
  1174.         mcall   12,2
  1175.         ret
  1176. ;---------------------------------------------------------------------
  1177. copy_name:
  1178.         lea     edx,[edi+48]
  1179. ;--------------------------------------
  1180. @@:
  1181.         lodsb
  1182.         cmp     al,' '
  1183.         jbe     copy_name_done
  1184.  
  1185.         stosb
  1186.         cmp     edi,edx
  1187.         jb      @b
  1188. ;--------------------------------------
  1189. @@:
  1190.         lodsb
  1191.         cmp     al,' '
  1192.         ja      @b
  1193. ;--------------------------------------
  1194. copy_name_done:
  1195.         dec     esi
  1196.         sub     edx,48
  1197.         sub     edi,edx
  1198.         mov     [edx-4],edi
  1199. ;--------------------------------------
  1200. skip_spaces:
  1201.         lodsb
  1202.         cmp     al,0
  1203.         jz      @f
  1204.  
  1205.         cmp     al,' '
  1206.         jbe     skip_spaces
  1207. ;--------------------------------------
  1208. @@:
  1209.         dec     esi
  1210.         ret
  1211. ;---------------------------------------------------------------------
  1212. clear_edit_points:
  1213. ; clear edit points (if is)
  1214.         mov     esi,[curedit]
  1215.         test    esi,esi
  1216.         jz      cleared_edit_points
  1217.  
  1218.         push    eax
  1219.         mov     ebx,[esi-4]
  1220.         imul    ebx,6
  1221.         mov     edi,ebx
  1222.         add     ebx,40h
  1223.         shl     ebx,16
  1224.         add     ebx,48*6
  1225.         sub     bx,di
  1226.         mov     ecx,[curedit_y]
  1227.         shl     ecx,16
  1228.         or      cx,9
  1229.         mcall   13,,,[color_table+20]
  1230.         pop     eax
  1231. ;--------------------------------------
  1232. cleared_edit_points:
  1233.         ret
  1234. ;---------------------------------------------------------------------
  1235. ;lzma_compress:
  1236. include 'lzma_compress.inc'
  1237. ;---------------------------------------------------------------------
  1238. ;lzma_set_dict_size:
  1239. include 'lzma_set_dict_size.inc'
  1240. ;---------------------------------------------------------------------
  1241. ;lzma_decompress:
  1242. include 'lzma_decompress.inc'
  1243. ;---------------------------------------------------------------------
  1244. ;initialized variables and constants
  1245. include 'const_var.inc'
  1246. ;---------------------------------------------------------------------
  1247. IM_END:
  1248. ;---------------------------------------------------------------------
  1249. ;uninitialized data
  1250. include 'data.inc'
  1251. ;---------------------------------------------------------------------
  1252. I_END:
  1253. ;---------------------------------------------------------------------