Skip to content

Commit a63397f

Browse files
committed
fix: address review comments
1 parent 50ca44e commit a63397f

File tree

4 files changed

+55
-40
lines changed

4 files changed

+55
-40
lines changed

include/patchestry/Ghidra/PcodeOperations.hpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,44 @@ namespace patchestry::ghidra {
6767
return iter != kind_map.end() ? iter->second : VARNODE_UNKNOWN;
6868
}
6969

70+
#ifdef ENABLE_DEBUG
7071
std::string dump() const {
7172
std::string result;
7273
result += "Varnode {\n";
73-
74+
7475
// Convert kind to string
7576
std::string kind_str;
7677
switch (kind) {
77-
case VARNODE_UNKNOWN: kind_str = "UNKNOWN"; break;
78-
case VARNODE_GLOBAL: kind_str = "GLOBAL"; break;
79-
case VARNODE_LOCAL: kind_str = "LOCAL"; break;
80-
case VARNODE_PARAM: kind_str = "PARAM"; break;
81-
case VARNODE_FUNCTION: kind_str = "FUNCTION"; break;
82-
case VARNODE_TEMPORARY: kind_str = "TEMPORARY"; break;
83-
case VARNODE_CONSTANT: kind_str = "CONSTANT"; break;
84-
case VARNODE_STRING: kind_str = "STRING"; break;
78+
case VARNODE_UNKNOWN:
79+
kind_str = "UNKNOWN";
80+
break;
81+
case VARNODE_GLOBAL:
82+
kind_str = "GLOBAL";
83+
break;
84+
case VARNODE_LOCAL:
85+
kind_str = "LOCAL";
86+
break;
87+
case VARNODE_PARAM:
88+
kind_str = "PARAM";
89+
break;
90+
case VARNODE_FUNCTION:
91+
kind_str = "FUNCTION";
92+
break;
93+
case VARNODE_TEMPORARY:
94+
kind_str = "TEMPORARY";
95+
break;
96+
case VARNODE_CONSTANT:
97+
kind_str = "CONSTANT";
98+
break;
99+
case VARNODE_STRING:
100+
kind_str = "STRING";
101+
break;
85102
}
86-
103+
87104
result += " kind: " + kind_str + "\n";
88105
result += " size: " + std::to_string(size) + "\n";
89106
result += " type_key: " + type_key + "\n";
90-
107+
91108
if (operation) {
92109
result += " operation: " + *operation + "\n";
93110
}
@@ -103,10 +120,11 @@ namespace patchestry::ghidra {
103120
if (global) {
104121
result += " global: " + *global + "\n";
105122
}
106-
123+
107124
result += "}";
108125
return result;
109126
}
127+
#endif
110128

111129
Kind kind;
112130
uint32_t size;

include/patchestry/Ghidra/PcodeTypes.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ namespace patchestry::ghidra {
3838

3939
static VarnodeType::Kind convertToKind(const std::string &kind) {
4040
static const std::unordered_map< std::string, VarnodeType::Kind > kind_map = {
41-
{ "invalid", VT_INVALID},
42-
{ "bool", VT_BOOLEAN},
43-
{ "integer", VT_INTEGER},
44-
{ "float", VT_FLOAT},
45-
{ "pointer", VT_POINTER},
46-
{ "function", VT_FUNCTION},
47-
{ "array", VT_ARRAY},
48-
{ "struct", VT_STRUCT},
49-
{ "union", VT_UNION},
50-
{ "enum", VT_ENUM},
51-
{ "typedef", VT_TYPEDEF},
52-
{"undefined", VT_UNDEFINED},
53-
{ "void", VT_VOID},
54-
{"WideCharDataType", VT_WIDECHAR}
41+
{ "invalid", VT_INVALID },
42+
{ "bool", VT_BOOLEAN },
43+
{ "integer", VT_INTEGER },
44+
{ "float", VT_FLOAT },
45+
{ "pointer", VT_POINTER },
46+
{ "function", VT_FUNCTION },
47+
{ "array", VT_ARRAY },
48+
{ "struct", VT_STRUCT },
49+
{ "union", VT_UNION },
50+
{ "enum", VT_ENUM },
51+
{ "typedef", VT_TYPEDEF },
52+
{ "undefined", VT_UNDEFINED },
53+
{ "void", VT_VOID },
54+
{ "wchar", VT_WIDECHAR }
5555
};
5656

5757
// if kind is not present in the map, return vt_invalid

lib/patchestry/AST/OperationBuilder.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ namespace patchestry::ast {
258258

259259
if (!vnode.string_value) {
260260
LOG(ERROR) << "No string value found, invalid varnode.\n";
261+
#ifdef ENABLE_DEBUG
261262
LOG(ERROR) << vnode.dump() << "\n";
263+
#endif
262264
return {};
263265
}
264266

@@ -267,31 +269,26 @@ namespace patchestry::ast {
267269
if (!vnode.type_key.empty()) {
268270
if (type_builder().get_serialized_types().contains(vnode.type_key)) {
269271
auto type = type_builder().get_serialized_types().at(vnode.type_key);
270-
is_wide = type->isWideCharType();
272+
is_wide = type->isWideCharType();
271273
}
272274
}
273275

274276
// For empty string, we still need an array of size 1 for the null terminator
275277
const size_t string_length = vnode.string_value->length();
276-
const size_t array_size = string_length + 1; // +1 for null terminator
278+
const size_t array_size = string_length + 1; // +1 for null terminator
277279

278280
// Create the appropriate array type
279-
auto char_type = is_wide ? ctx.WideCharTy : ctx.CharTy;
281+
auto char_type = is_wide ? ctx.WideCharTy : ctx.CharTy;
280282
auto string_array = ctx.getConstantArrayType(
281-
char_type.withConst(),
282-
llvm::APInt(32, array_size),
283-
nullptr,
284-
clang::ArraySizeModifier::Normal,
285-
0
283+
char_type.withConst(), llvm::APInt(32, array_size), nullptr,
284+
clang::ArraySizeModifier::Normal, 0
286285
);
287286

288287
return clang::StringLiteral::Create(
289-
ctx,
290-
*vnode.string_value, // Use the string value directly
288+
ctx,
289+
*vnode.string_value, // Use the string value directly
291290
is_wide ? clang::StringLiteralKind::Wide : clang::StringLiteralKind::Ordinary,
292-
false,
293-
string_array,
294-
clang::SourceLocation()
291+
false, string_array, clang::SourceLocation()
295292
);
296293
}
297294

scripts/ghidra/PatchestryDecompileFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ private void serialize(DataType data_type) throws Exception {
584584
name("size").value(data_type.getLength());
585585

586586
} else if (data_type instanceof WideCharDataType) {
587-
name("kind").value("WideCharDataType");
587+
name("kind").value("wchar");
588588
name("size").value(data_type.getLength());
589589

590590
} else if (data_type instanceof StringDataType) {

0 commit comments

Comments
 (0)