1 ; ------------------------------------------------------------- ;
2 ; KWINE is a fork of program PELoad written by 0CodErr
3 ; author of fork - rgimad
4 ; ------------------------------------------------------------- ;
7 ; ------------------------------------------------------------- ;
11 END_
equ IMAGE_BASE
- (PATH_SIZE
+ PARAMS_SIZE
+ STACK_SIZE
)
12 ; ------------------------------------------------------------- ;
13 IMAGE_BASE
equ 400000H
14 ; ------------------------------------------------------------- ;
15 MENUET01
db 'MENUET01'
17 program.start
dd start_
19 program.memory
dd END_
+ PATH_SIZE
+ PARAMS_SIZE
+ STACK_SIZE
20 program.stack
dd END_
+ PATH_SIZE
+ PARAMS_SIZE
+ STACK_SIZE
21 program.params
dd END_
+ PATH_SIZE
23 ; ------------------------------------------------------------- ;
30 ; ------------------------------------------------------------- ;
56 ; ------------------------------------------------------------- ;
63 ; ------------------------------------------------------------- ;
64 set.current.
directory:
70 ; ------------------------------------------------------------- ;
73 %define number
[esp + 8 + 8 * 4]
74 %define buffer
[esp + 4 + 8 * 4]
77 mov eax, " " ; 4 spaces
90 add edx, 48 ; edx = (eax MOD ecx) + 48
100 ; ------------------------------------------------------------- ;
101 ; test_file_path db "/hd3/1/mntest.exe",0
119 ; ------------------------------------------------------------- ;
120 sz_pe_load
db "KWINE",0
121 ; ------------------------------------------------------------- ;
123 con_write_asciiz
dd 0
126 sz_con_init
db "con_init",0
127 sz_con_write_asciiz
db "con_write_asciiz",0
128 sz_con_exit
db "con_exit",0
129 sz_console
db "/sys/lib/console.obj",0
130 ; ------------------------------------------------------------- ;
134 NumberOfSections
dd 0
135 SizeOfOptionalHeader
dd 0
142 ; ------------------------------------------------------------- ;
144 err_params
db "Parameters error",0
145 err_file_path
db "No input file path",0
146 err_read_file
db "Read file error",0
147 err_mz_not_found
db "No DOS signature found",0
148 err_pe_not_found
db "No PE signature found",0
149 err_load_library
db "Error load library: ",0
150 err_func_not_found
db "Not found function: ",0
152 ; ------------------------------------------------------------- ;
157 sz_space_colon_space
db " : ",0
163 ; ------------------------------------------------------------- ;
164 ; find params and file path
165 ; mov eax, test_file_path
166 mov eax, [program.params
]
167 cmp [eax], byte 34 ; quote
174 cmp [edi], byte 34 ; quote
177 jmp .find_quote_or_zero
183 cmp [edi], byte 32 ; space
186 jmp .find_space_or_zero
195 mov [ERROR_MESSAGE
], dword err_file_path
198 ; check MZ signature (IMAGE_DOS_HEADER.e_magic)
199 push dword [file_path
];filepath
205 push dword 0;position
212 mov [ERROR_MESSAGE
], dword err_read_file
217 mov [ERROR_MESSAGE
], dword err_mz_not_found
220 ; get lfa_new (IMAGE_DOS_HEADER.e_lfanew)
221 push dword [file_path
];filepath
224 push dword lfa_new
;buffer
227 push dword 60;position
232 ; check PE signature (IMAGE_OPTIONAL_HEADER.Magic)
233 push dword [file_path
];filepath
239 push dword [lfa_new
];position
246 mov [ERROR_MESSAGE
], dword err_pe_not_found
249 ; get size of headers (IMAGE_OPTIONAL_HEADER.SizeOfHeaders)
250 push dword [file_path
];filepath
253 push dword SizeOfHeaders
;buffer
263 ; resize app memory and load headers
265 add eax, [SizeOfHeaders
]
269 push dword [file_path
];filepath
272 push dword IMAGE_BASE
;buffer
273 push dword [SizeOfHeaders
];count
275 push dword 0;position
281 add esp, (25 * 5) ; restore our stack top
284 ; get SizeOfImage (IMAGE_OPTIONAL_HEADER.SizeOfImage)
285 mov eax, [IMAGE_BASE
+ edx + 80]
286 mov [SizeOfImage
], eax
287 ; get EntryPoint (IMAGE_OPTIONAL_HEADER.AddressOfEntryPoint)
288 mov eax, [IMAGE_BASE
+ edx + 40]
289 mov [EntryPoint
], eax
290 ; get DataDirectories (IMAGE_OPTIONAL_HEADER.DataDirectory)
292 mov [DataDirectories
], eax
293 ; get SizeOfOptionalHeader (IMAGE_FILE_HEADER.SizeOfOptionalHeader)
294 movzx eax, word [IMAGE_BASE
+ edx + 20]
295 mov [SizeOfOptionalHeader
], ax
298 add ax, [SizeOfOptionalHeader
]
299 mov [SectionsTable
], eax
302 add eax, [DataDirectories
]
306 ; get NumberOfSections (IMAGE_FILE_HEADER.NumberOfSections)
307 movzx eax, word [IMAGE_BASE
+ edx + 6]
308 mov [NumberOfSections
], eax
309 ; resize app memory and load sections to their virtual address
311 add eax, [SizeOfImage
]
315 mov ecx, [NumberOfSections
]
318 lea eax, [eax * 4 + eax]
321 add eax, [SectionsTable
]
323 push dword [file_path
] ; filepath
328 push edx ; buffer (IMAGE_SECTION_HEADER.VirtualAddress)
329 push dword [eax + 16] ; count (IMAGE_SECTION_HEADER.SizeOfRawData)
331 push dword [eax + 20] ; position (IMAGE_SECTION_HEADER.PointerToRawData)
340 mov eax, [NumberOfSections
]
341 lea eax, [eax * 4 + eax]
342 lea eax, [eax * 4 + eax]
343 add esp, eax ; restore our stack top
348 ; ==========================================================
354 mov ebx, getprocaddress
360 push sz_con_write_asciiz
362 mov [con_write_asciiz
], eax
374 mov ecx, [NumberOfSections
]
377 lea eax, [eax * 4 + eax]
380 add eax, [SectionsTable
]
384 call [con_write_asciiz
]
385 push sz_space_colon_space
386 call [con_write_asciiz
]
396 call [con_write_asciiz
]
399 call [con_write_asciiz
]
405 ; ==============================================
406 ; program.path = program.path_without_filename & "lib/"
407 mov edi, [program.path
]
425 lea eax, [ecx * 4 + ecx]
435 call [con_write_asciiz
]
437 call [con_write_asciiz
]
442 ; concatenate (program.path_without_filename & "lib/") & lib_name
450 ; try to load library
451 push dword [program.path
]
455 ; concatenate "Error load library: " & lib_name
458 mov edi, err_load_library
469 mov [ERROR_MESSAGE
], dword err_load_library
477 lea esi, [edx + ebx * 4 + IMAGE_BASE
]
489 call [con_write_asciiz
]
491 call [con_write_asciiz
]
497 ; look for address of imported function
504 ; concatenate "Not found function: " & name of function
505 mov edi, err_func_not_found
529 mov [ERROR_MESSAGE
], dword err_func_not_found
540 lea eax, [ecx * 4 + ecx]
549 ; set.current.directory
559 mov [edi + 1], byte 0
560 push dword [file_path
]
561 call set.current.directory
562 mov [edi + 1], byte "/" ; restore full file_path
564 ; ---------------------- ;
565 ; call load_console_lib ;
566 ; ---------------------- ;
569 mov eax, [EntryPoint
]
574 ; push dword [EntryPoint]
578 ; call [con_write_asciiz]
586 ; dump ---------------------------------------
587 push dword dump_path
;filepath
592 add eax, [SizeOfImage
]
595 push dword 0;position
606 dump_path
db "/hd3/1/dump.bin",0
608 ; ==========================================================
617 mov ebx, getprocaddress
623 push sz_con_write_asciiz
625 mov [con_write_asciiz
], eax
637 push dword [ERROR_MESSAGE
]
638 call [con_write_asciiz
]
654 ; call getprocaddress
655 ; mov [con_init], eax