mirror of
https://github.com/siemens-mobile-hacks/ptr89.git
synced 2026-11-25 18:27:22 +00:00
fix(search): preserve bytes for adjusted addresses
This commit is contained in:
parent
25adfbce09
commit
3af0d25b0d
5 changed files with 15 additions and 6 deletions
|
|
@ -171,14 +171,15 @@ uint32_t Pattern::resolveThunks(uint32_t addr, const Memory &memory) {
|
|||
return getArch(memory.arch).resolveThunks(addr, memory);
|
||||
}
|
||||
|
||||
std::pair<bool, Pattern::SearchResult> Pattern::decodeResult(const std::shared_ptr<PtrExp> &pattern, uint32_t offset, const Memory &memory) {
|
||||
std::pair<bool, Pattern::SearchResult> Pattern::decodeResult(const std::shared_ptr<PtrExp> &pattern, uint32_t matchOffset, const Memory &memory) {
|
||||
uint32_t offset = matchOffset + pattern->inputOffset;
|
||||
uint32_t address = memory.base + offset;
|
||||
|
||||
switch (pattern->type) {
|
||||
case RESULT_TYPE_OFFSET:
|
||||
{
|
||||
uint32_t value = getArch(memory.arch).offsetValue(address, offset, memory);
|
||||
return { true, { value, offset, pattern->bytes.size() } };
|
||||
return { true, { value, matchOffset, pattern->bytes.size() } };
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -318,7 +319,7 @@ std::vector<Pattern::SearchResult> Pattern::find(const std::shared_ptr<PtrExp> &
|
|||
spdlog::debug("Possible result at {:08X}", memory.base + foundOffset);
|
||||
|
||||
if (checkSubpatterns(pattern, foundOffset, memory)) {
|
||||
auto [isDecoded, result] = decodeResult(pattern, foundOffset + pattern->inputOffset, memory);
|
||||
auto [isDecoded, result] = decodeResult(pattern, foundOffset, memory);
|
||||
if (isDecoded) {
|
||||
searchResults.push_back(result);
|
||||
|
||||
|
|
@ -354,7 +355,7 @@ std::vector<Pattern::SearchResult> Pattern::find(const std::shared_ptr<PtrExp> &
|
|||
size_t foundOffset = i - firstNonWildcardByte;
|
||||
spdlog::debug("Possible result at {:08X}", memory.base + foundOffset);
|
||||
if (checkSubpatterns(pattern, foundOffset, memory)) {
|
||||
auto [isDecoded, result] = decodeResult(pattern, foundOffset + pattern->inputOffset, memory);
|
||||
auto [isDecoded, result] = decodeResult(pattern, foundOffset, memory);
|
||||
if (isDecoded) {
|
||||
searchResults.push_back(result);
|
||||
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class Pattern {
|
|||
private:
|
||||
static bool checkSubpatterns(const std::shared_ptr<PtrExp> &pattern, size_t offset, const Memory &memory);
|
||||
static bool fuzzyMatch(const uint8_t *bytes, const uint8_t *masks, int patternSize, const uint8_t *memory);
|
||||
static std::pair<bool, SearchResult> decodeResult(const std::shared_ptr<PtrExp> &pattern, uint32_t offset, const Memory &memory);
|
||||
static std::pair<bool, SearchResult> decodeResult(const std::shared_ptr<PtrExp> &pattern, uint32_t matchOffset, const Memory &memory);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@sie-js/ptr89",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"description": "ARM/THUMB/C166 binary pattern finder",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
|
|
|||
|
|
@ -253,6 +253,9 @@ static void testThumbPattern() {
|
|||
Pattern::Memory functionMemory = { 0xA0000000, functionBytes, sizeof(functionBytes), 1, ARCH_ARM };
|
||||
auto functionResults = Pattern::find(Pattern::parse("10 B5"), functionMemory, 1);
|
||||
assert(functionResults.size() == 1 && functionResults[0].address == 0xA0000001 && functionResults[0].size == 2);
|
||||
auto adjustedResults = Pattern::find(Pattern::parse("00 BF + 1"), functionMemory, 1);
|
||||
assert(adjustedResults.size() == 1 && adjustedResults[0].address == 0xA0000003 &&
|
||||
adjustedResults[0].offset == 2 && adjustedResults[0].size == 2);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ describe("Ptr89 WASM", () => {
|
|||
offset: 10,
|
||||
bytes: "10B5",
|
||||
}]);
|
||||
expect(ptr89.find("00 BF + 1", 1)).toEqual([{
|
||||
address: 0xA0000003,
|
||||
offset: 2,
|
||||
bytes: "00BF",
|
||||
}]);
|
||||
expect(ptr89.find("48", 1, 2)).toEqual([]);
|
||||
|
||||
ptr89.close();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue