Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
836 | diamond | 1 | |
2 | |||
3 | |||
4 | DLL_EXIT equ -1 |
||
5 | REQ_DLL_VER equ 2 |
||
6 | |||
7 | |||
8 | db 'MENUET01' |
||
9 | dd 1 |
||
10 | dd start |
||
11 | dd i_end |
||
12 | dd mem |
||
13 | dd mem |
||
14 | dd 0 |
||
15 | dd 0 |
||
16 | |||
17 | |||
18 | stdcall load_dll_and_import, dllname, imports |
||
19 | test eax, eax |
||
20 | jz exit |
||
21 | |||
22 | |||
23 | cmp word [dll_ver], REQ_DLL_VER |
||
24 | jb exit |
||
25 | cmp word [dll_ver+2], REQ_DLL_VER |
||
26 | ja exit |
||
27 | push DLL_ENTRY |
||
28 | call [dll_start] |
||
29 | |||
30 | |||
31 | |||
32 | |||
33 | push -1 |
||
34 | push -1 |
||
35 | push -1 |
||
36 | push -1 |
||
37 | call [con_init] |
||
38 | ; C-equivalent of the following code: |
||
39 | ; for (ebx=0;ebx<0x100;ebx++) |
||
40 | ; { |
||
41 | ; con_printf(t1,ebx); |
||
42 | ; eax = con_set_flags(ebx); |
||
43 | ; con_write_asciiz(text); |
||
44 | ; con_set_flags(eax); |
||
45 | ; } |
||
46 | ; N.B. For efficiency result of first con_set_flags is not saved |
||
47 | ; in register, but is pushed beforehand to the stack |
||
48 | ; for second con_set_flags. |
||
49 | ; Note that such code cannot be generated by stdcall macros. |
||
50 | xor ebx, ebx |
||
51 | @@: |
||
52 | push ebx |
||
53 | push t1 |
||
54 | call [con_printf] |
||
55 | add esp, 8 |
||
56 | push ebx |
||
57 | call [con_set_flags] |
||
58 | push eax |
||
59 | push text |
||
60 | call [con_write_asciiz] |
||
61 | call [con_set_flags] |
||
62 | inc bl |
||
63 | jnz @b |
||
64 | push text2 |
||
65 | call [con_write_asciiz] |
||
66 | push 0 |
||
67 | call [con_exit] |
||
68 | exit: |
||
69 | or eax, -1 |
||
70 | int 0x40 |
||
71 | |||
72 | |||
73 | pushad |
||
74 | ; load DLL |
||
75 | push 68 |
||
76 | pop eax |
||
77 | push 19 |
||
78 | pop ebx |
||
79 | mov ecx, [_dllname] |
||
80 | int 0x40 |
||
81 | test eax, eax |
||
82 | jz import_fail |
||
83 | |||
84 | |||
85 | mov edi, eax |
||
86 | mov esi, [_imports] |
||
87 | import_loop: |
||
88 | lodsd |
||
89 | test eax, eax |
||
90 | jz import_done |
||
91 | mov edx, edi |
||
92 | import_find: |
||
93 | mov ebx, [edx] |
||
94 | test ebx, ebx |
||
95 | jz import_not_found |
||
96 | push eax |
||
97 | @@: |
||
98 | mov cl, [eax] |
||
99 | cmp cl, [ebx] |
||
100 | jnz import_find_next |
||
101 | test cl, cl |
||
102 | jz import_found |
||
103 | inc eax |
||
104 | inc ebx |
||
105 | jmp @b |
||
106 | import_find_next: |
||
107 | pop eax |
||
108 | add edx, 8 |
||
109 | jmp import_find |
||
110 | import_found: |
||
111 | pop eax |
||
112 | mov eax, [edx+4] |
||
113 | mov [esi-4], eax |
||
114 | jmp import_loop |
||
115 | import_not_found: |
||
116 | import_fail: |
||
117 | popad |
||
118 | xor eax, eax |
||
119 | ret |
||
120 | import_done: |
||
121 | popad |
||
122 | xor eax, eax |
||
123 | inc eax |
||
124 | ret |
||
125 | endp |
||
126 | |||
127 | |||
128 | |||
129 | |||
130 | dll_start dd szStart |
||
131 | dll_ver dd szVersion |
||
132 | con_init dd szcon_init |
||
133 | con_write_asciiz dd szcon_write_asciiz |
||
134 | con_printf dd szcon_printf |
||
135 | con_set_flags dd szcon_set_flags |
||
136 | con_exit dd szcon_exit |
||
137 | dd 0 |
||
138 | |||
139 | |||
140 | szVersion db 'version',0 |
||
141 | szcon_init db 'con_init',0 |
||
142 | szcon_write_asciiz db 'con_write_asciiz',0 |
||
143 | szcon_printf db 'con_printf',0 |
||
144 | szcon_set_flags db 'con_set_flags',0 |
||
145 | szcon_exit db 'con_exit',0 |
||
146 | |||
147 | |||
148 | |||
149 | |||
150 | t1 db 'Color 0x%02X: ',0 |
||
151 | text db 'This is sample text.',10,0 |
||
152 | text2 db 27,'[7mAnd this is an example of ' |
||
153 | db 27,'[1;36;41mEsc' |
||
154 | db 27,'[7m-sequences.',10,0 |
||
155 | |||
156 | |||
157 | |||
158 | |||
159 | rb 2048 ; stack |
||
160 | mem:0x100;ebx++) |
||
161 | ;> |