This commit is contained in:
Guus Waals 2025-05-29 15:56:11 +08:00
parent 58397127e7
commit 0383ef8f13
5 changed files with 92 additions and 76 deletions

View File

@ -1,64 +1,71 @@
add_executable(game_re function(setup_target TARGET)
r3/main.cpp add_executable(${TARGET}
r3/binders/static_mem.cxx r3/main.cpp
gh_global.cxx r3/binders/static_mem.cxx
) gh_global.cxx
target_compile_features(game_re PUBLIC cxx_std_20)
target_include_directories(game_re PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(
game_re PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
if(WIN32 AND R3_32BIT)
target_link_libraries(game_re PRIVATE
binkw32
d3d8
dinput8
) )
endif()
target_compile_definitions(game_re PRIVATE target_compile_features(${TARGET} PUBLIC cxx_std_20)
R3_GAME_DATA_DIR=\"${GAME_DATA_DIR}\" target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
)
get_filename_component(R3_DATA_SEGMENT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/gh_datasegment.bin" ABSOLUTE) set_target_properties(
target_compile_definitions(game_re PRIVATE ${TARGET} PROPERTIES
R3_DATA_SEGMENT_FILE=\"${R3_DATA_SEGMENT_FILE}\" RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
) )
target_compile_definitions(game_re PRIVATE if(WIN32 AND R3_32BIT)
_CRT_SECURE_NO_WARNINGS=1 target_link_libraries(${TARGET} PRIVATE
_CRT_NONSTDC_NO_WARNINGS=1) binkw32
d3d8
dinput8
)
endif()
target_link_libraries(game_re PRIVATE spdlog) target_compile_definitions(${TARGET} PRIVATE
R3_GAME_DATA_DIR=\"${GAME_DATA_DIR}\"
)
file(GLOB GH_AUTO_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_auto/*.cxx) get_filename_component(R3_DATA_SEGMENT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/gh_datasegment.bin" ABSOLUTE)
file(GLOB GH_FIX_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_fix/*.cxx) target_compile_definitions(${TARGET} PRIVATE
file(GLOB GH_STUB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_stub/*.cxx) R3_DATA_SEGMENT_FILE=\"${R3_DATA_SEGMENT_FILE}\"
)
target_sources(game_re PRIVATE target_compile_definitions(${TARGET} PRIVATE
${GH_AUTO_SOURCES} _CRT_SECURE_NO_WARNINGS=1
${GH_FIX_SOURCES} _CRT_NONSTDC_NO_WARNINGS=1)
${GH_STUB_SOURCES}
)
# Ignore -Wformat-security target_link_libraries(${TARGET} PRIVATE spdlog)
target_compile_options(game_re PRIVATE -Wno-format-security)
# Ignore -Wmicrosoft-cast file(GLOB GH_AUTO_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_auto/*.cxx)
target_compile_options(game_re PRIVATE -Wno-microsoft-cast) file(GLOB GH_FIX_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_fix/*.cxx)
file(GLOB GH_STUB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/gh_stub/*.cxx)
# Automatically re-run CMake if any gh_*.cxx files change target_sources(${TARGET} PRIVATE
# due to ghidra script runs ${GH_AUTO_SOURCES}
set_property( ${GH_FIX_SOURCES}
DIRECTORY ${GH_STUB_SOURCES}
APPEND )
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gh_cmake_timestamp
)
target_precompile_headers(game_re PRIVATE # Ignore -Wformat-security
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/r3/binders/auto_pch.cxx>" target_compile_options(${TARGET} PRIVATE -Wno-format-security)
)
# Ignore -Wmicrosoft-cast
target_compile_options(${TARGET} PRIVATE -Wno-microsoft-cast)
# Automatically re-run CMake if any gh_*.cxx files change
# due to ghidra script runs
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gh_cmake_timestamp
)
target_precompile_headers(${TARGET} PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/r3/binders/auto_pch.cxx>"
)
endfunction()
setup_target(game_re)
setup_target(game_dbg)
target_compile_definitions(game_dbg PRIVATE RE_DBG_INJECTED=1)

View File

@ -6,14 +6,21 @@ set -e
pushd $script_dir pushd $script_dir
file_list=files.txt mkdir -p logs
rm -f $file_list types=(auto ref fix stub)
for dir in gh_auto gh_stub gh_fix; do for type in "${types[@]}"; do
for file in $dir/*.cxx; do file_list="logs/files_${type}.txt"
echo $file >>$file_list rm -f "$file_list"
done
if [ -d "gh_${type}" ]; then
for file in "gh_${type}"/*.cxx; do
echo "$file" >>"$file_list"
done
$tool "@$file_list" -v --type=$type --log-file=logs/log-functions-${type}.txt
fi
done done
$tool @$file_list $tool gh_global.h -mglobals -v --log-file=logs/log-globals.txt
$tool -mduplicates -v --log-file=logs/log-duplicates.txt
popd popd

View File

@ -1,5 +1,6 @@
// @category _Reman3 // @category _Reman3
// @menupath Reman3.Test // @menupath Reman3.Test
// @importpackage org.sqlite
import ghidra.app.script.GhidraScript; import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
@ -26,15 +27,15 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
public class Test extends GhidraScript { import org.sqlite.JDBC;
// Will rebuild all functions
public boolean rebuildAllGlobals = true;
FunctionDatabase functionDB;
public class Test extends GhidraScript {
@Override @Override
public void run() throws Exception { public void run() throws Exception {
RecompileConfig.INSTANCE = new RecompileConfig(this); RecompileConfig.INSTANCE = new RecompileConfig(this);
java.sql.DriverManager.registerDriver(new JDBC());
// Example SQLite usage // Example SQLite usage
testSQLite(); testSQLite();
} }
@ -80,14 +81,4 @@ public class Test extends GhidraScript {
throw e; throw e;
} }
} }
private void scanDirectory(File directory, FunctionDatabase.Type type) throws Exception {
File[] files = directory.listFiles((dir, name) -> name.endsWith(".cxx"));
if (files == null)
return;
for (File file : files) {
scanFile(file, type);
}
}
} }

View File

@ -16,7 +16,8 @@ public class FunctionDatabase {
public enum Type { public enum Type {
Auto, Auto,
Fix, Fix,
Stub Stub,
Ref
} }
public class Dependency implements java.io.Serializable { public class Dependency implements java.io.Serializable {

View File

@ -1,3 +1,13 @@
# Ghidra Scripts # Ghidra Scripts
Add this to your scripts folder and run to generate c code for all functions in the project Add this to your ghidra scripts folder to add the reman decompile scripts to ghidra
NOTE: Make sure to also add the include `sqlite-jdbc-3.49.1.0.jar` to the ghidra scripts folders, as this is required for the ghidra scripts to read the decompile database.
## Decompile database
The decompile database is a sqlite database that contains a list of all files that implement decompiled functions and their source address. It is used to regenerate files, check for duplicates, and more.
To generate the database from the current set of files, run the scan_sources script in the /game_re folder.
Make sure you have set up the tooling by running the /tooling/setup script.