mirror of
https://github.com/siemens-mobile-hacks/ptr89.git
synced 2026-11-25 18:27:22 +00:00
more fixes
This commit is contained in:
parent
e4a69bf75b
commit
2a455e8066
5 changed files with 109 additions and 67 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
|||
build
|
||||
.cache
|
||||
*.vkp
|
||||
*.ini
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
|
|||
|
||||
include_directories("./lib" "./third_party/argparse/include" "./third_party/json/include")
|
||||
|
||||
add_executable(ptr89 src/main.cpp lib/src/Pattern.cpp lib/src/Tokenizer.cpp lib/src/Parser.cpp lib/src/utils.cpp)
|
||||
set(LIB_SRC lib/src/Pattern.cpp lib/src/Tokenizer.cpp lib/src/Parser.cpp lib/src/utils.cpp)
|
||||
|
||||
add_executable(ptr89 src/main.cpp ${LIB_SRC})
|
||||
target_precompile_headers(ptr89 PRIVATE <argparse/argparse.hpp> <nlohmann/json.hpp> <string> <vector> <memory> <regex> <map> <tuple> <stdexcept>)
|
||||
install(TARGETS ptr89 DESTINATION /usr/bin)
|
||||
|
||||
# enable_testing()
|
||||
# add_executable(ptr89-tests src/tests.cpp src/Pattern.cpp src/Tokenizer.cpp src/Parser.cpp src/utils.cpp)
|
||||
# add_test(NAME test COMMAND ptr89-tests)
|
||||
enable_testing()
|
||||
add_executable(ptr89-test src/tests ${LIB_SRC})
|
||||
add_test(NAME test COMMAND ptr89-tests)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@
|
|||
|
||||
namespace Ptr89 {
|
||||
|
||||
static const char *MNEMONICS[] = { "EQ", "NE", "CS", "CC", "MI", "PL", "VS", "VC", "HI", "LS", "GE", "LT", "GT", "LE", "", "??" };
|
||||
static const char *REGNAMES[] = { "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12", "SP", "LR", "PC" };
|
||||
|
||||
Pattern::DebugHandlerFunc Pattern::m_debugHandler = nullptr;
|
||||
int Pattern::m_debugLevel = 0;
|
||||
|
||||
|
|
@ -57,7 +60,7 @@ bool Pattern::fuzzyMatch(const uint8_t *bytes, const uint8_t *masks, int pattern
|
|||
bool Pattern::checkPattern(const std::shared_ptr<PtrExp> &pattern, size_t offset, const Memory &memory) {
|
||||
debugSectionBegin();
|
||||
if (m_debugHandler) {
|
||||
debug("Checking pattern: '%s' at %08lX\n", stringify(pattern).c_str(), offset);
|
||||
debug("Checking pattern: '%s' at %08lX\n", stringify(pattern).c_str(), memory.base + offset);
|
||||
if (m_debugLevel == 0)
|
||||
debug("Memory: %08X %08lX\n", memory.base, memory.size);
|
||||
}
|
||||
|
|
@ -113,10 +116,10 @@ bool Pattern::checkSubpatterns(const std::shared_ptr<PtrExp> &pattern, size_t of
|
|||
case SUB_PATTERN_TYPE_BRANCH_2B:
|
||||
{
|
||||
if (m_debugHandler)
|
||||
debug("Decoding THUMB B at %08lX\n", offset + p.offset);
|
||||
debug("Decoding THUMB B at %08lX\n", memory.base + offset + p.offset);
|
||||
|
||||
auto [isThumb, thumbAddr] = decodeThumbB(memory.base + offset + p.offset, memory.data + offset + p.offset);
|
||||
if (isThumb && thumbAddr >= memory.base && thumbAddr < memory.base + memory.size) {
|
||||
if (isThumb && inMemory(memory, thumbAddr, 4)) {
|
||||
uint32_t fileOffset = thumbAddr - memory.base;
|
||||
if (checkPattern(p.pattern, fileOffset, memory)) {
|
||||
debugSectionEnd();
|
||||
|
|
@ -132,10 +135,11 @@ bool Pattern::checkSubpatterns(const std::shared_ptr<PtrExp> &pattern, size_t of
|
|||
case SUB_PATTERN_TYPE_BRANCH_4B:
|
||||
{
|
||||
if (m_debugHandler)
|
||||
debug("Decoding THUMB BL/BLX at %08lX\n", offset + p.offset);
|
||||
debug("Try decoding THUMB BL/BLX at %08lX\n", memory.base + offset + p.offset);
|
||||
|
||||
auto [isThumb, thumbAddr] = decodeThumbBL(memory.base + offset + p.offset, memory.data + offset + p.offset);
|
||||
if (isThumb && thumbAddr >= memory.base && thumbAddr < memory.base + memory.size) {
|
||||
if (isThumb && inMemory(memory, thumbAddr, 4)) {
|
||||
thumbAddr = resolveThrunks(thumbAddr, memory);
|
||||
uint32_t fileOffset = thumbAddr - memory.base;
|
||||
if (checkPattern(p.pattern, fileOffset, memory)) {
|
||||
debugSectionEnd();
|
||||
|
|
@ -147,10 +151,27 @@ bool Pattern::checkSubpatterns(const std::shared_ptr<PtrExp> &pattern, size_t of
|
|||
}
|
||||
|
||||
if (m_debugHandler)
|
||||
debug("Decoding ARM B/BL/BLX at %08lX\n", offset + p.offset);
|
||||
debug("Try decoding ARM B/BL/BLX at %08lX\n", memory.base + offset + p.offset);
|
||||
|
||||
auto [isArm, armAddr] = decodeArmBL(memory.base + offset + p.offset, memory.data + offset + p.offset);
|
||||
if (isArm && armAddr >= memory.base && armAddr < memory.base + memory.size) {
|
||||
if (isArm && inMemory(memory, armAddr, 4)) {
|
||||
armAddr = resolveThrunks(armAddr, memory);
|
||||
uint32_t fileOffset = armAddr - memory.base;
|
||||
if (checkPattern(p.pattern, fileOffset, memory)) {
|
||||
debugSectionEnd();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (m_debugHandler)
|
||||
debug("FAIL: not instruction!\n");
|
||||
}
|
||||
|
||||
if (m_debugHandler)
|
||||
debug("Try decoding ARM THRUNK at %08lX\n", memory.base + offset + p.offset);
|
||||
|
||||
auto [isArmLdr, ldrAddr, isThrunk] = decodeArmLDR(memory.base + offset + p.offset, memory.data + offset + p.offset);
|
||||
if (isArmLdr && isThrunk && inMemory(memory, armAddr, 4)) {
|
||||
armAddr = resolveThrunks(armAddr, memory);
|
||||
uint32_t fileOffset = armAddr - memory.base;
|
||||
if (checkPattern(p.pattern, fileOffset, memory)) {
|
||||
debugSectionEnd();
|
||||
|
|
@ -177,8 +198,8 @@ bool Pattern::checkSubpatterns(const std::shared_ptr<PtrExp> &pattern, size_t of
|
|||
std::pair<bool, uint32_t> Pattern::decodeReference(uint32_t offset, const Memory &memory) {
|
||||
offset &= ~1;
|
||||
|
||||
debug("Decoding ARM LDR at %08X\n", offset);
|
||||
auto [isARM, armLDR] = decodeArmLDR(memory.base + offset, memory.data + offset);
|
||||
debug("Try decoding ARM LDR at %08X\n", memory.base + offset);
|
||||
auto [isARM, armLDR, isArmThrunk] = decodeArmLDR(memory.base + offset, memory.data + offset);
|
||||
if (isARM) {
|
||||
auto [success, addr] = decodePointer(armLDR, memory);
|
||||
if (success)
|
||||
|
|
@ -186,7 +207,7 @@ std::pair<bool, uint32_t> Pattern::decodeReference(uint32_t offset, const Memory
|
|||
}
|
||||
debug("FAIL: not instruction!\n");
|
||||
|
||||
debug("Decoding THUMB LDR at %08X\n", offset);
|
||||
debug("Try decoding THUMB LDR at %08X\n", memory.base + offset);
|
||||
auto [isThumb, thumbLDR] = decodeThumbLDR(memory.base + offset, memory.data + offset);
|
||||
if (isThumb) {
|
||||
auto [success, addr] = decodePointer(thumbLDR, memory);
|
||||
|
|
@ -199,8 +220,8 @@ std::pair<bool, uint32_t> Pattern::decodeReference(uint32_t offset, const Memory
|
|||
}
|
||||
|
||||
std::pair<bool, uint32_t> Pattern::decodePointer(uint32_t addr, const Memory &memory) {
|
||||
debug("Decoding pointer at %08X\n", addr - memory.base);
|
||||
if (addr >= memory.base && addr + 4 <= memory.base + memory.size) {
|
||||
debug("Try decoding pointer at %08X\n", addr);
|
||||
if (inMemory(memory, addr, 4)) {
|
||||
uint32_t value = *reinterpret_cast<const uint32_t *>(memory.data + (addr - memory.base));
|
||||
debug("Pointer address: %08X\n", value);
|
||||
return { true, value };
|
||||
|
|
@ -210,6 +231,20 @@ std::pair<bool, uint32_t> Pattern::decodePointer(uint32_t addr, const Memory &me
|
|||
return { false, 0 };
|
||||
}
|
||||
|
||||
uint32_t Pattern::resolveThrunks(uint32_t addr, const Memory &memory) {
|
||||
if (inMemory(memory, addr, 4)) {
|
||||
auto [isArmLdr, ldrAddr, isThrunk] = decodeArmLDR(addr, memory.data + (addr - memory.base));
|
||||
if (isThrunk && inMemory(memory, ldrAddr)) {
|
||||
uint32_t value = *reinterpret_cast<const uint32_t *>(memory.data + (ldrAddr - memory.base));
|
||||
if (inMemory(memory, value)) {
|
||||
debug("Found thrunk at %08X: PC->%08X\n", addr, value);
|
||||
return resolveThrunks(value, memory);
|
||||
}
|
||||
}
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
std::pair<bool, Pattern::SearchResult> Pattern::decodeResult(const std::shared_ptr<PtrExp> &pattern, uint32_t offset, const Memory &memory) {
|
||||
uint32_t address = memory.base + offset;
|
||||
|
||||
|
|
@ -217,7 +252,7 @@ std::pair<bool, Pattern::SearchResult> Pattern::decodeResult(const std::shared_p
|
|||
case PATTERN_TYPE_OFFSET:
|
||||
{
|
||||
uint32_t value = address;
|
||||
if ((address & 1) == 0 && address >= memory.base && address < memory.base + memory.size) {
|
||||
if ((address & 1) == 0 && inMemory(memory, address, 4)) {
|
||||
uint16_t instr = *reinterpret_cast<const uint16_t *>(memory.data + offset);
|
||||
if ((instr & 0xFE00) == 0xB400) // PUSH
|
||||
value |= 1;
|
||||
|
|
@ -258,7 +293,6 @@ std::vector<Pattern::SearchResult> Pattern::find(const std::shared_ptr<PtrExp> &
|
|||
if (m_debugHandler) {
|
||||
debug("Searching pattern: %s\n", stringify(pattern).c_str());
|
||||
debug("Memory: %08X %08lX\n", memory.base, memory.size);
|
||||
debug("firstNonWildcardByte=%d\n", firstNonWildcardByte);
|
||||
debug("\n");
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +341,7 @@ std::vector<Pattern::SearchResult> Pattern::find(const std::shared_ptr<PtrExp> &
|
|||
size_t foundOffset = i - firstNonWildcardByte;
|
||||
|
||||
if (m_debugHandler)
|
||||
debug("Possible result at %08lX\n", foundOffset);
|
||||
debug("Possible result at %08lX\n", memory.base + foundOffset);
|
||||
|
||||
if (checkSubpatterns(pattern, foundOffset, memory)) {
|
||||
auto [isDecoded, result] = decodeResult(pattern, foundOffset + pattern->inputOffset, memory);
|
||||
|
|
@ -346,7 +380,7 @@ std::vector<Pattern::SearchResult> Pattern::find(const std::shared_ptr<PtrExp> &
|
|||
if (fuzzyMatch(bytes, masks, size, memory.data + i)) {
|
||||
size_t foundOffset = i - firstNonWildcardByte;
|
||||
if (m_debugHandler)
|
||||
debug("Possible result at %08lX\n", foundOffset);
|
||||
debug("Possible result at %08lX\n", memory.base + foundOffset);
|
||||
if (checkSubpatterns(pattern, foundOffset, memory)) {
|
||||
auto [isDecoded, result] = decodeResult(pattern, foundOffset + pattern->inputOffset, memory);
|
||||
if (isDecoded) {
|
||||
|
|
@ -487,7 +521,6 @@ std::pair<bool, uint32_t> Pattern::decodeArmBL(uint32_t offset, const uint8_t *b
|
|||
if (m_debugHandler) {
|
||||
uint32_t cond = (instr & 0xF0000000) >> 28;
|
||||
uint32_t L = (instr & 0x0F000000) == 0x0B000000;
|
||||
const char *MNEMONICS[] = { "EQ", "NE", "CS", "CC", "MI", "PL", "VS", "VC", "HI", "LS", "GE", "LT", "GT", "LE", "", "??" };
|
||||
debug("%08X: %02X %02X %02X %02X B%s%s #0x%08X\n", offset, bytes[0], bytes[1], bytes[2], bytes[3], L ? "L" : "", MNEMONICS[cond], addr);
|
||||
}
|
||||
return { true, addr };
|
||||
|
|
@ -512,7 +545,6 @@ std::pair<bool, uint32_t> Pattern::decodeThumbB(uint32_t offset, const uint8_t *
|
|||
uint32_t addr = offset + 4 + offset8;
|
||||
if (m_debugHandler) {
|
||||
uint32_t cond = (instr & 0x0F00) >> 8;
|
||||
const char *MNEMONICS[] = { "EQ", "NE", "CS", "CC", "MI", "PL", "VS", "VC", "HI", "LS", "GE", "LT", "GT", "LE", "", "??" };
|
||||
debug("%08X: %02X %02X B%s #0x%08X\n", offset, bytes[0], bytes[1], MNEMONICS[cond], addr);
|
||||
}
|
||||
return { true, addr };
|
||||
|
|
@ -532,18 +564,18 @@ std::pair<bool, uint32_t> Pattern::decodeThumbLDR(uint32_t offset, const uint8_t
|
|||
uint32_t instr1_offset8 = (instr1 & 0xFF) << 2;
|
||||
uint32_t instr1_Rd = (instr1 & 0x700) >> 8;
|
||||
uint32_t addr = offset + (offset % 4 == 0 ? 4 : 2) + instr1_offset8;
|
||||
debug("%08X: %02X %02X LDR R%d, [PC, #0x%X] ; 0x%08X\n", offset, bytes[0], bytes[1], instr1_Rd, instr1_offset8, addr);
|
||||
debug("%08X: %02X %02X LDR %s, [PC, #0x%X] ; 0x%08X\n", offset, bytes[0], bytes[1], REGNAMES[instr1_Rd], instr1_offset8, addr);
|
||||
return { true, addr };
|
||||
}
|
||||
|
||||
return { false, 0 };
|
||||
}
|
||||
|
||||
std::pair<bool, uint32_t> Pattern::decodeArmLDR(uint32_t offset, const uint8_t *bytes) {
|
||||
std::tuple<bool, uint32_t, bool> Pattern::decodeArmLDR(uint32_t offset, const uint8_t *bytes) {
|
||||
uint32_t instr = (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
|
||||
|
||||
if ((offset % 4) != 0)
|
||||
return { false, 0 };
|
||||
return { false, 0, false };
|
||||
|
||||
if ((instr & 0xE0F0000) == 0x40F0000) { // Immediate offset/index
|
||||
int32_t U = (instr & (1 << 23)) != 0;
|
||||
|
|
@ -553,15 +585,14 @@ std::pair<bool, uint32_t> Pattern::decodeArmLDR(uint32_t offset, const uint8_t *
|
|||
|
||||
if (m_debugHandler) {
|
||||
uint32_t cond = (instr & 0xF0000000) >> 28;
|
||||
const char *MNEMONICS[] = { "EQ", "NE", "CS", "CC", "MI", "PL", "VS", "VC", "HI", "LS", "GE", "LT", "GT", "LE", "", "??" };
|
||||
debug("%08X: %02X %02X %02X %02X LDR%s R%d, [PC, #%c0x%X] ; 0x%08X\n", offset, bytes[0], bytes[1], bytes[2], bytes[3],
|
||||
MNEMONICS[cond], Rd, U ? '+' : '-', abs(offset_12), addr);
|
||||
debug("%08X: %02X %02X %02X %02X LDR%s %s, [PC, #%c0x%X] ; 0x%08X\n", offset, bytes[0], bytes[1], bytes[2], bytes[3],
|
||||
MNEMONICS[cond], REGNAMES[Rd], U ? '+' : '-', abs(offset_12), addr);
|
||||
}
|
||||
|
||||
return { true, addr };
|
||||
return { true, addr, Rd == 0xF };
|
||||
}
|
||||
|
||||
return { false, 0 };
|
||||
return { false, 0, false };
|
||||
}
|
||||
|
||||
void Pattern::debug(const char *format, ...) {
|
||||
|
|
|
|||
|
|
@ -83,9 +83,15 @@ class Pattern {
|
|||
static std::pair<bool, uint32_t> decodeArmBL(uint32_t offset, const uint8_t *bytes);
|
||||
static std::pair<bool, uint32_t> decodeThumbB(uint32_t offset, const uint8_t *bytes);
|
||||
static std::pair<bool, uint32_t> decodeThumbLDR(uint32_t offset, const uint8_t *bytes);
|
||||
static std::pair<bool, uint32_t> decodeArmLDR(uint32_t offset, const uint8_t *bytes);
|
||||
static std::tuple<bool, uint32_t, bool> decodeArmLDR(uint32_t offset, const uint8_t *bytes);
|
||||
static std::pair<bool, uint32_t> decodeArmThrunk(uint32_t offset, const uint8_t *bytes);
|
||||
static std::pair<bool, uint32_t> decodeReference(uint32_t offset, const Memory &memory);
|
||||
static std::pair<bool, uint32_t> decodePointer(uint32_t offset, const Memory &memory);
|
||||
static std::pair<bool, uint32_t> decodePointer(uint32_t addr, const Memory &memory);
|
||||
static uint32_t resolveThrunks(uint32_t addr, const Memory &memory);
|
||||
|
||||
static inline bool inMemory(const Memory &memory, uint32_t addr, uint32_t size = 1) {
|
||||
return addr >= memory.base && addr + size <= memory.base + memory.size;
|
||||
}
|
||||
|
||||
static void setDebugHandler(DebugHandlerFunc debugHandler) {
|
||||
m_debugHandler = debugHandler;
|
||||
|
|
|
|||
|
|
@ -1,79 +1,80 @@
|
|||
#include <cstdint>
|
||||
#include <ptr89.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace Ptr89;
|
||||
|
||||
void testArmDecoder() {
|
||||
static inline uint8_t *I(const std::vector<uint8_t> &value) {
|
||||
static std::vector<uint8_t> tmp;
|
||||
tmp = value;
|
||||
return &tmp[0];
|
||||
}
|
||||
|
||||
static void testArmDecoder() {
|
||||
// ARM BL #-offset
|
||||
uint8_t instr1[] = { 0xFE, 0xFB, 0xFF, 0x0B };
|
||||
assert(Pattern::decodeArmBL(0xA0001000, instr1) == std::make_pair(true, 0xA0000000));
|
||||
assert(Pattern::decodeArmBL(0xA0001000, I({ 0xFE, 0xFB, 0xFF, 0x0B })) == std::make_pair(true, 0xA0000000));
|
||||
|
||||
// ARM BLX #-offset
|
||||
uint8_t instr2[] = { 0xFE, 0xFB, 0xFF, 0xFA };
|
||||
assert(Pattern::decodeArmBL(0xA0001000, instr2) == std::make_pair(true, 0xA0000000));
|
||||
assert(Pattern::decodeArmBL(0xA0001000, I({ 0xFE, 0xFB, 0xFF, 0xFA })) == std::make_pair(true, 0xA0000000));
|
||||
|
||||
// ARM BL #+offset
|
||||
uint8_t instr3[] = { 0xFE, 0x03, 0x00, 0x0B };
|
||||
assert(Pattern::decodeArmBL(0xA0000000, instr3) == std::make_pair(true, 0xA0001000));
|
||||
assert(Pattern::decodeArmBL(0xA0000000, I({ 0xFE, 0x03, 0x00, 0x0B })) == std::make_pair(true, 0xA0001000));
|
||||
|
||||
// ARM BLX #+offset
|
||||
uint8_t instr4[] = { 0xFE, 0x03, 0x00, 0xFA };
|
||||
assert(Pattern::decodeArmBL(0xA0000000, instr4) == std::make_pair(true, 0xA0001000));
|
||||
assert(Pattern::decodeArmBL(0xA0000000, I({ 0xFE, 0x03, 0x00, 0xFA })) == std::make_pair(true, 0xA0001000));
|
||||
|
||||
// ARM BLX #-offset with H=1
|
||||
uint8_t instr5[] = { 0xFE, 0xFB, 0xFF, 0xFB };
|
||||
assert(Pattern::decodeArmBL(0xA0001000, instr5) == std::make_pair(true, 0xA0000002));
|
||||
assert(Pattern::decodeArmBL(0xA0001000, I({ 0xFE, 0xFB, 0xFF, 0xFB })) == std::make_pair(true, 0xA0000002));
|
||||
|
||||
// ARM BLX #+offset with H=1
|
||||
uint8_t instr6[] = { 0xFE, 0x03, 0x00, 0xFB };
|
||||
assert(Pattern::decodeArmBL(0xA0000000, instr6) == std::make_pair(true, 0xA0001002));
|
||||
assert(Pattern::decodeArmBL(0xA0000000, I({ 0xFE, 0x03, 0x00, 0xFB })) == std::make_pair(true, 0xA0001002));
|
||||
|
||||
// THUMB BL #-offset
|
||||
uint8_t instr7[] = { 0xFE, 0xF7, 0xFE, 0xFF };
|
||||
assert(Pattern::decodeThumbBL(0xA0001000, instr7) == std::make_pair(true, 0xA0000000));
|
||||
assert(Pattern::decodeThumbBL(0xA0001000, I({ 0xFE, 0xF7, 0xFE, 0xFF })) == std::make_pair(true, 0xA0000000));
|
||||
|
||||
// THUMB BLX #-offset
|
||||
uint8_t instr8[] = { 0xFE, 0xF7, 0xFE, 0xEF };
|
||||
assert(Pattern::decodeThumbBL(0xA0001000, instr8) == std::make_pair(true, 0xA0000000));
|
||||
assert(Pattern::decodeThumbBL(0xA0001000, I({ 0xFE, 0xF7, 0xFE, 0xEF })) == std::make_pair(true, 0xA0000000));
|
||||
|
||||
// THUMB BL #+offset
|
||||
uint8_t instr9[] = { 0x00, 0xF0, 0xFE, 0xFF };
|
||||
assert(Pattern::decodeThumbBL(0xA0000000, instr9) == std::make_pair(true, 0xA0001000));
|
||||
assert(Pattern::decodeThumbBL(0xA0000000, I({ 0x00, 0xF0, 0xFE, 0xFF })) == std::make_pair(true, 0xA0001000));
|
||||
|
||||
// THUMB BLX #+offset
|
||||
uint8_t instr10[] = { 0x00, 0xF0, 0xFE, 0xEF };
|
||||
assert(Pattern::decodeThumbBL(0xA0000000, instr10) == std::make_pair(true, 0xA0001000));
|
||||
assert(Pattern::decodeThumbBL(0xA0000000, I({ 0x00, 0xF0, 0xFE, 0xEF })) == std::make_pair(true, 0xA0001000));
|
||||
|
||||
// THUMB B #-offset
|
||||
uint8_t instr11[] = { 0x7E, 0xE7 };
|
||||
assert(Pattern::decodeThumbB(0xA0000100, instr11) == std::make_pair(true, 0xA0000000));
|
||||
assert(Pattern::decodeThumbB(0xA0000100, I({ 0x7E, 0xE7 })) == std::make_pair(true, 0xA0000000));
|
||||
|
||||
// THUMB B #+offset
|
||||
uint8_t instr12[] = { 0x7E, 0xE0 };
|
||||
assert(Pattern::decodeThumbB(0xA0000000, instr12) == std::make_pair(true, 0xA0000100));
|
||||
assert(Pattern::decodeThumbB(0xA0000000, I({ 0x7E, 0xE0 })) == std::make_pair(true, 0xA0000100));
|
||||
|
||||
// THUMB BEQ #-offset
|
||||
uint8_t instr13[] = { 0xF6, 0xD0 };
|
||||
assert(Pattern::decodeThumbB(0xA0000010, instr13) == std::make_pair(true, 0xA0000000));
|
||||
assert(Pattern::decodeThumbB(0xA0000010, I({ 0xF6, 0xD0 })) == std::make_pair(true, 0xA0000000));
|
||||
|
||||
// THUMB BEQ #+offset
|
||||
uint8_t instr14[] = { 0x06, 0xD0 };
|
||||
assert(Pattern::decodeThumbB(0xA0000000, instr14) == std::make_pair(true, 0xA0000010));
|
||||
assert(Pattern::decodeThumbB(0xA0000000, I({ 0x06, 0xD0 })) == std::make_pair(true, 0xA0000010));
|
||||
|
||||
// THUMB LDR Rd, [PC, #offset]
|
||||
uint8_t instr15[] = { 0x16, 0x48 };
|
||||
assert(Pattern::decodeThumbLDR(0xA0000000, instr15) == std::make_pair(true, 0xA000005C));
|
||||
assert(Pattern::decodeThumbLDR(0xA0000000, I({ 0x16, 0x48 })) == std::make_pair(true, 0xA000005C));
|
||||
|
||||
// THUMB LDR Rd, [PC, #offset]
|
||||
assert(Pattern::decodeThumbLDR(0xA0000002, I({ 0x16, 0x48 })) == std::make_pair(true, 0xA000005C));
|
||||
|
||||
// ARM LDR Rd, [PC, #+offset]
|
||||
uint8_t instr16[] = { 0x00, 0x01, 0x9F, 0xE5 };
|
||||
assert(Pattern::decodeArmLDR(0xA0000000, instr16) == std::make_pair(true, 0xA0000108));
|
||||
assert(Pattern::decodeArmLDR(0xA0000000, I({ 0x00, 0x01, 0x9F, 0xE5 })) == std::tuple(true, 0xA0000108, false));
|
||||
|
||||
// ARM LDR Rd, [PC, #-offset]
|
||||
uint8_t instr17[] = { 0x00, 0x01, 0x1F, 0xE5 };
|
||||
assert(Pattern::decodeArmLDR(0xA0000100, instr17) == std::make_pair(true, 0xA0000008));
|
||||
assert(Pattern::decodeArmLDR(0xA0000100, I({ 0x00, 0x01, 0x1F, 0xE5 })) == std::tuple(true, 0xA0000008, false));
|
||||
|
||||
// ARM LDR PC, [PC, #+offset]
|
||||
assert(Pattern::decodeArmLDR(0xA0000000, I({ 0x00, 0xF1, 0x9F, 0xE5 })) == std::tuple(true, 0xA0000108, true));
|
||||
|
||||
// ARM LDR PC, [PC, #-offset]
|
||||
assert(Pattern::decodeArmLDR(0xA0000100, I({ 0x00, 0xF1, 0x1F, 0xE5 })) == std::tuple(true, 0xA0000008, true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
Pattern::setDebugHandler(vprintf);
|
||||
testArmDecoder();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue