Skip to content

Introduce sanitize_va() & has_prefix() for VA formatting #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/rp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
Options_t g_opts;

int main(int argc, char *argv[]) {
CLI::App rp("rp++: a fast ROP gadget finder for pe/elf/mach-o x86/x64/ARM/ARM64 "
"binaries\nby Axel '0vercl0k' Souchet.\n");
CLI::App rp(
"rp++: a fast ROP gadget finder for pe/elf/mach-o x86/x64/ARM/ARM64 "
"binaries\nby Axel '0vercl0k' Souchet.\n");
rp.add_option("-f,--file", g_opts.file, "Binary path")->required();
rp.add_option("-i,--info", g_opts.display,
"display information about the binary header");
Expand All @@ -58,7 +59,7 @@ int main(int argc, char *argv[]) {
rp.add_flag("--thumb", g_opts.thumb,
"enable thumb mode when looking for ARM gadgets");
rp.add_option("--va", g_opts.va,
"don't use the image base of the binary, but yours instead");
"don't use the image base of the binary, but yours instead");
rp.add_flag("--allow-branches", g_opts.allow_branches,
"allow branches in a gadget");
rp.add_flag("--print-bytes", g_opts.print_bytes, "print the gadget bytes");
Expand All @@ -78,9 +79,8 @@ int main(int argc, char *argv[]) {

// Here we set the base being 0 if we want to have absolute virtual
// memory address displayed
const uint64_t base = g_opts.va.size() > 0
? std::strtoull(g_opts.va.c_str(), nullptr, 0)
: p.get_image_base_address();
const uint64_t base = g_opts.va.size() > 0 ? va_to_integer(g_opts.va)
: p.get_image_base_address();
if (g_opts.rop > 0) {
const uint32_t options = g_opts.thumb ? 1 : 0;
fmt::print("\nWait a few seconds, rp++ is looking for gadgets ({} "
Expand Down
16 changes: 16 additions & 0 deletions src/rp/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ std::streampos get_file_size(std::ifstream &file) {
return fsize;
}

uint64_t va_to_integer(std::string va) {
// Look for backticks; WinDbg splits a QWORD in two with one. We'll get rid of
// it if we find one as this makes it easier to copy the address directly off
// the debugger. It also means that if we find one, we'll assume the address
// is specified in base 16 so we'll force that.
const auto it = std::remove(va.begin(), va.end(), '`');
const int radix = it != va.end() ? 16 : 0;
// If `std::remove` returned a valid iterator, this is where we want
// `strtoull` to stop; so let's terminate the string there.
if (it != va.end()) {
*it = 0;
}

return std::strtoull(va.c_str(), nullptr, radix);
}

// this function is completely inspirated from the previous work of jonathan
// salwan
bool is_matching(const std::string &str, const std::string &pattern) {
Expand Down
8 changes: 8 additions & 0 deletions src/rp/toolbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ enum VerbosityLevel {
*/
std::string verbosity_to_string(const VerbosityLevel lvl);

/**
* \fn uint64_t va_to_integer(std::string va)
* \brief Convert va to an integer
*
* \param va The virtual address string
*/
uint64_t va_to_integer(std::string va);

/**
* \fn std::streampos get_file_size(std::ifstream &file)
* \brief Get the size in byte of your file
Expand Down
2 changes: 2 additions & 0 deletions src/third_party/capstone/MathExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#ifndef CS_LLVM_SUPPORT_MATHEXTRAS_H
#define CS_LLVM_SUPPORT_MATHEXTRAS_H

#if 0
#if defined(_WIN32_WCE) && (_WIN32_WCE < 0x800)
#include "windowsce/intrin.h"
#elif defined(_MSC_VER)
#include <intrin.h>
#endif
#endif

#ifndef __cplusplus
#if defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)
Expand Down