Created
November 8, 2010 02:51
-
-
Save ice799/667331 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pid = proc->pid; | |
int n, m; | |
int started = 0; | |
union { | |
long val; | |
char x[sizeof(long)]; | |
} u; | |
if (addr & (sizeof(long) - 1)) { | |
/* addr not a multiple of sizeof(long) */ | |
n = addr - (addr & -sizeof(long)); /* residue */ | |
addr &= -sizeof(long); /* residue */ | |
errno = 0; | |
u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0); | |
if (errno) { | |
if (started && (errno==EPERM || errno==EIO)) { | |
/* Ran into 'end of memory' - stupid "printpath" */ | |
return 0; | |
} | |
/* But if not started, we had a bogus address. */ | |
if (addr != 0 && errno != EIO && errno != ESRCH) | |
perror("ptrace: umoven"); | |
return -1; | |
} | |
started = 1; | |
memcpy(laddr, &u.x[n], m = MIN(sizeof(long) - n, len)); | |
addr += sizeof(long), laddr += m, len -= m; | |
} | |
while (len) { | |
errno = 0; | |
u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0); | |
if (errno) { | |
if (started && (errno==EPERM || errno==EIO)) { | |
/* Ran into 'end of memory' - stupid "printpath" */ | |
return 0; | |
} | |
if (addr != 0 && errno != EIO && errno != ESRCH) | |
perror("ptrace: umoven"); | |
return -1; | |
} | |
started = 1; | |
memcpy(laddr, u.x, m = MIN(sizeof(long), len)); | |
addr += sizeof(long), laddr += m, len -= m; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment