-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinject.h
63 lines (54 loc) · 1.8 KB
/
inject.h
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
#include "ErrHandling.h"
#include <vector>
class Inject: public ErrHandling {
public:
typedef unsigned long ptr_t;
struct user_regs_struct {
long ebx, ecx, edx, esi, edi, ebp, eax;
unsigned short ds, __ds, es, __es;
unsigned short fs, __fs, gs, __gs;
long orig_eax, eip;
unsigned short cs, __cs;
long eflags, esp;
unsigned short ss, __ss;
};
protected:
int pid;
bool attached;
int verbose;
std::string argv0;
bool injected;
ptr_t codebase;
ptr_t database;
int pagesize;
struct user_regs_struct oldregs;
std::vector<char> olddatapage;
std::vector<char> oldcodepage;
void peekpoke(const char *data, ptr_t addr, size_t len, bool poke);
void peek(const char *data,
ptr_t addr,
size_t len) { peekpoke(data, addr, len, false); }
void poke(const char *data,
ptr_t addr,
size_t len) { peekpoke(data, addr, len, true); }
public:
class ErrSysPtrace: public ErrSys {
int req;
public:
ErrSysPtrace(const std::string &func, int req,
const std::string &msg)
:ErrSys(func, "ptrace", msg), req(req) { }
};
Inject(pid_t pid, int verbose, const char *argv0);
~Inject();
void attach();
void detach();
ptr_t codeBase();
ptr_t dataBase();
void run();
void dumpregs(bool onlyIfEAX=false);
int pageSize() { attach(); return pagesize; }
size_t wordSize() { return sizeof(ptr_t); }
void inject(void *code, void *data);
void uninject();
};