Last active
January 24, 2022 15:25
-
-
Save hal0x2328/1d9c86e65aba748024ec22d5ac488aca to your computer and use it in GitHub Desktop.
N3 disassembler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# useful to disassemble an invocation script - won't work to | |
# disassemble an entire NEF because it will stop at the first RET | |
from neo3 import contracts, vm | |
import base64 | |
class Disassembler(contracts.ApplicationEngine): | |
def pre_execute_instruction(self) -> None: | |
ins = self.current_context.current_instruction() | |
if ins.opcode != vm.OpCode.SYSCALL: | |
print(ins.opcode, ins.operand.hex()) | |
def on_syscall(self, method_id: int): | |
descriptor = self.interop.InteropService.get_descriptor(method_id) | |
if descriptor is None: | |
print(f"SYSCALL - invalid method id -> {method_id}") | |
else: | |
print(f"SYSCALL {descriptor.method}") | |
if __name__ == "__main__": | |
script = base64.b64decode( | |
b'FQwhAjmjdDZlL0GzuALKRMvLfWXTqguIyaA4AkO9vhqqXLNbDCECSG/RVwLESQomcDESpcwdCSP9aXozQGvVocAOABOwmnAMIQKq7DhHD2qtAELG6HfP2Ah9Jnaw9Rb93TYoAbm9OTY5ngwhA7IJ/U9TpxcOpERODLCmu2pTwr0BaSaYnPhfmw+6F6cMDCEDuNnVdx2PUTqghpucyNUJhkA7eMbaNokGOMPUalrc4EoMIQLKDidpe5wkj28W4IX9AGHib0TahbWO6DXBEMql7DulVAwhA9nosWvZsi0zRdbUzeMb4cPh0WFTLj0MzsuV7OLrWDNuF0Ge0Nw6') | |
engine = Disassembler(contracts.TriggerType.APPLICATION, None, None, 99999) | |
engine.load_script(vm.Script(script)) | |
engine.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment