Given assembled machine code bytes, execute them. Example: >>> insn_bytes = asm('mov ebx, 3; mov eax, SYS_exit; int 0x80;') >>> p = run_shellcode(insn_bytes) >>> p.wait_for_close() >>> p.poll() 3 >>> insn_bytes = asm('mov r0, #12; mov r7, #1; sv
(bytes, **kw)
| 44 | |
| 45 | @LocalContext |
| 46 | def run_shellcode(bytes, **kw): |
| 47 | """Given assembled machine code bytes, execute them. |
| 48 | |
| 49 | Example: |
| 50 | |
| 51 | >>> insn_bytes = asm('mov ebx, 3; mov eax, SYS_exit; int 0x80;') |
| 52 | >>> p = run_shellcode(insn_bytes) |
| 53 | >>> p.wait_for_close() |
| 54 | >>> p.poll() |
| 55 | 3 |
| 56 | |
| 57 | >>> insn_bytes = asm('mov r0, #12; mov r7, #1; svc #0', arch='arm') |
| 58 | >>> p = run_shellcode(insn_bytes, arch='arm') |
| 59 | >>> p.wait_for_close() |
| 60 | >>> p.poll() |
| 61 | 12 |
| 62 | """ |
| 63 | if context.os == 'darwin': |
| 64 | if sys.platform != 'darwin': |
| 65 | raise ValueError('Running Mach-O only supported on Darwin machines. Please use:\n' |
| 66 | '- https://github.com/MatthewCroughan/NixThePlanet\n' |
| 67 | '- https://github.com/sickcodes/Docker-OSX') |
| 68 | from pwnlib.asm import make_macho |
| 69 | return process(make_macho(bytes)) |
| 70 | |
| 71 | return ELF.from_bytes(bytes, **kw).process() |
| 72 | |
| 73 | @LocalContext |
| 74 | def run_assembly_exitcode(assembly): |
no test coverage detected