disasm(data, ...) -> str Disassembles a bytestring into human readable assembler. To see which architectures are supported, look in :mod:`pwnlib.contex`. Arguments: data(str): Bytestring to disassemble. vma(int): Passed through to the --adjust-vma argument of objdump
(data, vma = 0, byte = True, offset = True, instructions = True)
| 894 | |
| 895 | @LocalContext |
| 896 | def disasm(data, vma = 0, byte = True, offset = True, instructions = True): |
| 897 | """disasm(data, ...) -> str |
| 898 | |
| 899 | Disassembles a bytestring into human readable assembler. |
| 900 | |
| 901 | To see which architectures are supported, |
| 902 | look in :mod:`pwnlib.contex`. |
| 903 | |
| 904 | Arguments: |
| 905 | data(str): Bytestring to disassemble. |
| 906 | vma(int): Passed through to the --adjust-vma argument of objdump |
| 907 | byte(bool): Include the hex-printed bytes in the disassembly |
| 908 | offset(bool): Include the virtual memory address in the disassembly |
| 909 | |
| 910 | Kwargs: |
| 911 | Any arguments/properties that can be set on ``context`` |
| 912 | |
| 913 | Examples: |
| 914 | |
| 915 | >>> print(disasm(unhex('b85d000000'), arch = 'i386')) |
| 916 | 0: b8 5d 00 00 00 mov eax, 0x5d |
| 917 | >>> print(disasm(unhex('b85d000000'), arch = 'i386', byte = 0)) |
| 918 | 0: mov eax, 0x5d |
| 919 | >>> print(disasm(unhex('b85d000000'), arch = 'i386', byte = 0, offset = 0)) |
| 920 | mov eax, 0x5d |
| 921 | >>> print(disasm(unhex('b817000000'), arch = 'amd64')) |
| 922 | 0: b8 17 00 00 00 mov eax, 0x17 |
| 923 | >>> print(disasm(unhex('48c7c017000000'), arch = 'amd64')) |
| 924 | 0: 48 c7 c0 17 00 00 00 mov rax, 0x17 |
| 925 | >>> print(disasm(unhex('04001fe552009000'), arch = 'arm')) # doctest: +ELLIPSIS |
| 926 | 0: e51f0004 ldr r0, [pc, #-4] ... |
| 927 | 4: 00900052 addseq r0, r0, r2, asr r0 |
| 928 | >>> print(disasm(unhex('4ff00500'), arch = 'thumb', bits=32)) |
| 929 | 0: f04f 0005 mov.w r0, #5 |
| 930 | >>> print(disasm(unhex('656664676665400F18A4000000000051'), byte=0, arch='amd64')) |
| 931 | 0: gs data16 fs rex nop WORD PTR gs:[eax+eax*1+0x0] |
| 932 | f: push rcx |
| 933 | >>> print(disasm(unhex('01000000'), arch='sparc64')) |
| 934 | 0: 01 00 00 00 nop |
| 935 | >>> print(disasm(unhex('60000000'), arch='powerpc64')) |
| 936 | 0: 60 00 00 00 nop |
| 937 | >>> print(disasm(unhex('00000000'), arch='mips64')) |
| 938 | 0: 00000000 nop |
| 939 | >>> print(disasm(unhex('48b84141414141414100c3'), arch='amd64')) |
| 940 | 0: 48 b8 41 41 41 41 41 41 41 00 movabs rax, 0x41414141414141 |
| 941 | a: c3 ret |
| 942 | >>> print(disasm(unhex('00000000'), vma=0x80000000, arch='mips')) |
| 943 | 80000000: 00000000 nop |
| 944 | """ |
| 945 | result = '' |
| 946 | |
| 947 | arch = context.arch |
| 948 | |
| 949 | tmpdir = tempfile.mkdtemp(prefix = 'pwn-disasm-') |
| 950 | step1 = path.join(tmpdir, 'step1') |
| 951 | step2 = path.join(tmpdir, 'step2') |
| 952 | |
| 953 | bfdarch = _bfdarch() |