Skip to content

Commit 95c9d09

Browse files
authored
🤖 Merge PR DefinitelyTyped#75066 [frida-gum] Add Memory.findPointers by @oleavr
1 parent 49ed2e3 commit 95c9d09

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

types/frida-gum/frida-gum-tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ Memory.scan(ptr("0x1234"), Process.pageSize, new MatchPattern("13 37"), {
173173
},
174174
});
175175

176+
// $ExpectType MemoryPointerMatch[]
177+
Memory.findPointers({ base: ptr("0x1234"), size: Process.pageSize }, [ptr("0xdeadbeef")]);
178+
// $ExpectType MemoryPointerMatch[]
179+
const pointerMatches = Memory.findPointers(
180+
[{ base: ptr("0x1234"), size: Process.pageSize }],
181+
[ptr("0xdeadbeef")],
182+
{ mask: ptr("0x00007ffffffffff8") },
183+
);
184+
// $ExpectType NativePointer
185+
pointerMatches[0].address;
186+
// $ExpectType NativePointer
187+
pointerMatches[0].value;
188+
176189
// $ExpectType Module
177190
Process.mainModule;
178191

types/frida-gum/index.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,22 @@ declare namespace Memory {
757757
pattern: string | MatchPattern,
758758
): MemoryScanMatch[];
759759

760+
/**
761+
* Scans one or more memory ranges for pointer-aligned words matching any of `values`.
762+
*
763+
* This is a focused, SIMD-accelerated alternative to `scan()` for the common task of finding pointers, e.g.
764+
* references to a given address. All matches are collected and returned sorted by address.
765+
*
766+
* @param ranges Memory range, or array of ranges, to scan.
767+
* @param values Pointer-width values to look for.
768+
* @param options Options to customize the scan.
769+
*/
770+
function findPointers(
771+
ranges: MemoryRange | MemoryRange[],
772+
values: NativePointerValue[],
773+
options?: MemoryFindPointersOptions,
774+
): MemoryPointerMatch[];
775+
760776
/**
761777
* Allocates `size` bytes of memory on Frida's private heap, or, if `size` is a multiple of Process#pageSize,
762778
* one or more raw memory pages managed by the OS. The allocated memory will be released when the returned
@@ -1461,6 +1477,26 @@ interface MemoryScanMatch {
14611477
size: number;
14621478
}
14631479

1480+
interface MemoryFindPointersOptions {
1481+
/**
1482+
* Bitmask applied to each scanned word and each value before comparing. Defaults to an exact match.
1483+
* Pass e.g. `ptr("0x00007ffffffffff8")` to strip arm64e PAC and non-pointer-isa bits.
1484+
*/
1485+
mask?: NativePointerValue;
1486+
}
1487+
1488+
interface MemoryPointerMatch {
1489+
/**
1490+
* Memory address where a matching word was found.
1491+
*/
1492+
address: NativePointer;
1493+
1494+
/**
1495+
* The matching word, i.e. the value stored at `address`, before masking.
1496+
*/
1497+
value: NativePointer;
1498+
}
1499+
14641500
interface KernelMemoryScanCallbacks {
14651501
/**
14661502
* Called with each occurence that was found.

types/frida-gum/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/frida-gum",
4-
"version": "19.3.9999",
4+
"version": "19.4.9999",
55
"nonNpm": true,
66
"nonNpmDescription": "frida-gum",
77
"projects": [

0 commit comments

Comments
 (0)