-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed tests, added reg aliases and began library implementation
- Loading branch information
George
authored and
George
committed
Nov 8, 2022
1 parent
a28eecb
commit ffd77f7
Showing
8 changed files
with
140 additions
and
1 deletion.
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
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from maat import * | ||
from pathlib import Path | ||
import pytest | ||
m = MaatEngine(ARCH.ARM32) | ||
# EOR R0, R0 | ||
# ADD R0, R0, #1 | ||
# MOV R1, R0 | ||
# ADD R0, R0, #10 | ||
buf = b'\x00\x00\x20\xe0\x01\x00\x80\xe2\x00\x10\xa0\xe1\x0a\x00\x80\xe2\x00\x40\x0f\xe1' | ||
m.mem.map(0x100, 0xFFF, PERM.RWX) | ||
m.mem.write(0x100, buf, len(buf)) | ||
m.cpu.R3 = 0xDEADBEEF | ||
m.cpu.R4 = 0xDEADCAFE | ||
print("PC = " + str(m.cpu.PC) + "\n*PC = " + str(m.mem.read(m.cpu.PC.as_int(), 4))) | ||
print("R0 = " + str(m.cpu.R0.as_int()) + "\nR1 = " + str(m.cpu.R1.as_int())) | ||
m.run_from(0x100, 1) | ||
print("PC = " + str(m.cpu.PC) + "\n*PC = " + str(m.mem.read(m.cpu.PC.as_int(), 4))) | ||
print("R0 = " + str(m.cpu.R0.as_int()) + "\nR1 = " + str(m.cpu.R1.as_int())) | ||
assert m.cpu.R0.as_int() == 0 | ||
m.run(1) | ||
print("PC = " + str(m.cpu.PC) + "\n*PC = " + str(m.mem.read(m.cpu.PC.as_int(), 4))) | ||
print("R0 = " + str(m.cpu.R0.as_int()) + "\nR1 = " + str(m.cpu.R1.as_int())) | ||
#assert m.cpu.R0.as_int() == 1 | ||
m.run(1) | ||
print("PC = " + str(m.cpu.PC) + "\n*PC = " + str(m.mem.read(m.cpu.PC.as_int(), 4))) | ||
print("R0 = " + str(m.cpu.R0.as_int()) + "\nR1 = " + str(m.cpu.R1.as_int())) | ||
#assert m.cpu.R1.as_int() == 1 | ||
m.run(1); | ||
print("PC = " + str(m.cpu.PC) + "\n*PC = " + str(m.mem.read(m.cpu.PC.as_int(), 4))) | ||
print("R0 = " + str(m.cpu.R0.as_int()) + "\nR1 = " + str(m.cpu.R1.as_int())) | ||
m.run(1) | ||
print("R0 = " + str(m.cpu.R0.as_int()) + "\nR1 = " + str(m.cpu.R1.as_int()) + "\nR4 = " + str(bin(m.cpu.R4.as_uint())) + "\nCPSR = " + str(bin(m.cpu.CPSR.as_uint()))) | ||
#assert m.cpu.R0.as_int() == 11 |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "maat/arch.hpp" | ||
#include "maat/varcontext.hpp" | ||
#include "maat/engine.hpp" | ||
#include "maat/exception.hpp" | ||
#include <cassert> | ||
#include <iostream> | ||
#include <string> | ||
#include <sstream> | ||
|
||
using std::cout; | ||
using std::endl; | ||
using std::string; | ||
|
||
namespace test | ||
{ | ||
namespace archARM32 | ||
{ | ||
|
||
using namespace maat; | ||
|
||
unsigned int _assert(bool val, const string& msg){ | ||
if( !val){ | ||
cout << "\nFail: " << msg << std::endl; | ||
throw test_exception(); | ||
} | ||
return 1; | ||
} | ||
|
||
unsigned int test_ARM32 () { | ||
string code; | ||
MaatEngine sym = MaatEngine(Arch::Type::ARM32); | ||
sym.mem->map(0x1000, 0x2000); | ||
code = "\x00\x00\x20\xe0\x01\x00\x80\xe2\x00\x10\xa0\xe1\x0a\x00\x80\xe2"; | ||
sym.mem->write_buffer(0x1000, (uint8_t*)code.c_str(), code.size()); | ||
sym.cpu.ctx().set(ARM32::R2, exprcst(32, 0xDEADBEEF)); | ||
sym.run_from(0x1000, 4); | ||
|
||
unsigned int return_val = 0; | ||
return_val += _assert(sym.cpu.ctx().get(ARM32::R2).as_uint() == 0xDEADBEEF, "R2 is not DEADBEEF"); | ||
//return_val += _assert(sym.cpu.ctx().get(ARM32::R0).as_int() == 11, "R0 is not equal to 11"); | ||
cout << | ||
"\nR0 = " << sym.cpu.ctx().get(ARM32::R0).as_uint() << | ||
"\nR1 = " << sym.cpu.ctx().get(ARM32::R1).as_uint() << | ||
"\nR2 = " << sym.cpu.ctx().get(ARM32::R2).as_uint() << "\n\n"; | ||
|
||
return return_val; | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
using namespace test::archARM32; | ||
|
||
void test_archARM32() { | ||
unsigned int total = 0; | ||
string green = "\033[1;32m"; | ||
string def = "\033[0m"; | ||
string bold = "\033[1m"; | ||
|
||
// Start testing | ||
cout << bold << "[" << green << "+" << def << bold << "]" << def << std::left << std::setw(34) << " Testing arch ARM32 support... " << std::flush; | ||
|
||
MaatEngine engine(Arch::Type::ARM32); | ||
engine.mem->map(0x0, 0x10000); | ||
|
||
total += test_ARM32(); | ||
cout << "\t" << total << "/" << total << green << "\tOK" << def << endl; | ||
} |