Subversion Repositories Kolibri OS

Rev

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

  1. ;---------------------------------------------------------------------
  2. ; Kpack - Kolibri Packer
  3. ; Kolibri version
  4. ; Written by diamond in 2006, 2007 specially for KolibriOS
  5. ;
  6. ; Disassemled and corrected in 2010-2011 specially for FASM
  7. ;            by Marat Zakiyanov aka Mario79, aka Mario
  8. ;
  9. ; Uses LZMA compression library by Igor Pavlov
  10. ; (for more information on LZMA and 7-Zip visit http://www.7-zip.org)
  11. ; (plain-C packer and ASM unpacker are ported by diamond)
  12. ;---------------------------------------------------------------------
  13. use32
  14.         org     0
  15.  
  16.         db 'MENUET01'
  17.         dd 1
  18.         dd START
  19.         dd IM_END
  20.         dd I_END
  21.         dd stacktop
  22.         dd params
  23.         dd cur_dir_path
  24. ;---------------------------------------------------------------------
  25. include '../../../config.inc'           ;for nightbuild
  26. include '../../../macros.inc'
  27. include '../../../gui_patterns.inc'
  28. include '../../../develop/libraries/box_lib/trunk/box_lib.mac'
  29. include '../../../develop/libraries/box_lib/load_lib.mac'
  30.   @use_library
  31.  
  32. START:
  33.         mcall   68,11
  34.         mcall   40,0x80000027
  35.  
  36. load_libraries l_libs_start,load_lib_end
  37.         cmp eax,-1
  38.         je exit
  39.  
  40.         init_checkboxes2 check1,check1_end
  41.         ;push   check1
  42.         ;call   [init_checkbox]
  43.  
  44.         call    clear_messages
  45. ; set default path = /RD/1/
  46.         mov     esi,defpath
  47.         mov     edi,path
  48.         mov     [edi-4],dword 6
  49.         movsw
  50.         movsd
  51. ; get system window info
  52.         xor     eax,eax
  53.         cmp     [params],al
  54.         je      default
  55.        
  56.         mov     edi,path
  57.         mov     esi,params
  58.         call    copy_1
  59.  
  60.         sub     esi,2
  61.         std
  62. @@:
  63.         lodsb
  64.         dec     edi
  65.         cmp     al,byte '/'
  66.         jnz     @r
  67.        
  68.         mov     [edi-1],byte 0
  69.         mov     edi,inname
  70.         add     esi,2
  71.         push    esi
  72.         call    copy_1
  73.         pop     esi
  74.         mov     edi,outname
  75.         call    copy_1
  76. ;---------------------------------------------------------------------
  77.         call set_editbox_position_all
  78. ;---------------------------------------------------------------------
  79.         call    draw_window
  80.         call    pack
  81.         jmp     OD_initialization
  82. ;*********************************************************************
  83. default:
  84.         mov     esi,definoutname
  85.         mov     edi,esi
  86.         xor     ecx,ecx
  87.         xor     eax,eax
  88.         dec     ecx
  89.         repnz   scasb
  90.         not     ecx
  91.         dec     ecx
  92.         mov     [innamelen],ecx
  93.         push    ecx
  94.         push    esi
  95.         mov     edi,inname
  96.         rep     movsb
  97.         pop     esi
  98.         pop     ecx
  99.         mov     [outnamelen],ecx
  100.         mov     edi,outname
  101.         rep     movsb
  102. ;---------------------------------------------------------------------
  103.         call    set_editbox_position_all
  104. ;---------------------------------------------------------------------
  105. OD_initialization:
  106. ;OpenDialog     initialisation
  107.         push    dword OpenDialog_data
  108.         call    [OpenDialog_Init]
  109. ;---------------------------------------------------------------------
  110. red:
  111.         call    draw_window
  112. ;--------------------------------------
  113. still:
  114.         mcall   10
  115.         dec     eax
  116.         jz      red
  117.  
  118.         dec     eax
  119.         jz      key
  120.  
  121.         dec     eax
  122.         jz      button
  123.  
  124.         push    dword edit1
  125.         call    [edit_box_mouse]
  126.  
  127.         push    dword edit2
  128.         call    [edit_box_mouse]
  129.  
  130.         push    dword edit3
  131.         call    [edit_box_mouse]
  132.  
  133.         push    dword check1
  134.         call    [check_box_mouse]
  135.        
  136.         jmp     still
  137. ;*********************************************************************
  138. tell_compress_mess:
  139.         push    compressing_len
  140.         pop     ecx
  141.         mov     esi,compressing_str
  142.         call    write_string
  143.         ret
  144. ;*********************************************************************
  145. clear_mess_and_displogo:
  146.         call    refresh_editbox_data
  147. ; clear messages
  148.         call    clear_messages
  149. ; display logo
  150.         mov     esi,info_str
  151.         push    info_len
  152.         pop     ecx
  153.         call    write_string
  154.         ret
  155. ;*********************************************************************
  156. clear_messages:
  157.         xor     eax,eax
  158.         mov     ecx,80*20/4+1
  159.         mov     edi,message_mem
  160.         rep     stosd
  161.         ret
  162. ;*********************************************************************
  163. exit:
  164.         xor     eax,eax
  165.         dec     eax
  166.         mcall
  167. ;*********************************************************************
  168. button:
  169. ; button pressed
  170.         mcall   17
  171.         xchg    al,ah
  172.         cmp     al,7
  173.         jz      but7
  174.  
  175.         dec     eax
  176.         jz      exit
  177.  
  178.         dec     eax
  179.         jnz     nopack
  180.  
  181.         bt dword[check1.flags],1
  182.         jc      @f
  183.  
  184.         call    pack
  185.         jmp     still
  186. ;--------------------------------------------------------------------- 
  187. @@:
  188.         call    kerpack
  189.         jmp     still  
  190. ;---------------------------------------------------------------------
  191. nopack:
  192.         dec     eax
  193.         jnz     nounpack
  194.        
  195.         call    unpack
  196.         jmp     still
  197. ;--------------------------------------------------------------------- 
  198. but7:
  199.         call    clear_messages
  200. ; display logo
  201.         mov     esi,info_str
  202.         push    info_len
  203.         pop     ecx
  204.         call    write_string
  205. ; display info
  206.         mov     esi,usage_str
  207.         mov     ecx,usage_len
  208.         call    write_string
  209.         jmp     still
  210. ;---------------------------------------------------------------------
  211. nounpack:
  212.         dec     eax
  213.         jnz     still
  214.  
  215.         call    OpenDialog_start
  216.         jmp     still
  217. ;*********************************************************************
  218. OpenDialog_start:
  219.         mov     esi,path
  220.         mov     edi,temp_dir_pach
  221.         call    copy_1 
  222.  
  223.         push    dword OpenDialog_data
  224.         call    [OpenDialog_Start]
  225.         cmp     [OpenDialog_data.status],1
  226.         jne     @f
  227.  
  228.         mov     esi,filename_area
  229.         mov     edi,inname
  230.         call    copy_1
  231.  
  232.         mov     esi,filename_area
  233.         mov     edi,outname
  234.         call    copy_1
  235.        
  236.         mov     esi,temp_dir_pach
  237.         mov     edi,path
  238.         call    copy_1
  239.        
  240.         call    refresh_editbox_data
  241.  
  242.         call    set_editbox_position_all
  243.  
  244.         call    draw_editbox
  245. @@:
  246.         ret
  247. ;*********************************************************************
  248. copy_1:
  249.         xor     eax,eax
  250.         cld    
  251. @@:
  252.         lodsb
  253.         stosb
  254.         test    eax,eax
  255.         jnz     @r
  256.         ret
  257. ;*********************************************************************
  258. refresh_editbox_data:
  259.         mov     esi,inname
  260.         mov     edi,innamelen
  261.         call    refresh_data
  262.  
  263.         mov     esi,outname
  264.         mov     edi,outnamelen
  265.         call    refresh_data
  266.  
  267.         mov     esi,path
  268.         mov     edi,pathlen
  269.         call    refresh_data
  270.  
  271.         ret
  272. ;*********************************************************************
  273. refresh_data:
  274.         push    esi
  275.         xor     eax,eax
  276.         cld    
  277. @@:
  278.         lodsb
  279.         test    eax,eax
  280.         jnz     @r
  281.         pop     eax
  282.         sub     esi,eax
  283.         dec     esi
  284.         mov     [edi],esi
  285.         ret
  286. ;*********************************************************************
  287. set_editbox_position_all:
  288.         mov     ebx,inname
  289.         mov     edi,edit1
  290.         call    set_editbox_position
  291.  
  292.         mov     ebx,outname
  293.         mov     edi,edit2
  294.         call    set_editbox_position
  295.  
  296.         mov     ebx,path
  297.         mov     edi,edit3
  298.         call    set_editbox_position
  299.         ret
  300. ;*********************************************************************
  301. key:
  302.         mcall   2
  303.  
  304.         push    dword edit1
  305.         call    [edit_box_key]
  306.  
  307.         push    dword edit2
  308.         call    [edit_box_key]
  309.  
  310.         push    dword edit3
  311.         call    [edit_box_key]
  312.  
  313.         jmp     still
  314. ;*********************************************************************
  315. get_full_name:
  316.         push    esi
  317.         mov     esi,path
  318.         mov     ecx,[esi-4]
  319.         mov     edi,fullname
  320.         rep     movsb
  321.         mov     al,'/'
  322.         cmp     [edi-1],al
  323.         jz      @f
  324.  
  325.         stosb
  326. ;--------------------------------------
  327. @@:
  328.         pop     esi
  329.         cmp     [esi],al
  330.         jnz     @f
  331.  
  332.         mov     edi,fullname
  333. ;--------------------------------------
  334. @@:
  335.         mov     ecx,[esi-4]
  336.         rep     movsb
  337.         xor     eax,eax
  338.         stosb
  339.         ret
  340. ;*********************************************************************
  341. write_string:
  342. ; in: esi=pointer, ecx=length
  343.         mov     edx,[message_cur_pos]
  344. ;--------------------------------------
  345. x1:
  346.         lea     edi,[message_mem+edx]
  347. ;--------------------------------------
  348. do_write_char:
  349.         lodsb
  350.         cmp     al,10
  351.         jz      newline
  352.  
  353.         stosb
  354.         inc     edx
  355.         loop    do_write_char
  356.         jmp     x2
  357. ;---------------------------------------------------------------------
  358. newline:
  359.         xor     eax,eax
  360.         stosb
  361.         xchg    eax,edx
  362.         push    ecx
  363.         push    eax
  364.         mov     ecx,80
  365.         div     ecx
  366.         pop     eax
  367.         xchg    eax,edx
  368.         sub     edx,eax
  369.         add     edx,ecx
  370.         pop     ecx
  371.         loop    x1
  372. ;--------------------------------------
  373. x2:
  374.         mov     [message_cur_pos],edx
  375. ; update window
  376.         call draw_log_area
  377. ;--------------------------------------
  378. draw_messages:
  379.         mov     ebx,12 shl 16 + LOG_Y + 7
  380.         mov     edi,message_mem
  381. ;--------------------------------------
  382. @@:
  383.         push    edi
  384.         xor     eax,eax
  385.         push    80
  386.         pop     ecx
  387.         repnz   scasb
  388.         sub     ecx,79
  389.         neg     ecx
  390.         mov     esi,ecx
  391.         pop     edi
  392.         mcall   4,,0xB0000000,edi
  393.         add     ebx,16
  394.         add     edi,80
  395.         cmp     edi,message_cur_pos
  396.         jb      @b
  397.  
  398.         ret
  399. ;*********************************************************************
  400. draw_log_area:
  401.         DrawRectangle 5, LOG_Y, WIN_W-12, LOG_H, [sc.work_graph]       
  402.         mcall   13, <6,WIN_W-13>, <LOG_Y+1,LOG_H-1>, 0xFFFfff
  403.         ret
  404. ;*********************************************************************
  405. draw_window:
  406. ; start redraw
  407.         mcall   12,1   
  408.         mcall   48,3,sc,40
  409.         ;--------------------------------------
  410.         edit_boxes_set_sys_color edit1,editboxes_end,sc
  411.         check_boxes_set_sys_color2 check1,check1_end,sc
  412.         ;--------------------------------------
  413. ; define window
  414.         mcall 48,4
  415.  
  416.         mov     ecx,100 shl 16 + WIN_H
  417.         add ecx, eax
  418.        
  419.         mov     edx,[sc.work]
  420.         add     edx,34000000h
  421.         xor     esi,esi
  422.         xor     edi,edi
  423.         mcall   0,<250,WIN_W+10>,,,,caption_str
  424.         mcall   9,procinfo,-1
  425.        
  426.         mov     eax,[procinfo+70] ;status of window
  427.         test    eax,100b
  428.         jne     .end   
  429. ;--------------------------------------
  430. ; draw lines and frame
  431.         call    draw_log_area
  432. ; draw buttons
  433.         call    draw_buttons
  434. ; draw messages
  435.         call    draw_messages
  436. ; draw editbox's
  437.         call    draw_editbox
  438. ; end redraw
  439. .end:
  440.         mcall   12,2
  441.         ret
  442. ;*********************************************************************
  443. draw_editbox:
  444.         push    dword edit1
  445.         call    [edit_box_draw]
  446.        
  447.         push    dword edit2
  448.         call    [edit_box_draw]
  449.        
  450.         push    dword edit3
  451.         call    [edit_box_draw]
  452.        
  453.         mov eax,[sc.work_text]
  454.         or eax, 0x90000000
  455.         mov     [check1.text_color], eax
  456.         push    dword check1
  457.         call    [check_box_draw]
  458.         ret
  459. ;*********************************************************************
  460. set_editbox_position:
  461.         mov     esi,ebx
  462.         cld
  463. @@:
  464.         lodsb
  465.         test    al,al
  466.         jne     @r
  467.         sub     esi,ebx
  468.         mov     eax,esi
  469.         dec     eax
  470.         mov     [edi+48], eax  ;ed_size
  471.         mov     [edi+52], eax  ;ed_pos
  472.         ret
  473. ;*********************************************************************
  474. draw_buttons:
  475. ; define compress button
  476.         mov     cx,18
  477.         mcall   8,<WIN_W - RIGHT_BTN_W - 5, RIGHT_BTN_W>, <3, 20>,2,[sc.work_button]
  478. ; uncompress button
  479.         inc     edx
  480.         add     ecx,LINE_H shl 16
  481.         mcall
  482. ; question button
  483.         push    esi
  484.         mov     dl,7
  485.         mcall   ,<WIN_W-25,18>,<LINE_H*2+3,18>
  486.         mov ecx,[sc.work_button_text]
  487.         or  ecx,0x90000000
  488.         mov edx,aQuestion
  489.         mcall  4,<WIN_W-19, LINE_H*2+5>
  490.         pop     esi
  491. ; define Path button
  492.         mcall   8,<6,64>,<LINE_H*2+3,20>,4
  493. ; text on Path button
  494.         mov     ebx,8 shl 16+5
  495.         mov     al,4
  496.         mov     ecx,[sc.work_text]
  497.         push    buttons1names
  498.         pop     edx
  499.         push    8
  500.         pop     esi
  501. ;--------------------------------------
  502. ; text on settings buttons
  503.         mov ecx, [sc.work_text]
  504.         or ecx, 0x10000000
  505.         mcall , <8, 5>, , buttons1names, 8
  506.  
  507.         add     edx,esi
  508.         add     ebx,LINE_H
  509.         mcall
  510.         add     edx,esi
  511.         add     ebx,LINE_H
  512.         mov     ecx,[sc.work_button_text]
  513.         or ecx, 0x10000000
  514.         sub ebx, 10 shl 16
  515.         mcall
  516. ; text on compress and decompress buttons
  517.         or      ecx,0x80000000
  518.         mcall   ,<WIN_W - RIGHT_BTN_W+7,6>,,aCompress
  519.         mcall   ,<WIN_W - RIGHT_BTN_W+7,LINE_H+6>,,aDecompress
  520.         ret
  521. ;*********************************************************************
  522. ;Pack procedures
  523. include 'packpoc.inc'
  524. ;---------------------------------------------------------------------
  525. ;UnPack procedures
  526. include 'upacproc.inc'
  527. ;---------------------------------------------------------------------
  528. ;lzma_compress:
  529. include 'lzma_compress.inc'
  530. ;---------------------------------------------------------------------
  531. ;lzma_set_dict_size:
  532. include 'lzma_set_dict_size.inc'
  533. ;---------------------------------------------------------------------
  534. ;lzma_decompress:
  535. include 'lzma_decompress.inc'
  536. ;---------------------------------------------------------------------
  537. ;kerpack code:
  538. include 'kerpack.inc'
  539. ;---------------------------------------------------------------------
  540. ;initialized variables and constants
  541. include 'const_var.inc'
  542. ;---------------------------------------------------------------------
  543. IM_END:
  544. ;---------------------------------------------------------------------
  545. ;uninitialized data
  546. include 'data.inc'
  547. ;---------------------------------------------------------------------
  548. I_END:
  549. ;---------------------------------------------------------------------