Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions types/frida-gum/frida-gum-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ Memory.scan(ptr("0x1234"), Process.pageSize, new MatchPattern("13 37"), {
},
});

// $ExpectType MemoryPointerMatch[]
Memory.findPointers({ base: ptr("0x1234"), size: Process.pageSize }, [ptr("0xdeadbeef")]);
// $ExpectType MemoryPointerMatch[]
const pointerMatches = Memory.findPointers(
[{ base: ptr("0x1234"), size: Process.pageSize }],
[ptr("0xdeadbeef")],
{ mask: ptr("0x00007ffffffffff8") },
);
// $ExpectType NativePointer
pointerMatches[0].address;
// $ExpectType NativePointer
pointerMatches[0].value;

// $ExpectType Module
Process.mainModule;

Expand Down
36 changes: 36 additions & 0 deletions types/frida-gum/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,22 @@ declare namespace Memory {
pattern: string | MatchPattern,
): MemoryScanMatch[];

/**
* Scans one or more memory ranges for pointer-aligned words matching any of `values`.
*
* This is a focused, SIMD-accelerated alternative to `scan()` for the common task of finding pointers, e.g.
* references to a given address. All matches are collected and returned sorted by address.
*
* @param ranges Memory range, or array of ranges, to scan.
* @param values Pointer-width values to look for.
* @param options Options to customize the scan.
*/
function findPointers(
ranges: MemoryRange | MemoryRange[],
values: NativePointerValue[],
options?: MemoryFindPointersOptions,
): MemoryPointerMatch[];

/**
* Allocates `size` bytes of memory on Frida's private heap, or, if `size` is a multiple of Process#pageSize,
* one or more raw memory pages managed by the OS. The allocated memory will be released when the returned
Expand Down Expand Up @@ -1461,6 +1477,26 @@ interface MemoryScanMatch {
size: number;
}

interface MemoryFindPointersOptions {
/**
* Bitmask applied to each scanned word and each value before comparing. Defaults to an exact match.
* Pass e.g. `ptr("0x00007ffffffffff8")` to strip arm64e PAC and non-pointer-isa bits.
*/
mask?: NativePointerValue;
}

interface MemoryPointerMatch {
/**
* Memory address where a matching word was found.
*/
address: NativePointer;

/**
* The matching word, i.e. the value stored at `address`, before masking.
*/
value: NativePointer;
}

interface KernelMemoryScanCallbacks {
/**
* Called with each occurence that was found.
Expand Down
2 changes: 1 addition & 1 deletion types/frida-gum/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/frida-gum",
"version": "19.3.9999",
"version": "19.4.9999",
"nonNpm": true,
"nonNpmDescription": "frida-gum",
"projects": [
Expand Down