Rev 6574 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
145 | halyavin | 1 | format ELF |
2 | section '.text' executable |
||
3 | public start |
||
6424 | siemargl | 4 | public start as '_start' |
5 | ;extrn mf_init |
||
145 | halyavin | 6 | extrn main |
6424 | siemargl | 7 | ;include 'debug2.inc' |
8 | __DEBUG__=0 |
||
215 | victor | 9 | |
6424 | siemargl | 10 | ;start_: |
145 | halyavin | 11 | virtual at 0 |
215 | victor | 12 | db 'MENUET01' ; 1. Magic number (8 bytes) |
13 | dd 0x01 ; 2. Version of executable file |
||
6424 | siemargl | 14 | dd start ; 3. Start address |
215 | victor | 15 | dd 0x0 ; 4. Size of image |
16 | dd 0x100000 ; 5. Size of needed memory |
||
17 | dd 0x100000 ; 6. Pointer to stack |
||
18 | hparams dd 0x0 ; 7. Pointer to program arguments |
||
19 | hpath dd 0x0 ; 8. Pointer to program path |
||
145 | halyavin | 20 | end virtual |
6424 | siemargl | 21 | |
145 | halyavin | 22 | start: |
6424 | siemargl | 23 | ;DEBUGF 'Start programm\n' |
24 | ;init heap of memory |
||
25 | mov eax,68 |
||
26 | mov ebx,11 |
||
27 | int 0x40 |
||
28 | |||
29 | ;DEBUGF ' path "%s"\n params "%s"\n', .path, .params |
||
145 | halyavin | 30 | ; check for overflow |
6443 | siemargl | 31 | ;; that not work |
32 | ; mov al, [path+buf_len-1] |
||
33 | ; or al, [params+buf_len-1] |
||
34 | ; jnz .crash |
||
145 | halyavin | 35 | ; check if path written by OS |
6574 | siemargl | 36 | mov [argc], 0 |
145 | halyavin | 37 | mov eax, [hparams] |
38 | test eax, eax |
||
215 | victor | 39 | jz .without_path |
145 | halyavin | 40 | mov eax, path |
7520 | siemargl | 41 | cmp word ptr eax, 32fh ; '/#3' UTF8 |
42 | jne .without_path |
||
43 | mov word ptr eax, 12fh ; '/#1' fix to CP866 |
||
145 | halyavin | 44 | .without_path: |
45 | mov esi, eax |
||
46 | call push_param |
||
47 | ; retrieving parameters |
||
48 | mov esi, params |
||
49 | xor edx, edx ; dl - идёт параметр(1) или разделители(0) |
||
215 | victor | 50 | ; dh - символ с которого начался параметр (1 кавычки, 0 остальное) |
145 | halyavin | 51 | mov ecx, 1 ; cl = 1 |
215 | victor | 52 | ; ch = 0 просто ноль |
145 | halyavin | 53 | .parse: |
54 | lodsb |
||
55 | test al, al |
||
215 | victor | 56 | jz .run |
145 | halyavin | 57 | test dl, dl |
58 | jnz .findendparam |
||
215 | victor | 59 | ;{если был разделитель |
145 | halyavin | 60 | cmp al, ' ' |
215 | victor | 61 | jz .parse ;загружен пробел, грузим следующий символ |
145 | halyavin | 62 | mov dl, cl ;начинается параметр |
63 | cmp al, '"' |
||
215 | victor | 64 | jz @f ;загружены кавычки |
145 | halyavin | 65 | mov dh, ch ;параметр без кавычек |
66 | dec esi |
||
67 | call push_param |
||
68 | inc esi |
||
69 | jmp .parse |
||
70 | |||
71 | @@: |
||
72 | mov dh, cl ;параметр в кавычеках |
||
73 | call push_param ;если не пробел значит начинается какой то параметр |
||
74 | jmp .parse ;если был разделитель} |
||
75 | |||
76 | .findendparam: |
||
77 | test dh, dh |
||
215 | victor | 78 | jz @f ; без кавычек |
145 | halyavin | 79 | cmp al, '"' |
215 | victor | 80 | jz .clear |
145 | halyavin | 81 | jmp .parse |
82 | @@: |
||
83 | cmp al, ' ' |
||
84 | jnz .parse |
||
85 | |||
86 | .clear: |
||
87 | lea ebx, [esi - 1] |
||
88 | mov [ebx], ch |
||
89 | mov dl, ch |
||
90 | jmp .parse |
||
91 | |||
92 | .run: |
||
6424 | siemargl | 93 | ;DEBUGF 'call main(%x, %x) with params:\n', [argc], argv |
145 | halyavin | 94 | if __DEBUG__ = 1 |
95 | mov ecx, [argc] |
||
96 | @@: |
||
97 | lea esi, [ecx * 4 + argv-4] |
||
6424 | siemargl | 98 | DEBUGF '0x%x) "%s"\n', cx, [esi] |
145 | halyavin | 99 | loop @b |
100 | end if |
||
215 | victor | 101 | push argv |
145 | halyavin | 102 | push [argc] |
103 | call main |
||
104 | .exit: |
||
6424 | siemargl | 105 | ;DEBUGF 'Exit from prog\n'; |
145 | halyavin | 106 | xor eax,eax |
107 | dec eax |
||
108 | int 0x40 |
||
215 | victor | 109 | dd -1 |
145 | halyavin | 110 | .crash: |
6424 | siemargl | 111 | ;DEBUGF 'E:buffer overflowed\n' |
145 | halyavin | 112 | jmp .exit |
113 | ;============================ |
||
114 | push_param: |
||
115 | ;============================ |
||
116 | ;parameters |
||
117 | ; esi - pointer |
||
118 | ;description |
||
119 | ; procedure increase argc |
||
120 | ; and add pointer to array argv |
||
121 | ; procedure changes ebx |
||
122 | mov ebx, [argc] |
||
123 | cmp ebx, max_parameters |
||
124 | jae .dont_add |
||
125 | mov [argv+4*ebx], esi |
||
126 | inc [argc] |
||
127 | .dont_add: |
||
128 | ret |
||
129 | ;============================== |
||
6424 | siemargl | 130 | public argc as '__argc' |
145 | halyavin | 131 | public params as '__argv' |
132 | public path as '__path' |
||
133 | |||
6443 | siemargl | 134 | section '.bss' |
145 | halyavin | 135 | buf_len = 0x400 |
136 | max_parameters=0x20 |
||
215 | victor | 137 | argc rd 1 |
138 | argv rd max_parameters |
||
6443 | siemargl | 139 | path rb buf_len |
140 | params rb buf_len |
||
145 | halyavin | 141 | |
6424 | siemargl | 142 | ;section '.data' |
7520 | siemargl | 143 | ;include_debug_strings ; ALWAYS present in data section |