Subversion Repositories Kolibri OS

Rev

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