Skip to content

Commit

Permalink
Fixes socketcall()
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Sep 3, 2014
1 parent 634ca22 commit 60b82ba
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
30 changes: 29 additions & 1 deletion reprozip/native/ptrace_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static long tracee_getword(pid_t tid, const void *addr)
return res;
}

static void *tracee_getptr(int mode, pid_t tid, const void *addr)
void *tracee_getptr(int mode, pid_t tid, const void *addr)
{
if(mode == MODE_I386)
{
Expand All @@ -44,6 +44,34 @@ static void *tracee_getptr(int mode, pid_t tid, const void *addr)
}
}

uint64_t tracee_getlong(int mode, pid_t tid, const void *addr)
{
if(mode == MODE_I386)
{
/* Longs are 32 bits */
uint32_t val;
tracee_read(tid, (void*)&val, addr, sizeof(val));
return (uint64_t)val;
}
else /* mode == MODE_X86_64 */
{
/* Longs are 64 bits */
uint64_t val;
tracee_read(tid, (void*)&val, addr, sizeof(val));
return val;
}
}

size_t tracee_getwordsize(int mode)
{
if(mode == MODE_I386)
/* Pointers are 32 bits */
return 4;
else /* mode == MODE_X86_64 */
/* Pointers are 64 bits */
return 8;
}

size_t tracee_strlen(pid_t tid, const char *str)
{
uintptr_t ptr = (uintptr_t)str;
Expand Down
4 changes: 4 additions & 0 deletions reprozip/native/ptrace_utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef PTRACE_UTILS_H
#define PTRACE_UTILS_H

void *tracee_getptr(int mode, pid_t tid, const void *addr);
uint64_t tracee_getlong(int mode, pid_t tid, const void *addr);
size_t tracee_getwordsize(int mode);

size_t tracee_strlen(pid_t tid, const char *str);

void tracee_read(pid_t tid, char *dst, const char *src, size_t size);
Expand Down
14 changes: 12 additions & 2 deletions reprozip/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,22 @@ static int handle_connect(struct Process *process,
static int syscall_socketcall(const char *name, struct Process *process,
unsigned int udata)
{
/* Argument 1 is an array of longs, which are either numbers of pointers */
uint64_t args = process->params[1].u;
/* Size of each element in the array */
const size_t wordsize = tracee_getwordsize(process->mode);
if(process->params[0].u == SYS_ACCEPT)
return handle_accept(process,
process->params[2].p, process->params[3].p);
tracee_getptr(process->mode, process->tid,
args + 1*wordsize),
tracee_getptr(process->mode, process->tid,
args + 2*wordsize));
else if(process->params[0].u == SYS_CONNECT)
return handle_connect(process,
process->params[2].p, process->params[3].u);
tracee_getptr(process->mode, process->tid,
args + 1*wordsize),
tracee_getlong(process->mode, process->tid,
args + 2*wordsize));
else
return 0;
}
Expand Down

0 comments on commit 60b82ba

Please sign in to comment.