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