blasphemy: add command to produce a patched copy of the input binary
This commit is contained in:
parent
cb8f881ce2
commit
fd4c380025
19
blasphemy
19
blasphemy
@ -3,6 +3,7 @@ from subprocess import run, check_output
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import shutil
|
||||
|
||||
SEPARATOR = " => "
|
||||
LIBRARY_STORE = os.path.join("/", "gnu", "store")
|
||||
@ -88,9 +89,11 @@ parser.add_argument("--run", nargs="*", help="run command with specified args")
|
||||
parser.add_argument("--command", help="command to wrap or run (default to the first input binary)")
|
||||
parser.add_argument("--arguments", nargs="+", default=[], help="Additional arguments to pass to command")
|
||||
parser.add_argument("--inputs", nargs="+", default=[], help="input binaries to scan for dependencies")
|
||||
parser.add_argument("--paths", nargs="*", default=[], help="Additional paths to add to library search path")
|
||||
parser.add_argument("--patch", help="create a patched copy of command with the given name")
|
||||
args = parser.parse_args()
|
||||
|
||||
paths = []
|
||||
paths = args.paths
|
||||
pre_command = [LOADER]
|
||||
command = args.command
|
||||
|
||||
@ -106,13 +109,21 @@ if (not command) and args.inputs:
|
||||
|
||||
#command[0] = os.path.abspath(command[0])
|
||||
|
||||
command = pre_command + [command] + args.arguments
|
||||
full_command = pre_command + [command] + args.arguments
|
||||
if args.run is not None:
|
||||
environment = {"LD_LIBRARY_PATH": make_ld_library_path(paths)}
|
||||
environment.update(os.environ)
|
||||
completed_process = run(command + args.run, env=environment)
|
||||
completed_process = run(full_command + args.run, env=environment)
|
||||
sys.exit(completed_process.returncode)
|
||||
elif args.wrap:
|
||||
print(generate_wrapper(paths, command))
|
||||
print(generate_wrapper(paths, full_command))
|
||||
elif args.patch is not None:
|
||||
shutil.copy(command, args.patch)
|
||||
run([
|
||||
"patchelf",
|
||||
"--set-interpreter", LOADER,
|
||||
"--set-rpath", make_ld_library_path(paths),
|
||||
args.patch
|
||||
])
|
||||
else:
|
||||
print_paths(paths)
|
||||
|
Loading…
x
Reference in New Issue
Block a user