Rev 6443 | 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 |
41 | .without_path: |
||
42 | mov esi, eax |
||
43 | call push_param |
||
44 | ; retrieving parameters |
||
45 | mov esi, params |
||
46 | xor edx, edx ; dl - идёт параметр(1) или разделители(0) |
||
215 | victor | 47 | ; dh - символ с которого начался параметр (1 кавычки, 0 остальное) |
145 | halyavin | 48 | mov ecx, 1 ; cl = 1 |
215 | victor | 49 | ; ch = 0 просто ноль |
145 | halyavin | 50 | .parse: |
51 | lodsb |
||
52 | test al, al |
||
215 | victor | 53 | jz .run |
145 | halyavin | 54 | test dl, dl |
55 | jnz .findendparam |
||
215 | victor | 56 | ;{если был разделитель |
145 | halyavin | 57 | cmp al, ' ' |
215 | victor | 58 | jz .parse ;загружен пробел, грузим следующий символ |
145 | halyavin | 59 | mov dl, cl ;начинается параметр |
60 | cmp al, '"' |
||
215 | victor | 61 | jz @f ;загружены кавычки |
145 | halyavin | 62 | mov dh, ch ;параметр без кавычек |
63 | dec esi |
||
64 | call push_param |
||
65 | inc esi |
||
66 | jmp .parse |
||
67 | |||
68 | @@: |
||
69 | mov dh, cl ;параметр в кавычеках |
||
70 | call push_param ;если не пробел значит начинается какой то параметр |
||
71 | jmp .parse ;если был разделитель} |
||
72 | |||
73 | .findendparam: |
||
74 | test dh, dh |
||
215 | victor | 75 | jz @f ; без кавычек |
145 | halyavin | 76 | cmp al, '"' |
215 | victor | 77 | jz .clear |
145 | halyavin | 78 | jmp .parse |
79 | @@: |
||
80 | cmp al, ' ' |
||
81 | jnz .parse |
||
82 | |||
83 | .clear: |
||
84 | lea ebx, [esi - 1] |
||
85 | mov [ebx], ch |
||
86 | mov dl, ch |
||
87 | jmp .parse |
||
88 | |||
89 | .run: |
||
6424 | siemargl | 90 | ;DEBUGF 'call main(%x, %x) with params:\n', [argc], argv |
145 | halyavin | 91 | if __DEBUG__ = 1 |
92 | mov ecx, [argc] |
||
93 | @@: |
||
94 | lea esi, [ecx * 4 + argv-4] |
||
6424 | siemargl | 95 | DEBUGF '0x%x) "%s"\n', cx, [esi] |
145 | halyavin | 96 | loop @b |
97 | end if |
||
215 | victor | 98 | push argv |
145 | halyavin | 99 | push [argc] |
100 | call main |
||
101 | .exit: |
||
6424 | siemargl | 102 | ;DEBUGF 'Exit from prog\n'; |
145 | halyavin | 103 | xor eax,eax |
104 | dec eax |
||
105 | int 0x40 |
||
215 | victor | 106 | dd -1 |
145 | halyavin | 107 | .crash: |
6424 | siemargl | 108 | ;DEBUGF 'E:buffer overflowed\n' |
145 | halyavin | 109 | jmp .exit |
110 | ;============================ |
||
111 | push_param: |
||
112 | ;============================ |
||
113 | ;parameters |
||
114 | ; esi - pointer |
||
115 | ;description |
||
116 | ; procedure increase argc |
||
117 | ; and add pointer to array argv |
||
118 | ; procedure changes ebx |
||
119 | mov ebx, [argc] |
||
120 | cmp ebx, max_parameters |
||
121 | jae .dont_add |
||
122 | mov [argv+4*ebx], esi |
||
123 | inc [argc] |
||
124 | .dont_add: |
||
125 | ret |
||
126 | ;============================== |
||
6424 | siemargl | 127 | public argc as '__argc' |
145 | halyavin | 128 | public params as '__argv' |
129 | public path as '__path' |
||
130 | |||
6443 | siemargl | 131 | section '.bss' |
145 | halyavin | 132 | buf_len = 0x400 |
133 | max_parameters=0x20 |
||
215 | victor | 134 | argc rd 1 |
135 | argv rd max_parameters |
||
6443 | siemargl | 136 | path rb buf_len |
137 | params rb buf_len |
||
145 | halyavin | 138 | |
6424 | siemargl | 139 | ;section '.data' |
140 | ;include_debug_strings ; ALWAYS present in data section |