2022-01-24 18:43:00 +01:00
|
|
|
|
;
|
|
|
|
|
; 2021, Edited by Coldy
|
|
|
|
|
;
|
|
|
|
|
; This module same as original crt0.asm, but cut:
|
|
|
|
|
; 1. virtual header block (hparams change to __app_params, hpath change to __app_path)
|
|
|
|
|
; 2. init heap of memory - not needed because 68.18 (68.19) init heap implicitly
|
|
|
|
|
; (it is does dll.obj)
|
|
|
|
|
; 3. loader (he lives in dll.obj)
|
|
|
|
|
;
|
|
|
|
|
|
2021-04-27 18:33:31 +02:00
|
|
|
|
format ELF
|
|
|
|
|
section '.text' executable
|
|
|
|
|
public start
|
|
|
|
|
public start as '_start'
|
2022-01-24 18:43:00 +01:00
|
|
|
|
|
2021-04-27 18:33:31 +02:00
|
|
|
|
extrn main
|
|
|
|
|
|
2022-01-24 18:43:00 +01:00
|
|
|
|
include '../../../../../../proc32.inc'
|
|
|
|
|
include '../../../../../../macros.inc'
|
|
|
|
|
__DEBUG__ = 0
|
|
|
|
|
|
|
|
|
|
__app_params equ 0x1C ; Pointer to program arguments
|
|
|
|
|
;__app_path equ 0x20 ; Pointer to program path
|
2021-04-27 18:33:31 +02:00
|
|
|
|
|
|
|
|
|
start:
|
|
|
|
|
;DEBUGF 'Start programm\n'
|
|
|
|
|
|
|
|
|
|
mov [argc], 0
|
2022-01-24 18:43:00 +01:00
|
|
|
|
mov eax, [__app_params]
|
2021-04-27 18:33:31 +02:00
|
|
|
|
test eax, eax
|
2022-01-24 18:43:00 +01:00
|
|
|
|
jz .without_path
|
2021-04-27 18:33:31 +02:00
|
|
|
|
mov eax, path
|
2022-01-24 18:43:00 +01:00
|
|
|
|
cmp word ptr eax, 32fh ; '/#3' UTF8
|
2021-04-27 18:33:31 +02:00
|
|
|
|
jne .without_path
|
|
|
|
|
mov word ptr eax, 12fh ; '/#1' fix to CP866
|
|
|
|
|
.without_path:
|
|
|
|
|
mov esi, eax
|
|
|
|
|
call push_param
|
|
|
|
|
; retrieving parameters
|
|
|
|
|
mov esi, params
|
|
|
|
|
xor edx, edx ; dl - <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(1) <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(0)
|
2022-01-24 18:43:00 +01:00
|
|
|
|
; dh - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
2021-04-27 18:33:31 +02:00
|
|
|
|
mov ecx, 1 ; cl = 1
|
2022-01-24 18:43:00 +01:00
|
|
|
|
; ch = 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
2021-04-27 18:33:31 +02:00
|
|
|
|
.parse:
|
|
|
|
|
lodsb
|
|
|
|
|
test al, al
|
2022-01-24 18:43:00 +01:00
|
|
|
|
jz .run
|
2021-04-27 18:33:31 +02:00
|
|
|
|
test dl, dl
|
|
|
|
|
jnz .findendparam
|
2022-01-24 18:43:00 +01:00
|
|
|
|
;{<7B><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2021-04-27 18:33:31 +02:00
|
|
|
|
cmp al, ' '
|
2022-01-24 18:43:00 +01:00
|
|
|
|
jz .parse ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2021-04-27 18:33:31 +02:00
|
|
|
|
mov dl, cl ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
cmp al, '"'
|
2022-01-24 18:43:00 +01:00
|
|
|
|
jz @f ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2021-04-27 18:33:31 +02:00
|
|
|
|
mov dh, ch ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
dec esi
|
|
|
|
|
call push_param
|
|
|
|
|
inc esi
|
|
|
|
|
jmp .parse
|
|
|
|
|
|
|
|
|
|
@@:
|
|
|
|
|
mov dh, cl ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
call push_param ;<3B><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
jmp .parse ;<3B><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}
|
|
|
|
|
|
|
|
|
|
.findendparam:
|
|
|
|
|
test dh, dh
|
2022-01-24 18:43:00 +01:00
|
|
|
|
jz @f ; <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2021-04-27 18:33:31 +02:00
|
|
|
|
cmp al, '"'
|
2022-01-24 18:43:00 +01:00
|
|
|
|
jz .clear
|
2021-04-27 18:33:31 +02:00
|
|
|
|
jmp .parse
|
|
|
|
|
@@:
|
|
|
|
|
cmp al, ' '
|
|
|
|
|
jnz .parse
|
|
|
|
|
|
|
|
|
|
.clear:
|
|
|
|
|
lea ebx, [esi - 1]
|
|
|
|
|
mov [ebx], ch
|
|
|
|
|
mov dl, ch
|
|
|
|
|
jmp .parse
|
|
|
|
|
|
|
|
|
|
.run:
|
|
|
|
|
push argv
|
|
|
|
|
push [argc]
|
|
|
|
|
call main
|
|
|
|
|
.exit:
|
|
|
|
|
xor eax,eax
|
|
|
|
|
dec eax
|
|
|
|
|
int 0x40
|
2022-01-24 18:43:00 +01:00
|
|
|
|
dd -1
|
2021-04-27 18:33:31 +02:00
|
|
|
|
.crash:
|
|
|
|
|
jmp .exit
|
|
|
|
|
;============================
|
|
|
|
|
push_param:
|
|
|
|
|
;============================
|
|
|
|
|
;parameters
|
|
|
|
|
; esi - pointer
|
|
|
|
|
;description
|
|
|
|
|
; procedure increase argc
|
|
|
|
|
; and add pointer to array argv
|
|
|
|
|
; procedure changes ebx
|
|
|
|
|
mov ebx, [argc]
|
|
|
|
|
cmp ebx, max_parameters
|
|
|
|
|
jae .dont_add
|
|
|
|
|
mov [argv+4*ebx], esi
|
|
|
|
|
inc [argc]
|
|
|
|
|
.dont_add:
|
|
|
|
|
ret
|
2022-01-24 18:43:00 +01:00
|
|
|
|
|
|
|
|
|
|
2021-04-27 18:33:31 +02:00
|
|
|
|
;==============================
|
|
|
|
|
public argc as '__argc'
|
|
|
|
|
public params as '__argv'
|
|
|
|
|
public path as '__path'
|
|
|
|
|
|
|
|
|
|
section '.bss'
|
|
|
|
|
buf_len = 0x400
|
|
|
|
|
max_parameters=0x20
|
2022-01-24 18:43:00 +01:00
|
|
|
|
argc rd 1
|
|
|
|
|
argv rd max_parameters
|
|
|
|
|
path rb buf_len
|
|
|
|
|
params rb buf_len
|
2021-04-27 18:33:31 +02:00
|
|
|
|
|
2022-01-24 18:43:00 +01:00
|
|
|
|
;section '.data'
|
|
|
|
|
;include_debug_strings ; ALWAYS present in data section
|