A lightweight ARM64 assembly code and memory simulator designed to parse and execute ARM64 assembly instructions from .s
files, typically generated by IDA Pro's disassembly.
This repository contains a lightweight ARM64 assembly code and memory simulator designed to parse and execute ARM64 assembly instructions from .s
files, typically generated by IDA Pro's disassembly. It's an ideal tool for those looking to understand the behavior of ARM64 instructions, particularly useful for educational purposes, security analysis, and performance tuning.
- Lightweight and Standalone: Easy to deploy and run without heavy dependencies.
- Direct Parsing from IDA Outputs: Seamlessly integrates with disassembly files generated by IDA Pro.
- Detailed Execution Trace: Tracks and displays changes in register and memory states after each instruction execution.
- Support for Step-by-step and Continuous Execution: Offers flexibility in instruction execution to cater to different analysis needs.
- Simulates Register and Memory Operations: Enhances understanding of ARM64 operations through practical simulation.
- Extensibility: Supports custom pre- and post-execution hooks, allowing the insertion of custom logic before and after instruction execution.
- Educational Tool: Helps in learning and teaching the structure and applications of the ARM64 instruction set.
- Prototyping and Testing: Allows for quick simulation of instruction effects before actual implementation.
- Security Analysis: Useful in analyzing how code manipulations affect program states, potentially uncovering security vulnerabilities.
- Performance Analysis: Assists in understanding and optimizing code that is critical for performance.
Ensure you have Python 3.x installed on your machine. This simulator does not require any additional libraries for basic operations.
Clone the repository to your local machine:
git clone https://github.com/suifei/arm64-assembly-simulator.git
cd arm64-assembly-simulator
- Place your
.s
files containing ARM64 assembly code in thesrc/samples
directory. - Run the simulator with the following command:
cd arm64_simulator
python arm64_simulator.py
You can modify the ARM64Simulator
class instantiation in arm64_simulator.py
to enable step-by-step execution or verbose output, depending on your analysis needs.
- Basic Setup and Execution:
# Load assembly code and memory settings
asm_data = read_file("samples/diasm.s")
asm_code = load_asm_code(asm_data)
memory_lines = read_file("samples/memory.s")
memory_data = parse_memory_lines(memory_lines)
# Initialize the simulator
vm = ARM64Simulator(memory_data, step_pause=False, verbose=True, output_file="samples/output.s")
# Run the simulator starting from a specified PC address
vm.run(asm_code, pc=0x100AE0D64)
- Using Hooks to Modify Instruction Behavior:
# Define a post-execution hook to convert all CSET instructions to NOP
def nop_ops_after_hook(vm, op_name, operands):
if op_name == "CSET":
print(f"AFTER-HOOK# {op_name} to NOP")
op_name = "NOP"
operands = []
return op_name, operands
# Set the simulator's output file
vm.set_output_file("samples/output_with_hooks.s")
# Add the hook and rerun the simulator
vm.hook_instruction(after=nop_ops_after_hook)
vm.run(asm_code, pc=0x100AE0D64)
For more examples and a deeper understanding of the simulator's capabilities, please refer to the source code available in this repository. The source files contain detailed comments and diverse use cases that can help you get acquainted with advanced features and customization options.
Contributions are welcome! Please feel free to submit pull requests, suggest features, or report bugs.
This project is licensed under the MIT License - see the LICENSE file for details.
- c3VpZmUgQGdtYWlsIGRvdGNvbQ==
- QQ Group: 555354813
Feel free to contact me for any questions or feedback related to this project.