![]() |
Baseer 0.2.0
Baseer is an advanced binary analysis tool designed to provide deep insights into any file.
|
Implementation of a lightweight debugger for ELF binaries using ptrace. More...
#include <stdint.h>
#include <elf.h>
#include <stdio.h>
#include <ctype.h>
#include "udis86.h"
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include "debugger.h"
#include <sys/ptrace.h>
#include "../bx_elf_utils/bx_elf_utils.h"
Functions | |
void | parse_cmd (context *ctx) |
Parse and execute a user command entered in the debugger prompt. | |
bool | handle_action (context *ctx, void *args) |
Handle actions that correspond directly to simple commands (e.g., quit, help, continue, single-step). | |
void | print_helpCMD () |
Print the list of available debugger commands. | |
bool | set_mem_reg (context *ctx, void *args) |
Modify the value of a register or memory location. | |
bool | examin_mem (context *ctx, void *args) |
Examine memory at a specific address. | |
bool | delBP (context *ctx, void *args) |
Delete a breakpoint by ID. | |
bool | step_over (context *ctx, void *args) |
Step over a function call instruction. | |
uint64_t | find_sym (context *ctx, char *name) |
Find the address of a symbol in the loaded program. | |
bool | setBP (context *ctx, void *args) |
Set a breakpoint at a given address or symbol name. | |
void | handle_bpoint (context *ctx) |
Handle a breakpoint hit by restoring the instruction and adjusting RIP. | |
bool | listBP (context *ctx, void *args) |
List all active breakpoints. | |
void | restore_all_BP (context *ctx, int opt) |
Restore all breakpoints to their original values or reapply traps. | |
void | dis_ctx (context *ctx) |
Display process registers, flags, disassembly, and stack contents. | |
void | init_values (bparser *target, context *ctx) |
Initialize the debugger context from a parsed ELF binary. | |
void | destroy_bp_sym (context *ctx) |
Free all breakpoint and symbol structures in the context. | |
void | destroy_all (context *ctx) |
Free all allocated resources in the debugger context. | |
bool | b_debugger (bparser *target, void *arg) |
Run the debugger on a given binary. |
Implementation of a lightweight debugger for ELF binaries using ptrace.
This file provides functionality for:
bool b_debugger | ( | bparser * | target, |
void * | arg ) |
Run the debugger on a given binary.
Launch and manage the debugger main loop.
Forks a child process, loads the binary via memfd_create, and sets an initial breakpoint. Then enters the main command loop for user interaction.
target | Pointer to binary parser structure with ELF data. |
arg | Arguments structure containing argc and argv. |
bool delBP | ( | context * | ctx, |
void * | args ) |
Delete a breakpoint by ID.
ctx | Pointer to debugger context. |
args | Breakpoint ID. |
void destroy_all | ( | context * | ctx | ) |
Free all allocated resources in the debugger context.
Destroy all context-related memory.
ctx | Pointer to debugger context. |
void destroy_bp_sym | ( | context * | ctx | ) |
Free all breakpoint and symbol structures in the context.
Free all breakpoints and symbols in the context.
ctx | Pointer to debugger context. |
void dis_ctx | ( | context * | ctx | ) |
Display process registers, flags, disassembly, and stack contents.
Display current registers, flags, disassembly, and stack.
ctx | Pointer to debugger context. |
bool examin_mem | ( | context * | ctx, |
void * | args ) |
Examine memory at a specific address.
Examine memory at a given address.
Command format: x ADDR SIZE
ctx | Pointer to debugger context. |
args | Address and size arguments. |
uint64_t find_sym | ( | context * | ctx, |
char * | name ) |
Find the address of a symbol in the loaded program.
ctx | Pointer to debugger context. |
name | Symbol name to search for. |
bool handle_action | ( | context * | ctx, |
void * | args ) |
Handle actions that correspond directly to simple commands (e.g., quit, help, continue, single-step).
Execute a user command.
ctx | Pointer to debugger context. |
args | Optional arguments passed with the command. |
void handle_bpoint | ( | context * | ctx | ) |
Handle a breakpoint hit by restoring the instruction and adjusting RIP.
Handle breakpoint hit logic.
ctx | Pointer to debugger context. |
Initialize the debugger context from a parsed ELF binary.
Initialize context values from target binary.
Reads ELF headers and symbol tables to populate context values.
target | Pointer to binary parser structure with ELF data. |
ctx | Pointer to debugger context to initialize. |
bool listBP | ( | context * | ctx, |
void * | args ) |
List all active breakpoints.
List all breakpoints.
ctx | Pointer to debugger context. |
args | Unused. |
void parse_cmd | ( | context * | ctx | ) |
Parse and execute a user command entered in the debugger prompt.
Parse and dispatch a command from the user.
Reads a command from stdin, splits it into operator and arguments, and executes the corresponding debugger function.
ctx | Pointer to debugger context structure containing process state. |
void print_helpCMD | ( | ) |
Print the list of available debugger commands.
Print available debugger commands.
void restore_all_BP | ( | context * | ctx, |
int | opt ) |
Restore all breakpoints to their original values or reapply traps.
Restore all breakpoints (enable or disable).
ctx | Pointer to debugger context. |
opt | If 1, restore original instruction. If 0, reset breakpoint trap. |
bool set_mem_reg | ( | context * | ctx, |
void * | args ) |
Modify the value of a register or memory location.
Modify memory or registers.
Command format: $REG=VALUE or ADDR=VALUE
ctx | Pointer to debugger context. |
args | Command argument string. |
bool setBP | ( | context * | ctx, |
void * | args ) |
Set a breakpoint at a given address or symbol name.
Set a breakpoint at an address or symbol.
ctx | Pointer to debugger context. |
args | Address or symbol name. |
bool step_over | ( | context * | ctx, |
void * | args ) |
Step over a function call instruction.
Step over a function call.
Inserts a temporary breakpoint after the call instruction and continues execution.
ctx | Pointer to debugger context. |
args | Unused. |