Reputation: 105
I'm trying to trace system call in ARM(Android armeabi-v7a) using ptrace
function(not using ptrace in shell, I mean using ptrace
in the code). And below is code what I wrote.
int trace(int pid)
{
struct pt_regs regs;
ptrace(PTRACE_SYSCALL, pid, 0, 0);
while(1)
{
// wait debugee process to stop
waitpid(pid, &status, 0);
ptrace(PTRACE_GETREGS, pid, 0, ®s);
// debugee process has stopped
if(WSTOPSIG(status) == SIGTRAP)
{
// check all register
fprintf(stderr, "ORIG_R0(%11ld), R0(%11ld), R1(%11ld), R2(%11ld), R3(%11ld), R4(%11ld), R5(%11ld), R6(%11ld), R7(%11ld), R8(%11ld), R9(%11ld), R10(%11ld), SP(%11ld), FP(%11ld), IP(%11ld), LR(%11ld), PC(%11ld), CPSR(%11ld)\n", regs.ARM_ORIG_r0, regs.ARM_r0, regs.ARM_r1, regs.ARM_r2, regs.ARM_r3, regs.ARM_r4, regs.ARM_r5, regs.ARM_r6, regs.ARM_r7, regs.ARM_r8, regs.ARM_r9, regs.ARM_r10, regs.ARM_sp, regs.ARM_fp, regs.ARM_ip, regs.ARM_lr, regs.ARM_pc, regs.ARM_cpsr);
}
// continue debugee process
ptrace(PTRACE_SYSCALL, pid, 0, 0);
}
}
And below is the result of execution.
ORIG_R0( 6), R0( 6), R1( -286709396), R2( 1), R3( -286704568), R4( -286704588), R5( 4774880), R6( 1348301426), R7( 0), R8( 64), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4773736), CPSR( 0)
ORIG_R0( 6), R0( 1), R1( -286709396), R2( 1), R3( -286704568), R4( -286704588), R5( 4774880), R6( 1348301426), R7( 1), R8( 64), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4773736), CPSR( 0)
ORIG_R0( 1), R0( 1), R1( -286709396), R2( 1), R3( -286704568), R4( -286704588), R5( 4774880), R6( 1348301426), R7( 0), R8( 139), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4784360), CPSR( 0)
ORIG_R0( 1), R0( 0), R1( 1), R2( 17), R3( -286704568), R4( -286704588), R5( 4774880), R6( 1348301426), R7( 1), R8( 209), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4773760), CPSR( 0)
ORIG_R0( -286704576), R0( -286704576), R1( 1), R2( -286704704), R3( 0), R4( 0), R5( 128), R6( 2), R7( 0), R8( 73), R9( 2), R10( 0), SP( 5353472), FP( 0), IP( 12), LR( 5390336), PC( 4774312), CPSR( 0)
ORIG_R0( -286704576), R0( 1), R1( 1), R2( -286704704), R3( 0), R4( 0), R5( 128), R6( 2), R7( 1), R8( 73), R9( 2), R10( 0), SP( 5353472), FP( 0), IP( 12), LR( 5390336), PC( 4774312), CPSR( 0)
ORIG_R0( 8), R0( 8), R1( -286704344), R2( 128), R3( 64), R4( 0), R5( 0), R6( 2), R7( 0), R8( 207), R9( 2), R10( 0), SP( 5353472), FP( 0), IP( 12), LR( 5390336), PC( 4774504), CPSR( 536870912)
ORIG_R0( 8), R0( 128), R1( -286704344), R2( 128), R3( 64), R4( 0), R5( 0), R6( 2), R7( 1), R8( 207), R9( 2), R10( 0), SP( 5353472), FP( 0), IP( 12), LR( 5390336), PC( 4774504), CPSR( 536870912)
ORIG_R0( 8), R0( 8), R1( 1), R2( 31), R3( 2036548096), R4( -286704692), R5( 64), R6( 63), R7( 0), R8( 209), R9( 4), R10( 2), SP( 1), FP( 1), IP( 2036351360), LR( 2036351360), PC( 4773760), CPSR( 1073741824)
ORIG_R0( 8), R0( 0), R1( 1), R2( 31), R3( 2036548096), R4( -286704692), R5( 64), R6( 63), R7( 1), R8( 209), R9( 4), R10( 2), SP( 1), FP( 1), IP( 2036351360), LR( 2036351360), PC( 4773760), CPSR( 1073741824)
ORIG_R0( -100), R0( -100), R1( 2035645536), R2( 0), R3( 0), R4( 2036362616), R5( 1348301426), R6( 75039744), R7( 0), R8( 56), R9( 246), R10( 2037383168), SP( 75690976), FP( 5353472), IP( 5396536), LR( 75039616), PC( 4775008), CPSR( 1610612736)
ORIG_R0( -100), R0( 14), R1( 2035645536), R2( 0), R3( 0), R4( 2036362616), R5( 1348301426), R6( 75039744), R7( 1), R8( 56), R9( 246), R10( 2037383168), SP( 75690976), FP( 5353472), IP( 5396536), LR( 75039616), PC( 4775008), CPSR( 1610612736)
ORIG_R0( 14), R0( 14), R1( 2036469760), R2( 4095), R3( 4), R4( 0), R5( 64), R6( 63), R7( 0), R8( 63), R9( 4), R10( 5390336), SP( 14839), FP( 0), IP( 14838), LR( 5390336), PC( 4774360), CPSR( 1073741824)
ORIG_R0( 14), R0( 12), R1( 2036469760), R2( 4095), R3( 4), R4( 0), R5( 64), R6( 63), R7( 1), R8( 63), R9( 4), R10( 5390336), SP( 14839), FP( 0), IP( 14838), LR( 5390336), PC( 4774360), CPSR( 1073741824)
ORIG_R0( 14), R0( 14), R1( 2037383168), R2( 5353472), R3( 20), R4( 0), R5( 0), R6( 2036380216), R7( 0), R8( 57), R9( 251), R10( 93), SP( 5396544), FP( 2036335336), IP( 5353472), LR( 32768), PC( 4774672), CPSR(-2147483648)
ORIG_R0( 14), R0( 0), R1( 2037383168), R2( 5353472), R3( 20), R4( 0), R5( 0), R6( 2036380216), R7( 1), R8( 57), R9( 251), R10( 93), SP( 5396544), FP( 2036335336), IP( 5353472), LR( 32768), PC( 4774672), CPSR(-2147483648)
ORIG_R0( -286706232), R0( -286706232), R1( 1), R2( -286706320), R3( 0), R4( 0), R5( 0), R6( 0), R7( 0), R8( 73), R9( 0), R10( 0), SP( 5), FP( 0), IP( 0), LR( 2036351040), PC( 4774312), CPSR( 1610612736)
ORIG_R0( -286706232), R0( 0), R1( 1), R2( -286706320), R3( 0), R4( 0), R5( 0), R6( 0), R7( 1), R8( 73), R9( 0), R10( 0), SP( 5), FP( 0), IP( 0), LR( 2036351040), PC( 4774312), CPSR( 1610612736)
ORIG_R0( 2039265648), R0( 2039265648), R1( 1), R2( 2147483647), R3( 0), R4( 117440573), R5( 62), R6( 62), R7( 0), R8( 98), R9( 2139062143), R10( 2139062143), SP( -1), FP( 16843009), IP( 32), LR( 0), PC( 4712472), CPSR(-2147483648)
ORIG_R0( 2039265648), R0( 0), R1( 1), R2( 2147483647), R3( 0), R4( 117440573), R5( 62), R6( 62), R7( 1), R8( 98), R9( 2139062143), R10( 2139062143), SP( -1), FP( 16843009), IP( 32), LR( 0), PC( 4712472), CPSR(-2147483648)
ORIG_R0( 2039209988), R0( 2039209988), R1( 1), R2( 2147483647), R3( 0), R4( 62), R5( 62), R6( 62), R7( 0), R8( 98), R9( 14802), R10( 2139062143), SP( -1), FP( 16843009), IP( 32), LR( 0), PC( 4712472), CPSR( 0)
ORIG_R0( 2039209988), R0( 0), R1( 1), R2( 2147483647), R3( 0), R4( 62), R5( 62), R6( 62), R7( 1), R8( 98), R9( 14802), R10( 2139062143), SP( -1), FP( 16843009), IP( 32), LR( 0), PC( 4712472), CPSR( 0)
ORIG_R0( 8), R0( 8), R1( 4957456), R2( 9), R3( 186), R4(-1187365760), R5( 0), R6( 84543233), R7( 0), R8( 57), R9( 2139062143), R10( 2139062143), SP( 0), FP( 16843009), IP( 7), LR( -256), PC( 4774672), CPSR( 1610612736)
ORIG_R0( 8), R0( 0), R1( 4957456), R2( 9), R3( 186), R4(-1187365760), R5( 0), R6( 84543233), R7( 1), R8( 57), R9( 2139062143), R10( 2139062143), SP( 0), FP( 16843009), IP( 7), LR( -256), PC( 4774672), CPSR( 1610612736)
ORIG_R0( -286704080), R0( -286704080), R1( 2), R2( 0), R3( 0), R4( 0), R5( -1), R6( 1348301426), R7( 0), R8( 73), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4774312), CPSR( 1610612736)
ORIG_R0( -286704080), R0( 2), R1( 2), R2( 0), R3( 0), R4( 0), R5( -1), R6( 1348301426), R7( 1), R8( 73), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4774312), CPSR( 1610612736)
ORIG_R0( 5), R0( 5), R1( -286704456), R2( -286704592), R3( 0), R4( 5357568), R5( 4774880), R6( 1348301426), R7( 0), R8( 242), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4774888), CPSR( 1610612736)
ORIG_R0( 5), R0( 8), R1( -286704456), R2( -286704592), R3( 0), R4( 5357568), R5( 4774880), R6( 1348301426), R7( 1), R8( 242), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4774888), CPSR( 1610612736)
ORIG_R0( 8), R0( 8), R1( 1), R2( 17), R3( -286704568), R4( -286704588), R5( 4774880), R6( 1348301426), R7( 0), R8( 209), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4773760), CPSR( 0)
ORIG_R0( 8), R0( 0), R1( 1), R2( 17), R3( -286704568), R4( -286704588), R5( 4774880), R6( 1348301426), R7( 1), R8( 209), R9( 1348301426), R10( -48), SP( 5353472), FP( -128), IP( 12), LR( 5390336), PC( 4773760), CPSR( 0)
I learned that the ARM EABI sets the registers R0
to R6
(argument) and R7
(system call number) to execute the system call. However, the results of the above code were slightly different. It was correct that register R0
to R6
have system call arguments, but register R7
only had 0 and 1 repeatedly. The problem is that I don't know which register has the system call number. As you can see from the above code execution results, no register has a value that looks like a system call number. Even registers SP
have values that do not look like stack pointers at all.
(Presumably, the value of register R7
seems to mean system call entering and exiting)
Could you please explain what I am doing wrong?
Upvotes: 1
Views: 470