-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreclass-to-ida.js
76 lines (69 loc) · 2.65 KB
/
reclass-to-ida.js
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
/*
usage: node reclass-to-ida.js
takes reclass classes and renames them to struts. removes any inheritance done in reclass.
*/
const fs = require('fs');
const path = require('path');
const vmts = require('./D2R/data/reclass_vmts.json');
let lines = fs.readFileSync(`${__dirname}/D2R/Reclass.h`, 'utf8').split(/\r\n|\r|\n/);
let structs = [];
for(let i = 0; i < lines.length; i++) {
var line = lines[i];
if(lines[i].indexOf(' //') >= 0) {
line = lines[i].substring(0, lines[i].indexOf(' //'));
}
let m = line.match(/^class (\w+)$/i);
if(m) {
struct = { name: m[1], fields: [], hasVMT: false };
i+=3; //skip '{' and 'public:'
do {
let field = lines[i];
field = field.replace('class ', '')
i++;
if(field.indexOf('virtual void') >= 0) {
struct.hasVMT = true;
continue;
}
struct.fields.push(field);
} while(!lines[i+1].includes('static_assert'));
if(struct.hasVMT) {
let vmt = vmts[struct.name];
if(!vmt) {
throw new Error(`No VMT found for ${struct.name}!`);
}
structs.push({ name: `${struct.name}_VMT`, fields: vmt.map(e => `\t${e.ret}(${e.conv}* ${e.name})${e.args};`) });
struct.fields.unshift(`\t${struct.name}_VMT *_VMT;`);
}
structs.push(struct);
}
m = line.match(/^class (\w+) : public (\w+)$/i);
if(m) {
let parent = structs.find(e => e.name == m[2]);
struct = { name: m[1], fields: [...parent.fields], parent: parent, hasVMT: parent.hasVMT };
i+=3; //skip '{' and 'public:'
do {
let field = lines[i];
field = field.replace('class ', '')
i++;
if(field.indexOf('virtual void') >= 0) {
struct.hasVMT = true;
continue;
}
struct.fields.push(field);
} while(!lines[i+1].includes('static_assert'));
if(struct.hasVMT) {
let vmt = vmts[struct.name];
if(!vmt) {
throw new Error(`No VMT found for ${struct.name}!`);
}
structs.push({ name: `${struct.name}_VMT`, fields: vmt.map(e => `\t${e.ret}(${e.conv}* ${e.name})${e.args};`) });
struct.fields.unshift(`\t${struct.name}_VMT *_VMT;`);
}
structs.push(struct);
}
}
var output = structs.map(e => `struct ${e.name};`).join('\n');
output += '\n#pragma pack(push, 1)\n\n' +
structs.map(e => `struct ${e.name} {\n ${e.fields.join('\n')} \n};\n`).join('\n')
+ '\n#pragma pack(pop)';
fs.writeFileSync(`${__dirname}/D2R/IDA.h`, output);