From b376658d59d72a62e43d8072e5e829f3ca426427 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sun, 22 Sep 2024 21:37:21 +0200 Subject: [PATCH] Move type hints to __init__.py --- python/icicle/__init__.py | 138 +++++++++++++++++++++++++++++++++++++- python/icicle/icicle.pyi | 134 ------------------------------------ python/icicle/py.typed | 0 3 files changed, 137 insertions(+), 135 deletions(-) delete mode 100644 python/icicle/icicle.pyi delete mode 100644 python/icicle/py.typed diff --git a/python/icicle/__init__.py b/python/icicle/__init__.py index 5fb47c3..3e931e5 100644 --- a/python/icicle/__init__.py +++ b/python/icicle/__init__.py @@ -1,4 +1,137 @@ -from .icicle import * +from typing import List, Dict, Tuple +from enum import Enum + +class MemoryProtection(Enum): + NoAccess = ... + ReadOnly = ... + ReadWrite = ... + ExecuteOnly = ... + ExecuteRead = ... + ExecuteReadWrite = ... + +class MemoryExceptionCode(Enum): + Unallocated = ... + Unmapped = ... + UnmappedRegisters = ... + Uninitialized = ... + ReadViolation = ... + WriteViolation = ... + ExecViolation = ... + ReadWatch = ... + WriteWatch = ... + Unaligned = ... + OutOfMemory = ... + SelfModifyingCode = ... + AddressOverflow = ... + Unknown = ... + +class RunStatus(Enum): + Running = ... + InstructionLimit = ... + Breakpoint = ... + Interrupted = ... + Halt = ... + Killed = ... + Deadlock = ... + OutOfMemory = ... + Unimplemented = ... + UnhandledException = ... + +class ExceptionCode(Enum): + NoException = ... + InstructionLimit = ... + Halt = ... + Sleep = ... + Syscall = ... + CpuStateChanged = ... + DivisionException = ... + ReadUnmapped = ... + ReadPerm = ... + ReadUnaligned = ... + ReadWatch = ... + ReadUninitialized = ... + WriteUnmapped = ... + WritePerm = ... + WriteWatch = ... + WriteUnaligned = ... + ExecViolation = ... + SelfModifyingCode = ... + OutOfMemory = ... + AddressOverflow = ... + InvalidInstruction = ... + UnknownInterrupt = ... + UnknownCpuID = ... + InvalidOpSize = ... + InvalidFloatSize = ... + CodeNotTranslated = ... + ShadowStackOverflow = ... + ShadowStackInvalid = ... + InvalidTarget = ... + UnimplementedOp = ... + ExternalAddr = ... + Environment = ... + JitError = ... + InternalError = ... + UnmappedRegister = ... + UnknownError = ... + +class Icicle: + def __init__(self, architecture: str, *, + jit = True, + jit_mem = True, + shadow_stack = True, + recompilation = True, + track_uninitialized = False, + optimize_instructions = True, + optimize_block = True, + tracing = False, + ) -> None: ... + + @property + def exception_code(self) -> ExceptionCode: ... + + @property + def exception_value(self) -> int: ... + + icount: int + + icount_limit: int + + # TODO: API to get memory information? + + def mem_map(self, address: int, size: int, protection: MemoryProtection): ... + + def mem_unmap(self, address: int, size: int): ... + + def mem_protect(self, address: int, size: int, protection: MemoryProtection): ... + + def mem_read(self, address: int, size: int) -> bytes: ... + + def mem_write(self, address: int, data: bytes) -> None: ... + + def reg_list(self) -> Dict[str, Tuple[int, int]]: ... + + def reg_offset(self, name: str) -> int: ... + + def reg_size(self, name: str) -> int: ... + + def reg_read(self, name: str) -> int: ... + + def reg_write(self, name: str, value: int) -> None: ... + + def reset(self): ... + + def run(self) -> RunStatus: ... + + def run_until(self, address: int) -> RunStatus: ... + + def step(self, count: int) -> RunStatus: ... + + def add_breakpoint(self, address: int) -> bool: ... + + def remove_breakpoint(self, address: int) -> bool: ... + +def architectures() -> List[str]: ... class MemoryException(Exception): def __init__(self, message: str, code: MemoryExceptionCode): @@ -19,3 +152,6 @@ def __ghidra_init(): raise FileNotFoundError("Ghidra processor definitions not found") __ghidra_init() + +# NOTE: This overrides the stubs at runtime with the actual implementation +from .icicle import * \ No newline at end of file diff --git a/python/icicle/icicle.pyi b/python/icicle/icicle.pyi deleted file mode 100644 index fbb3900..0000000 --- a/python/icicle/icicle.pyi +++ /dev/null @@ -1,134 +0,0 @@ -from typing import List, Dict, Tuple -from enum import Enum - -class MemoryProtection(Enum): - NoAccess = ... - ReadOnly = ... - ReadWrite = ... - ExecuteOnly = ... - ExecuteRead = ... - ExecuteReadWrite = ... - -class MemoryExceptionCode(Enum): - Unallocated = ... - Unmapped = ... - UnmappedRegisters = ... - Uninitialized = ... - ReadViolation = ... - WriteViolation = ... - ExecViolation = ... - ReadWatch = ... - WriteWatch = ... - Unaligned = ... - OutOfMemory = ... - SelfModifyingCode = ... - AddressOverflow = ... - Unknown = ... - -class RunStatus(Enum): - Running = ... - InstructionLimit = ... - Breakpoint = ... - Interrupted = ... - Halt = ... - Killed = ... - Deadlock = ... - OutOfMemory = ... - Unimplemented = ... - UnhandledException = ... - -class ExceptionCode(Enum): - NoException = ... - InstructionLimit = ... - Halt = ... - Sleep = ... - Syscall = ... - CpuStateChanged = ... - DivisionException = ... - ReadUnmapped = ... - ReadPerm = ... - ReadUnaligned = ... - ReadWatch = ... - ReadUninitialized = ... - WriteUnmapped = ... - WritePerm = ... - WriteWatch = ... - WriteUnaligned = ... - ExecViolation = ... - SelfModifyingCode = ... - OutOfMemory = ... - AddressOverflow = ... - InvalidInstruction = ... - UnknownInterrupt = ... - UnknownCpuID = ... - InvalidOpSize = ... - InvalidFloatSize = ... - CodeNotTranslated = ... - ShadowStackOverflow = ... - ShadowStackInvalid = ... - InvalidTarget = ... - UnimplementedOp = ... - ExternalAddr = ... - Environment = ... - JitError = ... - InternalError = ... - UnmappedRegister = ... - UnknownError = ... - -class Icicle: - def __init__(self, architecture: str, *, - jit = True, - jit_mem = True, - shadow_stack = True, - recompilation = True, - track_uninitialized = False, - optimize_instructions = True, - optimize_block = True, - tracing = False, - ) -> None: ... - - @property - def exception_code(self) -> ExceptionCode: ... - - @property - def exception_value(self) -> int: ... - - icount: int - - icount_limit: int - - # TODO: API to get memory information? - - def mem_map(self, address: int, size: int, protection: MemoryProtection): ... - - def mem_unmap(self, address: int, size: int): ... - - def mem_protect(self, address: int, size: int, protection: MemoryProtection): ... - - def mem_read(self, address: int, size: int) -> bytes: ... - - def mem_write(self, address: int, data: bytes) -> None: ... - - def reg_list(self) -> Dict[str, Tuple[int, int]]: ... - - def reg_offset(self, name: str) -> int: ... - - def reg_size(self, name: str) -> int: ... - - def reg_read(self, name: str) -> int: ... - - def reg_write(self, name: str, value: int) -> None: ... - - def reset(self): ... - - def run(self) -> RunStatus: ... - - def run_until(self, address: int) -> RunStatus: ... - - def step(self, count: int) -> RunStatus: ... - - def add_breakpoint(self, address: int) -> bool: ... - - def remove_breakpoint(self, address: int) -> bool: ... - -def architectures() -> List[str]: ... diff --git a/python/icicle/py.typed b/python/icicle/py.typed deleted file mode 100644 index e69de29..0000000