mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 10:15:07 +00:00
ptrace: Add PT_SETREGS
PT_SETTREGS sets the regsiters of the traced thread. It can only be used when the tracee is stopped. Also, refactor ptrace. The implementation was getting long and cluttered the alraedy large Process.cpp file. This commit moves the bulk of the implementation to Kernel/Ptrace.cpp, and factors out peek & poke to separate methods of the Process class.
This commit is contained in:
parent
0431712660
commit
9e51e295cf
11 changed files with 299 additions and 157 deletions
|
@ -161,19 +161,17 @@ int main(int argc, char** argv)
|
|||
auto entry_point = get_entry_point(g_pid);
|
||||
dbg() << "entry point:" << entry_point;
|
||||
|
||||
uint32_t data = ptrace(PT_PEEK, g_pid, (void*)entry_point.as_ptr(), 0);
|
||||
const uint32_t original_instruction_data = ptrace(PT_PEEK, g_pid, (void*)entry_point.as_ptr(), 0);
|
||||
|
||||
// u8* as_bytes = reinterpret_cast<u8*>(&data);
|
||||
// as_bytes[0] = 0xcc;
|
||||
dbg() << "peeked data:" << (void*)data;
|
||||
data = (data & ~(uint32_t)0xff) | 0xcc;
|
||||
data = 0xccccccc;
|
||||
dbg() << "peeked data:" << (void*)original_instruction_data;
|
||||
|
||||
if (ptrace(PT_POKE, g_pid, (void*)entry_point.as_ptr(), data) < 0) {
|
||||
if (ptrace(PT_POKE, g_pid, (void*)entry_point.as_ptr(), (original_instruction_data & ~(uint32_t)0xff) | 0xcc) < 0) {
|
||||
perror("poke");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dbg() << "continuting";
|
||||
|
||||
if (ptrace(PT_CONTINUE, g_pid, 0, 0) == -1) {
|
||||
perror("continue");
|
||||
}
|
||||
|
@ -187,14 +185,28 @@ int main(int argc, char** argv)
|
|||
|
||||
printf("hit breakpoint\n");
|
||||
|
||||
if (ptrace(PT_POKE, g_pid, (void*)entry_point.as_ptr(), original_instruction_data) < 0) {
|
||||
perror("poke");
|
||||
return 1;
|
||||
}
|
||||
|
||||
PtraceRegisters regs;
|
||||
if (ptrace(PT_GETREGS, g_pid, ®s, 0) == -1) {
|
||||
if (ptrace(PT_GETREGS, g_pid, ®s, 0) < 0) {
|
||||
perror("getregs");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dbg() << "eip after breakpoint: " << (void*)regs.eip;
|
||||
|
||||
regs.eip = reinterpret_cast<u32>(entry_point.as_ptr());
|
||||
dbg() << "settings eip back to:" << (void*)regs.eip;
|
||||
if (ptrace(PT_SETREGS, g_pid, ®s, 0) < 0) {
|
||||
perror("setregs");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dbg() << "continuig";
|
||||
|
||||
if (ptrace(PT_CONTINUE, g_pid, 0, 0) == -1) {
|
||||
perror("continue");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue