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 授權許可。