Fix global uniqueness

This commit is contained in:
Guus Waals 2025-06-02 12:43:30 +08:00
parent 4dc6fb2176
commit 0d488e24e3
20 changed files with 120 additions and 14 deletions

View File

@ -1,6 +1,7 @@
// Cleanup the database of all missing files, and report duplicates
// @category _Reman3
// @menupath Reman3.Cleanup Database
// @importpackage org.sqlite
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Function;

View File

@ -1,6 +1,7 @@
// Script to export decompiled C code for selected function from Ghidra
// @category _Reman3
// @menupath Reman3.Dump Current Function
// @importpackage org.sqlite
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Function;

View File

@ -1,6 +1,7 @@
// Script to export decompiled C code for selected function from Ghidra as Fix type
// @category _Reman3
// @menupath Reman3.Dump Current Function (Fix)
// @importpackage org.sqlite
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Function;

View File

@ -17,7 +17,6 @@ public class DumpGlobals extends GhidraScript {
try (FunctionDatabase functionDatabase = new FunctionDatabase(this)) {
GlobalDumper globalDumper = new GlobalDumper(this, functionDatabase);
globalDumper.dumpGlobals();
TypeDumper dumper = new TypeDumper(this);

View File

@ -1,6 +1,7 @@
// Exports binary read only and data segments to a binary + header file
// @category _Reman3
// @menupath Reman3.Export Data Segment
// @importpackage org.sqlite
import java.io.File;
import java.io.FileOutputStream;

View File

@ -22,8 +22,6 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.data.AbstractStringDataType;
import ghidra.program.model.data.Array;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.program.model.data.DataTypePath;
import ghidra.program.model.data.PointerDataType;
import ghidra.program.model.listing.Data;
import ghidra.program.model.pcode.HighSymbol;

View File

@ -15,6 +15,7 @@ import ghidra.program.model.data.DataType;
import ghidra.program.model.data.Enum;
import ghidra.program.model.data.EnumDataType;
import ghidra.program.model.data.FunctionDefinition;
import ghidra.program.model.data.Pointer;
import ghidra.program.model.data.ProgramBasedDataTypeManager;
import ghidra.program.model.data.Structure;
import ghidra.program.model.data.TypeDef;
@ -44,15 +45,19 @@ public class TypeDumper {
for (GlobalEntry globalEntry : globals) {
// Fetch type of global from ghidra
Address addr = globalEntry.address;
if (globalEntry.name == "p_fn_vDisplayAll")
script.println("EEEEE");
if (globalEntry.name.equals("p_fn_vDisplayAll"))
script.println("EE" + globalEntry.name + "EE");
// script.print("Global: " + globalEntry.name);
Data data = script.getDataAt(addr);
if (data != null) {
DataType type = data.getDataType();
if (type instanceof FunctionDefinition) {
requiredFunctionTypes.add(type.getDisplayName());
script.println("Adding required global function type: " + type.getDisplayName());
if (type instanceof Pointer) {
DataType inner = ((Pointer) type).getDataType();
if (inner instanceof FunctionDefinition) {
requiredFunctionTypes.add(inner.getDisplayName());
script.println("Adding required global function type: " + type.getDisplayName());
}
}
}
}

View File

@ -6,7 +6,7 @@
extern "C" {
undefined FUN_00470350(void); // 00470350 // FUN_00470350 // cdecl
undefined r3_load_textures_2(void); // 00471760 // r3_load_textures_2 // cdecl
void level_displayFn(byte param); // 00446fc0 // level_displayFn // cdecl
void r3_levelDisplayFn(byte param); // 00446fc0 // r3_levelDisplayFn // cdecl
void r3_noop(void * p_cTxt1, void * p_cTxt2); // 00401100 // r3_noop // stdcall
undefined r3_closeConcatTextureFile(void); // 004711d0 // r3_closeConcatTextureFile // cdecl
undefined FUN_00470db0(void); // 00470db0 // FUN_00470db0 // cdecl

View File

@ -117,6 +117,9 @@ char(&s_volumeNameBuffer)[128] = reinterpret_cast<char(&)[128]>(GH_MEM(0x005d27b
r3_main_data& r3_main_data_005d28b6= (r3_main_data&) GH_MEM(0x005d28b6);
dword& g_soundOnHD= (dword&) GH_MEM(0x005d29bc);
dword& g_complete= (dword&) GH_MEM(0x005d29c0);
undefined1& DAT_005d2b18= (undefined1&) GH_MEM(0x005d2b18);
undefined4& DAT_005e693c= (undefined4&) GH_MEM(0x005e693c);
undefined4& DAT_0063be24= (undefined4&) GH_MEM(0x0063be24);
int& g_windowInitialized= (int&) GH_MEM(0x0077d0a4);
int& g_runMaximized= (int&) GH_MEM(0x0077d0a8);
undefined4& g_engineShouldRun= (undefined4&) GH_MEM(0x0077d0b0);
@ -136,6 +139,7 @@ char *& g_crt_cmdLine= (char *&) GH_MEM(0x0077ea84);
char(&s_quitting1)[64] = reinterpret_cast<char(&)[64]>(GH_MEM(0x007825c0));
char(&s_wndStrQuiting)[56] = reinterpret_cast<char(&)[56]>(GH_MEM(0x00782600));
GAM_EngineStructure& g_stEngineStructure= (GAM_EngineStructure&) GH_MEM(0x007d7dc0);
undefined1& DAT_007d98fc= (undefined1&) GH_MEM(0x007d98fc);
undefined4& DAT_007d9cc4= (undefined4&) GH_MEM(0x007d9cc4);
byte& g_config_unused0= (byte&) GH_MEM(0x007d9df0);
char(&g_driveLetter)[4] = reinterpret_cast<char(&)[4]>(GH_MEM(0x007d9e70));

View File

@ -122,6 +122,9 @@ extern char(&s_volumeNameBuffer)[128]; // 005d27b0
extern r3_main_data& r3_main_data_005d28b6; // 005d28b6
extern dword& g_soundOnHD; // 005d29bc
extern dword& g_complete; // 005d29c0
extern undefined1& DAT_005d2b18; // 005d2b18
extern undefined4& DAT_005e693c; // 005e693c
extern undefined4& DAT_0063be24; // 0063be24
extern int& g_windowInitialized; // 0077d0a4
extern int& g_runMaximized; // 0077d0a8
extern undefined4& g_engineShouldRun; // 0077d0b0
@ -141,6 +144,7 @@ extern char *& g_crt_cmdLine; // 0077ea84
extern char(&s_quitting1)[64]; // 007825c0
extern char(&s_wndStrQuiting)[56]; // 00782600
extern GAM_EngineStructure& g_stEngineStructure; // 007d7dc0
extern undefined1& DAT_007d98fc; // 007d98fc
extern undefined4& DAT_007d9cc4; // 007d9cc4
extern byte& g_config_unused0; // 007d9df0
extern char(&g_driveLetter)[4]; // 007d9e70

View File

@ -6,8 +6,8 @@
#include <r3/binders/stub.h>
#include <gh_global.h>
// 00446fc0
// level_displayFn
extern "C" void level_displayFn(byte param) {
gh_stub_impl_cdecl<0x00446fc0, void>(param);
// 00447130
// FUN_00447130
extern "C" undefined FUN_00447130(void) {
return gh_stub_impl_cdecl<0x00447130, undefined>();
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 00451530
// FUN_00451530
extern "C" undefined FUN_00451530(undefined4 param_1) {
return gh_stub_impl_cdecl<0x00451530, undefined>(param_1);
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 0045fc70
// FUN_0045fc70
extern "C" undefined FUN_0045fc70(undefined4 param_1) {
return gh_stub_impl_cdecl<0x0045fc70, undefined>(param_1);
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 0046fec0
// FUN_0046fec0
extern "C" undefined FUN_0046fec0(void) {
return gh_stub_impl_cdecl<0x0046fec0, undefined>();
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 0048a920
// FUN_0048a920
extern "C" undefined FUN_0048a920(undefined4 param_1) {
return gh_stub_impl_cdecl<0x0048a920, undefined>(param_1);
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 00447200
// ?r3_renderViewport
extern "C" undefined UNKr3_renderViewport(undefined4 viewportIdx) {
return gh_stub_impl_cdecl<0x00447200, undefined>(viewportIdx);
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 00447460
// doGraphics
extern "C" void doGraphics(byte param_1) {
gh_stub_impl_stdcall<0x00447460, void>(param_1);
}

View File

@ -0,0 +1,13 @@
// AUTO-GENERATED FILE!!!!
// This function has yet to be decompiled using 'Dump Current Function' in ghidra
// with possible manualy fixes
#include <r3/binders/auto.h>
#include <r3/binders/stub.h>
#include <gh_global.h>
// 0046f2c0
// get_one
extern "C" int get_one(void) {
return gh_stub_impl_cdecl<0x0046f2c0, int>();
}

View File

@ -5153,6 +5153,7 @@ struct tdstCsaList_ {
#define C_wTimerPaused 4
struct _tdstRangeSplitListDisk {
};
typedef undefined (*level_displayFn)(void);
#define __STDC__ 1
#define C_SNDREAL_0 0
#define C_SNDREAL_1 65536

View File

@ -82,7 +82,7 @@ DatabaseManager::DatabaseManager(const std::string &db_path) : db(nullptr) {
const char *create_tables = R"(
CREATE TABLE IF NOT EXISTS Functions (filepath TEXT, name TEXT, address TEXT, type INTEGER DEFAULT 0, calling_convention INTEGER DEFAULT 0, parameter_names TEXT DEFAULT '', parameter_types TEXT DEFAULT '', return_type TEXT DEFAULT '', PRIMARY KEY (name, filepath));
CREATE TABLE IF NOT EXISTS Imports (filepath TEXT, name TEXT, address TEXT, type INTEGER DEFAULT 0, calling_convention INTEGER DEFAULT 0, parameter_names TEXT DEFAULT '', parameter_types TEXT DEFAULT '', return_type TEXT DEFAULT '', PRIMARY KEY (name, filepath));
CREATE TABLE IF NOT EXISTS Globals (filepath TEXT, name TEXT, address TEXT);
CREATE TABLE IF NOT EXISTS Globals (filepath TEXT, name TEXT, address TEXT, PRIMARY KEY (name, filepath));
)";
sqlite3_exec(db, create_tables, nullptr, nullptr, nullptr);