-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.h
More file actions
92 lines (81 loc) · 2.62 KB
/
Copy pathdebugger.h
File metadata and controls
92 lines (81 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef DEBUGGER_H
#define DEBUGGER_H
#include <capstone/capstone.h>
#include <elf.h>
#include <sys/ptrace.h>
#include <sys/user.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
enum DebuggerState
{
NOT_LOADED,
LOADED,
RUNNING
};
struct Breakpoint
{
uintptr_t addr;
uint64_t original_data;
};
struct TextSegment
{
uintptr_t start;
uintptr_t end;
};
class Debugger
{
public:
Debugger();
~Debugger();
void run(bool use_script, const std::string &script_file);
void load_initial_program(const std::string &path);
private:
DebuggerState state;
pid_t pid;
std::string program_path;
uintptr_t entry_point;
std::map<int, Breakpoint> breakpoints; // id -> bp
std::unordered_map<uintptr_t, Breakpoint> addr_to_bp; // addr -> bp
int breakpoint_id_counter = 0;
TextSegment text_segment;
csh capstone_handle;
void handle_command(const std::string &line);
void set_breakpoint(uintptr_t addr); // break
void continue_execution(); // cont
void delete_breakpoint(int id); // delete
void disassemble(uintptr_t addr); // disasm
void dump_memory(uintptr_t addr); // dump
void exit_debugger(); // exit
void get_register(const std::string ®); // get
void get_registers(); // getregs
void print_help(); // help
void list_breakpoints(); // list
void load_program(const std::string &path); // load
void run_program(); // run
void show_vmmap(); // vmmap
void set_register(const std::string ®, uint64_t value); // set
void single_step(); // si
void start_program(); // start
void wait_for_signal();
void handle_breakpoint();
void apply_all_breakpoints();
bool parse_elf(const std::string &path);
uint64_t get_register_value(const std::string ®, struct user_regs_struct ®s);
void set_register_value(const std::string ®, uint64_t value, struct user_regs_struct ®s);
void print_instruction_at(uintptr_t pc);
void show_breakpoint_info(uintptr_t pc);
};
#endif