-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathCppDLL_Class.h
701 lines (649 loc) · 19.9 KB
/
CppDLL_Class.h
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/********************************************************************
Created: 2012/05/19 18:17
Filename: CppDLL_Class.h
Author: rrrfff
Url: http://blog.csdn.net/rrrfff
*********************************************************************/
#include <RLib_LibImport.h>
#include "CppDLL_Resource.h"
//-------------------------------------------------------------------------
class CppDLL
{
private:
enum EXPORTTYPE
{
TYPE_NAMESPACE = 0,
TYPE_CLASS
};
struct Global
{
public:
string undnamed;
string mangled;
public:
Global() {};
Global(const string &s1, const string &s2) {
undnamed = s1;
mangled = s2;
}
};
struct EXPORTINFO
{
public:
string access;
string type;
string name;
string param_other;
string mangled;
string oristr;
EXPORTTYPE node_type;
public:
RLIB_DECLARE_DYNCREATE;
public:
bool operator < (const EXPORTINFO &ei) const {
return this->name < ei.name;
}
bool operator > (const EXPORTINFO &ei) const {
return this->name > ei.name;
}
bool operator == (const EXPORTINFO &ei) const {
return (this->mangled == ei.mangled);
}
};
struct VECTOR
{
public:
string name;
List<VECTOR> *children;
List<EXPORTINFO> *element;
public:
VECTOR() {
this->children = NULL;
this->element = NULL;
}
~VECTOR() {
RLIB_Delete(this->children);
RLIB_Delete(this->element);
}
RLIB_DECLARE_DYNCREATE;
public:
void TryInitChildren() {
if (this->children == NULL)this->children = new List<VECTOR>;
}
void TryInitElement() {
if(this->element == NULL) this->element = new List<EXPORTINFO>;
}
bool HasChildren() {
return (this->children != NULL);
}
bool HasElement() {
return (this->element != NULL);
}
bool IsClass() {
if (HasElement() == false) { // 容器没有元素, 考虑是命名空间
return false;
} //if
foreach(pe, (*this->element))
{
if (pe->node_type == TYPE_NAMESPACE) {
return false;
} //if
}
return true;
}
};
public:
String m_output_path;
String m_dll_path;
List<String> m_export_symbols_list;
List<Global> m_global_symbols_list;
List<String> m_undef_symbols_list;
List<EXPORTINFO> m_class_element_list;
VECTOR m_tree_top;
UInt32 m_number_of_names;
Integer m_number_of_translated;
Boolean m_x64;
private:
template<class HDR>
intptr_t GetFileOffset(IO::FileStream *file, DWORD RVA, IMAGE_DOS_HEADER &dosHeader, HDR &ntHeaders)
{
LARGE_INTEGER byteOffset;
IMAGE_SECTION_HEADER sectionHeader;
WORD c = ntHeaders.FileHeader.NumberOfSections;
byteOffset.LowPart = dosHeader.e_lfanew + sizeof(ntHeaders);
file->Position = static_cast<intptr_t>(byteOffset.LowPart);
while (c-- && byteOffset.LowPart < ntHeaders.OptionalHeader.SizeOfHeaders - dosHeader.e_lfanew) {
if (file->Read(§ionHeader, sizeof(IMAGE_SECTION_HEADER)) > 0) {
if (RVA >= sectionHeader.VirtualAddress && RVA < sectionHeader.VirtualAddress + sectionHeader.SizeOfRawData) {
return static_cast<intptr_t>(RVA - sectionHeader.VirtualAddress + sectionHeader.PointerToRawData);
} //if
} else {
break;
} //if
} //if
return 0;
}
/// <summary>
/// 分析导出表数据 忽略非C++风格导出函数
/// </summary>
intptr_t ReadAllExportSymbols(IO::FileStream *file)
{
IMAGE_DOS_HEADER dosHeader;
if (file->Read(&dosHeader, sizeof(IMAGE_DOS_HEADER)) <= 0 ||
dosHeader.e_magic != IMAGE_DOS_SIGNATURE) {
return 0;
} //if
union
{
IMAGE_NT_HEADERS32 x86;
IMAGE_NT_HEADERS64 x64;
} ntHeaders;
file->Position = dosHeader.e_lfanew;
file->Read(&ntHeaders, sizeof(IMAGE_NT_HEADERS32));
bool x64 = false;
this->m_x64 = false;
switch (ntHeaders.x86.OptionalHeader.Magic) {
case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
file->Read(reinterpret_cast<LPBYTE>(&ntHeaders) + sizeof(IMAGE_NT_HEADERS32),
sizeof(IMAGE_NT_HEADERS64) - sizeof(IMAGE_NT_HEADERS32));
this->m_x64 = x64 = true;
case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
break;
default:
return 0;
}
auto &expData = (x64 ? ntHeaders.x64.OptionalHeader.DataDirectory : ntHeaders.x86.OptionalHeader.DataDirectory)[IMAGE_DIRECTORY_ENTRY_EXPORT];
intptr_t count = 0;
DWORD ExpRVA = expData.VirtualAddress;
DWORD ExpSize = expData.Size;
if (ExpRVA && ExpSize) {
IMAGE_EXPORT_DIRECTORY expDir;
file->Position = x64 ?
GetFileOffset(file, ExpRVA, dosHeader, ntHeaders.x64) :
GetFileOffset(file, ExpRVA, dosHeader, ntHeaders.x86);
if (file->Read(&expDir, sizeof(IMAGE_EXPORT_DIRECTORY)) > 0) {
char export_name[RLIB_DEFAULT_BUFFER_SIZE], demangled[RLIB_COUNTOF(export_name)];
intptr_t offsetOfNameRVA = x64 ?
GetFileOffset(file, expDir.AddressOfNames, dosHeader, ntHeaders.x64) :
GetFileOffset(file, expDir.AddressOfNames, dosHeader, ntHeaders.x86);
this->m_number_of_names = expDir.NumberOfNames;
this->m_export_symbols_list.InitStorage(static_cast<intptr_t>(expDir.NumberOfNames));
this->m_global_symbols_list.InitStorage(static_cast<intptr_t>(expDir.NumberOfNames / 2));
this->m_undef_symbols_list.InitStorage(static_cast<intptr_t>(expDir.NumberOfNames / 2));
this->m_class_element_list.InitStorage(static_cast<intptr_t>(expDir.NumberOfNames));
DWORD dwNameRVA;
for (DWORD i = 0; i < expDir.NumberOfNames; ++i, offsetOfNameRVA += 4) {
file->Position = offsetOfNameRVA;
if (file->Read(&dwNameRVA, sizeof(dwNameRVA)) > 0) {
file->Position = x64 ?
GetFileOffset(file, dwNameRVA, dosHeader, ntHeaders.x64) :
GetFileOffset(file, dwNameRVA, dosHeader, ntHeaders.x86);
DWORD dwIndex = 0;
while (file->Read(&export_name[dwIndex], 4) > 0) {
if (export_name[dwIndex] == '\0' || export_name[dwIndex + 1] == '\0' ||
export_name[dwIndex + 2] == '\0' || export_name[dwIndex + 3] == '\0') break;
dwIndex += 4;
static_assert(RLIB_COUNTOF(export_name) % 4 == 0, "BOOM");
if (dwIndex >= RLIB_COUNTOF(export_name)) {
assert(!"缓冲区太小");
goto __continue_next;
} //if
}
this->m_export_symbols_list.Add(export_name);
if (export_name[0] != '?') {
goto __continue_next;
} //if
extern char *rlib_unDName(char *buffer, const char *mangled, int buflen);
auto demangled_name = rlib_unDName(demangled, export_name, RLIB_COUNTOF(demangled));
if (demangled_name != NULL) {
if (strstr(demangled_name, "`default") == NULL &&
strstr(demangled_name, "`vftable") == NULL) {
Analysis(demangled_name, export_name);
++count;
} //if
if (demangled_name != demangled) AppBase::Collect(demangled_name);
} //if
__continue_next:
continue;
} //if
} //for
} //if
} //if
return count;
}
/// <summary>
/// 分析导出的名称
/// </summary>
void Analysis(string name, const string &mangled)
{
// 寻找访问修饰符
if (name.IndexOf(_T("::")) == -1) {
m_global_symbols_list.Add(Global(name, mangled));
return;
} //if
EXPORTINFO ei;
ei.mangled = mangled;
ei.oristr = name;
intptr_t k = name.IndexOf(_T(": "));
if (k == -1) {
ei.node_type = TYPE_NAMESPACE;
} else {
ei.access = name.Substring(0, k);
name.substring(k + 2);
} //if
k = name.LastIndexOf(_T("("));
bool is_func = (k != -1);
if (is_func) {
ei.param_other = name.Substring(k);
name.substring(0, k);
} //if
intptr_t operator_index = name.IndexOfR(_T("::operator "));
if (operator_index > 0) name.replace(_T(" "), _T("?"), operator_index + RLIB_COUNTOF_STR(_T("::operator")));
k = name.LastIndexOf(_T(" "));
if (name.IndexOf(_T("<")) == -1) {
ei.type = name.Substring(0, k);
ei.name = name.Substring(k + 1);
} else {
intptr_t left_count = -1;
intptr_t white_char = -1;
foreach(pc, name)
{
if (*pc == _T('<')) {
left_count = left_count != -1 ? left_count + 1 : 1;
} else if (*pc == _T('>')) {
left_count--;
} else if (*pc == _T(' ')) {
if (left_count <= 0) white_char = i;
} //if
}
ei.type = name.Substring(0, white_char);
ei.name = name.Substring(ei.type.Length + 1);
} //if
if (operator_index > 0) ei.name.replace(_T("?"), _T(" "));
if (ei.name.IsNull()) { // unrecognized
m_global_symbols_list.Add(Global(_R("// ") + ei.oristr, mangled));
return;
} //if
m_class_element_list.Add(ei);
}
/// <summary>
/// 输出缩进空格
/// </summary>
void Tab(IO::FileStream *outfile, intptr_t current_tabsize)
{
while (--current_tabsize >= 0) {
RLIB_StreamWriteA(outfile, " ");
}
}
/// <summary>
/// 按逻辑层次输出
/// </summary>
void Print(IO::FileStream *outfile, intptr_t ¤t_tabsize, VECTOR *current_pv)
{
if (current_pv->HasChildren())
{
for (auto &v : (*current_pv->children)) // 遍历子节点
{
Tab(outfile, current_tabsize);
if (v.IsClass()) {
RLIB_StreamWriteA(outfile, "class ");
GlobalizeString un(v.name);
outfile->Write(un.toGBK(), un.sizeofGBK());
RLIB_StreamWriteA(outfile, "\r\n");
Tab(outfile, current_tabsize);
RLIB_StreamWriteA(outfile, "{\r\n");
Tab(outfile, current_tabsize);
RLIB_StreamWriteA(outfile, "public: // guess member\r\n");
Tab(outfile, current_tabsize + 4);
RLIB_StreamWriteA(outfile, "TCHAR *unused[64];\r\n\r\n");
goto __next;
} else {
RLIB_StreamWriteA(outfile, "namespace ");
} //if
RLIB_StreamWriteStringA(outfile, v.name);
RLIB_StreamWriteA(outfile, "\r\n");
Tab(outfile, current_tabsize);
RLIB_StreamWriteA(outfile, "{\r\n");
__next:
current_tabsize += 4;
Print(outfile, current_tabsize, &v);
current_tabsize -= 4;
Tab(outfile, current_tabsize);
RLIB_StreamWriteA(outfile, "};\r\n");
if (current_tabsize == 0)
{
RLIB_StreamWriteA(outfile, "\r\n");
} //if
}
delete current_pv->children;
current_pv->children = NULL;
} //if
if (current_pv->HasElement())
{
current_pv->element->Sort();
string current_access;
// 输出子元素
for (auto &e : (*current_pv->element))
{
if (!e.access.IsNullOrEmpty() && (current_access.IsNull() || current_access != e.access)) {
if (!current_access.IsNull()) RLIB_StreamWriteA(outfile, "\r\n");
current_tabsize -= 4;
current_access = e.access;
Tab(outfile, current_tabsize);
RLIB_StreamWriteStringA(outfile, e.access);
RLIB_StreamWriteA(outfile, ":\r\n");
current_tabsize += 4;
} //if
// 输出注释
Tab(outfile, current_tabsize);
RLIB_StreamWriteA(outfile, "/// <summary>\r\n");
Tab(outfile, current_tabsize);
RLIB_StreamWriteA(outfile, "/// ");
RLIB_StreamWriteStringA(outfile, e.mangled);
RLIB_StreamWriteA(outfile, "\r\n");
// Tab(outfile, current_tabsize);
// RLIB_StreamWriteA(outfile, "/// ");
// RLIB_StreamWriteStringA(outfile, (e.type + T("(*)") + e.param_other));
// RLIB_StreamWriteA(outfile, "\r\n");
Tab(outfile, current_tabsize);
RLIB_StreamWriteA(outfile, "/// </summary>\r\n");
Tab(outfile, current_tabsize);
e.type.replace(_T("__thiscall"), _T(""));
if (!e.type.IsNullOrEmpty()) {
RLIB_StreamWriteStringA(outfile, e.type);
RLIB_StreamWriteA(outfile, " ");
} //if
RLIB_StreamWriteStringA(outfile, e.name);
RLIB_StreamWriteStringA(outfile, e.param_other);
RLIB_StreamWriteA(outfile, ";");
RLIB_StreamWriteA(outfile, "\r\n");
}
delete current_pv->element;
current_pv->element = NULL;
} //if
}
/// <summary>
/// 输出到指定文件
/// </summary>
void GenerateCppHeader()
{
Path path(this->m_dll_path);
String fn = StringReference(path.GetInfo().Fname);
auto outfile = IO::File::Create(this->m_output_path + fn + _R(".h"), FileMode::CreateNew);
RLIB_StreamWriteA(outfile,
"//\r\n// This File has been generated by CppDLL"
"\r\n// Copyright (c) 2017 rrrfff, [email protected]"
"\r\n// http://blog.csdn.net/rrrfff"
"\r\n\r\n//===========================================================================\r\n\r\n");
RLIB_StreamWriteA(outfile, "#pragma comment(lib, \"");
RLIB_StreamWriteStringA(outfile, fn + _R(".lib"));
RLIB_StreamWriteA(outfile, "\")\r\n\r\n//");
{
String count_str = _R(" File Path: ") + path.GetDosPath() + _R("\r\n//");
count_str += _R(" Number Of Names: ") + this->m_number_of_names.ToString() + _R("\r\n//");
count_str += _R(" Number Of Translated: ") + this->m_number_of_translated.ToString();
RLIB_StreamWriteStringA(outfile, count_str);
}
RLIB_StreamWriteA(outfile, "\r\n\r\n");
RLIB_StreamWriteA(outfile, "// 未知类型符号\r\n");
{
for(auto &v : m_undef_symbols_list) {
RLIB_StreamWriteStringA(outfile, (_R("// ") + v));
RLIB_StreamWriteA(outfile, "\r\n");
}
if (m_undef_symbols_list.Length != 0) {
RLIB_StreamWriteA(outfile, "\r\n");
m_undef_symbols_list.Clear();
} else {
RLIB_StreamWriteA(outfile, "// 没有任何未知类型符号\r\n\r\n");
} //if
}
intptr_t curr_tabsize = 0;
RLIB_StreamWriteA(outfile, "// 类型导出符号\r\n");
Print(outfile, curr_tabsize, &m_tree_top);
RLIB_StreamWriteA(outfile, "// 全局导出符号\r\n");
foreach(pv, m_global_symbols_list)
{
RLIB_StreamWriteStringA(outfile, pv->undnamed.Replace(_T("__cdecl "), _T("")));
RLIB_StreamWriteA(outfile, ";//");
RLIB_StreamWriteStringA(outfile, pv->mangled);
RLIB_StreamWriteA(outfile, "\r\n");
}
if (m_global_symbols_list.Length != 0) {
RLIB_StreamWriteA(outfile, "\r\n");
m_global_symbols_list.Clear();
} else {
RLIB_StreamWriteA(outfile, "// 未找到任何全局导出符号\r\n\r\n");
} //if
delete outfile;
}
void GenerateExportDef()
{
Path path(this->m_dll_path);
String fn = StringReference(path.GetInfo().Fname);
auto outfile = IO::File::Create(this->m_output_path + fn + _R(".def"), FileMode::CreateNew);
RLIB_StreamWriteA(outfile,
";\r\n; This File has been generated by CppDLL"
"\r\n; Copyright (c) 2017 rrrfff, [email protected]\r\n; http://blog.csdn.net/rrrfff"
"\r\n;\r\nLIBRARY ");
RLIB_StreamWriteStringA(outfile, path.GetFileName());
RLIB_StreamWriteA(outfile, "\r\nEXPORTS\r\n");
for (auto &v : m_export_symbols_list) {
RLIB_StreamWriteStringA(outfile, v);
RLIB_StreamWriteA(outfile, "\r\n");
}
delete outfile;
m_export_symbols_list.Clear();
}
void GenerateImportLib()
{
String linkerpath = IO::Path::ToNtPath(_R("link100.dll"));
if (!File::Exist(linkerpath)) {
auto file = IO::File::Create(linkerpath, FileMode::CreateNew, FileAccess::Write, FileAttributes::Hidden);
if (file != NULL) {
file->Write(link_exe, sizeof(link_exe));
delete file;
file = IO::File::Create(_R("mspdb100.dll"), FileMode::CreateNew, FileAccess::Write, FileAttributes::Hidden);
if (file != NULL) {
file->Write(mspdb100_dll, sizeof(mspdb100_dll));
delete file;
} //if
file = IO::File::Create(_R("msvcr100.dll"), FileMode::CreateNew, FileAccess::Write, FileAttributes::Hidden);
if (file != NULL) {
file->Write(msvcr100_dll, sizeof(msvcr100_dll));
delete file;
} //if
} else {
printf(" 无法生成所需文件: link.exe" RLIB_NEWLINEA);
return;
} //if
} //if
PROCESS_INFORMATION ProcessInformation = { 0 };
STARTUPINFO start = { sizeof(start) };
start.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
start.wShowWindow = SW_HIDE;
Path path(this->m_dll_path);
String fn = StringReference(path.GetInfo().Fname);
String parameter = _R("LINK /LIB /MACHINE:");
parameter += this->m_x64 ? _R("X64 /DEF:\"") : _R("X86 /DEF:\"");
parameter += this->m_output_path + fn + _R(".def");
parameter += _R("\" /OUT:\"");
parameter += this->m_output_path + fn + _R(".lib");
parameter += _R("\"");
if (!CreateProcess(linkerpath.Substring(4), parameter, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &start, &ProcessInformation)) {
printf(" 无法生成库文件, 命令行如下: %s" RLIB_NEWLINEA,
GlobalizeString(parameter).toGBK());
} //if
}
/// <summary>
/// 计算分割符
/// </summary>
intptr_t Calc(string &name, intptr_t begin = 0)
{
intptr_t left_count = -1;
intptr_t white_char = -1;
for(intptr_t i = begin; i < name.Length; ++i)
{
if (name[i] == _T('<')) {
left_count = left_count != -1 ? left_count + 1 : 1;
} else if (name[i] == _T('>')) {
--left_count;
} else if (i == name.Length - 1) {
break;
} else if (name[i] == _T(':') && name[i + 1] == _T(':')) {
if (left_count <= 0) {
white_char = i;
break;
} //if
} //if
}
return white_char;
}
intptr_t CalcWhite(string &name, intptr_t begin = 0)
{
intptr_t left_count = -1;
intptr_t white_char = -1;
for(intptr_t i = begin; i < name.Length; ++i)
{
if (name[i] == _T('<')) {
left_count = left_count != -1 ? left_count + 1 : 1;
} else if (name[i] == _T('>')) {
left_count--;
} else if (i == name.Length - 1) {
break;
} else if (name[i] == _T(' ')) {
if (left_count <= 0) {
white_char = i;
break;
} //if
} //if
}
return white_char;
}
/// <summary>
/// 建立结构
/// </summary>
void Tree()
{
m_tree_top.TryInitChildren();
// 处理导出符号
for (auto &ei : m_class_element_list)
{
intptr_t k = 0, v = 0;
VECTOR *pvr = &m_tree_top;
while((k = Calc(ei.name, k)) != -1)
{
String &&curr_name = ei.name.Substring(v, k - v);
pvr->TryInitChildren();
foreach(pc, (*pvr->children))
{
if (pc->name == curr_name) {
pvr = pc;
goto __do_next;
} //if
}
// insert if not exsit
{
VECTOR vr;
vr.name = curr_name;
pvr->children->Add(vr);
pvr = &pvr->children->Get(pvr->children->Length - 1);
}
__do_next:
k += 2;
v = k;
}
pvr->TryInitElement();
ei.name.substring(v);
pvr->element->Add(ei);
continue;
}
m_class_element_list.Clear();
}
/// <summary>
/// 调整顺序
/// </summary>
void Adjust()
{
auto class_list = m_class_element_list;
for (auto &ei : m_class_element_list)
{
if (ei.param_other.IsNullOrEmpty()) continue;
auto params = ei.param_other.Substring(1, ei.param_other.Length - 2).Split(_T(","), 1, 64);
foreach(param, (*params))
{
// 如果参数中没有类型关系则忽略
if (param->IndexOf(_T("enum")) == -1 && param->IndexOf(_T("class")) == -1 &&
param->IndexOf(_T("struct")) == -1) {
continue;
} //if
if (param->EndsWith(_T('*'))) {
continue; // 忽略指针
} //if
intptr_t begin = param->IndexOfR(_T(" ")); assert(begin != -1);
intptr_t end = CalcWhite(*param, begin);
string type = param->Substring(begin, (end == -1) ? 0 : (end - begin));
// 查找符号
{
intptr_t order = -1, orderfind = -1;
for (auto &e : class_list)
{
if (e.name.IndexOf(type) != -1) {
orderfind = i;
if (order != -1) {
goto __success_find;
} //if
continue;
} //if
if (e == ei) {
order = i;
if (orderfind != -1) {
goto __success_find;
} //if
} //if
}
if (orderfind == -1) m_undef_symbols_list.Add(type);
break;
__success_find:
if (orderfind < order) {
class_list.RemoveAt(order);
class_list.InsertAt(orderfind, ei);
} //if
}
}
delete params;
}
m_class_element_list.Clear();
for (auto &e : class_list) {
m_class_element_list.Add(e);
}
}
public:
RLIB_DECLARE_DYNCREATE;
bool Work(string filename)
{
this->m_dll_path = Path::ToDosPath(filename);
this->m_output_path = Path::ToNtPath(_R("Output\\"));
!Directory::Exist(this->m_output_path) && Directory::Create(this->m_output_path);
// this->m_output_path += this->m_dll_path.Substring(this->m_dll_path.LastIndexOfR(_T("\\")));
// 分析导出符号
auto file = IO::File::Open(filename, FileMode::OpenExist, FileAccess::Read, FileShare::Read);
if (file != nullptr) {
this->m_number_of_translated = ReadAllExportSymbols(file);
delete file;
} else {
return false;
} //if
// if (this->m_number_of_translated <= 0) {
// return false;
// } //if
// 调整结构
// Adjust();
Tree();
// 输出文件
GenerateCppHeader();
GenerateExportDef();
GenerateImportLib();
return true;
}
};