This commit is contained in:
2024-09-24 04:40:28 +08:00
parent 96ea861c26
commit faa171b56b
27 changed files with 464 additions and 564 deletions

View File

@@ -156,6 +156,11 @@ public class FunctionDumper {
// Parse preliminary line tokens
for (int i = 0; i < line.getNumTokens(); i++) {
ClangToken token = line.getToken(i);
if (token.getText().equals("__cdecl") || token.getText().equals("__thiscall")
|| token.getText().equals("__stdcall")) {
// Remove function declaration
continue;
}
if (!token.getText().isEmpty())
tokens.add(token);
}
@@ -208,8 +213,14 @@ public class FunctionDumper {
address = gsym.getStorage().getMinAddress();
}
// Check if it's a function pointer, otherwise add to globals
if (address.isMemoryAddress()) {
globalDumper.addGlobal(address, gsym);
Function maybeFunction = script.getFunctionAt(address);
if (maybeFunction != null) {
externalFunctionCalls.add(maybeFunction);
} else {
globalDumper.addGlobal(address, gsym);
}
}
}
@@ -223,10 +234,6 @@ public class FunctionDumper {
Function calledFunction = script.getFunctionAt(callAddr);
if (calledFunction != null) {
if (isValidFunction(calledFunction)) {
String proto = calledFunction.getSignature().getPrototypeString(false);
headers.add("" + proto
+ "; // " + calledFunction.getEntryPoint() + " // "
+ calledFunction.getName());
externalFunctionCalls.add(calledFunction);
}
}
@@ -243,6 +250,13 @@ public class FunctionDumper {
codeWriter.write('\n');
}
for (Function externalFunction : externalFunctionCalls) {
String proto = externalFunction.getSignature().getPrototypeString(false);
headers.add("" + proto
+ "; // " + externalFunction.getEntryPoint() + " // "
+ externalFunction.getName());
}
for (String header : headers) {
writer2.println(header);
}

View File

@@ -103,6 +103,21 @@ public class GlobalDumper {
public void addGlobal(Address addr, HighSymbol sym) {
DataType dt = sym.getDataType();
// if(symb.get
if (sym.getDataType().getName() == "undefined") {
// script.println("UNDEFINED: " + addr + " - " + dt.getDisplayName() + " - " +
// dt.getClass().getName());
Data data = script.getDataAt(addr);
if (data != null) {
dt = data.getDataType();
// script.println("DATA: " + addr + " - " + dt.getDisplayName());
}
}
// if(sym.getName().startsWith("s_SALIR")) {
// script.println("SALIR: " + addr + " - " + dt.getDisplayName() + " - " +
// dt.getClass().getName());
// // script.println("SALIR: " + sym.getdata());
// }
if (dt == null) {
script.println("WARNING: Missing type for global: " + sym.getName() + " at " + addr);
return;
@@ -195,7 +210,8 @@ public class GlobalDumper {
Array adt = (Array) dt;
DataType baseType = adt.getDataType();
hwriter.println(
linkagePrefix + baseType.getDisplayName() + "(&" + name + ")[" + adt.getNumElements() + "]; // " + addr);
linkagePrefix + baseType.getDisplayName() + "(&" + name + ")[" + adt.getNumElements() + "]; // "
+ addr);
cwriter.println(
baseType.getDisplayName() + "(&" + name + ")[" + adt.getNumElements() + "] = *reinterpret_cast<"
+ baseType.getDisplayName() + "(*)[" + adt.getNumElements() + "]>(GH_MEM(0x" + addr + "));");