Subversion Repositories Kolibri OS

Rev

Rev 1681 | Rev 1688 | 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.         dd I_END                ;memf
  20.         dd stacktop
  21.         dd params
  22.         dd cur_dir_path
  23. ;---------------------------------------------------------------------
  24. include '..\..\..\macros.inc'
  25. include '../../../develop/libraries/box_lib/trunk/box_lib.mac'
  26. include '../../../develop/libraries/box_lib/load_lib.mac'
  27.   @use_library
  28.  
  29. START:
  30.         mcall   68,11
  31.         mcall   40,100111b
  32.  
  33.         call    clear_messages
  34. ; set default path = /RD/1/
  35.         mov     esi,defpath
  36.         mov     edi,path
  37.         mov     [edi-4],dword 6
  38.         movsw
  39.         movsd
  40. ; get system window info
  41.         mcall   48,3,color_table,40
  42.         inc     ebx
  43.         mcall
  44.         mov     [skinheight],eax
  45.         jmp     default
  46. ; check command line
  47.         mov     esi,params
  48.         mov     [esi+100h],byte 0
  49. ;--------------------------------------
  50. parse_opt:
  51.         call    skip_spaces
  52.         test    al,al
  53.         jz      default
  54.  
  55.         mov     edi,inname
  56.         call    copy_name
  57.         test    al,al
  58.         jz      outeqin
  59.  
  60.         mov     edi,outname
  61.         call    copy_name
  62.         test    al,al
  63.         jnz     default
  64. ;--------------------------------------
  65. doit:
  66.         call    draw_window
  67.         call    pack
  68.         jmp     still
  69. ;---------------------------------------------------------------------
  70. clear_messages:
  71.         xor     eax,eax
  72.         mov     ecx,80*20/4+1
  73.         mov     edi,message_mem
  74.         rep     stosd
  75.         ret
  76. ;---------------------------------------------------------------------
  77. exit:
  78.         xor     eax,eax
  79.         dec     eax
  80.         mcall
  81. ;--------------------------------------
  82. outeqin:
  83.         mov     ecx,256/4+1
  84.         mov     esi,inname-4
  85.         mov     edi,outname-4
  86.         rep     movsd
  87.         jmp     doit
  88. ;---------------------------------------------------------------------
  89. default:
  90.  
  91. load_libraries l_libs_start,load_lib_end
  92.         cmp eax,-1
  93.         je exit
  94.  
  95.         mov     esi,definoutname
  96.         mov     edi,esi
  97.         xor     ecx,ecx
  98.         xor     eax,eax
  99.         dec     ecx
  100.         repnz   scasb
  101.         not     ecx
  102.         dec     ecx
  103.         mov     [innamelen],ecx
  104.         push    ecx
  105.         push    esi
  106.         mov     edi,inname
  107.         rep     movsb
  108.         pop     esi
  109.         pop     ecx
  110.         mov     [outnamelen],ecx
  111.         mov     edi,outname
  112.         rep     movsb
  113. ;---------------------------------------------------------------------
  114. ;       mov     edi,fname_buf
  115. ;       mov     esi,path4
  116. ;       call    copy_1
  117.        
  118. ;OpenDialog     initialisation
  119.         push    dword OpenDialog_data
  120.         call    [OpenDialog_Init]
  121. ;---------------------------------------------------------------------
  122.         call    set_editbox_position_all
  123. ;---------------------------------------------------------------------
  124. red:
  125.         call    draw_window
  126. ;--------------------------------------
  127. still:
  128.         mcall   10
  129.         dec     eax
  130.         jz      red
  131.  
  132.         dec     eax
  133.         jz      key
  134.  
  135.         dec     eax
  136.         jz      button
  137.  
  138.         push    dword edit1
  139.         call    [edit_box_mouse]
  140.  
  141.         push    dword edit2
  142.         call    [edit_box_mouse]
  143.  
  144.         push    dword edit3
  145.         call    [edit_box_mouse]
  146.  
  147.         jmp     still
  148. ;*********************************************************************
  149. button:
  150. ; button pressed
  151.         mcall   17
  152.         xchg    al,ah
  153.         cmp     al,7
  154.         jz      but7
  155.  
  156.         dec     eax
  157.         jz      exit
  158.  
  159.         dec     eax
  160.         jnz     nopack
  161.  
  162.         call    pack
  163.         jmp     still
  164. ;---------------------------------------------------------------------
  165. nopack:
  166.         dec     eax
  167.         jnz     nounpack
  168.  
  169.         call    unpack
  170.         jmp     still
  171. ;---------------------------------------------------------------------
  172. but7:
  173.         call    clear_messages
  174. ; display logo
  175.         mov     esi,info_str
  176.         push    info_len
  177.         pop     ecx
  178.         call    write_string
  179. ; display info
  180.         mov     esi,usage_str
  181.         mov     ecx,usage_len
  182.         call    write_string
  183.         jmp     still
  184. ;---------------------------------------------------------------------
  185. nounpack:
  186.         dec     eax
  187.         jnz     still
  188.  
  189.         call    OpenDialog_start
  190.         jmp     still
  191. ;*********************************************************************
  192. OpenDialog_start:
  193.         push    dword OpenDialog_data
  194.         call    [OpenDialog_Start]
  195.         cmp     [OpenDialog_data.status],1
  196.         jne     @f
  197.  
  198.         mov     esi,filename_area
  199.         mov     edi,inname
  200.         call    copy_1
  201.         sub     edi,inname
  202.         mov     [innamelen],edi
  203.  
  204.         mov     esi,filename_area
  205.         mov     edi,outname
  206.         call    copy_1
  207.         sub     edi,outname
  208.         mov     [outnamelen],edi
  209.        
  210.         mov     esi,temp_dir_pach
  211.         mov     edi,path
  212.         call    copy_1
  213.         sub     edi,path
  214.         dec     edi
  215.         mov     [pathlen],edi
  216.        
  217.         call    set_editbox_position_all
  218.  
  219.         call    draw_editbox
  220. @@:
  221.         ret
  222. ;*********************************************************************
  223. copy_1:
  224.         xor     eax,eax
  225.         cld    
  226. @@:
  227.         lodsb
  228.         stosb
  229.         test    eax,eax
  230.         jnz     @r
  231.         ret
  232. ;*********************************************************************
  233. set_editbox_position_all:
  234.         mov     ebx,inname
  235.         mov     edi,edit1
  236.         call    set_editbox_position
  237.  
  238.         mov     ebx,outname
  239.         mov     edi,edit2
  240.         call    set_editbox_position
  241.  
  242.         mov     ebx,path
  243.         mov     edi,edit3
  244.         call    set_editbox_position
  245.         ret
  246. ;*********************************************************************
  247. key:
  248.         mcall   2
  249.  
  250.         push    dword edit1
  251.         call    [edit_box_key]
  252.  
  253.         push    dword edit2
  254.         call    [edit_box_key]
  255.  
  256.         push    dword edit3
  257.         call    [edit_box_key]
  258.  
  259.         jmp     still
  260. ;*********************************************************************
  261. onenter:
  262. ;       cmp     [curedit],inname
  263. ;       jnz     @f
  264.  
  265.         push    2
  266.         pop     eax
  267.         jmp     nounpack
  268. ;*********************************************************************
  269. get_full_name:
  270.         push    esi
  271.         mov     esi,path
  272.         mov     ecx,[esi-4]
  273.         mov     edi,fullname
  274.         rep     movsb
  275.         mov     al,'/'
  276.         cmp     [edi-1],al
  277.         jz      @f
  278.  
  279.         stosb
  280. ;--------------------------------------
  281. @@:
  282.         pop     esi
  283.         cmp     [esi],al
  284.         jnz     @f
  285.  
  286.         mov     edi,fullname
  287. ;--------------------------------------
  288. @@:
  289.         mov     ecx,[esi-4]
  290.         rep     movsb
  291.         xor     eax,eax
  292.         stosb
  293.         ret
  294. ;*********************************************************************
  295. write_string:
  296. ; in: esi=pointer, ecx=length
  297.         mov     edx,[message_cur_pos]
  298. ;--------------------------------------
  299. x1:
  300.         lea     edi,[message_mem+edx]
  301. ;--------------------------------------
  302. do_write_char:
  303.         lodsb
  304.         cmp     al,10
  305.         jz      newline
  306.  
  307.         stosb
  308.         inc     edx
  309.         loop    do_write_char
  310.         jmp     x2
  311. ;---------------------------------------------------------------------
  312. newline:
  313.         xor     eax,eax
  314.         stosb
  315.         xchg    eax,edx
  316.         push    ecx
  317.         push    eax
  318.         mov     ecx,80
  319.         div     ecx
  320.         pop     eax
  321.         xchg    eax,edx
  322.         sub     edx,eax
  323.         add     edx,ecx
  324.         pop     ecx
  325.         loop    x1
  326. ;--------------------------------------
  327. x2:
  328.         mov     [message_cur_pos],edx
  329. ; update window
  330.         mov     ecx,[skinheight]
  331.         shl     ecx,16
  332.         add     ecx,3700DEh
  333.         mcall   13,<9,417>,,[color_table+20]
  334. ;--------------------------------------
  335. draw_messages:
  336.         mov     ebx,[skinheight]
  337.         add     ebx,3Ch+12*10000h
  338.         mov     edi,message_mem
  339. ;--------------------------------------
  340. @@:
  341.         push    edi
  342.         xor     eax,eax
  343.         push    80
  344.         pop     ecx
  345.         repnz   scasb
  346.         sub     ecx,79
  347.         neg     ecx
  348.         mov     esi,ecx
  349.         pop     edi
  350.         mcall   4,,[color_table+32],edi
  351.         add     ebx,10
  352.         add     edi,80
  353.         cmp     edi,message_cur_pos
  354.         jb      @b
  355.  
  356.         ret
  357. ;*********************************************************************
  358. draw_window:
  359. ; start redraw
  360.         mcall   12,1
  361.         mov     edi,[skinheight]
  362. ;--------------------------------------
  363. ; define window
  364.         xor     eax,eax
  365.         mov     ecx,100 shl 16+286
  366.         add     ecx,edi
  367.         mov     edx,[color_table+20]
  368.         add     edx,13000000h
  369. ;       push    edi
  370.         xor     esi,esi
  371.         mcall   ,<100,435>,,,,fullname  ;temp_dir_pach  ;caption_str
  372. ;       pop     edi
  373.         mcall   9,procinfo,-1
  374. ;--------------------------------------
  375. ; draw lines and frame
  376.         call    draw_lines
  377. ; draw buttons
  378.         call    draw_bittons
  379. ; infile, outfile, path strings
  380. ;       call    draw_strings
  381. ; draw messages
  382.         call    draw_messages
  383. ; draw editbox's
  384.         mov     eax,[procinfo+42]
  385.         sub     eax,65+72+10
  386.         mov     [edit1.width],eax ; óñòàíàâëèâàåì øèðèíó òåêñòîâûõ ïîëåé
  387.         mov     [edit2.width],eax
  388.         mov     [edit3.width],eax
  389.  
  390.         call    draw_editbox
  391. ; end redraw
  392.         mcall   12,2
  393.         ret
  394. ;*********************************************************************
  395. draw_editbox:
  396.         push    dword edit1
  397.         call    [edit_box_draw]
  398.         push    dword edit2
  399.         call    [edit_box_draw]
  400.         push    dword edit3
  401.         call    [edit_box_draw]
  402.         ret
  403. ;*********************************************************************
  404. set_editbox_position:
  405.         mov     esi,ebx
  406.         cld
  407. @@:
  408.         lodsb
  409.         test    al,al
  410.         jne     @r
  411.         sub     esi,ebx
  412.         mov     eax,esi
  413.         dec     eax
  414.         mov     [edi+48], eax  ;ed_size
  415.         mov     [edi+52], eax  ;ed_pos
  416.         ret
  417. ;*********************************************************************
  418. draw_lines:
  419. ;       mov     edi,[skinheight]
  420. ; lines - horizontal
  421. ;       mov     ebx,8 shl 16+352
  422. ;       mov     ecx,edi
  423. ;       shl     ecx,16
  424. ;       or      ecx,edi
  425. ;       add     ecx,2 shl 16+2
  426. ;       mcall   38,,,[color_table+36]
  427. ;       mov     esi,3
  428. ;@@:
  429. ;       add     ecx,12 shl 16+12
  430. ;       mcall
  431. ;       dec     esi
  432. ;       jnz     @r
  433. ;--------------------------------------
  434. ; lines - vertical
  435. ;       sub     ecx,36 shl 16
  436. ;       mcall   ,<8,8>
  437. ;       add     ebx,52 shl 16+52
  438. ;       mcall
  439. ;       add     ebx,292 shl 16+292
  440. ;       mcall
  441. ;--------------------------------------
  442.         mov     edi,[skinheight]
  443.         mov     ecx,edi
  444.         shl     ecx,16
  445.         or      ecx,edi
  446.         add     ecx,2 shl 16+2+12*3
  447. ;       add     ecx,12*3
  448. ; draw frame for messages data
  449.         push    ecx
  450.         add     ecx,52 shl 16+16
  451.         mcall   38,<8,425>,,[color_table+36]
  452.         add     ecx,224*(1 shl 16+1)
  453.         mcall
  454.         sub     cx,224
  455.         mcall   ,<8,8>
  456.         mcall   ,<426,426>
  457.         pop     ecx
  458.         ret
  459. ;*********************************************************************
  460. draw_bittons:
  461. ; define compress button
  462.         mov     cx,18
  463.         mcall   8,<354,72>,,2,[color_table+36]
  464. ; uncompress button
  465.         add     ecx,18 shl 16
  466.         inc     edx
  467.         mcall
  468.         add     ecx,-12h+0Ah+140000h
  469. ; question button
  470.         push    esi
  471.         mov     dl,7
  472.         mcall   ,<417,9>
  473.         shr     ecx,16
  474.         lea     ebx,[ecx+1A40002h]
  475.         mcall   4,,[color_table+28],aQuestion,1
  476. ;       mov     al,8
  477.         pop     esi
  478. ; define settings buttons
  479. ;       mov     ebx,9 shl 16+50
  480.         lea     ecx,[edi+2]
  481.         add     ecx,16*2
  482.         shl     ecx,16
  483.         mov     cx,13
  484. ;       push    4
  485. ;       pop     edx
  486. ;--------------------------------------
  487. ;@@:
  488. ;       mcall
  489. ;       add     ecx,12 shl 16
  490. ;       inc     edx
  491. ;       cmp     edx,6
  492. ;       jbe     @b
  493.         mcall   8,<9,50>,,4
  494. ; text on settings buttons
  495.         lea     ebx,[edi+5+0C0000h]
  496.         mov     al,4
  497.         mov     ecx,[color_table+28]
  498.         push    buttons1names
  499.         pop     edx
  500.         push    8
  501.         pop     esi
  502. ;--------------------------------------
  503. @@:
  504.         mcall
  505.         add     edx,esi
  506.         add     ebx,16
  507.         cmp     [edx-6],byte ' '
  508.         jnz     @b
  509. ; text on compress and decompress buttons
  510.         lea     ebx,[edi+8+1720000h]
  511.         or      ecx,80000000h
  512.         mcall   ,,,aCompress
  513.         lea     ebx,[edi+1Ah+16A0000h]
  514.         mcall   ,,,aDecompress
  515.         ret
  516. ;*********************************************************************
  517. copy_name:
  518.         lea     edx,[edi+256]
  519. ;--------------------------------------
  520. @@:
  521.         lodsb
  522.         cmp     al,' '
  523.         jbe     copy_name_done
  524.  
  525.         stosb
  526.         cmp     edi,edx
  527.         jb      @b
  528. ;--------------------------------------
  529. @@:
  530.         lodsb
  531.         cmp     al,' '
  532.         ja      @b
  533. ;--------------------------------------
  534. copy_name_done:
  535.         dec     esi
  536.         sub     edx,256
  537.         sub     edi,edx
  538.         mov     [edx-4],edi
  539. ;--------------------------------------
  540. skip_spaces:
  541.         lodsb
  542.         cmp     al,0
  543.         jz      @f
  544.  
  545.         cmp     al,' '
  546.         jbe     skip_spaces
  547. ;--------------------------------------
  548. @@:
  549.         dec     esi
  550.         ret
  551. ;*********************************************************************
  552. ;Pack procedures
  553. include 'packpoc.inc'
  554. ;---------------------------------------------------------------------
  555. ;UnPack procedures
  556. include 'upacproc.inc'
  557. ;---------------------------------------------------------------------
  558. ;lzma_compress:
  559. include 'lzma_compress.inc'
  560. ;---------------------------------------------------------------------
  561. ;lzma_set_dict_size:
  562. include 'lzma_set_dict_size.inc'
  563. ;---------------------------------------------------------------------
  564. ;lzma_decompress:
  565. include 'lzma_decompress.inc'
  566. ;---------------------------------------------------------------------
  567. ;initialized variables and constants
  568. include 'const_var.inc'
  569. ;---------------------------------------------------------------------
  570. IM_END:
  571. ;---------------------------------------------------------------------
  572. ;uninitialized data
  573. include 'data.inc'
  574. ;---------------------------------------------------------------------
  575. I_END:
  576. ;---------------------------------------------------------------------