Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ; ------------------------------------------------------------- ;
  2. ; KWINE is a fork of program PELoad written by 0CodErr
  3. ; author - rgimad
  4. ; ------------------------------------------------------------- ;
  5. ; standard device (Winbase.h)
  6. %define STD_INPUT_HANDLE     -10
  7. %define STD_OUTPUT_HANDLE    -11
  8. %define STD_ERROR_HANDLE     -12
  9.  
  10. ; starting point for file pointer move (Winbase.h)
  11. %define FILE_BEGIN            0 ; zero or beginning of file
  12. %define FILE_CURRENT          1 ; current value of file pointer
  13. %define FILE_END              2 ; current end-of-file position
  14.  
  15. ; file system operation codes (kernel/trunk/fs/fs_lfn.inc)
  16. %define F70_READ_F            0 ; read file
  17. %define F70_READ_D            1 ; read folder
  18. %define F70_CREATE_F          2 ; create/rewrite file
  19. %define F70_WRITE_F           3 ; write/append to file
  20. %define F70_SETSIZE_F         4 ; set end of file
  21. %define F70_GETATTR_FD        5 ; get file/directory attributes structure
  22. %define F70_SETATTR_FD        6 ; set file/directory attributes structure
  23. %define F70_START_F           7 ; start application
  24. %define F70_DELETE_FD         8 ; delete file
  25. %define F70_CREATE_D          9 ; create directory
  26.  
  27. ; action to take on file that exists or does not exist (Winbase.h)
  28. %define CREATE_NEW            1 ; creates a new file, only if it does not already exist
  29. %define CREATE_ALWAYS         2 ; creates new file, always
  30. %define OPEN_EXISTING         3 ; opens file, only if it exists
  31. %define OPEN_ALWAYS           4 ; opens file, always
  32. %define TRUNCATE_EXISTING     5 ; opens file and truncates it so that its size is zero bytes, only if it exists
  33.  
  34. %define INVALID_HANDLE_VALUE -1
  35. %define INVALID_FILE_SIZE    -1
  36.  
  37. GLOBAL EXPORTS
  38. section '.exprt' align 16
  39. ;**********************************************************************************
  40. EXPORTS: ;/////////////////////////////////////////////////////////////////////////
  41. ;**********************************************************************************
  42. dd sz_ExitProcess,              ExitProcess
  43. dd sz_GetStdHandle,             GetStdHandle
  44. dd sz_SetConsoleMode,           SetConsoleMode
  45. dd sz_WriteFile,                WriteFile
  46. dd sz_ReadFile,                 ReadFile
  47. dd sz_GetCommandLineA,          GetCommandLineA
  48. dd sz_GlobalAlloc,              GlobalAlloc
  49. dd sz_GlobalFree,               GlobalFree
  50. dd sz_GlobalReAlloc,            GlobalReAlloc
  51. dd sz_Sleep,                    Sleep
  52. dd sz_FlushConsoleInputBuffer,  FlushConsoleInputBuffer
  53. dd sz_CloseHandle,              CloseHandle
  54. dd sz_GetFileSize,              GetFileSize
  55. dd sz_CreateFileA,              CreateFileA
  56. dd sz_SetFilePointer,           SetFilePointer
  57. dd sz_VirtualAlloc,             VirtualAlloc
  58. dd sz_VirtualFree,              VirtualFree
  59. dd sz_SetConsoleCursorPosition, SetConsoleCursorPosition
  60. dd sz_DeleteFileA,              DeleteFileA
  61. dd sz_FindClose,                FindClose
  62. dd sz_FindFirstFileA,           FindFirstFileA
  63. dd sz_GetLocalTime,             GetLocalTime
  64. dd sz_GetLastError,             GetLastError
  65. dd sz_GetProcessHeap,           GetProcessHeap
  66. dd sz_HeapAlloc,                HeapAlloc
  67. dd sz_HeapFree,                 HeapFree
  68. dd sz_HeapReAlloc,              HeapReAlloc
  69. dd 0
  70. sz_ExitProcess              db "ExitProcess",0
  71. sz_GetStdHandle             db "GetStdHandle",0
  72. sz_SetConsoleMode           db "SetConsoleMode",0
  73. sz_WriteFile                db "WriteFile",0
  74. sz_ReadFile                 db "ReadFile",0
  75. sz_GetCommandLineA          db "GetCommandLineA",0
  76. sz_GlobalAlloc              db "GlobalAlloc",0
  77. sz_GlobalFree               db "GlobalFree",0
  78. sz_GlobalReAlloc            db "GlobalReAlloc",0
  79. sz_Sleep                    db "Sleep",0
  80. sz_FlushConsoleInputBuffer  db "FlushConsoleInputBuffer",0
  81. sz_CloseHandle              db "CloseHandle",0
  82. sz_GetFileSize              db "GetFileSize",0
  83. sz_CreateFileA              db "CreateFileA",0
  84. sz_SetFilePointer           db "SetFilePointer",0
  85. sz_VirtualAlloc             db "VirtualAlloc",0
  86. sz_VirtualFree              db "VirtualFree",0
  87. sz_SetConsoleCursorPosition db "SetConsoleCursorPosition",0
  88. sz_DeleteFileA              db "DeleteFileA",0
  89. sz_FindClose                db "FindClose",0
  90. sz_FindFirstFileA           db "FindFirstFileA",0
  91. sz_GetLocalTime             db "GetLocalTime",0
  92. sz_GetLastError             db "GetLastError",0
  93. sz_GetProcessHeap           db "GetProcessHeap",0
  94. sz_HeapAlloc                db "HeapAlloc",0
  95. sz_HeapFree                 db "HeapFree",0
  96. sz_HeapReAlloc              db "HeapReAlloc",0
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. section '.code' align 16
  106. align 16
  107. ;**********************************************************************************
  108. ExitProcess: ;/////////////////////////////////////////////////////////////////////
  109. ;**********************************************************************************
  110.         xor    eax, eax
  111.         dec    eax
  112.         int    64
  113.         ; ret not need
  114. align 16                       
  115. ;**********************************************************************************
  116. GetStdHandle: ;////////////////////////////////////////////////////////////////////
  117. ;**********************************************************************************
  118.         push   ebx
  119.         push   esi
  120.         push   edi
  121. ; if already loaded then do nothing
  122.         cmp    [console], dword 0
  123.         jne    .do_nothing
  124.  
  125.         push   sz_console
  126.         call   load.library
  127.         mov    [console], eax
  128.         mov    ecx, eax
  129.         mov    ebx, getprocaddress
  130.         push   ecx
  131.         push   sz_con_init
  132.         call   ebx
  133.         mov    [con_init], eax
  134.         push   ecx
  135.         push   sz_con_write_asciiz
  136.         call   ebx
  137.         mov    [con_write_asciiz], eax
  138.         push   ecx
  139.         push   sz_con_exit
  140.         call   ebx
  141.         mov    [con_exit], eax
  142.         push   ecx
  143.         push   sz_con_gets
  144.         call   ebx
  145.         mov    [con_gets], eax
  146.         push   ecx
  147.         push   sz_con_write_string
  148.         call   ebx
  149.         mov    [con_write_string], eax
  150.         push   ecx
  151.         push   sz_con_set_flags
  152.         call   ebx
  153.         mov    [con_set_flags], eax    
  154.         push   ecx
  155.         push   sz_con_set_cursor_pos
  156.         call   ebx
  157.         mov    [con_set_cursor_pos], eax
  158.         push   ecx
  159.         push   sz_con_printf
  160.         call   ebx
  161.         mov    [con_printf], eax
  162.                                
  163.                                 mov    eax, [28]
  164.                                 cmp    [eax], byte 34 ; quote
  165.                                 jne    .no_quote
  166.                                 inc    eax
  167. .no_quote:                             
  168.         push   eax
  169.         push   -1
  170.         push   -1
  171.         push   -1
  172.         push   -1
  173.         call   [con_init]
  174. .do_nothing:
  175.  
  176.         mov    eax, con_handle ; return pointer to console descriptor
  177.  
  178.         pop    edi
  179.         pop    esi
  180.         pop    ebx
  181.         ret    4
  182. align 16                               
  183. ;**********************************************************************************
  184. WriteFile: ;///////////////////////////////////////////////////////////////////////
  185. ;**********************************************************************************
  186. %define hFile                  [ebp +  8] ; handle to the file
  187. %define lpBuffer               [ebp + 12] ; pointer to buffer containing data
  188. %define nNumberOfBytesToWrite  [ebp + 16] ; number of bytes to be written
  189. %define lpNumberOfBytesWritten [ebp + 20] ; pointer to variable that receives number of bytes written
  190. %define lpOverlapped           [ebp + 24] ; pointer to OVERLAPPED structure
  191.                                 push   ebp
  192.                                 mov    ebp, esp
  193.         push   ebx
  194.         push   esi
  195.         push   edi
  196. ;---------
  197.         mov    eax, hFile
  198.         cmp    [eax + 8], dword "CON"
  199.         je     .con
  200.         lea    edx, [eax + 8]
  201.         push   edx ;filepath
  202.         dec    esp
  203.         mov    [esp], byte 0
  204.         push   dword lpBuffer ;buffer
  205.         push   dword nNumberOfBytesToWrite;count
  206.         push   dword 0
  207.         push   dword [eax + 4];position ;  in InternalFileInfo in libio
  208.         push   dword F70_WRITE_F
  209.         mov    ebx, esp
  210.         mov    eax, 70
  211.         int    64
  212.         add    esp, 25 ; restore stack
  213.         mov    edx, lpNumberOfBytesWritten
  214.         mov    [edx], ebx
  215.                                 mov    edx, hFile
  216.                                 add    [edx + 4], ebx
  217.         jmp    .exit
  218. .con:
  219.  
  220.         ; push    dword lpBuffer
  221.         ; call    [con_printf]
  222.         ; add     esp, 4
  223.  
  224.         push   dword nNumberOfBytesToWrite
  225.         push   dword lpBuffer
  226.         call   [con_write_string]
  227.  
  228.         ; push   dword lpBuffer
  229.         ; call   [con_write_asciiz]
  230.  
  231. .exit:
  232. ;---------
  233.         pop    edi
  234.         pop    esi
  235.         pop    ebx
  236.                                 pop    ebp
  237.         ret    20
  238. %undef hFile
  239. %undef lpBuffer
  240. %undef nNumberOfBytesToWrite
  241. %undef lpNumberOfBytesWritten
  242. %undef lpOverlapped
  243. align 16
  244. ;**********************************************************************************
  245. ReadFile: ;////////////////////////////////////////////////////////////////////////
  246. ;**********************************************************************************
  247. %define hFile                  [ebp +  8] ; handle to the file
  248. %define lpBuffer               [ebp + 12] ; pointer to buffer that receives data
  249. %define nNumberOfBytesToRead   [ebp + 16] ; maximum number of bytes to read
  250. %define lpNumberOfBytesRead    [ebp + 20] ; pointer to variable that receives number of bytes read
  251. %define lpOverlapped           [ebp + 24] ; pointer to OVERLAPPED structure
  252.                                 push   ebp
  253.                                 mov    ebp, esp
  254.         push   ebx
  255.         push   esi
  256.         push   edi
  257.                                
  258.         ; push   dword 0
  259.                                 ; call   GetStdHandle                          
  260.                                
  261. ;---------
  262.         mov    eax, hFile
  263.         cmp    [eax + 8], dword "CON"
  264.         je     .con
  265.                                
  266.  
  267.                                
  268.                                 ; lea    eax, [eax + 8]
  269.         ; push   eax
  270.         ; call   [con_write_asciiz]            
  271.                                
  272.         lea    edx, [eax + 8]
  273.         push   edx ;filepath
  274.         dec    esp
  275.         mov    [esp], byte 0
  276.         push   dword lpBuffer ;buffer
  277.         push   dword nNumberOfBytesToRead;count
  278.         push   dword 0
  279.         push   dword [eax + 4];position ;  in InternalFileInfo in libio
  280.         push   dword F70_READ_F
  281.         mov    ebx, esp
  282.         mov    eax, 70
  283.         int    64
  284.         add    esp, 25 ; restore stack
  285.         mov    edx, lpNumberOfBytesRead
  286.         mov    [edx], ebx
  287.                                 mov    edx, hFile
  288.                                 add    [edx + 4], ebx
  289.         jmp    .exit
  290. .con:
  291.         push   dword nNumberOfBytesToRead
  292.         push   dword lpBuffer
  293.         call   [con_gets]
  294. .exit:
  295. ;---------
  296.         pop    edi
  297.         pop    esi
  298.         pop    ebx
  299.         pop    ebp                             
  300.         ret    20
  301. %undef hFile
  302. %undef lpBuffer
  303. %undef nNumberOfBytesToRead
  304. %undef lpNumberOfBytesRead
  305. %undef lpOverlapped
  306. align 16
  307. ;**********************************************************************************
  308. SetConsoleMode: ;//////////////////////////////////////////////////////////////////
  309. ;**********************************************************************************
  310. ; ignore input parameters
  311.         xor    eax, eax
  312.                                 dec    eax
  313.         ret    8
  314. align 16                               
  315. ;**********************************************************************************
  316. GetCommandLineA: ;/////////////////////////////////////////////////////////////////
  317. ;**********************************************************************************
  318.         push   edi
  319.                                 mov    edi, [28]
  320.                                 xor    al, al
  321.                                 xor    ecx, ecx
  322.                                 dec    ecx
  323.                                 repne scasb
  324.                                 mov    eax, edi
  325.                                 pop    edi
  326.         ret
  327. align 16                               
  328. ;**********************************************************************************
  329. GlobalAlloc: ;/////////////////////////////////////////////////////////////////////
  330. ;**********************************************************************************
  331. %define uFlags                [esp +  4 +1*4] ; memory allocation attributes
  332. %define dwBytes               [esp +  8 +1*4] ; number of bytes to allocate
  333.         push   ebx
  334. ; uFlags ignored
  335.         mov    eax, 68
  336.         mov    ebx, 12
  337.         mov    ecx, dwBytes
  338.         int    64
  339.  
  340.         pop    ebx
  341.         ret    8
  342. %undef uFlags
  343. %undef dwBytes
  344. align 16
  345. ;**********************************************************************************
  346. GlobalFree: ;//////////////////////////////////////////////////////////////////////
  347. ;**********************************************************************************
  348. %define hMem                  [esp +  4 +1*4] ; handle to global memory object
  349.         push   ebx
  350.  
  351.         mov    eax, 68
  352.         mov    ebx, 13
  353.         mov    ecx, hMem
  354.         int    64
  355.  
  356.         pop    ebx
  357.         ret    4
  358. %undef hMem
  359. align 16
  360. ;**********************************************************************************
  361. GlobalReAlloc: ;///////////////////////////////////////////////////////////////////
  362. ;**********************************************************************************
  363. %define hMem                  [esp +  4 +1*4] ; handle to global memory object
  364. %define dwBytes               [esp +  8 +1*4] ; new size of memory block in bytes
  365. %define uFlags                [esp + 12 +1*4] ; reallocation options
  366.         push   ebx
  367. ; uFlags ignored
  368.         mov    eax, 68
  369.         mov    ebx, 20
  370.         mov    ecx, dwBytes
  371.         mov    edx, hMem
  372.         int    64
  373.  
  374.         pop    ebx
  375.         ret    12
  376. %undef hMem
  377. %undef dwBytes
  378. %undef uFlags
  379. align 16
  380. ;**********************************************************************************
  381. Sleep: ;///////////////////////////////////////////////////////////////////////////
  382. ;**********************************************************************************
  383. %define dwMilliseconds        [esp +  4 +1*4] ; time interval
  384.         push   ebx
  385.  
  386.         mov    eax, dwMilliseconds
  387.         mov    ebx, 10
  388.                                 cmp    eax, ebx
  389.                                 jae    .ae
  390.                                 add    eax, 10 ; avoid zero result if dwMilliseconds < 10
  391. .ae:                           
  392.         xor    edx, edx
  393.         div    ebx
  394.         mov    ebx, eax
  395.  
  396.         mov    eax, 5
  397.         int    64
  398.  
  399.         pop    ebx
  400.         ret    4
  401. %undef dwMilliseconds
  402. align 16
  403. ;**********************************************************************************
  404. FlushConsoleInputBuffer: ;/////////////////////////////////////////////////////////
  405. ;**********************************************************************************
  406. ; not implemented correctly
  407.         xor    eax, eax
  408.         dec    eax
  409.         ret    4
  410. align 16                               
  411. ;**********************************************************************************
  412. CloseHandle: ;/////////////////////////////////////////////////////////////////////
  413. ;**********************************************************************************
  414. %define hObject               [esp +  4 +1*4]
  415.         push   ebx
  416.         mov    eax, 68
  417.         mov    ebx, 13
  418.         mov    ecx, hObject
  419.         int    64
  420.                                 pop    ebx
  421.         ret    4
  422. %undef hObject
  423. align 16
  424. ;**********************************************************************************
  425. GetFileSize: ;/////////////////////////////////////////////////////////////////////
  426. ;**********************************************************************************
  427. %define hFile                 [esp +  4 +3*4]
  428. %define lpFileSizeHigh        [esp +  8 +3*4]
  429.         push   ebx
  430.         push   esi
  431.         push   edi
  432. ; lpFileSizeHigh ignored
  433.         mov    [esp - (25 + 40) + 0], dword F70_GETATTR_FD
  434.         mov    [esp - (25 + 40) + 8], dword 0
  435.         mov    [esp - (25 + 40) + 20], byte 0
  436.         lea    eax, [esp - 40]
  437.         mov    [esp - (25 + 40) + 16], eax
  438.         lea    ebx, [esp - (25 + 40)]
  439.         mov    eax, hFile
  440.         lea    eax, [eax + 8] ; as in InternalFileInfo in libio
  441.         mov    [esp - (25 + 40) + 21], eax
  442.         mov    eax, 70
  443.         int    64
  444.         test   eax, eax
  445.         jz     .no_error
  446.         mov    eax, INVALID_FILE_SIZE
  447.         jmp    .exit
  448. .no_error:
  449.         mov    eax, [esp - (25 + 40) + 25 + 32] ; file.size
  450. .exit:
  451.         pop    edi
  452.         pop    esi
  453.         pop    ebx
  454.         ret    8
  455. %undef hFile
  456. %undef lpFileSizeHigh
  457. align 16
  458. ;**********************************************************************************
  459. CreateFileA: ;//////////////////////////////////////////////////////////////////////
  460. ;**********************************************************************************
  461. %define lpFileName            [esp +  4 +3*4]
  462. %define dwDesiredAccess       [esp +  8 +3*4]
  463. %define dwShareMode           [esp + 12 +3*4]
  464. %define lpSecurityAttributes  [esp + 16 +3*4]
  465. %define dwCreationDisposition [esp + 20 +3*4]
  466. %define dwFlagsAndAttributes  [esp + 24 +3*4]
  467. %define hTemplateFile         [esp + 28 +3*4]
  468.         push   ebx
  469.         push   esi
  470.         push   edi
  471. ;---------
  472.  
  473.         ; push   dword 0
  474.                                 ; call   GetStdHandle
  475.                                
  476.         ; push   dword lpFileName
  477.         ; call   [con_write_asciiz]            
  478.  
  479.  
  480.  
  481.         mov    eax, 68
  482.         mov    ebx, 12
  483.         mov    ecx, 4096
  484.         int    64
  485.  
  486.         mov    edx, eax
  487.  
  488.         lea     edi, [eax + 8] ; as in InternalFileInfo in libio
  489.         mov     esi, lpFileName
  490. .copy_name:
  491.         lodsb
  492.         stosb
  493.         test   al, al
  494.         jnz    .copy_name
  495.        
  496.                                 mov    eax, dwCreationDisposition
  497.         cmp    eax, CREATE_ALWAYS
  498.                                 je     .create_always
  499.         cmp    eax, OPEN_EXISTING
  500.                                 je     .open_existing
  501.                                 mov    eax, INVALID_HANDLE_VALUE
  502.                                 jmp    .exit
  503. .open_existing:
  504.         lea    eax, [edx + 8]
  505.         push   eax ;filepath
  506.         dec    esp
  507.         mov    [esp], byte 0
  508.         push   dword 0 ; buffer
  509.         push   dword 0 ; count
  510.         push   dword 0
  511.         push   dword 0
  512.         push   dword F70_READ_F
  513.         mov    ebx, esp
  514.         mov    eax, 70
  515.         int    64
  516.         add    esp, 25 ; restore stack
  517.                                 test   eax, eax
  518.                                 jz     .no_error
  519.                                 mov    eax, INVALID_HANDLE_VALUE
  520.                                 jmp    .exit
  521. .no_error:                             
  522.         mov    eax, edx ; return pointer to file descriptor
  523.         jmp    .exit
  524. .create_always:
  525.         lea    eax, [edx + 8]
  526.         push   eax ;filepath
  527.         dec    esp
  528.         mov    [esp], byte 0
  529.         push   dword 0 ; buffer
  530.         push   dword 0 ; count
  531.         push   dword 0
  532.         push   dword 0
  533.         push   dword F70_CREATE_F
  534.         mov    ebx, esp
  535.         mov    eax, 70
  536.         int    64
  537.         add    esp, 25 ; restore stack
  538.         mov    eax, edx ; return pointer to file descriptor
  539.                                 jmp    .exit
  540.                                
  541. .exit:                         
  542. ;---------
  543.         pop    edi
  544.         pop    esi
  545.         pop    ebx
  546.         ret    28
  547. %undef lpFileName
  548. %undef dwDesiredAccess
  549. %undef dwShareMode
  550. %undef lpSecurityAttributes
  551. %undef dwCreationDisposition
  552. %undef dwFlagsAndAttributes
  553. %undef hTemplateFile
  554. align 16
  555. ;**********************************************************************************
  556. SetFilePointer: ;//////////////////////////////////////////////////////////////////
  557. ;**********************************************************************************
  558. %define hFile                 [esp +  4 +3*4]
  559. %define lDistanceToMove       [esp +  8 +3*4]
  560. %define lpDistanceToMoveHigh  [esp + 12 +3*4]
  561. %define dwMoveMethod          [esp + 16 +3*4]
  562.         push   ebx
  563.         push   esi
  564.         push   edi
  565. ;---------
  566.         mov    eax, hFile
  567.                                 cmp    dwMoveMethod, dword FILE_BEGIN
  568.                                 je     .FILE_BEGIN
  569.                                 cmp    dwMoveMethod, dword FILE_CURRENT
  570.                                 je     .FILE_CURRENT
  571.                                 jmp    .FILE_END
  572. .FILE_BEGIN:
  573.                                 mov    edx, lDistanceToMove
  574.                                 mov    [eax + 4], edx
  575.                                 jmp    .exit
  576. .FILE_CURRENT:
  577.                                 mov    edx, lDistanceToMove
  578.                                 add    [eax + 4], edx
  579.                                 jmp    .exit
  580. .FILE_END:
  581.                                 push   dword 0
  582.                                 push   eax
  583.                                 call   GetFileSize
  584.                                 mov    edx, eax
  585.                                
  586.                                 mov    eax, hFile
  587.                                 mov    [eax + 4], edx
  588.                                 mov    edx, lDistanceToMove
  589.                                 add    [eax + 4], edx
  590. .exit:
  591.         mov    eax, [eax + 4]
  592. ;---------
  593.         pop    edi
  594.         pop    esi
  595.         pop    ebx
  596.         ret    16
  597. %undef hFile
  598. %undef lDistanceToMove
  599. %undef lpDistanceToMoveHigh
  600. %undef dwMoveMethod
  601. align 16                               
  602. ;**********************************************************************************
  603. VirtualAlloc: ;////////////////////////////////////////////////////////////////////
  604. ;**********************************************************************************
  605. %define lpAddress             [esp +  4 +1*4]
  606. %define dwSize                [esp +  8 +1*4]
  607. %define flAllocationType      [esp + 12 +1*4]
  608. %define flProtect             [esp + 16 +1*4]
  609.         push   ebx
  610.  
  611.         mov    eax, 68
  612.         mov    ebx, 12
  613.         mov    ecx, dwSize
  614.         int    64
  615.  
  616.         pop    ebx
  617.         ret    16
  618. %undef lpAddress
  619. %undef dwSize
  620. %undef flAllocationType
  621. %undef flProtect
  622. align 16
  623. ;**********************************************************************************
  624. VirtualFree: ;/////////////////////////////////////////////////////////////////////
  625. ;**********************************************************************************
  626. %define lpAddress             [esp +  4 +1*4]
  627. %define dwSize                [esp +  8 +1*4]
  628. %define dwFreeType            [esp + 12 +1*4]
  629.         push   ebx
  630.  
  631.         mov    eax, 68
  632.         mov    ebx, 13
  633.         mov    ecx, lpAddress
  634.         int    64
  635.  
  636.         pop    ebx
  637.         ret    12
  638. %undef lpAddress
  639. %undef dwSize
  640. %undef dwFreeType
  641. align 16
  642. ;**********************************************************************************
  643. SetConsoleCursorPosition: ;////////////////////////////////////////////////////////
  644. ;**********************************************************************************
  645. %define hConsoleOutput        [esp +  4 +3*4]
  646. %define dwCursorPosition      [esp +  8 +3*4]
  647.         push   ebx
  648.         push   esi
  649.         push   edi
  650.        
  651.                                 mov    edx, dwCursorPosition
  652.                                 shld   eax, edx, 16
  653.                                 shr    edx, 16
  654.                                
  655.                                 push   eax
  656.                                 push   edx
  657.         call   [con_set_cursor_pos]
  658.  
  659.         pop    edi
  660.         pop    esi
  661.         pop    ebx
  662.         ret    8
  663. %undef hConsoleOutput
  664. %undef dwCursorPosition
  665. align 16
  666. ;**********************************************************************************
  667. DeleteFileA: ;/////////////////////////////////////////////////////////////////////
  668. ;**********************************************************************************
  669. %define lpFileName            [esp +  4 +1*4] ; name of file
  670.         push   ebx
  671.                                
  672.         mov    [esp - (25 + 40) + 0], dword F70_DELETE_FD
  673.         mov    [esp - (25 + 40) + 8], dword 0
  674.         mov    [esp - (25 + 40) + 20], byte 0
  675.         lea    eax, [esp - 40]
  676.         mov    [esp - (25 + 40) + 16], eax
  677.         lea    ebx, [esp - (25 + 40)]
  678.         mov    eax, lpFileName
  679.         mov    [esp - (25 + 40) + 21], eax
  680.         mov    eax, 70
  681.         int    64
  682.                                
  683.                                 pop    ebx
  684.         ret    4
  685. %undef lpFileName
  686. align 16                               
  687. ;**********************************************************************************
  688. FindClose: ;///////////////////////////////////////////////////////////////////////
  689. ;**********************************************************************************
  690. %define hFindFile             [esp +  4 +1*4] ; file search handle
  691.  
  692.         ret    4
  693. %undef hFindFile
  694. align 16
  695. ;**********************************************************************************
  696. FindFirstFileA: ;//////////////////////////////////////////////////////////////////
  697. ;**********************************************************************************
  698. %define lpFileName            [esp +  4 +3*4] ; name of file
  699. %define lpFindFileData        [esp +  8 +3*4] ; pointer to WIN32_FIND_DATA structure
  700.         push   ebx
  701.         push   esi
  702.         push   edi
  703.  
  704.         pop    edi
  705.         pop    esi
  706.         pop    ebx
  707.         ret    8
  708. %undef lpFileName
  709. %undef lpFindFileData
  710. align 16                               
  711. ;**********************************************************************************
  712. GetLocalTime: ;///////////////////////////////////////////////////////////////////////
  713. ;**********************************************************************************
  714. %define lpSystemTime             [esp +  4] ; pointer to SYSTEMTIME structure
  715. ; yet not implemented
  716.         ; mov    eax, lpSystemTime
  717.                                 ; mov    [eax + 0],  dword 12345678H
  718.                                 ; mov    [eax + 4],  dword 12345678H
  719.                                 ; mov    [eax + 8],  dword 12345678H
  720.                                 ; mov    [eax + 12], dword 12345678H                           
  721.         ; MSDN: This function does not return a value.
  722.         ret    4
  723. %undef lpSystemTime
  724. align 16                               
  725. ;**********************************************************************************
  726. GetLastError: ;////////////////////////////////////////////////////////////////////
  727. ;**********************************************************************************
  728.         xor    eax, eax
  729.         ret
  730. align 16                               
  731. ;**********************************************************************************
  732. GetProcessHeap: ;////////////////////////////////////////////////////////////////////
  733. ;**********************************************************************************
  734.         xor    eax, eax
  735.                                 dec    eax
  736.         ret
  737. align 16                               
  738. ;**********************************************************************************
  739. HeapAlloc: ;///////////////////////////////////////////////////////////////////////
  740. ;**********************************************************************************
  741. %define hHeap                 [esp +  4 +1*4]
  742. %define dwFlags               [esp +  8 +1*4]
  743. %define dwBytes               [esp + 12 +1*4]
  744.         push   ebx
  745.  
  746.         mov    eax, 68
  747.         mov    ebx, 12
  748.         mov    ecx, dwBytes
  749.         int    64
  750.  
  751.         pop    ebx
  752.         ret    12
  753. %undef hHeap                           
  754. %undef dwFlags
  755. %undef dwBytes
  756. align 16
  757. ;**********************************************************************************
  758. HeapFree: ;////////////////////////////////////////////////////////////////////////
  759. ;**********************************************************************************
  760. %define hHeap                 [esp +  4 +1*4]
  761. %define dwFlags               [esp +  8 +1*4]
  762. %define lpMem                 [esp + 12 +1*4]
  763.         push   ebx
  764.  
  765.         mov    eax, 68
  766.         mov    ebx, 13
  767.         mov    ecx, lpMem
  768.         int    64
  769.  
  770.         pop    ebx
  771.         ret    12
  772. %undef hHeap                           
  773. %undef dwFlags
  774. %undef lpMem
  775. align 16
  776. ;**********************************************************************************
  777. HeapReAlloc: ;/////////////////////////////////////////////////////////////////////
  778. ;**********************************************************************************
  779. %define hHeap                 [esp +  4 +1*4]
  780. %define dwFlags               [esp +  8 +1*4]
  781. %define lpMem                 [esp + 12 +1*4]
  782. %define dwBytes               [esp + 16 +1*4]
  783.         push   ebx
  784.  
  785.         mov    eax, 68
  786.         mov    ebx, 20
  787.         mov    ecx, dwBytes
  788.         mov    edx, lpMem
  789.         int    64
  790.  
  791.         pop    ebx
  792.         ret    16
  793. %undef hHeap
  794. %undef dwFlags
  795. %undef lpMem
  796. %undef dwBytes
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803. ; ------------------------------------------------------------- ;
  804. load.library:
  805.         mov    eax, 68
  806.         mov    ebx, 19
  807.         mov    ecx, [esp + 4]
  808.         int    64
  809.         ret    4
  810. ; ------------------------------------------------------------- ;
  811. getprocaddress:
  812.         mov    edx, [esp + 8]
  813.         xor    eax, eax
  814.         test   edx, edx
  815.         jz     .end
  816. .next:
  817.         xor    eax, eax
  818.         cmp    [edx], dword 0
  819.         jz     .end
  820.         mov    esi, [edx]
  821.         mov    edi, [esp + 4]
  822. .next_:
  823.         lodsb
  824.         scasb
  825.         jne    .fail
  826.         or     al, al
  827.         jnz    .next_
  828.         jmp    .ok
  829. .fail:
  830.         add    edx, 8
  831.         jmp    .next
  832. .ok:
  833.         mov    eax, [edx + 4]
  834. .end:
  835.         ret    8
  836. ; ------------------------------------------------------------- ;
  837.  
  838.  
  839.  
  840.  
  841.  
  842. section '.data' align 16
  843.  
  844. con_init              dd 0
  845. con_write_asciiz      dd 0
  846. con_exit              dd 0
  847. con_gets              dd 0
  848. con_write_string      dd 0
  849. con_set_flags         dd 0
  850. con_set_cursor_pos    dd 0
  851. con_printf            dd 0
  852. console               dd 0
  853. sz_con_init           db "con_init",0
  854. sz_con_write_asciiz   db "con_write_asciiz",0
  855. sz_con_exit           db "con_exit",0
  856. sz_con_gets           db "con_gets",0
  857. sz_con_write_string   db "con_write_string",0
  858. sz_console            db "/sys/lib/console.obj",0
  859. sz_con_set_flags      db "con_set_flags",0
  860. sz_con_set_cursor_pos db "con_set_cursor_pos",0
  861. sz_con_printf         db "con_printf",0
  862.  
  863. con_handle:
  864. dd 0
  865. dd 0
  866. dd "CON"
  867.  
  868.  
  869.