forcebru / pyvm Goto Github PK
View Code? Open in Web Editor NEWA virtual machine written in Python that executes x86 binaries according to the Intel Software Developer Manual
License: MIT License
A virtual machine written in Python that executes x86 binaries according to the Intel Software Developer Manual
License: MIT License
This is the code used for testing:
import timeit
from io import StringIO
print("Testing...")
t = timeit.repeat(
"vm.execute_elf('C/bin/bubblesort.elf');vm.execute_elf('C/bin/quicksort.elf');vm.execute_elf('C/bin/insertionsort.elf');vm.execute_elf('C/bin/memcpy_test.elf')",
"void=StringIO();vm=VM(0x0017801d, void, void, void)",
globals={'VM': VM.VM, 'StringIO': StringIO}, number=10, repeat=10)
avg = lambda x: sum(x) / len(x)
print(f"NEW: {min(t):.4f}, {avg(t):.4f}, {max(t):.4f}")
# OLD: 26.6493, 28.4966, 29.9140
# NEW: 28.6566, 29.1709, 29.9998
Here the change was introduced here:
Line 39 in 27ae445
reg_check
argument to process_ModRM
) and was meant to interrupt parsing of ModRM if its REG
field didn't match the criteria. Otherwise it would've parsed the whole thing and wasted time.
Apparently, this doesn't really speed things up, so it should be removed or re-implemented.
TODO list:
process_ModRM does not expect any args.
Commit 831d87b breaks debug messages.
Many of them use hex(loc) if type else reg_names[loc][sz]
to output either the name of the register or the address in hex. First of all, this is super ugly and should be refactored.
Now that type
is either vm.reg
or vm.mem
, it'll always be truthy, so, hex(loc)
will be always evaluated, which is incorrect.
ModR/M byte processing is currently only for 32-bit addressing, and there's a whole table of possible values of the ModR/M byte for 16-bit addressing, which isn't supported at all.
Should probably implement that? Cuz stuff like lea ax, [bx]
doesn't work since it's 16-bit addressing.
The movzx
instruction attempts to access invalid memory from [ebp - 1]
. ebp
is loaded with some value from memory before that, and this value is weird. The address seems to depend on the first inputted operand.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.