Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathonReinhart committed Jul 8, 2020
1 parent ca73510 commit 12a950d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ setup_environment(void)
}
}

static void
adjust_env(void)
{
char *envstr;
if (asprintf(&envstr, "LD_PRELOAD=%s/%s", m_bundle_dir, "libnsskill.so") < 0)
error(2, 0, "Failed to allocate env var string");
putenv(envstr);
}

/**
* Run the user application in a child process.
*
Expand All @@ -321,6 +330,8 @@ run_app(int argc, char **argv, char *prog_path)
debug_printf(" [%d] = \"%s\"\n", i, a);
}

adjust_env();

/* Create new process */
child_pid = fork();
if (child_pid < 0)
Expand All @@ -329,6 +340,8 @@ run_app(int argc, char **argv, char *prog_path)

if (child_pid == 0) {
/*** Child ***/
// TODO: If we can avoid doing anything here but call exec,
// we could use the less-expensive vfork()
debug_printf("Child process started; ready to call execv()\n");

execv(new_argv[0], new_argv);
Expand Down
6 changes: 6 additions & 0 deletions staticx/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def add_symlink(self, name, target):

self.tar.addfile(t)

def add_fileobj(self, name, fileobj):
logging.info("Adding {}".format(name))
tarinfo = self.tar.gettarinfo(arcname=name, fileobj=fileobj)
tarinfo.mode = make_mode_executable(tarinfo.mode)
self.tar.addfile(tarinfo, fileobj)

def add_program(self, path, name):
"""Add user program to the archive
Expand Down
2 changes: 2 additions & 0 deletions staticx/hooks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .pyinstaller import process_pyinstaller_archive
from .glibc import process_glibc_prog

hooks = [
process_pyinstaller_archive,
process_glibc_prog,
]

def run_hooks(ar, prog):
Expand Down
12 changes: 12 additions & 0 deletions staticx/hooks/glibc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from ..assets import locate_asset

def process_glibc_prog(sx_ar, prog):
# Is this program linked aginst GLIBC?

# If so, add dependencies on libnss_files.so, libnss_dns.so
# TODO: How do we find these?
sx_ar.add_library('/usr/lib/x86_64-linux-gnu/libnss_files.so')
sx_ar.add_library('/usr/lib/x86_64-linux-gnu/libnss_dns.so')

nsskill = locate_asset('libnsskill.so', debug=True)
sx_ar.add_fileobj('libnsskill.so', nsskill)

0 comments on commit 12a950d

Please sign in to comment.