Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update utils.js #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,29 @@ const STRUCTRON_TYPE_STRING = memoryjs => (handle, structAddress, platform, enco
SIZE: platform === '64' ? SIZEOF_STDSTRING_64BIT : SIZEOF_STDSTRING_32BIT,
});

module.exports = { STRUCTRON_TYPE_STRING };
/**
* Reads the memory pointer from the specified address with optional offsets.
*
* @param {number} handle - The handle or identifier for the memory region.
* @param {number} address - The memory address to read.
* @param {number[]} [offsets] - Optional array of offsets to traverse.
* @returns {number} The value read from the memory address.
*/
const readPointer = memoryjs => (handle, address, offsets) => {
let addr = address

if (offsets) {
addr = memoryjs.readMemory(handle, addr, memoryjs.INT)
for (let offset of offsets) {
if (offset == offsets.at(-1)) {
addr += offset
continue
}
addr = memoryjs.readMemory(handle, addr + offset, memoryjs.INT)
}
}

return addr
}

module.exports = { STRUCTRON_TYPE_STRING, readPointer };