Skip to content

Commit e658654

Browse files
authored
🤖 Merge PR DefinitelyTyped#72177 Sync frida-gum typings with Frida 16.7.0 by @oleavr
1 parent 1cc6578 commit e658654

File tree

3 files changed

+186
-1
lines changed

3 files changed

+186
-1
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,33 @@ Process.enumerateThreads().forEach(t => {
424424
Process.enumerateThreads().forEach(t => {
425425
t.unsetHardwareWatchpoint(0);
426426
});
427+
428+
const threadObserver = Process.attachThreadObserver({
429+
onAdded(thread) {
430+
// $ExpectType StableThreadDetails
431+
thread;
432+
},
433+
onRemoved(thread) {
434+
// $ExpectType StableThreadDetails
435+
thread;
436+
},
437+
onRenamed(thread, previousName) {
438+
// $ExpectType StableThreadDetails
439+
thread;
440+
// $ExpectType string | null
441+
previousName;
442+
},
443+
});
444+
threadObserver.detach();
445+
446+
const moduleObserver = Process.attachModuleObserver({
447+
onAdded(module) {
448+
// $ExpectType Module
449+
module;
450+
},
451+
onRemoved(module) {
452+
// $ExpectType Module
453+
module;
454+
},
455+
});
456+
moduleObserver.detach();

types/frida-gum/index.d.ts

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,15 @@ declare namespace Process {
371371
*/
372372
function enumerateThreads(): ThreadDetails[];
373373

374+
/**
375+
* Starts observing threads, calling the provided callbacks as threads are
376+
* added, removed, and renamed. Calls `onAdded` with all existing threads
377+
* right away, so the initial state vs. updates can be managed easily
378+
* without worrying about race conditions.
379+
* All callbacks are optional, but at least one of them must be provided.
380+
*/
381+
function attachThreadObserver(callbacks: ThreadObserverCallbacks): ThreadObserver;
382+
374383
/**
375384
* Looks up a module by address. Returns null if not found.
376385
*/
@@ -396,6 +405,15 @@ declare namespace Process {
396405
*/
397406
function enumerateModules(): Module[];
398407

408+
/**
409+
* Starts observing modules, calling the provided callbacks as modules are
410+
* added and removed. Calls `onAdded` with all existing modules right away,
411+
* so the initial state vs. updates can be managed easily without worrying
412+
* about race conditions.
413+
* Both callbacks are optional, but at least one of them must be provided.
414+
*/
415+
function attachModuleObserver(callbacks: ModuleObserverCallbacks): ModuleObserver;
416+
399417
/**
400418
* Looks up a memory range by address. Returns null if not found.
401419
*/
@@ -576,6 +594,51 @@ declare class Module {
576594
static getExportByName(moduleName: string | null, exportName: string): NativePointer;
577595
}
578596

597+
declare class ThreadObserver {
598+
/**
599+
* Detaches observer previously attached through `Process#attachThreadObserver()`.
600+
*/
601+
detach(): void;
602+
}
603+
604+
interface ThreadObserverCallbacks {
605+
/**
606+
* Called synchronously when a Thread has been added.
607+
*/
608+
onAdded?(thread: StableThreadDetails): void;
609+
610+
/**
611+
* Called synchronously when a Thread has been removed.
612+
*/
613+
onRemoved?(thread: StableThreadDetails): void;
614+
615+
/**
616+
* Called synchronously when a Thread has been renamed.
617+
*/
618+
onRenamed?(thread: StableThreadDetails, previousName: string | null): void;
619+
}
620+
621+
type StableThreadDetails = Omit<ThreadDetails, "state" | "context">;
622+
623+
declare class ModuleObserver {
624+
/**
625+
* Detaches observer previously attached through `Process#attachModuleObserver()`.
626+
*/
627+
detach(): void;
628+
}
629+
630+
interface ModuleObserverCallbacks {
631+
/**
632+
* Called synchronously when a Module has been added.
633+
*/
634+
onAdded?(module: Module): void;
635+
636+
/**
637+
* Called synchronously when a Module has been removed.
638+
*/
639+
onRemoved?(module: Module): void;
640+
}
641+
579642
declare class ModuleMap {
580643
/**
581644
* Creates a new module map optimized for determining which module a given memory address belongs to, if any.
@@ -829,6 +892,11 @@ interface MemoryAccessCallbacks {
829892
}
830893

831894
interface MemoryAccessDetails {
895+
/**
896+
* The ID of the thread performing the access.
897+
*/
898+
threadId: ThreadId;
899+
832900
/**
833901
* The kind of operation that triggered the access.
834902
*/
@@ -865,6 +933,11 @@ interface MemoryAccessDetails {
865933
* Overall number of pages that were initially monitored.
866934
*/
867935
pagesTotal: number;
936+
937+
/**
938+
* CPU registers. You may also update register values by assigning to these keys.
939+
*/
940+
context: CpuContext;
868941
}
869942

870943
declare namespace Thread {
@@ -969,6 +1042,11 @@ interface ThreadDetails {
9691042
*/
9701043
context: CpuContext;
9711044

1045+
/**
1046+
* Where the thread started its execution, if applicable and available.
1047+
*/
1048+
entrypoint?: ThreadEntrypoint;
1049+
9721050
/**
9731051
* Set a hardware breakpoint.
9741052
*
@@ -1007,6 +1085,18 @@ interface ThreadDetails {
10071085
unsetHardwareWatchpoint(id: HardwareWatchpointId): void;
10081086
}
10091087

1088+
interface ThreadEntrypoint {
1089+
/**
1090+
* The thread's start routine.
1091+
*/
1092+
routine: NativePointer;
1093+
1094+
/**
1095+
* Parameter passed to `routine`, if available.
1096+
*/
1097+
parameter?: NativePointer;
1098+
}
1099+
10101100
interface KernelModuleDetails {
10111101
/**
10121102
* Canonical module name.
@@ -1744,6 +1834,7 @@ declare class NativePointer {
17441834
writeUtf8String(value: string): NativePointer;
17451835
writeUtf16String(value: string): NativePointer;
17461836
writeAnsiString(value: string): NativePointer;
1837+
writeVolatile(value: ArrayBuffer | number[]): NativePointer;
17471838
}
17481839

17491840
type PointerAuthenticationKey = "ia" | "ib" | "da" | "db";
@@ -4549,6 +4640,70 @@ declare namespace Cloak {
45494640
function hasFileDescriptor(fd: number): boolean;
45504641
}
45514642

4643+
declare class Profiler {
4644+
/**
4645+
* Starts instrumenting the specified function using the specified sampler.
4646+
*/
4647+
instrument(functionAddress: NativePointerValue, sampler: Sampler, callbacks: ProfilerInstrumentCallbacks): void;
4648+
4649+
/**
4650+
* Generates an XML report from the live profiler state. May be called at
4651+
* any point, and as many times as desired.
4652+
*/
4653+
generateReport(): string;
4654+
}
4655+
4656+
interface ProfilerInstrumentCallbacks {
4657+
/**
4658+
* Called synchronously when a new worst-case has been discovered, and a
4659+
* description should be captured from the argument list and/or other
4660+
* relevant state.
4661+
*/
4662+
describe?(this: InvocationContext, args: InvocationArguments): string;
4663+
}
4664+
4665+
declare abstract class Sampler {
4666+
/**
4667+
* Retrieves a new sample. What it denotes depends on the specific sampler.
4668+
*/
4669+
sample(): bigint;
4670+
}
4671+
4672+
/**
4673+
* Sampler that measures CPU cycles, e.g. using the RDTSC instruction on x86.
4674+
*/
4675+
declare class CycleSampler extends Sampler {}
4676+
4677+
/**
4678+
* Sampler that measures CPU cycles only spent by the current thread, e.g.
4679+
* using QueryThreadCycleTime() on Windows.
4680+
*/
4681+
declare class BusyCycleSampler extends Sampler {}
4682+
4683+
/**
4684+
* Sampler that measures passage of time.
4685+
*/
4686+
declare class WallClockSampler extends Sampler {}
4687+
4688+
/**
4689+
* Sampler that measures time spent in user-space.
4690+
*/
4691+
declare class UserTimeSampler extends Sampler {
4692+
constructor(threadId?: ThreadId);
4693+
}
4694+
4695+
/**
4696+
* Sampler that counts the number of calls to malloc(), calloc(), and realloc().
4697+
*/
4698+
declare class MallocCountSampler extends Sampler {}
4699+
4700+
/**
4701+
* Sampler that counts the number of calls to functions of your choosing.
4702+
*/
4703+
declare class CallCountSampler extends Sampler {
4704+
constructor(functions: NativePointerValue[]);
4705+
}
4706+
45524707
declare namespace ObjC {
45534708
// tslint:disable:no-unnecessary-qualifier
45544709

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": "18.7.9999",
4+
"version": "18.8.9999",
55
"nonNpm": true,
66
"nonNpmDescription": "frida-gum",
77
"projects": [

0 commit comments

Comments
 (0)