Subversion Repositories Kolibri OS

Rev

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