Skip to content

Commit

Permalink
Merge pull request #237 from chaoticgd/comment_headers
Browse files Browse the repository at this point in the history
Add comment headers to the output of the stdump functions and stdump globals commands
  • Loading branch information
chaoticgd authored Sep 8, 2024
2 parents 6f557d4 + 6e75753 commit 7d0af05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v2.2

- stdump: The `functions` and `globals` subcommands now output a header comment like the `types` command.
- stdump: The output format of the `files` subcommand has been updated.

## v2.1

- Variable symbols are no longer incorrectly deduplicated as if they were types.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This is intended to be used with [ghidra-emotionengine-reloaded](https://github.

### uncc

This is similar to stdump except it organizes its output into separate source files, and has a number of extra features designed to try and make said output closer to valid source code. A `SOURCES.txt` file must be provided in the output directory, which can be generated using the `stdump files` command (you should fixup the paths manually so that they're relative to the output directory, and remove the address comments). Additionally, non-empty files that do not start with `// STATUS: NOT STARTED` will not be overwritten.
This is similar to stdump except it organizes its output into separate source files, and has a number of extra features designed to try and make said output closer to valid source code. A `SOURCES.txt` file must be provided in the output directory, which can be generated using the `stdump files` command (you should fixup the paths manually so that they're relative to the output directory, and remove the addresses). Additionally, non-empty files that do not start with `// STATUS: NOT STARTED` will not be overwritten.

If a `FUNCTIONS.txt` file is provided in the output directory, as can be generated using the included `CCCDecompileAllFunctions.java` script for Ghidra, the code from that file will be used to populate the function bodies in the output. In this case, the first group of local variable declarations emitted will be those recovered from the symbols, and the second group will be from the code provided in the functions file. Function names are demangled.

Expand Down
9 changes: 8 additions & 1 deletion src/stdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ static void print_functions(FILE* out, const Options& options)

CppPrinter printer(out, config);

printer.comment_block_beginning(options.input_file.filename().string().c_str(), "stdump", get_version());

bool first_iteration = true;
SourceFileHandle source_file_handle;
for(const Function* function : functions) {
Expand Down Expand Up @@ -267,6 +269,8 @@ static void print_globals(FILE* out, const Options& options)

CppPrinter printer(out, config);

printer.comment_block_beginning(options.input_file.filename().string().c_str(), "stdump", get_version());

bool first_iteration = true;
SourceFileHandle source_file_handle;
for(const GlobalVariable* global_variable : global_variables) {
Expand Down Expand Up @@ -304,9 +308,11 @@ static void print_types_deduplicated(FILE* out, SymbolDatabase& database, const
config.caller_stack_offsets = options.flags & FLAG_CALLER_STACK_OFFSETS;

CppPrinter printer(out, config);

printer.comment_block_beginning(options.input_file.filename().string().c_str(), "stdump", get_version());
printer.comment_block_toolchain_version_info(database);
printer.comment_block_builtin_types(database);

for(const DataType& data_type : database.data_types) {
printer.data_type(data_type, database);
}
Expand All @@ -318,6 +324,7 @@ static void print_types_per_file(FILE* out, SymbolDatabase& database, const Opti
config.caller_stack_offsets = options.flags & FLAG_CALLER_STACK_OFFSETS;

CppPrinter printer(out, config);

printer.comment_block_beginning(options.input_file.filename().string().c_str(), "stdump", get_version());

for(const SourceFile& source_file : database.source_files) {
Expand Down Expand Up @@ -422,7 +429,7 @@ static void print_files(FILE* out, const Options& options)
SymbolDatabase database = read_symbol_table(symbol_file, options);

for(const SourceFile& source_file : database.source_files) {
fprintf(out, "/* %08x */ %s\n", source_file.address().value, source_file.name().c_str());
fprintf(out, "%08x %s\n", source_file.address().value, source_file.name().c_str());
}
}

Expand Down

0 comments on commit 7d0af05

Please sign in to comment.