Skip to content

Commit cb19b00

Browse files
committed
chore(VB): refactoring and match KB names
1 parent 9dc63d8 commit cb19b00

7 files changed

Lines changed: 148 additions & 330 deletions

File tree

compilers/rtti/msvc/msvc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static void _rtti_msvc_process_vtable(RDContext* ctx, RDReader* r,
249249
RDType t;
250250

251251
if(rd_get_type(ctx, vtable_entryaddr, &t) &&
252-
!strcmp(t.name, objlocator_type)) {
252+
!strcmp(rd_typedef_name(t.def), objlocator_type)) {
253253
name = rd_format("%s::__obj_locator", classtag_ptr);
254254
rd_library_name(ctx, vtable_addr, name);
255255
rd_library_type(ctx, vtable_addr, rd_integral_from_size(stride),

compilers/vb/components.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "components.h"
22
#include <stdio.h>
33

4-
static const char* _pe_cv_guid_to_string(const PEGUID* guid) {
4+
static const char* _pe_cv_guid_to_string(const VBGUID* guid) {
55
static char buffer[37]; // "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + NUL
66

77
snprintf(buffer, sizeof(buffer),
@@ -13,10 +13,10 @@ static const char* _pe_cv_guid_to_string(const PEGUID* guid) {
1313
return buffer;
1414
}
1515

16-
const RDKBObject* pe_vb_components_find(RDContext* ctx, const PEGUID* guid) {
16+
const RDKBObject* vb_components_find(RDContext* ctx, const VBGUID* guid) {
1717
if(!guid) return NULL;
1818

19-
const RDKBObject* components = rd_kb_load(ctx, "pe/vb/components");
19+
const RDKBObject* components = rd_kb_load(ctx, "compiler/vb/components");
2020
if(!components) return NULL;
2121

2222
const char* guid_str = _pe_cv_guid_to_string(guid);

compilers/vb/components.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ typedef struct PEVBComponent {
88
const char* const* events;
99
} PEVBComponent;
1010

11-
const RDKBObject* pe_vb_components_find(RDContext* ctx, const PEGUID* guid);
11+
const RDKBObject* vb_components_find(RDContext* ctx, const VBGUID* guid);

compilers/vb/decompiler.c

Lines changed: 69 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include "vb/format.h"
44
#include <string.h>
55

6-
static const RDInstruction PE_VB_ENTRY_MATCH[] = {
6+
static const RDInstruction VB_ENTRY_MATCH[] = {
77
{.mnemonic = "push", .operands = {[0] = {.kind = RD_OP_ADDR}}},
88
{.mnemonic = "call", .operands = {[0] = {.kind = RD_OP_ADDR}}},
99
};
1010

11-
static const RDInstruction PE_VB_EVENT_ENTRY[] = {
11+
static const RDInstruction VB_EVENT_ENTRY[] = {
1212
{
1313
.mnemonic = "sub",
1414
.operands = {[0] = {.kind = RD_OP_DISPL}, [1] = {.kind = RD_OP_IMM}},
@@ -20,12 +20,12 @@ static const RDInstruction PE_VB_EVENT_ENTRY[] = {
2020
};
2121

2222
static inline bool
23-
_pe_vb_has_optional_info(const PEVBPublicObjectDescriptor* descr) {
23+
_vb_has_optional_info(const VBPublicObjectDescriptor* descr) {
2424
return (descr->fObjectType & 2) == 2;
2525
}
2626

27-
static void _pe_vb_apply_header_str(RDAddress vb_base, RDReader* r, u32 offset,
28-
const char* name, RDContext* ctx) {
27+
static void _vb_apply_header_str(RDAddress vb_base, RDReader* r, u32 offset,
28+
const char* name, RDContext* ctx) {
2929
if(!offset) return;
3030

3131
RDAddress address = vb_base + offset;
@@ -38,22 +38,22 @@ static void _pe_vb_apply_header_str(RDAddress vb_base, RDReader* r, u32 offset,
3838
rd_library_name(ctx, address, name);
3939
}
4040

41-
static void _pe_vb_decompiler_decode(RDAddress address, const char* name,
42-
RDContext* ctx) {
41+
static void _vb_decompiler_decode(RDAddress address, const char* name,
42+
RDContext* ctx) {
4343
RDInstruction instrs[2];
4444
if(!rd_decode_n(ctx, address, instrs, rd_count_of(instrs))) return;
4545

46-
if(!rd_instr_match_n(ctx, instrs, PE_VB_EVENT_ENTRY,
47-
rd_count_of(PE_VB_EVENT_ENTRY)))
46+
if(!rd_instr_match_n(ctx, instrs, VB_EVENT_ENTRY,
47+
rd_count_of(VB_EVENT_ENTRY)))
4848
return;
4949

5050
RDAddress event_ep = instrs[1].operands[0].addr;
5151
rd_library_function(ctx, event_ep, name);
5252
}
5353

54-
static void _pe_vb_decompiler_events(const PEVBPublicObjectDescriptor* descr,
55-
const PEVBControlInfo* ctrlinfo,
56-
RDReader* r, RDContext* ctx) {
54+
static void _vb_decompiler_events(const VBPublicObjectDescriptor* descr,
55+
const VBControlInfo* ctrlinfo, RDReader* r,
56+
RDContext* ctx) {
5757
if(!descr->lpszObjectName || !ctrlinfo->lpGuid || !ctrlinfo->lpszName ||
5858
!ctrlinfo->lpEventInfo)
5959
return;
@@ -64,18 +64,18 @@ static void _pe_vb_decompiler_events(const PEVBPublicObjectDescriptor* descr,
6464
rd_reader_seek(r, ctrlinfo->lpszName);
6565
char* ctrlname = rd_strdup(rd_reader_read_str(r, NULL));
6666

67-
PEGUID guid;
67+
VBGUID guid;
6868
rd_reader_seek(r, ctrlinfo->lpGuid);
69-
if(!pe_vb_read_guid(r, &guid)) goto cleanup;
69+
if(!vb_read_guid(r, &guid)) goto cleanup;
7070

71-
const RDKBObject* c = pe_vb_components_find(ctx, &guid);
71+
const RDKBObject* c = vb_components_find(ctx, &guid);
7272
if(!c) goto cleanup;
7373

74-
PEVBEventInfo evinfo;
74+
VBEventInfo evinfo;
7575
rd_reader_seek(r, ctrlinfo->lpEventInfo);
76-
if(!pe_vb_read_event_info(r, &evinfo)) goto cleanup;
76+
if(!vb_read_event_info(r, &evinfo)) goto cleanup;
7777

78-
rd_library_type(ctx, ctrlinfo->lpEventInfo, "PE_VB_EVENT_INFO", 0,
78+
rd_library_type(ctx, ctrlinfo->lpEventInfo, "VB_EVENT_INFO", 0,
7979
RD_TYPE_NONE);
8080

8181
if(evinfo.lpEVENT_SINK_QueryInterface)
@@ -99,129 +99,128 @@ static void _pe_vb_decompiler_events(const PEVBPublicObjectDescriptor* descr,
9999
if(!e) break;
100100

101101
const char* n = rd_format("%s_%s_%s", objname, ctrlname, e);
102-
_pe_vb_decompiler_decode((RDAddress)event_va, n, ctx);
102+
_vb_decompiler_decode((RDAddress)event_va, n, ctx);
103103
}
104104

105105
cleanup:
106106
rd_free(ctrlname);
107107
rd_free(objname);
108108
}
109109

110-
static bool _pe_vb_decompiler_controls(const PEVBPublicObjectDescriptor* descr,
111-
const PEVBObjectInfoOptional* objinfo,
112-
RDReader* r, RDContext* ctx) {
110+
static bool _vb_decompiler_controls(const VBPublicObjectDescriptor* descr,
111+
const VBObjectInfoOptional* objinfo,
112+
RDReader* r, RDContext* ctx) {
113113

114114
rd_reader_seek(r, objinfo->lpControls);
115115

116116
for(u32 i = 0; i < objinfo->dwControlCount; i++) {
117-
PEVBControlInfo ctrlinfo;
118-
bool ok = pe_vb_read_control_info(r, &ctrlinfo);
117+
VBControlInfo ctrlinfo;
118+
bool ok = vb_read_control_info(r, &ctrlinfo);
119119

120120
if(ok) {
121121
rd_reader_save(r);
122-
rd_library_type(ctx, rd_reader_tell(r), "PE_VB_CONTROL_INFO", 0,
122+
rd_library_type(ctx, rd_reader_tell(r), "VB_CONTROL_INFO", 0,
123123
RD_TYPE_NONE);
124-
_pe_vb_decompiler_events(descr, &ctrlinfo, r, ctx);
124+
_vb_decompiler_events(descr, &ctrlinfo, r, ctx);
125125
rd_reader_restore(r);
126126
}
127127
}
128128

129129
return !rd_reader_has_error(r);
130130
}
131131

132-
static bool _pe_vb_decompiler_obj(RDAddress address, RDReader* r,
133-
RDContext* ctx) {
134-
PEVBPublicObjectDescriptor descr;
135-
if(!pe_vb_read_public_object_descriptor(r, &descr)) return false;
132+
static bool _vb_decompiler_obj(RDAddress address, RDReader* r, RDContext* ctx) {
133+
VBPublicObjectDescriptor descr;
134+
if(!vb_read_public_object_descriptor(r, &descr)) return false;
136135

137-
rd_library_type(ctx, address, "PE_VB_PUBLIC_OBJECT_DESCRIPTOR", 0,
136+
rd_library_type(ctx, address, "VB_PUBLIC_OBJECT_DESCRIPTOR", 0,
138137
RD_TYPE_NONE);
139138

140139
if(descr.lpObjectInfo) {
141140
rd_reader_seek(r, descr.lpObjectInfo);
142-
if(!_pe_vb_has_optional_info(&descr)) goto done;
141+
if(!_vb_has_optional_info(&descr)) goto done;
143142

144-
PEVBObjectInfoOptional opt_objinfo;
145-
if(!pe_vb_read_object_info_optional(r, &opt_objinfo) ||
143+
VBObjectInfoOptional opt_objinfo;
144+
if(!vb_read_object_info_optional(r, &opt_objinfo) ||
146145
!opt_objinfo.lpControls)
147146
goto done;
148147

149-
rd_library_type(ctx, descr.lpObjectInfo, "PE_VB_OBJECT_INFO_OPTIONAL",
150-
0, RD_TYPE_NONE);
148+
rd_library_type(ctx, descr.lpObjectInfo, "VB_OBJECT_INFO_OPTIONAL", 0,
149+
RD_TYPE_NONE);
151150

152-
return _pe_vb_decompiler_controls(&descr, &opt_objinfo, r, ctx);
151+
return _vb_decompiler_controls(&descr, &opt_objinfo, r, ctx);
153152
}
154153

155154
done:
156155
return !rd_reader_has_error(r);
157156
}
158157

159-
static void pe_vb_decompiler_execute(RDContext* ctx) {
158+
static void vb_decompiler_execute(RDContext* ctx) {
160159
RDAddress ep;
161160
if(!rd_get_entry_point(ctx, &ep)) return;
162161

163-
RDInstruction instrs[rd_count_of(PE_VB_ENTRY_MATCH)] = {0};
162+
RDInstruction instrs[rd_count_of(VB_ENTRY_MATCH)] = {0};
164163
if(!rd_decode_n(ctx, ep, instrs, rd_count_of(instrs))) return;
165164

166-
if(!rd_instr_match_n(ctx, instrs, PE_VB_ENTRY_MATCH,
167-
rd_count_of(PE_VB_ENTRY_MATCH)))
165+
if(!rd_instr_match_n(ctx, instrs, VB_ENTRY_MATCH,
166+
rd_count_of(VB_ENTRY_MATCH)))
168167
return;
169168

170-
rd_kb_load(ctx, "pe/vb/types");
169+
rd_kb_load(ctx, "compiler/vb/types");
171170

172171
RDReader* r = rd_get_reader(ctx);
173172
RDAddress vb_base = instrs[0].operands[0].addr;
174173

175-
PEVBHeader vb_header;
176-
PEVBProjectInfo proj_info;
177-
PEVBGuiTable gui_table;
178-
PEVBObjectTable object_table;
179-
PEVBObjectTree object_tree;
180-
PEVBPublicObjectDescriptor pub_obj_descr;
174+
VBHeader vb_header;
175+
VBProjectInfo proj_info;
176+
VBGuiTable gui_table;
177+
VBObjectTable object_table;
178+
VBObjectTree object_tree;
179+
VBPublicObjectDescriptor pub_obj_descr;
181180

182181
rd_reader_seek(r, vb_base);
183182

184-
if(!pe_vb_read_header(r, &vb_header) ||
185-
strncmp("VB5!", vb_header.szVbMagic, PE_VB_SIGNATURE_SIZE) != 0)
183+
if(!vb_read_header(r, &vb_header) ||
184+
strncmp("VB5!", vb_header.szVbMagic, VB_SIGNATURE_SIZE) != 0)
186185
return;
187186

188-
_pe_vb_apply_header_str(vb_base, r, vb_header.bszProjectDescription,
189-
"vb_proj_desc", ctx);
190-
_pe_vb_apply_header_str(vb_base, r, vb_header.bszProjectExeName,
191-
"vb_proj_exe", ctx);
192-
_pe_vb_apply_header_str(vb_base, r, vb_header.bszProjectHelpFile,
193-
"vb_proj_help", ctx);
194-
_pe_vb_apply_header_str(vb_base, r, vb_header.bszProjectName,
195-
"vb_proj_name", ctx);
187+
_vb_apply_header_str(vb_base, r, vb_header.bszProjectDescription,
188+
"vb_proj_desc", ctx);
189+
_vb_apply_header_str(vb_base, r, vb_header.bszProjectExeName, "vb_proj_exe",
190+
ctx);
191+
_vb_apply_header_str(vb_base, r, vb_header.bszProjectHelpFile,
192+
"vb_proj_help", ctx);
193+
_vb_apply_header_str(vb_base, r, vb_header.bszProjectName, "vb_proj_name",
194+
ctx);
196195

197-
rd_library_type(ctx, vb_base, "PE_VB_HEADER", 0, RD_TYPE_NONE);
196+
rd_library_type(ctx, vb_base, "VB_HEADER", 0, RD_TYPE_NONE);
198197

199-
PEVBProjectInfo projinfo = {0};
198+
VBProjectInfo projinfo = {0};
200199

201200
if(vb_header.lpProjectData) {
202201
rd_reader_seek(r, vb_header.lpProjectData);
203202

204-
if(pe_vb_read_project_info(r, &proj_info)) {
205-
rd_library_type(ctx, vb_header.lpProjectData, "PE_VB_PROJECT_INFO",
206-
0, RD_TYPE_NONE);
203+
if(vb_read_project_info(r, &proj_info)) {
204+
rd_library_type(ctx, vb_header.lpProjectData, "VB_PROJECT_INFO", 0,
205+
RD_TYPE_NONE);
207206
}
208207
}
209208

210209
if(proj_info.lpObjectTable) {
211210
rd_reader_seek(r, proj_info.lpObjectTable);
212211

213-
if(pe_vb_read_object_table(r, &object_table)) {
214-
rd_library_type(ctx, proj_info.lpObjectTable, "PE_VB_OBJECT_TABLE",
215-
0, RD_TYPE_NONE);
212+
if(vb_read_object_table(r, &object_table)) {
213+
rd_library_type(ctx, proj_info.lpObjectTable, "VB_OBJECT_TABLE", 0,
214+
RD_TYPE_NONE);
216215
}
217216
}
218217

219218
if(object_table.lpObjectTreeInfo) {
220219
rd_reader_seek(r, object_table.lpObjectTreeInfo);
221220

222-
if(pe_vb_read_object_tree(r, &object_tree)) {
221+
if(vb_read_object_tree(r, &object_tree)) {
223222
rd_library_type(ctx, object_table.lpObjectTreeInfo,
224-
"PE_VB_OBJECT_TREE", 0, RD_TYPE_NONE);
223+
"VB_OBJECT_TREE", 0, RD_TYPE_NONE);
225224
}
226225
}
227226

@@ -230,7 +229,7 @@ static void pe_vb_decompiler_execute(RDContext* ctx) {
230229

231230
for(u16 i = 0; i < object_table.wTotalObjects; i++) {
232231
rd_reader_save(r);
233-
bool ok = _pe_vb_decompiler_obj(rd_reader_tell(r), r, ctx);
232+
bool ok = _vb_decompiler_obj(rd_reader_tell(r), r, ctx);
234233
rd_reader_restore(r);
235234

236235
if(!ok) break;
@@ -244,5 +243,5 @@ const RDAnalyzerPlugin VB_DECOMPILER = {
244243
.name = "Decompile VB5/6",
245244
.flags = RD_AF_SELECTED | RD_AF_RUNONCE,
246245
.order = 1000,
247-
.execute = pe_vb_decompiler_execute,
246+
.execute = vb_decompiler_execute,
248247
};

0 commit comments

Comments
 (0)