r"""cpp(shellcode, ...) -> str Runs CPP over the given shellcode. The output will always contain exactly one newline at the end. Arguments: shellcode(str): Shellcode to preprocess Kwargs: Any arguments/properties that can be set on ``context`` Examples:
(shellcode)
| 451 | |
| 452 | @LocalContext |
| 453 | def cpp(shellcode): |
| 454 | r"""cpp(shellcode, ...) -> str |
| 455 | |
| 456 | Runs CPP over the given shellcode. |
| 457 | |
| 458 | The output will always contain exactly one newline at the end. |
| 459 | |
| 460 | Arguments: |
| 461 | shellcode(str): Shellcode to preprocess |
| 462 | |
| 463 | Kwargs: |
| 464 | Any arguments/properties that can be set on ``context`` |
| 465 | |
| 466 | Examples: |
| 467 | |
| 468 | >>> cpp("mov al, SYS_setresuid", arch = "i386", os = "linux") |
| 469 | 'mov al, 164\n' |
| 470 | >>> cpp("weee SYS_setresuid", arch = "arm", os = "linux") |
| 471 | 'weee (0+164)\n' |
| 472 | >>> cpp("SYS_setresuid", arch = "thumb", os = "linux") |
| 473 | '(0+164)\n' |
| 474 | >>> cpp("SYS_setresuid", os = "freebsd") |
| 475 | '311\n' |
| 476 | """ |
| 477 | if platform.system() == 'Windows': |
| 478 | cpp = which_binutils('cpp') |
| 479 | else: |
| 480 | cpp = 'cpp' |
| 481 | |
| 482 | code = _include_header() + shellcode |
| 483 | cmd = [ |
| 484 | cpp, |
| 485 | '-Wno-unused-command-line-argument', |
| 486 | '-C', |
| 487 | '-nostdinc', |
| 488 | '-undef', |
| 489 | '-P', |
| 490 | '-I' + _incdir, |
| 491 | ] |
| 492 | return _run(cmd, code).strip('\n').rstrip() + '\n' |
| 493 | |
| 494 | |
| 495 | @LocalContext |
no test coverage detected