scrap-is-not-scrap/sins/disassemble.py

24 lines
502 B
Python
Raw Permalink Normal View History

#! /usr/bin/env python3
from capstone import Cs, CS_ARCH_X86, CS_MODE_64
import json
capstone = Cs(CS_ARCH_X86, CS_MODE_64)
2019-02-24 07:38:11 +00:00
def disasm(shellcode: bytes) -> list:
opcodes = list()
for opcode in capstone.disasm(shellcode, 0):
opcodes.append([opcode.mnemonic, opcode.op_str])
return opcodes
2019-02-24 06:18:46 +00:00
2019-02-24 07:38:11 +00:00
def objdump(shellcode: bytes) -> str:
2019-02-24 06:18:46 +00:00
opcodes = str()
for opcode in capstone.disasm(shellcode, 0):
2019-03-09 08:19:33 +00:00
opcodes += f'{opcode.mnemonic}\t{opcode.op_str}\n'
2019-02-24 06:18:46 +00:00
return opcodes