Baseer 0.2.0
Baseer is an advanced binary analysis tool designed to provide deep insights into any file.
Loading...
Searching...
No Matches
debugger.h File Reference

Core definitions, structs, and function prototypes for the debugger. More...

#include "../bparser/bparser.h"
#include <stdint.h>
#include <stdbool.h>
#include <sys/user.h>

Go to the source code of this file.

Classes

struct  Cmd
 Represents a parsed user command. More...
struct  sym_list
 Represents a symbol entry (function name and address). More...
struct  bp_list
 A linked list of breakpoints. More...
struct  bp
 Represents a single breakpoint. More...
struct  func_list
 Represents a debugger command and its associated function. More...
struct  pos_name
 Maps a register/flag name to its position. More...
struct  context
 Holds debugger state and process information. More...

Macros

#define ERROR(str)
 Print an error message in red.
#define INFO(str)
 Print an info message in blue.

Typedefs

typedef struct bp_list bp_list
 Forward declaration of debugger structs.
typedef struct bp bp
typedef struct sym_list sym_list
typedef struct context context
typedef struct func_list func_list
typedef struct pos_name pos_name
typedef bool(* func_callback_t) (context *ctx, void *args)
 Callback type for command handler functions.

Functions

void destroy_bp_sym (context *ctx)
 Free all breakpoints and symbols in the context.
void destroy_all (context *ctx)
 Destroy all context-related memory.
void print_helpCMD ()
 Print available debugger commands.
void init_values (bparser *target, context *ctx)
 Initialize context values from target binary.
bool b_debugger (bparser *target, void *arg)
 Launch and manage the debugger main loop.
void dis_ctx (context *ctx)
 Display current registers, flags, disassembly, and stack.
void handle_bpoint (context *ctx)
 Handle breakpoint hit logic.
bool setBP (context *ctx, void *args)
 Set a breakpoint at an address or symbol.
bool delBP (context *ctx, void *args)
 Delete a breakpoint by ID.
bool step_over (context *ctx, void *args)
 Step over a function call.
bool listBP (context *ctx, void *args)
 List all breakpoints.
bool examin_mem (context *ctx, void *args)
 Examine memory at a given address.
bool set_mem_reg (context *ctx, void *args)
 Modify memory or registers.
void restore_all_BP (context *ctx, int opt)
 Restore all breakpoints (enable or disable).
bool handle_action (context *ctx, void *args)
 Execute a user command.
void parse_cmd (context *ctx)
 Parse and dispatch a command from the user.

Detailed Description

Core definitions, structs, and function prototypes for the debugger.

This header defines the main data structures (context, breakpoints, symbols), and function prototypes used to implement the debugger.

Macro Definition Documentation

◆ ERROR

#define ERROR ( str)
Value:
printf(COLOR_RED "[x] " COLOR_RESET "%s",str);

Print an error message in red.

◆ INFO

#define INFO ( str)
Value:
printf(COLOR_BLUE "[*] " COLOR_RESET "%s",str);

Print an info message in blue.

Typedef Documentation

◆ func_callback_t

typedef bool(* func_callback_t) (context *ctx, void *args)

Callback type for command handler functions.

Parameters
ctxThe current debugger context.
argsAdditional arguments for the command.
Returns
true if successful, false otherwise.

Function Documentation

◆ b_debugger()

bool b_debugger ( bparser * target,
void * arg )

Launch and manage the debugger main loop.

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.

Parameters
targetPointer to binary parser structure with ELF data.
argArguments structure containing argc and argv.
Returns
true on success, false otherwise.

◆ delBP()

bool delBP ( context * ctx,
void * args )

Delete a breakpoint by ID.

Parameters
ctxPointer to debugger context.
argsBreakpoint ID.
Returns
true if deletion succeeds, false otherwise.

◆ destroy_all()

void destroy_all ( context * ctx)

Destroy all context-related memory.

Destroy all context-related memory.

Parameters
ctxPointer to debugger context.

◆ destroy_bp_sym()

void destroy_bp_sym ( context * ctx)

Free all breakpoints and symbols in the context.

Free all breakpoints and symbols in the context.

Parameters
ctxPointer to debugger context.

◆ dis_ctx()

void dis_ctx ( context * ctx)

Display current registers, flags, disassembly, and stack.

Display current registers, flags, disassembly, and stack.

Parameters
ctxPointer to debugger context.

◆ examin_mem()

bool examin_mem ( context * ctx,
void * args )

Examine memory at a given address.

Examine memory at a given address.

Command format: x ADDR SIZE

Parameters
ctxPointer to debugger context.
argsAddress and size arguments.
Returns
true on success, false otherwise.

◆ handle_action()

bool handle_action ( context * ctx,
void * args )

Execute a user command.

Execute a user command.

Parameters
ctxPointer to debugger context.
argsOptional arguments passed with the command.
Returns
true if the command was successfully handled, false otherwise.

◆ handle_bpoint()

void handle_bpoint ( context * ctx)

Handle breakpoint hit logic.

Handle breakpoint hit logic.

Parameters
ctxPointer to debugger context.

◆ init_values()

void init_values ( bparser * target,
context * ctx )

Initialize context values from target binary.

Initialize context values from target binary.

Reads ELF headers and symbol tables to populate context values.

Parameters
targetPointer to binary parser structure with ELF data.
ctxPointer to debugger context to initialize.

◆ listBP()

bool listBP ( context * ctx,
void * args )

List all breakpoints.

List all breakpoints.

Parameters
ctxPointer to debugger context.
argsUnused.
Returns
true always.

◆ parse_cmd()

void parse_cmd ( context * ctx)

Parse and dispatch a command from the user.

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.

Parameters
ctxPointer to debugger context structure containing process state.

◆ print_helpCMD()

void print_helpCMD ( )

Print available debugger commands.

Print available debugger commands.

◆ restore_all_BP()

void restore_all_BP ( context * ctx,
int opt )

Restore all breakpoints (enable or disable).

Restore all breakpoints (enable or disable).

Parameters
ctxPointer to debugger context.
optIf 1, restore original instruction. If 0, reset breakpoint trap.

◆ set_mem_reg()

bool set_mem_reg ( context * ctx,
void * args )

Modify memory or registers.

Modify memory or registers.

Command format: $REG=VALUE or ADDR=VALUE

Parameters
ctxPointer to debugger context.
argsCommand argument string.
Returns
true on success, false otherwise.

◆ setBP()

bool setBP ( context * ctx,
void * args )

Set a breakpoint at an address or symbol.

Set a breakpoint at an address or symbol.

Parameters
ctxPointer to debugger context.
argsAddress or symbol name.
Returns
true if the breakpoint was successfully set, false otherwise.

◆ step_over()

bool step_over ( context * ctx,
void * args )

Step over a function call.

Step over a function call.

Inserts a temporary breakpoint after the call instruction and continues execution.

Parameters
ctxPointer to debugger context.
argsUnused.
Returns
true on success, false otherwise.