MCPcopy
hub / github.com/Gallopsled/pwntools / _execve_script

Function _execve_script

pwnlib/gdb.py:250–283  ·  view source on GitHub ↗

_execve_script(argv, executable, env, ssh) -> str Returns the filename of a python script that calls execve the specified program with the specified arguments. This script is suitable to call with gdbservers ``--wrapper`` option, so we have more control over the environment of the

(argv, executable, env, ssh)

Source from the content-addressed store, hash-verified

248 return debug(tmp_elf, gdbscript=gdbscript, arch=context.arch, api=api)
249
250def _execve_script(argv, executable, env, ssh):
251 """_execve_script(argv, executable, env, ssh) -> str
252
253 Returns the filename of a python script that calls
254 execve the specified program with the specified arguments.
255 This script is suitable to call with gdbservers ``--wrapper`` option,
256 so we have more control over the environment of the debugged process.
257
258 Arguments:
259 argv(list): List of arguments to pass to the program
260 executable(bytes): Path to the program to run
261 env(dict): Environment variables to pass to the program
262 ssh(ssh): SSH connection to use if we are debugging a remote process
263
264 Returns:
265 The filename of the created script.
266 """
267 # Make sure args are bytes not bytearray.
268 argv = [bytes(arg) for arg in argv]
269 executable = packing._encode(executable)
270 if ssh:
271 # ssh.process with run=false creates the script for us
272 return ssh.process(argv, executable=executable, env=env, run=False)
273
274 script = misc._create_execve_script(argv=argv, executable=executable, env=env, log=log)
275 script = script.strip()
276 # Create a temporary file to hold the script
277 tmp = tempfile.NamedTemporaryFile(mode="w+t",prefix='pwnlib-execve-', suffix='.py', delete=False)
278 tmp.write(script)
279 # Make script executable
280 os.fchmod(tmp.fileno(), 0o755)
281 log.debug("Created execve wrapper script %s:\n%s", tmp.name, script)
282
283 return tmp.name
284
285
286def _gdbserver_args(pid=None, path=None, port=0, gdbserver_args=None, args=None, which=None, env=None, python_wrapper_script=None):

Callers 1

debugFunction · 0.85

Calls 4

processMethod · 0.45
writeMethod · 0.45
filenoMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected