/** * Huan(202106): * - type: agent * A label for the frida target address * This is for the dynamic purpose, * i.e. we need to call/hook a PTR that generated by the init agent. * - type: objc: * ?? * - type: module * loadModule('libc', 'open') * * See: Jumping to Labels in Inline Assembly * https://docs.microsoft.com/en-us/cpp/assembler/inline/jumping-to-labels-in-inline-assembly * */ /** * Function Target * * number: memory address of the function * - 0x1234 * * string: export name of the function * - lib: 'open' * - ObjC: '- connection:didReceiveData:' */ /** * Memory address */ export interface TargetPayloadAddress { address : string moduleName : null | string type : 'address' } /** * The variable name in the `initAgentScript` */ export interface TargetPayloadAgent { type : 'agent' funcName : string } /** * The module name and the module export */ export interface TargetPayloadExport { exportName : string moduleName : null | string type : 'export' } // TODO: // | 'java' // TODO: // | 'objc' // TODO: export type TargetPayloadRaw = number | string export type TargetPayloadObj = TargetPayloadAddress | TargetPayloadAgent | TargetPayloadExport export type FunctionTarget = TargetPayloadRaw | TargetPayloadObj export type FunctionTargetType = TargetPayloadObj['type'] const addressTarget = ( address : number, moduleName : null | string = null, ): TargetPayloadAddress => ({ address: `0x${Number(address).toString(16)}`, moduleName, type: 'address', }) const agentTarget = ( funcName: string, ): TargetPayloadAgent => ({ funcName, type : 'agent', }) const exportTarget = ( exportName: string, moduleName: null | string = null, ): TargetPayloadExport => ({ exportName, moduleName, type: 'export', }) /** * Convert the `string` and `number` type target to Obj */ function normalizeFunctionTarget ( target: FunctionTarget, ): TargetPayloadObj { if (typeof target === 'number') { return addressTarget(target) } else if (typeof target === 'string') { return agentTarget(target) } return target } export { addressTarget, agentTarget, exportTarget, normalizeFunctionTarget, }