Rev 7134 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7134 | Rev 8227 | ||
---|---|---|---|
1 | ;----------------------------------------------------------------------------- |
1 | ;----------------------------------------------------------------------------- |
2 | ; load one or more DLL file in COFF format and try to import functions by our list |
2 | ; load one or more DLL file in COFF format and try to import functions by our list |
3 | ; if first function in import list begins with 'lib_', call it as DLL initialization |
3 | ; if first function in import list begins with 'lib_', call it as DLL initialization |
4 | ; return eax = 1 as fail, if anyone of .obj file not found in /sys/lib |
4 | ; return eax = 1 as fail, if anyone of .obj file not found in /sys/lib |
5 | ; return 0 if all fine, but 0 not garantees in succesfull import - see dll.Link comment |
5 | ; return 0 if all fine, but 0 not garantees in succesfull import - see dll.Link comment |
6 | ; dirties all registers! eax, ebx, ecx, edx, esi, edi |
6 | ; dirties all registers! eax, ebx, ecx, edx, esi, edi |
7 | proc dll.Load, import_table:dword |
7 | proc dll.Load, import_table:dword |
8 | mov esi, [import_table] |
8 | mov esi, [import_table] |
9 | .next_lib: |
9 | .next_lib: |
10 | mov edx, [esi] |
10 | mov edx, [esi] |
11 | or edx, edx |
11 | or edx, edx |
12 | jz .exit |
12 | jz .exit |
13 | push esi |
13 | push esi |
14 | mov esi, [esi + 4] |
14 | mov esi, [esi + 4] |
15 | mov edi, s_libdir.fname |
15 | mov edi, s_libdir.fname |
16 | @@: |
16 | @@: |
17 | lodsb |
17 | lodsb |
18 | stosb |
18 | stosb |
19 | or al, al |
19 | or al, al |
20 | jnz @b |
20 | jnz @b |
21 | mcall 68, 19, s_libdir |
21 | mcall 68, 19, s_libdir |
22 | or eax, eax |
22 | or eax, eax |
23 | jz .fail |
23 | jz .fail |
24 | stdcall dll.Link, eax, edx |
24 | stdcall dll.Link, eax, edx |
25 | push eax |
25 | push eax |
26 | mov eax, [eax] |
26 | mov eax, [eax] |
27 | cmp dword[eax], 'lib_' |
27 | cmp dword[eax], 'lib_' |
28 | pop eax |
28 | pop eax |
29 | jnz @f |
29 | jnz @f |
30 | stdcall dll.Init, [eax + 4] |
30 | stdcall dll.Init, [eax + 4] |
31 | @@: |
31 | @@: |
32 | pop esi |
32 | pop esi |
33 | add esi, 8 |
33 | add esi, 8 |
34 | jmp .next_lib |
34 | jmp .next_lib |
35 | .exit: |
35 | .exit: |
36 | xor eax, eax |
36 | xor eax, eax |
37 | ret |
37 | ret |
38 | .fail: |
38 | .fail: |
39 | add esp, 4 |
39 | add esp, 4 |
40 | xor eax, eax |
40 | xor eax, eax |
41 | inc eax |
41 | inc eax |
42 | ret |
42 | ret |
43 | endp |
43 | endp |
44 | ;----------------------------------------------------------------------------- |
44 | ;----------------------------------------------------------------------------- |
45 | ; scans dll export table for a functions we want to import |
45 | ; scans dll export table for a functions we want to import |
46 | ; break scan on first unresolved import |
46 | ; break scan on first unresolved import |
47 | ; no return value |
47 | ; no return value |
48 | proc dll.Link, exp:dword, imp:dword |
48 | proc dll.Link, exp:dword, imp:dword |
49 | push eax |
49 | push eax |
50 | mov esi, [imp] |
50 | mov esi, [imp] |
51 | test esi, esi |
51 | test esi, esi |
52 | jz .done |
52 | jz .done |
53 | .next: |
53 | .next: |
54 | lodsd |
54 | lodsd |
55 | test eax, eax |
55 | test eax, eax |
56 | jz .done |
56 | jz .done |
57 | stdcall dll.GetProcAddress, [exp], eax |
57 | stdcall dll.GetProcAddress, [exp], eax |
58 | or eax, eax |
58 | or eax, eax |
59 | jz @f |
59 | jz @f |
60 | mov [esi - 4], eax |
60 | mov [esi - 4], eax |
61 | jmp .next |
61 | jmp .next |
62 | @@: |
62 | @@: |
63 | mov dword[esp], 0 |
63 | mov dword[esp], 0 |
64 | .done: |
64 | .done: |
65 | pop eax |
65 | pop eax |
66 | ret |
66 | ret |
67 | endp |
67 | endp |
68 | ;----------------------------------------------------------------------------- |
68 | ;----------------------------------------------------------------------------- |
69 | ; calls lib_init with predefined parameters |
69 | ; calls lib_init with predefined parameters |
70 | ; no return value |
70 | ; no return value |
71 | proc dll.Init, dllentry:dword |
71 | proc dll.Init, dllentry:dword |
72 | pushad |
72 | pushad |
73 | mov eax, mem.Alloc |
73 | mov eax, mem.Alloc |
74 | mov ebx, mem.Free |
74 | mov ebx, mem.Free |
75 | mov ecx, mem.ReAlloc |
75 | mov ecx, mem.ReAlloc |
76 | mov edx, dll.Load |
76 | mov edx, dll.Load |
77 | stdcall [dllentry] |
77 | stdcall [dllentry] |
78 | popad |
78 | popad |
79 | ret |
79 | ret |
80 | endp |
80 | endp |
81 | ;----------------------------------------------------------------------------- |
81 | ;----------------------------------------------------------------------------- |
82 | ; scans export table for a sz_name function |
82 | ; scans export table for a sz_name function |
83 | ; returns in eax function address or 0 if not found |
83 | ; returns in eax function address or 0 if not found |
84 | proc dll.GetProcAddress, exp:dword, sz_name:dword |
84 | proc dll.GetProcAddress, exp:dword, sz_name:dword |
85 | mov edx, [exp] |
85 | mov edx, [exp] |
86 | xor eax, eax |
86 | xor eax, eax |
87 | .next: |
87 | .next: |
88 | or edx, edx |
88 | or edx, edx |
89 | jz .end |
89 | jz .end |
90 | cmp dword[edx], 0 |
90 | cmp dword[edx], 0 |
91 | jz .end |
91 | jz .end |
92 | stdcall strcmp, [edx], [sz_name] |
92 | stdcall strcmp, [edx], [sz_name] |
93 | test eax, eax |
93 | test eax, eax |
94 | jz .ok |
94 | jz .ok |
95 | add edx, 8 |
95 | add edx, 8 |
96 | jmp .next |
96 | jmp .next |
97 | .ok: |
97 | .ok: |
98 | mov eax, [edx + 4] |
98 | mov eax, [edx + 4] |
99 | .end: |
99 | .end: |
100 | cmp eax, -1 |
100 | cmp eax, -1 |
101 | jnz @f |
101 | jnz @f |
102 | xor eax, eax |
102 | xor eax, eax |
103 | @@: |
103 | @@: |
104 | ret |
104 | ret |
105 | endp |
105 | endp |
106 | ;----------------------------------------------------------------------------- |
106 | ;----------------------------------------------------------------------------- |
107 | ; compares strings |
107 | ; compares strings |
108 | ; returns eax = 0 if equal, -1 otherwise |
108 | ; returns eax = 0 if equal, -1 otherwise |
109 | proc strcmp, str1:dword, str2:dword |
109 | proc strcmp, str1:dword, str2:dword |
110 | push esi edi |
110 | push esi edi |
111 | mov esi, [str1] |
111 | mov esi, [str1] |
112 | mov edi, [str2] |
112 | mov edi, [str2] |
113 | xor eax, eax |
113 | xor eax, eax |
114 | @@: |
114 | @@: |
115 | lodsb |
115 | lodsb |
116 | scasb |
116 | scasb |
117 | jne .fail |
117 | jne .fail |
118 | or al, al |
118 | or al, al |
119 | jnz @b |
119 | jnz @b |
120 | jmp .ok |
120 | jmp .ok |
121 | .fail: |
121 | .fail: |
122 | or eax, -1 |
122 | or eax, -1 |
123 | .ok: |
123 | .ok: |
124 | pop edi esi |
124 | pop edi esi |
125 | ret |
125 | ret |
126 | endp |
126 | endp |
127 | ;----------------------------------------------------------------------------- |
127 | ;----------------------------------------------------------------------------- |
- | 128 | if defined dll.Load |
|
128 | s_libdir: |
129 | s_libdir: |
129 | db '/sys/lib/' |
130 | db '/sys/lib/' |
130 | .fname rb 32 |
131 | .fname rb 32 |
- | 132 | end if |
|
131 | ;----------------------------------------------------------------------------- |
133 | ;----------------------------------------------------------------------------- |
132 | proc mem.Alloc, size |
134 | proc mem.Alloc, size |
133 | push ebx ecx |
135 | push ebx ecx |
134 | mov ecx, [size] |
136 | mov ecx, [size] |
135 | mcall 68, 12 |
137 | mcall 68, 12 |
136 | pop ecx ebx |
138 | pop ecx ebx |
137 | ret |
139 | ret |
138 | endp |
140 | endp |
139 | ;----------------------------------------------------------------------------- |
141 | ;----------------------------------------------------------------------------- |
140 | proc mem.ReAlloc, mptr, size |
142 | proc mem.ReAlloc, mptr, size |
141 | push ebx ecx edx |
143 | push ebx ecx edx |
142 | mov ecx, [size] |
144 | mov ecx, [size] |
143 | mov edx, [mptr] |
145 | mov edx, [mptr] |
144 | mcall 68, 20 |
146 | mcall 68, 20 |
145 | pop edx ecx ebx |
147 | pop edx ecx ebx |
146 | ret |
148 | ret |
147 | endp |
149 | endp |
148 | ;----------------------------------------------------------------------------- |
150 | ;----------------------------------------------------------------------------- |
149 | proc mem.Free, mptr |
151 | proc mem.Free, mptr |
150 | push ebx ecx |
152 | push ebx ecx |
151 | mov ecx,[mptr] |
153 | mov ecx,[mptr] |
152 | mcall 68, 13 |
154 | mcall 68, 13 |
153 | pop ecx ebx |
155 | pop ecx ebx |
154 | ret |
156 | ret |
155 | endp |
157 | endp |
156 | ;----------------------------------------------------------------------------- |
158 | ;----------------------------------------------------------------------------- |