memoryjs: Pattern scan always returns same (wrong) address
const memoryjs = require('memoryjs')
memoryjs.openProcess('notepad++.exe', (error, process) => {
if (error) { console.log(error) }
memoryjs.findPattern(process.handle, 'notepad++.exe', '65 6C 6C ? 20 57 6F 72 6C 64 21', memoryjs.NORMAL, 0, 0, (error, offset) => {
console.log(offset)
})
});
No matter what process name I use, or pattern, the above code will always output this:
18446744073709552000
Which is of course incorrect. And looking at notepad++.exe’s memory using Cheat Engine I can see Hello World! is definitely in the its memory, infact in three different locations, and not in utf16 format (it doesn’t have 00 between each character).
But using the address found via Cheat Engine to read the text I typed in notepad++.exe works correctly:
memoryjs.readMemory(process.handle, 0x1A338732FB0, 'string', (error, data) => {
console.log(data)
})
Will output:
Hello World!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (5 by maintainers)
These changes are implemented in a32ceee.
New implementation of
findPatternis:The
signatureOffsetparameter has been removed fromfindPatternto reduce the parameter count. The value of the parameter was just added to the memory address returned, so does not need to happen inside of this function.I’ll leave the issue open to take comments until I publish all the recent library changes to NPM.
Hey, @Rob--! Thanks so much for taking the time to test and reply with all of that. I totally didn’t think about exploring regions like that. I was incorrectly assuming that regions relative to the application’s modules were already taken into consideration. Thanks for clarifying!
I like the
findPatternchanges you’ve suggested, too. I think all three would be respectively beneficial.Thanks again, Rob!
@dsasmblr thanks, glad you’ve found it useful! I’ve also taken a look at the same example. The implementation of
findPatternseems correct, it’s just that in this specific case the address lies outside of a module…Opening up
notepad.exe, typingdeezand doing aSearch for textwithUTF-16checked shows two results:Running this script (using one of the two addresses) shows the address doesn’t lie inside of any modules, but lies inside of a single region:
I’ve edited the source code so that
findPatternsearches both modules and regions, so the output in this case finds a match:Searching all regions & modules takes too long, so it might be worth having a
findPatternthat searches everything, and afindPatternthat will search just a specified module or region…I think I’ll change
findPatternto have the following implementations:lib/memoryjs.cc 693:
uintptr_t address = -1;736:Local<Value> argv[argc] = { String::NewFromUtf8(isolate, errorMessage), Number::New(isolate, address) };https://v8docs.nodesource.com/node-10.15/d9/d29/classv8_1_1_number.html:
static Local< Number > | New (Isolate *isolate, double value)After conversion to double, the value of
addressin js is 18446744073709552000.000000, obviously the data overflowed.Comparing signed and unsigned numbers produces a logical error.Exceptions may never be thrown?