Skip to content

Commit

Permalink
added raw binary option
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed May 7, 2024
1 parent 19c2c68 commit 0912947
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ int main(int argc, char *argv[]) {
.required()
.help("The pattern to search for.");

program.add_argument("-r", "--raw")
.help("Treat the binary as raw executable code and not as a PE.")
.default_value(false)
.implicit_value(true);

program.add_argument("binaryPath")
.required()
.help("Path of the binary to search for gadgets. e.g. C:\\Windows\\System32\\ntdll.dll");
.help("Path of the file to search for gadgets. e.g. C:\\Windows\\System32\\ntdll.dll");

try {
program.parse_args(argc, argv);
Expand All @@ -30,14 +35,32 @@ int main(int argc, char *argv[]) {
std::exit(1);
}

bool isRaw = program.get<bool>("--raw");
std::stringstream results;
Gadgify::GetGadgets([&results](uint64_t offset, const std::string &gadget) {
results << "0x" << std::hex << std::setfill('0') << std::setw(8) << offset << ": " << gadget << std::endl;
}, program.get<std::string>(
"binaryPath"),

if (isRaw)
{
FileContents file = File::Read(program.get<std::string>("binaryPath"));
Gadgify::GetGadgets([&results](uint64_t offset, const std::string &gadget)
{
results << "0x" << std::hex << std::setfill('0') << std::setw(8) << offset << ": " << gadget << std::endl;
},
std::vector<char>(file.contents, file.contents+file.size),
program.get<std::string>("--pattern"),
program.get<uint32_t>("--gap")
);
}
else
{
Gadgify::GetGadgets([&results](uint64_t offset, const std::string &gadget)
{
results << "0x" << std::hex << std::setfill('0') << std::setw(8) << offset << ": " << gadget << std::endl;
},
program.get<std::string>("binaryPath"),
program.get<std::string>("--pattern"),
program.get<uint32_t>("--gap")
);
);
}

std::cout << results.str() << std::endl;

Expand Down

0 comments on commit 0912947

Please sign in to comment.