Here, I explain my problem, I am a beginner on the ptrace function and I would like to succeed in recovering the hard information of a structure. For example with this command, I will have strace -e trace = fstat ls a line: fstat (3, {st_mode = ..., st_size = ...} and I would like to successfully retrieve the contents of the structure (st_mode) and (st_size). I try this but to no avail:
int buffer(unsigned long long addr, pid_t child, size_t size, void *buffer)
{
size_t byte = 0;
size_t data;
unsigned long tmp;
while (byte < size) {
tmp = ptrace(PTRACE_PEEKDATA, child, addr + byte);
if ((size - byte) / sizeof(tmp))
data = sizeof(tmp);
else
data = size % sizeof(tmp);
memcpy((void *)(buffer + byte), &tmp, data);
byte += data;
}
}
and in params :
struct stat stat_i;
buffer(addr, pid, sizeof(stat_i), &stat_i);
printf("%lu", stat_i.st_size); -> fake value :/
Thank'ks !