Skip to content

Commit

Permalink
wip pdb dump2config support
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Apr 9, 2024
1 parent 7bb83ba commit cb34531
Show file tree
Hide file tree
Showing 4 changed files with 747 additions and 15 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(json)

FetchContent_Declare(
raw_pdb
GIT_REPOSITORY https://github.com/MolecularMatters/raw_pdb.git
GIT_TAG 5c29c02b897c884c7ead0b912b721346474e271e
)
FetchContent_MakeAvailable(raw_pdb)

set(GIT_PRE_CONFIGURE_FILE "gitinfo.cpp.in")
set(GIT_POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/gitinfo.cpp")
include(GitWatcher)
Expand All @@ -71,8 +78,10 @@ target_sources(unassemblize PRIVATE
function.cpp
function.h
main.cpp
progdb.cpp
progdb.h
)
target_link_libraries(unassemblize PRIVATE Zydis LIEF::LIEF nlohmann_json)
target_link_libraries(unassemblize PRIVATE Zydis LIEF::LIEF nlohmann_json raw_pdb)
target_include_directories(unassemblize PRIVATE .)

if(WINDOWS)
Expand Down
43 changes: 29 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* LICENSE
*/
#include "function.h"
#include "progdb.h"
#include "gitinfo.h"
#include <LIEF/LIEF.hpp>
#include <getopt.h>
Expand All @@ -33,20 +34,22 @@ void print_help()
"Usage:\n"
" unassemblize [OPTIONS] [INPUT]\n"
"Options:\n"
" -o --output Filename for single file output. Default is program.S\n"
" -f --format Assembly output format.\n"
" -c --config Configuration file describing how to dissassemble the input\n"
" file and containing extra symbol info. Default: config.json\n"
" -s --start Starting address of a single function to dissassemble in\n"
" hexidecimal notation.\n"
" -e --end Ending address of a single function to dissassemble in\n"
" hexidecimal notation.\n"
" -v --verbose Verbose output on current state of the program.\n"
" --section Section to target for dissassembly, defaults to '.text'.\n"
" --listsections Prints a list of sections in the exe then exits.\n"
" -d --dumpsyms Dumps symbols stored in the executable to the config file.\n"
" then exits.\n"
" -h --help Displays this help.\n\n",
" -o --output Filename for single file output. Default is program.S\n"
" -f --format Assembly output format.\n"
" -c --config Configuration file describing how to dissassemble the input\n"
" file and containing extra symbol info. Default: config.json\n"
" -s --start Starting address of a single function to dissassemble in\n"
" hexidecimal notation.\n"
" -e --end Ending address of a single function to dissassemble in\n"
" hexidecimal notation.\n"
" -v --verbose Verbose output on current state of the program.\n"
" --section Section to target for dissassembly, defaults to '.text'.\n"
" --listsections Prints a list of sections in the exe then exits.\n"
" -d --dumpsyms Dumps symbols stored in the executable to the config file\n"
" then exits.\n"
" -p --dumppdb Dumps symbol data stored in a pdb file to a config file\n"
" then exits.\n"
" -h --help Displays this help.\n\n",
revision,
GitUncommittedChanges ? "~" : "",
version);
Expand All @@ -70,11 +73,13 @@ int main(int argc, char **argv)
const char *section_name = ".text";
const char *output = "program.S";
const char *config_file = "config.json";
const char *pdb_config_file = "pdb.json";
const char *format_string = nullptr;
uint64_t start_addr = 0;
uint64_t end_addr = 0;
bool print_secs = false;
bool dump_syms = false;
bool dump_pdb = false;
bool verbose = false;

while (true) {
Expand All @@ -87,6 +92,7 @@ int main(int argc, char **argv)
{"section", required_argument, nullptr, 1},
{"listsections", no_argument, nullptr, 2},
{"dumpsyms", no_argument, nullptr, 'd'},
{"dumppdb", no_argument, nullptr, 'p'},
{"verbose", no_argument, nullptr, 'v'},
{"help", no_argument, nullptr, 'h'},
{nullptr, no_argument, nullptr, 0},
Expand All @@ -110,6 +116,9 @@ int main(int argc, char **argv)
case 'd':
dump_syms = true;
break;
case 'p':
dump_pdb = true;
break;
case 'o':
output = optarg;
break;
Expand Down Expand Up @@ -160,6 +169,7 @@ int main(int argc, char **argv)
}

unassemblize::Executable exe(argv[optind], format, verbose);
unassemblize::ProgramDatabase pdb(argv[optind], verbose);

if (print_secs) {
print_sections(exe);
Expand All @@ -171,6 +181,11 @@ int main(int argc, char **argv)
return 0;
}

if (dump_pdb) {
pdb.save_symbols_config(pdb_config_file);
return 0;
}

exe.load_config(config_file);

FILE *fp = nullptr;
Expand Down
Loading

0 comments on commit cb34531

Please sign in to comment.