Rev 4872 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | |
2 | |||
3 | |||
4 | DLL_ENTRY = 1 |
||
5 | |||
6 | |||
7 | dd 1 |
||
8 | dd start |
||
9 | dd i_end |
||
10 | dd mem |
||
11 | dd mem |
||
12 | dd cmdline |
||
13 | dd path |
||
14 | dd 0 |
||
15 | |||
16 | |||
17 | start: |
||
18 | mov eax, LIBC_VERSION |
||
19 | mov ecx, sz_libc |
||
20 | mov edx, libc |
||
21 | call load_library |
||
22 | test eax, eax |
||
23 | jz .fail |
||
24 | |||
25 | |||
26 | push cmdline |
||
27 | push path |
||
28 | push (my_app_end - my_app) |
||
29 | push my_app |
||
30 | call [libc.imp_exec] |
||
31 | |||
32 | |||
33 | .fail: |
||
34 | or eax, -1 |
||
35 | int 0x40 |
||
36 | |||
37 | |||
38 | load_library: ;eax=VERSION ecx=library path edx=import section |
||
39 | |||
40 | |||
41 | mov [esp+8], edx |
||
42 | mov [esp+12], eax |
||
43 | |||
44 | |||
45 | mov ebx, 19 |
||
46 | int 0x40 |
||
47 | test eax, eax |
||
48 | jz .fail |
||
49 | |||
50 | |||
51 | mov esi, edx ;import section |
||
52 | mov edx, eax ;export section |
||
53 | .import_loop: |
||
54 | lodsd |
||
55 | test eax, eax |
||
56 | jz .import_done |
||
57 | .import_find: |
||
58 | mov ebx, [edx] |
||
59 | test ebx, ebx |
||
60 | jz .fail ;import_not_found |
||
61 | |||
62 | |||
63 | @@: |
||
64 | mov cl, [eax] |
||
65 | cmp cl, [ebx] |
||
66 | jnz .import_find_next |
||
67 | |||
68 | |||
69 | jz .import_found |
||
70 | |||
71 | |||
72 | inc ebx |
||
73 | jmp @b |
||
74 | |||
75 | |||
76 | mov eax, [esp] |
||
77 | add edx, 8 |
||
78 | jmp .import_find |
||
79 | |||
80 | |||
81 | mov eax, [edx+4] |
||
82 | mov [esi-4], eax |
||
83 | mov edx, [esp+4] |
||
84 | jmp .import_loop |
||
85 | .import_done: |
||
86 | |||
87 | |||
88 | mov eax, [esp+12] |
||
89 | |||
90 | |||
91 | jb .fail |
||
92 | cmp word [edx+6], ax |
||
93 | ja .fail |
||
94 | |||
95 | |||
96 | call dword [edx] |
||
97 | .fail: |
||
98 | add esp, 16 |
||
99 | ret |
||
100 | |||
101 | |||
102 | |||
103 | |||
104 | |||
105 | szVersion db 'version',0 |
||
106 | szExec db 'exec',0 |
||
107 | |||
108 | |||
109 | |||
110 | |||
111 | .imp_ver dd szVersion |
||
112 | .imp_exec dd szExec |
||
113 | dd 0 |
||
114 | |||
115 | |||
116 | align 16 |
||
117 | my_app: |
||
118 | file 'myapp.exe' |
||
119 | my_app_end: |
||
120 | |||
121 | |||
122 | |||
123 | align 4 |
||
124 | i_end: |
||
125 | |||
126 | |||
127 | cmdline rb 256 |
||
128 | rb 128 ;required stack |
||
129 | ; keep this aligned |
||
130 | align 4096 |
||
131 | mem: |
||
132 |