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
30 changes: 30 additions & 0 deletions types/frida-gum/frida-gum-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,33 @@ Process.enumerateThreads().forEach(t => {
Process.enumerateThreads().forEach(t => {
t.unsetHardwareWatchpoint(0);
});

const threadObserver = Process.attachThreadObserver({
onAdded(thread) {
// $ExpectType StableThreadDetails
thread;
},
onRemoved(thread) {
// $ExpectType StableThreadDetails
thread;
},
onRenamed(thread, previousName) {
// $ExpectType StableThreadDetails
thread;
// $ExpectType string | null
previousName;
},
});
threadObserver.detach();

const moduleObserver = Process.attachModuleObserver({
onAdded(module) {
// $ExpectType Module
module;
},
onRemoved(module) {
// $ExpectType Module
module;
},
});
moduleObserver.detach();
155 changes: 155 additions & 0 deletions types/frida-gum/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ declare namespace Process {
*/
function enumerateThreads(): ThreadDetails[];

/**
* Starts observing threads, calling the provided callbacks as threads are
* added, removed, and renamed. Calls `onAdded` with all existing threads
* right away, so the initial state vs. updates can be managed easily
* without worrying about race conditions.
* All callbacks are optional, but at least one of them must be provided.
*/
function attachThreadObserver(callbacks: ThreadObserverCallbacks): ThreadObserver;

/**
* Looks up a module by address. Returns null if not found.
*/
Expand All @@ -396,6 +405,15 @@ declare namespace Process {
*/
function enumerateModules(): Module[];

/**
* Starts observing modules, calling the provided callbacks as modules are
* added and removed. Calls `onAdded` with all existing modules right away,
* so the initial state vs. updates can be managed easily without worrying
* about race conditions.
* Both callbacks are optional, but at least one of them must be provided.
*/
function attachModuleObserver(callbacks: ModuleObserverCallbacks): ModuleObserver;

/**
* Looks up a memory range by address. Returns null if not found.
*/
Expand Down Expand Up @@ -576,6 +594,51 @@ declare class Module {
static getExportByName(moduleName: string | null, exportName: string): NativePointer;
}

declare class ThreadObserver {
/**
* Detaches observer previously attached through `Process#attachThreadObserver()`.
*/
detach(): void;
}

interface ThreadObserverCallbacks {
/**
* Called synchronously when a Thread has been added.
*/
onAdded?(thread: StableThreadDetails): void;

/**
* Called synchronously when a Thread has been removed.
*/
onRemoved?(thread: StableThreadDetails): void;

/**
* Called synchronously when a Thread has been renamed.
*/
onRenamed?(thread: StableThreadDetails, previousName: string | null): void;
}

type StableThreadDetails = Omit<ThreadDetails, "state" | "context">;

declare class ModuleObserver {
/**
* Detaches observer previously attached through `Process#attachModuleObserver()`.
*/
detach(): void;
}

interface ModuleObserverCallbacks {
/**
* Called synchronously when a Module has been added.
*/
onAdded?(module: Module): void;

/**
* Called synchronously when a Module has been removed.
*/
onRemoved?(module: Module): void;
}

declare class ModuleMap {
/**
* Creates a new module map optimized for determining which module a given memory address belongs to, if any.
Expand Down Expand Up @@ -829,6 +892,11 @@ interface MemoryAccessCallbacks {
}

interface MemoryAccessDetails {
/**
* The ID of the thread performing the access.
*/
threadId: ThreadId;

/**
* The kind of operation that triggered the access.
*/
Expand Down Expand Up @@ -865,6 +933,11 @@ interface MemoryAccessDetails {
* Overall number of pages that were initially monitored.
*/
pagesTotal: number;

/**
* CPU registers. You may also update register values by assigning to these keys.
*/
context: CpuContext;
}

declare namespace Thread {
Expand Down Expand Up @@ -969,6 +1042,11 @@ interface ThreadDetails {
*/
context: CpuContext;

/**
* Where the thread started its execution, if applicable and available.
*/
entrypoint?: ThreadEntrypoint;

/**
* Set a hardware breakpoint.
*
Expand Down Expand Up @@ -1007,6 +1085,18 @@ interface ThreadDetails {
unsetHardwareWatchpoint(id: HardwareWatchpointId): void;
}

interface ThreadEntrypoint {
/**
* The thread's start routine.
*/
routine: NativePointer;

/**
* Parameter passed to `routine`, if available.
*/
parameter?: NativePointer;
}

interface KernelModuleDetails {
/**
* Canonical module name.
Expand Down Expand Up @@ -1744,6 +1834,7 @@ declare class NativePointer {
writeUtf8String(value: string): NativePointer;
writeUtf16String(value: string): NativePointer;
writeAnsiString(value: string): NativePointer;
writeVolatile(value: ArrayBuffer | number[]): NativePointer;
}

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

declare class Profiler {
/**
* Starts instrumenting the specified function using the specified sampler.
*/
instrument(functionAddress: NativePointerValue, sampler: Sampler, callbacks: ProfilerInstrumentCallbacks): void;

/**
* Generates an XML report from the live profiler state. May be called at
* any point, and as many times as desired.
*/
generateReport(): string;
}

interface ProfilerInstrumentCallbacks {
/**
* Called synchronously when a new worst-case has been discovered, and a
* description should be captured from the argument list and/or other
* relevant state.
*/
describe?(this: InvocationContext, args: InvocationArguments): string;
}

declare abstract class Sampler {
/**
* Retrieves a new sample. What it denotes depends on the specific sampler.
*/
sample(): bigint;
}

/**
* Sampler that measures CPU cycles, e.g. using the RDTSC instruction on x86.
*/
declare class CycleSampler extends Sampler {}

/**
* Sampler that measures CPU cycles only spent by the current thread, e.g.
* using QueryThreadCycleTime() on Windows.
*/
declare class BusyCycleSampler extends Sampler {}

/**
* Sampler that measures passage of time.
*/
declare class WallClockSampler extends Sampler {}

/**
* Sampler that measures time spent in user-space.
*/
declare class UserTimeSampler extends Sampler {
constructor(threadId?: ThreadId);
}

/**
* Sampler that counts the number of calls to malloc(), calloc(), and realloc().
*/
declare class MallocCountSampler extends Sampler {}

/**
* Sampler that counts the number of calls to functions of your choosing.
*/
declare class CallCountSampler extends Sampler {
constructor(functions: NativePointerValue[]);
}

declare namespace ObjC {
// tslint:disable:no-unnecessary-qualifier

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": "18.7.9999",
"version": "18.8.9999",
"nonNpm": true,
"nonNpmDescription": "frida-gum",
"projects": [
Expand Down