-
Notifications
You must be signed in to change notification settings - Fork 15
/
impexp.html
173 lines (141 loc) · 4.96 KB
/
impexp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<html>
<head>
<title>Èìïîðòû è ýêñïîðòû</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<body bgcolor=#B0B0B0 text=#000000 link=#0000FF vlink=#2020C0 alink=#000000>
<h2 align=center>Èìïîðòû è ýêñïîðòû</h2>
<p>Çäåñü áóäóò ïðèâåäåíû ïðèìåðû èìïîðòà è ýêñïîðòà ôóíêöèé,
ïðèìåíèòåëüíî ê Borland C/C++.
<p>Ïóñòü íàø ïðîåêò ñîñòîèò èç ôàéëà íà C++ (CPPFILE.CPP) è ôàéëà íà
àññåìáëåðå (ASMFILE.ASM), à ðåçóëüòèðóþùèé EXE-øíèê íàçûâàåòñÿ
EXEFILE.EXE.
<p>È ïóñòü ìû õîòèì âûçûâàòü ôóíêöèè, íàïèñàííûå â ñè-øíîì èñõîäíèêå èç
àññåìáëåðíîãî êîäà, è íàîáîðîò; à òàêæå ýêñïîðòèðîâàòü è ñè-øíûå è
àññåìáëåðíûå ôóíêöèè èç ïîëó÷åííîãî PE EXE ôàéëà.
<p>Ïóñòü òàêæå åñòü íåêîòîðàÿ âíåøíÿÿ áèáëèîòåêà ANYDLL.DLL, ôóíêöèè èç
êîòîðîé ìû õîòèì èñïîëüçîâàòü â îáîèõ ÷àñòÿõ ïðîåêòà, ò.å. è íà àññåìáëåðå
è íà ñè.
<p>Âîò êàê òîãäà áóäåò âûãëÿäåòü ôàéë ÑPPFILE.CPP:
<p>
<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#b8b8b8>
<tr>
<td>
<pre>
#include <stdio.h>
extern "C"
{
int __cdecl CodeInASM_UseInCPP_CName (int x);
int _import __cdecl CodeInEXTPE_UseInCPP_Cname (int x);
int _import __cdecl CodeInEXTPE_UseInCPP_Ordinal (int x);
int __cdecl CodeInCPP_UseInASM_CName (int x) { return x; }
int _export __cdecl CodeInCPP_UseInEXTPE_CName (int x) { return x; }
}
extern "C++"
{
int __cdecl CodeInASM_UseInCPP_CPPName (int x);
int _import __cdecl CodeInEXTPE_UseInCPP_CPPname (int x);
int __cdecl CodeInCPP_UseInASM_CPPName (int x) { return x; }
int _export __cdecl CodeInCPP_UseInEXTPE_CPPName (int x) { return x; }
}
int RegisterUsage()
{
return (int)&CodeInASM_UseInCPP_CName +
(int)&CodeInASM_UseInCPP_CPPName +
(int)&CodeInEXTPE_UseInCPP_Cname +
(int)&CodeInEXTPE_UseInCPP_CPPname +
(int)&CodeInEXTPE_UseInCPP_Ordinal +
(int)&CodeInCPP_UseInASM_CName +
(int)&CodeInCPP_UseInASM_CPPName +
(int)&CodeInCPP_UseInEXTPE_CName +
(int)&CodeInCPP_UseInEXTPE_CPPName;
}
int main()
{
RegisterUsage();
}
</pre>
</table>
<p> ñâîþ î÷åðåäü, ASMFILE.ASM áóäåò âûãëÿäåòü òàê:
<p>
<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#b8b8b8>
<tr>
<td>
<pre>
public _CodeInASM_UseInCPP_CName
_CodeInASM_UseInCPP_CName:
mov eax, [esp+4]
retn
public @CodeInASM_UseInCPP_CPPName$qi
@CodeInASM_UseInCPP_CPPName$qi:
mov eax, [esp+4]
retn
publicdll CodeInASM_UseInEXTPE
CodeInASM_UseInEXTPE:
mov eax, [esp+4]
retn
public CodeInASM_UseInEXTPE_RenameInDef
CodeInASM_UseInEXTPE_RenameInDef:
mov eax, [esp+4]
retn
extern CodeInEXTPE_UseInASM_Name:PROC
call CodeInEXTPE_UseInASM_Name
extern CodeInEXTPE_UseInASM_Ordinal:PROC
call CodeInEXTPE_UseInASM_Ordinal
</pre>
</table>
<p>Äëÿ óñïåøíîé êîìïèëÿöèè âñåãî ýòîãî ïîòðåáóåòñÿ EXEFILE.DEF ôàéë,
â êîòîðîì áóäóò îïèñàíû ñîîòâåòñòâèÿ âíóòðåííèõ è âíåøíèõ èìåí
ôóíêöèé ïðîåêòà:
<p>
<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#b8b8b8>
<tr>
<td>
<pre>
EXPORTS
AsmFunc = CodeInASM_UseInEXTPE_RenameInDef
IMPORTS
_CodeInEXTPE_UseInCPP_Cname = ANYDLL._CodeInEXTPE_UseInCPP_Cname
@CodeInEXTPE_UseInCPP_CPPname$qi = ANYDLL.@CodeInEXTPE_UseInCPP_CPPname$qi
_CodeInEXTPE_UseInCPP_Ordinal = ANYDLL.666
CodeInEXTPE_UseInASM_Name = ANYDLL.CodeInEXTPE_UseInASM_Name
CodeInEXTPE_UseInASM_Ordinal = ANYDLL.777
</pre>
</table>
<p>Òåïåðü, ÷òîáû âñå ýòî ñêîìïèëèðîâàòü, ïîíàäîáèòñÿ ôàéë MAKE.BAT:
<p>
<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#b8b8b8>
<tr>
<td>
<pre>
@echo off
set X=d:\whatever\borland\bcc55
%X%\bin\bcc32.exe -eEXEFILE -I%X%\include -L%X%\lib cppfile.cpp asmfile.asm
</pre>
</table>
<p>Ñ äðóãîé ñòîðîíû, ìîæíî áûëî áû ñäåëàòü ANYDLL.LIB, ïîñðåäñòâîì<br>
<pre>IMPLIB.EXE -f anydll.lib anydll.dll</pre>
ïîñëå ÷åãî âìåñòî IMPORTS-÷àñòè EXEFILE.DEF ôàéëà, èñïîëüçîâàòü ANYDLL.LIB;
ïðè ýòîì íàäî íå çàáûòü ïîäàòü ANYDLL.LIB â êîìàíäíóþ ñòðîêó bcc32.exe.
<p>Âîò ÷àñòü TDUMP'à îò ïîëó÷åííîãî EXEFILE.EXE:
<p>
<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#b8b8b8>
<tr>
<td>
<pre>
Exports from EXEFILE.exe
RVA Ord. Hint Name
-------- ---- ---- ----
00001168 3 0000 CodeInCPP_UseInEXTPE_CPPName(int)
000011C7 6 0001 AsmFunc
000011C2 4 0002 CodeInASM_UseInEXTPE
00001160 2 0003 _CodeInCPP_UseInEXTPE_CName
Imports from ANYDLL.DLL
_CodeInEXTPE_UseInCPP_Cname
CodeInEXTPE_UseInCPP_CPPname(int)
CodeInEXTPE_UseInASM_Name
(ord. = 777)
(ord. = 666)
</pre>
</table>
<p><hr