Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.         format PE GUI 4.0
  2. section '.text' code readable executable
  3. entry start
  4. start:
  5.         push    ebp
  6.         mov     ebp, info
  7.         xor     ebx, ebx
  8. ; set current directory to exe dir
  9.         push    300
  10.         push    ebp
  11.         push    ebx
  12.         call    [GetModuleFileNameA]
  13.         lea     edi, [ebp+eax]
  14.         xchg    eax, ecx
  15.         mov     al, '\'
  16.         std
  17.         repnz   scasb
  18.         cld
  19.         jz      @f
  20.         pop     ebp
  21.         ret
  22. @@:
  23.         mov     byte [edi+1], bl
  24.         push    ebp
  25.         call    [SetCurrentDirectoryA]
  26. ; parse command line
  27.         call    [GetCommandLineA]
  28.         xchg    eax, esi
  29. ; skip leading spaces
  30. @@:
  31.         lodsb
  32.         cmp     al, 0
  33.         jz      cmdlineend
  34.         cmp     al, ' '
  35.         jbe     @b
  36.         cmp     al, '"'
  37.         jz      p
  38. ; skip EXE name
  39. @@:
  40.         lodsb
  41.         cmp     al, ' '
  42.         ja      @b
  43.         dec     esi
  44.         jmp     q
  45. p:
  46.         lodsb
  47.         cmp     al, 0
  48.         jz      cmdlineend
  49.         cmp     al, '"'
  50.         jnz     p
  51. q:
  52. ; skip leading spaces
  53.         lodsb
  54.         cmp     al, 0
  55.         jz      cmdlineend
  56.         cmp     al, ' '
  57.         jbe     q
  58.         dec     esi
  59. ; now esi points to 1st argument
  60.         jmp     @f
  61. cmdlineend:
  62.         mov     esi, def
  63. @@:
  64.         mov     al, 'c'
  65.         cmp     byte [esi+1], ':'
  66.         jnz     @f
  67.         lodsb
  68.         inc     esi
  69. @@:
  70.         mov     [ebp], al
  71.         lodsb
  72.         cmp     al, '\'
  73.         jz      paramsok
  74. usage:
  75.         mov     esi, usagemsg
  76.         jmp     failmsg
  77. paramsok:
  78.         cmp     byte [esi], '\'
  79.         jz      usage
  80.         mov     edi, esi
  81.         mov     al, 0
  82.         xor     ecx, ecx
  83.         dec     ecx
  84.         repnz   scasb
  85.         not     ecx
  86.         cmp     ecx, 290
  87.         jae     usage
  88.         lea     edi, [ebp+1]
  89.         cmp     ecx, 1
  90.         rep     movsb
  91.         jz      copydefname
  92.         cmp     byte [edi-2], '\'
  93.         jnz     namegiven
  94. copydefname:
  95.         dec     edi
  96.         mov     ecx, defnamesz
  97.         mov     esi, defname
  98.         rep     movsb
  99. namegiven:
  100.         push    ebx             ; hTemplateFile
  101. ;       push    0x04000000      ; dwFlagsAndAttributes = FILE_FLAG_DELETE_ON_CLOSE
  102.         push    ebx
  103.         push    ebx             ; dwCreationDisposition
  104.         push    ebx             ; lpSecurityAttributes
  105.         push    ebx             ; dwShareMode
  106.         push    ebx             ; dwDesiredAccess
  107.         push    name            ; lpFileName
  108.         call    [CreateFileA]
  109.         inc     eax
  110.         mov     esi, errmsg
  111.         jz      failmsg
  112.         dec     eax
  113.         push    ebx
  114.         push    ebx
  115.         push    ebx
  116.         push    ebx
  117.         sub     edi, ebp
  118.         push    edi
  119.         push    ebp
  120.         push    0Fh
  121.         push    eax
  122.         call    [DeviceIoControl]
  123.         test    eax, eax
  124.         mov     esi, errmsg2
  125.         jz      failmsg
  126.         push    ebx
  127.         push    2               ; EWX_REBOOT
  128.         call    [ExitWindowsEx]
  129.         pop     ebp
  130.         ret
  131. failmsg:
  132.         push    ebx
  133.         push    ebx
  134.         push    esi
  135.         push    ebx
  136.         call    [MessageBoxA]
  137.         pop     ebp
  138.         ret
  139.  
  140. align 4
  141. data import
  142.         dd      0,0,0
  143.         dd      rva kernel32_name
  144.         dd      rva kernel32_thunks
  145.         dd      0,0,0
  146.         dd      rva user32_name
  147.         dd      rva user32_thunks
  148.         dd      0,0,0,0,0
  149. kernel32_thunks:
  150. CreateFileA     dd      rva CreateFileA_thunk
  151. CloseHandle     dd      rva CloseHandle_thunk
  152. DeviceIoControl dd      rva DeviceIoControl_thunk
  153. GetCommandLineA dd      rva GetCommandLineA_thunk
  154. SetCurrentDirectoryA dd rva SetCurrentDirectoryA_thunk
  155. GetModuleFileNameA dd   rva GetModuleFileNameA_thunk
  156.         dd      0
  157. user32_thunks:
  158. MessageBoxA     dd      rva MessageBoxA_thunk
  159. ExitWindowsEx   dd      rva ExitWindowsEx_thunk
  160.         dw      0
  161. CreateFileA_thunk:
  162.         dw      0
  163.         db      'CreateFileA'
  164. CloseHandle_thunk:
  165.         dw      0
  166.         db      'CloseHandle'
  167. DeviceIoControl_thunk:
  168.         dw      0
  169.         db      'DeviceIoControl'
  170. GetCommandLineA_thunk:
  171.         dw      0
  172.         db      'GetCommandLineA'
  173. SetCurrentDirectoryA_thunk:
  174.         dw      0
  175.         db      'SetCurrentDirectoryA'
  176. GetModuleFileNameA_thunk:
  177.         dw      0
  178.         db      'GetModuleFileNameA'
  179. MessageBoxA_thunk:
  180.         dw      0
  181.         db      'MessageBoxA'
  182. ExitWindowsEx_thunk:
  183.         dw      0
  184.         db      'ExitWindowsEx',0
  185. kernel32_name   db      'kernel32.dll',0
  186. user32_name     db      'user32.dll',0
  187. end data
  188.  
  189. section '.data' data readable writable
  190. data resource from 'klbrico.res'
  191. end data
  192.  
  193. name    db      '\\.\'
  194. vxdfilename db  'ldklbr.vxd',0
  195. errmsg  db      'Cannot load driver',0
  196. errmsg2 db      'Invalid parameter',0
  197. usagemsg db     'Usage: 9x2klbr [[drive:]\[path\][imagename]]',0
  198. def     db      '\'
  199. defname db      'kolibri.img',0
  200. defnamesz = $ - defname
  201.  
  202. info    rb      300
  203.