unicorn net
1.0.0
Unicorn 引擎的稍微更高级的WIP .NET 绑定/包装器。
目前 API 很容易发生变化。
这是如何使用它的示例。这也与此处提供的官方文档相同,但使用 C# 并使用 Unicorn.Net。
using ( var emulator = new X86Emulator ( X86Mode . b32 ) )
{
ulong addr = 0x1000000 ;
byte [ ] x86code =
{
0x41 , // INC ECX
0x4a // DEC EDX
} ;
var ecx = 0x1234 ;
var edx = 0x7890 ;
// Map 2mb of memory.
emulator . Memory . Map ( addr , 2 * 1024 * 1024 , MemoryPermissions . All ) ;
emulator . Registers . ECX = ecx ;
emulator . Registers . EDX = edx ;
emulator . Memory . Write ( addr , x86code , x86code . Length ) ;
emulator . Start ( addr , addr + ( ulong ) x86code . Length ) ;
Console . WriteLine ( emulator . Registers . ECX ) ;
Console . WriteLine ( emulator . Registers . EDX ) ;
}
读取和写入寄存器。
目前无法使用寄存器 ID 写入寄存器,但这可能会改变。
// Assume emulator is an instance of the X86Emulator type.
// Reading from registers.
var val = emulator . Registers . ECX ;
// Writing to registers.
emulator . Registers . ECX = 0x10 ;
映射、取消映射、读取、写入和更改内存权限。
var addr = 0x100000 ;
// Getting memory regions.
var regions = emulator . Memory . Regions ;
// Getting memory page size.
var pageSize = emulator . Memory . PageSize ;
// Mapping memory.
emulator . Memory . Map ( addr , 2 * 1024 , 2 * 1024 , MemoryPermissions . All ) ;
// Unmapping memory.
emulator . Memory . Unmap ( addr + ( 4 * 1024 ) , 4 * 1024 ) ;
// Changing memory permissions.
emulator . Memory . Protect ( addr + ( 4 * 1024 ) , 4 * 1024 , MemoryPermissions . Read ) ;
// Code to write to memory.
var code = new byte [ ]
{
0x41 , // INC ECX
0x4a // DEC EDX
}
// Buffer thats going to be the storage for data read from memory.
var buffer = new byte [ 2 ] ;
// Writing to memory.
emulator . Memory . Write ( code , 0 , code . Length ) ;
// Reading to memory.
emulator . Memory . Read ( buffer , 0 , buffer . Length ) ;
目前挂钩仍在进行中,可能会发生变化。
// Adding a memory read hook.
emulator . Hooks . Memory . Add ( MemoryHookType . Read , ( emu , type , address , size , val , userData ) => {
Console . WriteLine ( " stuff was read from memory." ) ;
} , addr , addr + ( ulong ) code . Length , null ) ;
捕获和恢复上下文。
// emulator.Context will create a new Context object
// which you will to dispose afterwards. Hence the `using` statement.
// Capturing the context.
using ( var ctx = emulator . Context )
{
.. .
// To restore the context simply do this.
emulator . Context = ctx ;
}
Unicorn.Net 还通过Bindings
类提供一些原始绑定。
var bindings = new Bindings ( ) ;
bindings . Open ( .. . ) ;
bindings . MemMap ( .. . ) ;
.. .
需要实施或已实施的内容列表。
模拟器
语境
寄存器
记忆
挂钩
拱门
实际绑定
Unicorn.Net 根据宽松的 MIT 许可证获得许可。