Skip to content

Commit

Permalink
Try to improve python interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-guene committed Dec 12, 2014
1 parent 4516103 commit 4aa8a8d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 25 deletions.
78 changes: 62 additions & 16 deletions src/extension/python/proot.i
Original file line number Diff line number Diff line change
@@ -1,18 +1,76 @@
%module proot
%{
#include "arch.h"
#include "syscall/sysnum.h"
#include "tracee/tracee.h"
#include "extension/extension.h"
#include "tracee/reg.h"
#include "tracee/mem.h"
#include "extension/extension.h"

extern Tracee *get_tracee_from_extension(long extension);
/* define an internal global with correct PR number */
#define SYSNUM(item) static const int PR_internal ## item = PR_ ## item;
#include "syscall/sysnums.list"
#undef SYSNUM
%}

/* now say PR_item has value PR_internal */
/* works but ugly. Another way to do this ? */
#define SYSNUM(item) static const int PR_ ## item = PR_internal ## item;
%include "syscall/sysnums.list"
#undef SYSNUM

/* python extension helper */
Tracee *get_tracee_from_extension(long extension);
%inline %{
Tracee *get_tracee_from_extension(long extension_handle)
{
Extension *extension = (Extension *)extension_handle;
Tracee *tracee = TRACEE(extension);

return tracee;
}
%}

/* arch.h */
typedef unsigned long word_t;

/* tracee/tracee.h */
typedef enum {
CURRENT = 0,
ORIGINAL = 1,
MODIFIED = 2,
NB_REG_VERSION
} RegVersion;

/* syscall/sysnum.h */
typedef enum Sysnum;
extern Sysnum get_sysnum(const Tracee *tracee, RegVersion version);
extern void set_sysnum(Tracee *tracee, Sysnum sysnum);

/* List of possible events. */
/* tracee/reg.h */
typedef enum {
SYSARG_NUM = 0,
SYSARG_1,
SYSARG_2,
SYSARG_3,
SYSARG_4,
SYSARG_5,
SYSARG_6,
SYSARG_RESULT,
STACK_POINTER,
INSTR_POINTER,
RTLD_FINI,
STATE_FLAGS,
USERARG_1,
} Reg;

extern word_t peek_reg(const Tracee *tracee, RegVersion version, Reg reg);
extern void poke_reg(Tracee *tracee, Reg reg, word_t value);

/* tracee/mem.h */
extern int write_data(const Tracee *tracee, word_t dest_tracee, const void *src_tracer, word_t size);
extern int read_data(const Tracee *tracee, void *dest_tracer, word_t src_tracee, word_t size);

/* extension/extention.h */
typedef enum {
GUEST_PATH,
HOST_PATH,
Expand All @@ -30,15 +88,3 @@ typedef enum {
PRINT_CONFIG,
PRINT_USAGE,
} ExtensionEvent;

typedef enum {
CURRENT = 0,
ORIGINAL = 1,
MODIFIED = 2,
NB_REG_VERSION
} RegVersion;


%include "syscall/sysnum.h"
%include "tracee/reg.h"
%include "tracee/mem.h"
18 changes: 9 additions & 9 deletions src/extension/python/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

static PyObject *python_callback_func;

//static bool is_seccomp_disabling_done = false;
/* List of syscalls handled by this extensions. */
static FilteredSysnum filtered_sysnums[] = {
FILTERED_SYSNUM_END,
Expand All @@ -12,15 +13,6 @@ static FilteredSysnum filtered_sysnums[] = {
/* build by swig */
extern void init_proot(void);

/* helper for proot module */
Tracee *get_tracee_from_extension(long extension_handle)
{
Extension *extension = (Extension *)extension_handle;
Tracee *tracee = TRACEE(extension);

return tracee;
}

/* init python once */
void init_python_env()
{
Expand Down Expand Up @@ -110,6 +102,14 @@ int python_callback(Extension *extension, ExtensionEvent event, intptr_t data1,
switch (event) {
case INITIALIZATION:
{
/* not working. Use 'export PROOT_NO_SECCOMP=1' */
/*if (!is_seccomp_disabling_done) {
Tracee *tracee = TRACEE(extension);
if (tracee->seccomp == ENABLED)
tracee->seccomp = DISABLING;
is_seccomp_disabling_done = true;
}*/
init_python_env();
res = python_callback_func_wrapper(extension, event, data1, data2);

Expand Down

0 comments on commit 4aa8a8d

Please sign in to comment.