📦
1648 /agent.js
2790 /value.js
✄
import{encodeValue as e}from"./value.js";const n=new class{#e=new Map;registerQuickCommand(e,n){this.#e.set(e,n)}unregisterQuickCommand(e){this.#e.delete(e)}_invokeQuickCommand(e){const n=e[0],o=this.#e.get(n);if(void 0!==o){const{minArity:r,onInvoke:i}=o;if(e.length-1<r)throw Error(`${n} needs at least ${r} arg${1===r?"":"s"}`);return i(...e.slice(1))}throw Error(`Unknown command ${n}`)}};function o(e){Object.defineProperty(globalThis,e,{enumerable:!0,configurable:!0,get:()=>function(e){let n;return send({type:"frida:load-bridge",name:e}),recv("frida:bridge-loaded",(o=>{n=Script.evaluate(`/frida/bridges/${o.filename}`,"(function () { "+[o.source,`Object.defineProperty(globalThis, '${e}', { value: bridge });`,"return bridge;"].join("\n")+" })();")})).wait(),n}(e)})}globalThis.REPL=n,globalThis.cm=null,globalThis.cs={},o("ObjC"),o("Swift"),o("Java");const r={fridaEvaluateExpression:e=>i((()=>globalThis.eval(e))),fridaEvaluateQuickCommand:e=>i((()=>n._invokeQuickCommand(e))),fridaLoadCmodule(e,n){const o=globalThis.cs;void 0===o._frida_log&&(o._frida_log=new NativeCallback(t,"void",["pointer"]));let r=e;null===e&&recv("frida:cmodule-payload",((e,n)=>{r=n})),globalThis.cm=new CModule(r,o,{toolchain:n})}};function i(n){try{const o=n();if(o instanceof ArrayBuffer)return o;const r=null===o?"null":typeof o,[i,t]=e(o,{maxDepth:5});return["inspect",r,i,null!==t?Array.from(new Uint8Array(t)):null]}catch(e){const n=e;return["error",{name:n.name,message:n.message,stack:n.stack}]}}function t(e){const n=e.readUtf8String();console.log(n)}Object.defineProperty(rpc,"exports",{get:()=>r,set(e){for(const[n,o]of Object.entries(e))r[n]=o}});
✄
export function encodeValue(e,r){const o=[],f=t(e,o,r?.maxDepth??3,0,{seen:new Map,nextId:1}),{blob:s,offsets:c}=function(t){if(0===t.length)return{blob:null,offsets:[]};let n=0;const e=t.map((({buf:t})=>(t instanceof ArrayBuffer?t:t.buffer).byteLength));for(const t of e)n+=t;const r=new Uint8Array(n),o=[];let f=0;return t.forEach((({buf:t},n)=>{const e=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);r.set(e,f),o[n]={offset:f,length:e.byteLength},f+=e.byteLength})),{blob:r.buffer,offsets:o}}(o);return[n(f,c),s]}function t(n,e,r,o,f){if(null===n)return[5];const s=typeof n;if("number"===s)return[0,n];if("string"===s)return[1,n];if("object"===s){const s=n;if(s instanceof NativePointer)return[4,s.toString()];if((c=s)instanceof ArrayBuffer||ArrayBuffer.isView(c)){const t=e.length,n=s,r=function(t){if(t instanceof ArrayBuffer)return"ArrayBuffer";if(t instanceof DataView)return"DataView";const n=t.constructor;return n?.name??"ArrayBuffer"}(n);return e.push({index:t,buf:n}),[7,t,r]}if(s instanceof Error){const t=s;return[9,t.name??"Error",t.message??"",t.stack??""]}if(s instanceof Date)return[13,s.toISOString()];if(s instanceof RegExp){const t=s;return[14,t.source,t.flags]}if(s instanceof Promise)return[17];if(s instanceof WeakMap)return[18];if(s instanceof WeakSet)return[19];const i=Array.isArray(s),u=s instanceof Map,a=s instanceof Set,y=f.seen.get(s);if(void 0!==y)return[21,y];if(o>=r)return i?[20,3]:u?[20,15]:a?[20,16]:[20,2];const b=f.nextId++;if(f.seen.set(s,b),u){const n=s,c=[];for(const[s,i]of n.entries()){const n=t(s,e,r,o+1,f),u=t(i,e,r,o+1,f);c.push([n,u])}return[15,b,c]}if(a){const n=s,c=[];for(const s of n.values())c.push(t(s,e,r,o+1,f));return[16,b,c]}if(i){const n=s.map((n=>t(n,e,r,o+1,f)));return[3,b,n]}try{const n=s.toJSON;if("function"==typeof n){return t(n.call(s),e,r,o,f)}}catch{}const l=[];for(const n of Object.keys(s)){const c=[1,n];let i;try{i=s[n]}catch{continue}const u=t(i,e,r,o+1,f);l.push([c,u])}const p=Object.getOwnPropertySymbols(s);for(const n of p){if(!Object.prototype.propertyIsEnumerable.call(s,n))continue;const c=[12,String(n)];let i;try{i=s[n]}catch{continue}const u=t(i,e,r,o+1,f);l.push([c,u])}return[2,b,l]}var c;if("boolean"===s)return[6,n];if("function"===s){const t=n.name??"";return[8,""===t?"[Function]":`[Function: ${t}]`]}if("undefined"===s)return[10];if("bigint"===s){return[11,n.toString()]}return"symbol"===s?[12,String(n)]:[10]}function n(t,e){const[r,...o]=t;switch(r){case 2:return[2,o[0],o[1].map((([t,r])=>[n(t,e),n(r,e)]))];case 3:return[3,o[0],o[1].map((t=>n(t,e)))];case 7:{const t=o[0],n=o[1],{offset:r,length:f}=e[t];return[7,r,f,n]}case 15:return[15,o[0],o[1].map((([t,r])=>[n(t,e),n(r,e)]))];case 16:return[16,o[0],o[1].map((t=>n(t,e)))];default:return t}}