Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
162 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"name": "Unicorn.Net.ConsoleTests", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
"preLaunchTask": "build Unicorn.Net.ConsoleTests", | ||
"program": "${workspaceFolder}/src/Unicorn.Net.ConsoleTests/bin/Debug/netcoreapp2.0/Unicorn.Net.ConsoleTests.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/src/Unicorn.Net.ConsoleTests", | ||
"console": "internalConsole", | ||
"stopAtEntry": false, | ||
"console": "internalConsole", | ||
"internalConsoleOptions": "openOnSessionStart" | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"name": "Unicorn.Net.Samples.Mips", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
"request": "launch", | ||
"preLaunchTask": "build Unicorn.Net.Samples.Mips", | ||
"program": "${workspaceRoot}/samples/Unicorn.Net.Samples.Mips/bin/Debug/netcoreapp2.0/Unicorn.Net.Samples.Mips.dll", | ||
"args": [], | ||
"cwd": "${workspaceRoot}/samples/Unicorn.Net.Samples.Mips", | ||
"stopAtEntry": false, | ||
"console": "internalConsole", | ||
"internalConsoleOptions": "openOnSessionStart" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,86 @@ | ||
using Unicorn.Mips; | ||
using System; | ||
using Unicorn.Mips; | ||
|
||
namespace Unicorn.Net.Samples.Mips | ||
{ | ||
// Similar to | ||
// samples/sample_mips.c | ||
|
||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
// test_mips_eb | ||
public static void TestMipsEb() | ||
{ | ||
using (var emulator = new MipsEmulator(MipsMode.III)) | ||
Console.WriteLine("Emulate MIPS code (big-endian)"); | ||
|
||
using (var emulator = new MipsEmulator(MipsMode.b32 | MipsMode.BigEndian)) | ||
{ | ||
ulong addr = 0x10000; | ||
byte[] mipscode = | ||
{ | ||
0x34, 0x21, 0x34, 0x56 | ||
}; | ||
|
||
emulator.Memory.Map(addr, 2 * 1024 * 1024, MemoryPermissions.All); | ||
emulator.Memory.Write(addr, mipscode, mipscode.Length); | ||
|
||
emulator.Registers.AT = 0x6789; | ||
// or | ||
// emulator.Registers._1 = 0x6789 | ||
|
||
emulator.Hooks.Block.Add(BlockHook, null); | ||
emulator.Hooks.Code.Add(CodeHook, addr, addr, null); | ||
emulator.Start(addr, addr + (ulong)mipscode.Length); | ||
|
||
Console.WriteLine(">>> Emulation done. Below is the CPU context"); | ||
Console.WriteLine($">>> R1 = 0x{emulator.Registers.AT.ToString("x2")}"); | ||
} | ||
} | ||
|
||
// test_mips_el | ||
public static void TestMipsEl() | ||
{ | ||
Console.WriteLine("==========================="); | ||
Console.WriteLine("Emulate MIPS code (little-endian)"); | ||
|
||
using (var emulator = new MipsEmulator(MipsMode.b32 | MipsMode.LittleEndian)) | ||
{ | ||
ulong addr = 0x10000; | ||
byte[] mipscode = | ||
{ | ||
0x56, 0x34, 0x21, 0x34 | ||
}; | ||
|
||
emulator.Memory.Map(addr, 2 * 1024 * 1024, MemoryPermissions.All); | ||
emulator.Memory.Write(addr, mipscode, mipscode.Length); | ||
|
||
emulator.Registers.AT = 0x6789; | ||
// or | ||
// emulator.Registers._1 = 0x6789 | ||
|
||
emulator.Hooks.Block.Add(BlockHook, null); | ||
emulator.Hooks.Code.Add(CodeHook, addr, addr, null); | ||
emulator.Start(addr, addr + (ulong)mipscode.Length); | ||
|
||
Console.WriteLine(">>> Emulation done. Below is the CPU context"); | ||
Console.WriteLine($">>> R1 = 0x{emulator.Registers.AT.ToString("x2")}"); | ||
} | ||
} | ||
|
||
public static void Main(string[] args) | ||
{ | ||
TestMipsEb(); | ||
TestMipsEl(); | ||
} | ||
|
||
private static void BlockHook(Emulator emulator, ulong address, int size, object userToken) | ||
{ | ||
Console.WriteLine($">>> Tracing basic block at 0x{address.ToString("x2")}, block size = 0x{size.ToString("x2")}"); | ||
} | ||
|
||
private static void CodeHook(Emulator emulator, ulong address, int size, object userToken) | ||
{ | ||
Console.WriteLine($">>> Tracing instruction at 0x{address.ToString("x2")}, instruction size = 0x{size.ToString("x2")}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters