📦
50167 /src/app.js
✄
var G=null,H={exceptions:"propagate"};function D(){if(G!==null)return G;let e={},t=[{module:"libsystem_malloc.dylib",functions:{free:["void",["pointer"]]}},{module:"libobjc.A.dylib",functions:{objc_msgSend:function(r){this.objc_msgSend=r},objc_msgSend_stret:function(r){this.objc_msgSend_stret=r},objc_msgSend_fpret:function(r){this.objc_msgSend_fpret=r},objc_msgSendSuper:function(r){this.objc_msgSendSuper=r},objc_msgSendSuper_stret:function(r){this.objc_msgSendSuper_stret=r},objc_msgSendSuper_fpret:function(r){this.objc_msgSendSuper_fpret=r},objc_getClassList:["int",["pointer","int"]],objc_lookUpClass:["pointer",["pointer"]],objc_allocateClassPair:["pointer",["pointer","pointer","pointer"]],objc_disposeClassPair:["void",["pointer"]],objc_registerClassPair:["void",["pointer"]],class_isMetaClass:["bool",["pointer"]],class_getName:["pointer",["pointer"]],class_getImageName:["pointer",["pointer"]],class_copyProtocolList:["pointer",["pointer","pointer"]],class_copyMethodList:["pointer",["pointer","pointer"]],class_getClassMethod:["pointer",["pointer","pointer"]],class_getInstanceMethod:["pointer",["pointer","pointer"]],class_getSuperclass:["pointer",["pointer"]],class_addProtocol:["bool",["pointer","pointer"]],class_addMethod:["bool",["pointer","pointer","pointer","pointer"]],class_copyIvarList:["pointer",["pointer","pointer"]],objc_getProtocol:["pointer",["pointer"]],objc_copyProtocolList:["pointer",["pointer"]],objc_allocateProtocol:["pointer",["pointer"]],objc_registerProtocol:["void",["pointer"]],protocol_getName:["pointer",["pointer"]],protocol_copyMethodDescriptionList:["pointer",["pointer","bool","bool","pointer"]],protocol_copyPropertyList:["pointer",["pointer","pointer"]],protocol_copyProtocolList:["pointer",["pointer","pointer"]],protocol_addProtocol:["void",["pointer","pointer"]],protocol_addMethodDescription:["void",["pointer","pointer","pointer","bool","bool"]],ivar_getName:["pointer",["pointer"]],ivar_getTypeEncoding:["pointer",["pointer"]],ivar_getOffset:["pointer",["pointer"]],object_isClass:["bool",["pointer"]],object_getClass:["pointer",["pointer"]],object_getClassName:["pointer",["pointer"]],method_getName:["pointer",["pointer"]],method_getTypeEncoding:["pointer",["pointer"]],method_getImplementation:["pointer",["pointer"]],method_setImplementation:["pointer",["pointer","pointer"]],property_getName:["pointer",["pointer"]],property_copyAttributeList:["pointer",["pointer","pointer"]],sel_getName:["pointer",["pointer"]],sel_registerName:["pointer",["pointer"]],class_getInstanceSize:["pointer",["pointer"]]},optionals:{objc_msgSend_stret:"ABI",objc_msgSend_fpret:"ABI",objc_msgSendSuper_stret:"ABI",objc_msgSendSuper_fpret:"ABI",object_isClass:"iOS8"}},{module:"libdispatch.dylib",functions:{dispatch_async_f:["void",["pointer","pointer","pointer"]]},variables:{_dispatch_main_q:function(r){this._dispatch_main_q=r}}}],n=0;return t.forEach(function(r){let o=r.module==="libobjc.A.dylib",i=r.functions||{},l=r.variables||{},u=r.optionals||{};n+=Object.keys(i).length+Object.keys(l).length;let a=(Process.findModuleByName(r.module)?.enumerateExports()??[]).reduce(function(s,c){return s[c.name]=c,s},{});Object.keys(i).forEach(function(s){let c=a[s];if(c!==void 0&&c.type==="function"){let p=i[s];typeof p=="function"?(p.call(e,c.address),o&&p.call(e,c.address)):(e[s]=new NativeFunction(c.address,p[0],p[1],H),o&&(e[s]=e[s])),n--}else u[s]&&n--}),Object.keys(l).forEach(function(s){let c=a[s];c!==void 0&&c.type==="variable"&&(l[s].call(e,c.address),n--)})}),n===0&&(e.objc_msgSend_stret||(e.objc_msgSend_stret=e.objc_msgSend),e.objc_msgSend_fpret||(e.objc_msgSend_fpret=e.objc_msgSend),e.objc_msgSendSuper_stret||(e.objc_msgSendSuper_stret=e.objc_msgSendSuper),e.objc_msgSendSuper_fpret||(e.objc_msgSendSuper_fpret=e.objc_msgSendSuper),G=e),G}var le=`#include <glib.h>
#include <ptrauth.h>

#define KERN_SUCCESS 0
#define MALLOC_PTR_IN_USE_RANGE_TYPE 1
#if defined (HAVE_I386) && GLIB_SIZEOF_VOID_P == 8
# define OBJC_ISA_MASK 0x7ffffffffff8ULL
#elif defined (HAVE_ARM64)
# define OBJC_ISA_MASK 0xffffffff8ULL
#endif

typedef struct _ChooseContext ChooseContext;

typedef struct _malloc_zone_t malloc_zone_t;
typedef struct _malloc_introspection_t malloc_introspection_t;
typedef struct _vm_range_t vm_range_t;

typedef gpointer Class;
typedef int kern_return_t;
typedef guint mach_port_t;
typedef mach_port_t task_t;
typedef guintptr vm_offset_t;
typedef guintptr vm_size_t;
typedef vm_offset_t vm_address_t;

struct _ChooseContext
{
  GHashTable * classes;
  GArray * matches;
};

struct _malloc_zone_t
{
  void * reserved1;
  void * reserved2;
  size_t (* size) (struct _malloc_zone_t * zone, const void * ptr);
  void * (* malloc) (struct _malloc_zone_t * zone, size_t size);
  void * (* calloc) (struct _malloc_zone_t * zone, size_t num_items, size_t size);
  void * (* valloc) (struct _malloc_zone_t * zone, size_t size);
  void (* free) (struct _malloc_zone_t * zone, void * ptr);
  void * (* realloc) (struct _malloc_zone_t * zone, void * ptr, size_t size);
  void (* destroy) (struct _malloc_zone_t * zone);
  const char * zone_name;

  unsigned (* batch_malloc) (struct _malloc_zone_t * zone, size_t size, void ** results, unsigned num_requested);
  void (* batch_free) (struct _malloc_zone_t * zone, void ** to_be_freed, unsigned num_to_be_freed);

  malloc_introspection_t * introspect;
};

typedef kern_return_t (* memory_reader_t) (task_t remote_task, vm_address_t remote_address, vm_size_t size, void ** local_memory);
typedef void (* vm_range_recorder_t) (task_t task, void * user_data, unsigned type, vm_range_t * ranges, unsigned count);
typedef kern_return_t (* enumerator_func) (task_t task, void * user_data, unsigned type_mask, vm_address_t zone_address, memory_reader_t reader,
      vm_range_recorder_t recorder);

struct _malloc_introspection_t
{
  enumerator_func enumerator;
};

struct _vm_range_t
{
  vm_address_t address;
  vm_size_t size;
};

extern int objc_getClassList (Class * buffer, int buffer_count);
extern Class class_getSuperclass (Class cls);
extern size_t class_getInstanceSize (Class cls);
extern kern_return_t malloc_get_all_zones (task_t task, memory_reader_t reader, vm_address_t ** addresses, unsigned * count);

static void collect_subclasses (Class klass, GHashTable * result);
static void collect_matches_in_ranges (task_t task, void * user_data, unsigned type, vm_range_t * ranges, unsigned count);
static kern_return_t read_local_memory (task_t remote_task, vm_address_t remote_address, vm_size_t size, void ** local_memory);

extern mach_port_t selfTask;

gpointer *
choose (Class * klass,
        gboolean consider_subclasses,
        guint * count)
{
  ChooseContext ctx;
  GHashTable * classes;
  vm_address_t * malloc_zone_addresses;
  unsigned malloc_zone_count, i;

  classes = g_hash_table_new_full (NULL, NULL, NULL, NULL);
  ctx.classes = classes;
  ctx.matches = g_array_new (FALSE, FALSE, sizeof (gpointer));
  if (consider_subclasses)
    collect_subclasses (klass, classes);
  else
    g_hash_table_insert (classes, klass, GSIZE_TO_POINTER (class_getInstanceSize (klass)));

  malloc_zone_count = 0;
  malloc_get_all_zones (selfTask, read_local_memory, &malloc_zone_addresses, &malloc_zone_count);

  for (i = 0; i != malloc_zone_count; i++)
  {
    vm_address_t zone_address = malloc_zone_addresses[i];
    malloc_zone_t * zone = (malloc_zone_t *) zone_address;
    enumerator_func enumerator;

    if (zone != NULL && zone->introspect != NULL &&
        (enumerator = (ptrauth_strip (zone->introspect, ptrauth_key_asda))->enumerator) != NULL)
    {
      enumerator = ptrauth_sign_unauthenticated (
          ptrauth_strip (enumerator, ptrauth_key_asia),
          ptrauth_key_asia, 0);

      enumerator (selfTask, &ctx, MALLOC_PTR_IN_USE_RANGE_TYPE, zone_address, read_local_memory,
          collect_matches_in_ranges);
    }
  }

  g_hash_table_unref (classes);

  *count = ctx.matches->len;

  return (gpointer *) g_array_free (ctx.matches, FALSE);
}

void
destroy (gpointer mem)
{
  g_free (mem);
}

static void
collect_subclasses (Class klass,
                    GHashTable * result)
{
  Class * classes;
  int count, i;

  count = objc_getClassList (NULL, 0);
  classes = g_malloc (count * sizeof (gpointer));
  count = objc_getClassList (classes, count);

  for (i = 0; i != count; i++)
  {
    Class candidate = classes[i];
    Class c;

    c = candidate;
    do
    {
      if (c == klass)
      {
        g_hash_table_insert (result, candidate, GSIZE_TO_POINTER (class_getInstanceSize (candidate)));
        break;
      }

      c = class_getSuperclass (c);
    }
    while (c != NULL);
  }

  g_free (classes);
}

static void
collect_matches_in_ranges (task_t task,
                           void * user_data,
                           unsigned type,
                           vm_range_t * ranges,
                           unsigned count)
{
  ChooseContext * ctx = user_data;
  GHashTable * classes = ctx->classes;
  unsigned i;

  for (i = 0; i != count; i++)
  {
    const vm_range_t * range = &ranges[i];
    gconstpointer candidate = GSIZE_TO_POINTER (range->address);
    gconstpointer isa;
    guint instance_size;

    isa = *(gconstpointer *) candidate;
#ifdef OBJC_ISA_MASK
    isa = GSIZE_TO_POINTER (GPOINTER_TO_SIZE (isa) & OBJC_ISA_MASK);
#endif

    instance_size = GPOINTER_TO_UINT (g_hash_table_lookup (classes, isa));
    if (instance_size != 0 && range->size >= instance_size)
    {
      g_array_append_val (ctx->matches, candidate);
    }
  }
}

static kern_return_t
read_local_memory (task_t remote_task,
                   vm_address_t remote_address,
                   vm_size_t size,
                   void ** local_memory)
{
  *local_memory = (void *) remote_address;

  return KERN_SUCCESS;
}
`,{pointerSize:ce}=Process,J=null;function re(){return J===null&&(J=ue()),J}function ue(){let{objc_getClassList:e,class_getSuperclass:t,class_getInstanceSize:n}=D(),r=Memory.alloc(4);r.writeU32(Module.getGlobalExportByName("mach_task_self_").readU32());let o=new CModule(le,{objc_getClassList:e,class_getSuperclass:t,class_getInstanceSize:n,malloc_get_all_zones:Process.getModuleByName("/usr/lib/system/libsystem_malloc.dylib").getExportByName("malloc_get_all_zones"),selfTask:r}),i=new NativeFunction(o.choose,"pointer",["pointer","bool","pointer"]),l=new NativeFunction(o.destroy,"void",["pointer"]);return{handle:o,choose(u,a){let s=[],c=Memory.alloc(4),p=i(u,a?1:0,c);try{let h=c.readU32();for(let g=0;g!==h;g++)s.push(p.add(g*ce).readPointer())}finally{l(p)}return s}}}function pe(){let pointerSize=Process.pointerSize,api=null,apiError=null,realizedClasses=new Set,classRegistry=new ClassRegistry,protocolRegistry=new ProtocolRegistry,replacedMethods=new Map,scheduledWork=new Map,nextId=1,workCallback=null,NSAutoreleasePool=null,bindings=new Map,readObjectIsa=null,msgSendBySignatureId=new Map,msgSendSuperBySignatureId=new Map,cachedNSString=null,cachedNSStringCtor=null,cachedNSNumber=null,cachedNSNumberCtor=null,singularTypeById=null,modifiers=null;try{tryInitialize()}catch(e){}function tryInitialize(){if(api!==null)return!0;if(apiError!==null)throw apiError;try{api=D()}catch(e){throw apiError=e,e}return api!==null}function dispose(){for(let[e,t]of replacedMethods.entries()){let n=ptr(e),[r,o]=t;api.method_getImplementation(n).equals(o)&&api.method_setImplementation(n,r)}replacedMethods.clear()}Script.bindWeak(this,dispose),Object.defineProperty(this,"available",{enumerable:!0,get(){return tryInitialize()}}),Object.defineProperty(this,"api",{enumerable:!0,get(){return D()}}),Object.defineProperty(this,"classes",{enumerable:!0,value:classRegistry}),Object.defineProperty(this,"protocols",{enumerable:!0,value:protocolRegistry}),Object.defineProperty(this,"Object",{enumerable:!0,value:ObjCObject}),Object.defineProperty(this,"Protocol",{enumerable:!0,value:ObjCProtocol}),Object.defineProperty(this,"Block",{enumerable:!0,value:Block}),Object.defineProperty(this,"mainQueue",{enumerable:!0,get(){return api?._dispatch_main_q??null}}),Object.defineProperty(this,"registerProxy",{enumerable:!0,value:registerProxy}),Object.defineProperty(this,"registerClass",{enumerable:!0,value:registerClass}),Object.defineProperty(this,"registerProtocol",{enumerable:!0,value:registerProtocol}),Object.defineProperty(this,"bind",{enumerable:!0,value:bind}),Object.defineProperty(this,"unbind",{enumerable:!0,value:unbind}),Object.defineProperty(this,"getBoundData",{enumerable:!0,value:getBoundData}),Object.defineProperty(this,"enumerateLoadedClasses",{enumerable:!0,value:enumerateLoadedClasses}),Object.defineProperty(this,"enumerateLoadedClassesSync",{enumerable:!0,value:enumerateLoadedClassesSync}),Object.defineProperty(this,"choose",{enumerable:!0,value:choose}),Object.defineProperty(this,"chooseSync",{enumerable:!0,value(e){let t=[];return choose(e,{onMatch(n){t.push(n)},onComplete(){}}),t}}),this.schedule=function(e,t){let n=ptr(nextId++);scheduledWork.set(n.toString(),t),workCallback===null&&(workCallback=new NativeCallback(performScheduledWorkItem,"void",["pointer"])),Script.pin(),api.dispatch_async_f(e,n,workCallback)};function performScheduledWorkItem(e){let t=e.toString(),n=scheduledWork.get(t);scheduledWork.delete(t),NSAutoreleasePool===null&&(NSAutoreleasePool=classRegistry.NSAutoreleasePool);let r=NSAutoreleasePool.alloc().init(),o=null;try{n()}catch(i){o=i}r.release(),setImmediate(performScheduledWorkCleanup,o)}function performScheduledWorkCleanup(e){if(Script.unpin(),e!==null)throw e}this.implement=function(e,t){return new NativeCallback(t,e.returnType,e.argumentTypes)},this.selector=selector,this.selectorAsString=selectorAsString;function selector(e){return api.sel_registerName(Memory.allocUtf8String(e))}function selectorAsString(e){return api.sel_getName(e).readUtf8String()}let registryBuiltins=new Set(["prototype","constructor","hasOwnProperty","toJSON","toString","valueOf"]);function ClassRegistry(){let e={},t=0,n=new Proxy(this,{has(s,c){return r(c)},get(s,c,p){switch(c){case"prototype":return s.prototype;case"constructor":return s.constructor;case"hasOwnProperty":return r;case"toJSON":return l;case"toString":return u;case"valueOf":return a;default:let h=i(c);return h!==null?h:void 0}},set(s,c,p,h){return!1},ownKeys(s){if(api===null)return[];let c=api.objc_getClassList(NULL,0);if(c!==t){let p=Memory.alloc(c*pointerSize);c=api.objc_getClassList(p,c);for(let h=0;h!==c;h++){let g=p.add(h*pointerSize).readPointer(),_=api.class_getName(g).readUtf8String();e[_]=g}t=c}return Object.keys(e)},getOwnPropertyDescriptor(s,c){return{writable:!1,configurable:!0,enumerable:!0}}});function r(s){return registryBuiltins.has(s)?!0:i(s)!==null}function o(s){let c=i(s);if(c===null)throw new Error("Unable to find class '"+s+"'");return c}function i(s){let c=e[s];if(c===void 0){if(c=api.objc_lookUpClass(Memory.allocUtf8String(s)),c.isNull())return null;e[s]=c,t++}return new ObjCObject(c,void 0,!0)}function l(){return Object.keys(n).reduce(function(s,c){return s[c]=o(c).toJSON(),s},{})}function u(){return"ClassRegistry"}function a(){return"ClassRegistry"}return n}function ProtocolRegistry(){let e={},t=0,n=new Proxy(this,{has(a,s){return r(s)},get(a,s,c){switch(s){case"prototype":return a.prototype;case"constructor":return a.constructor;case"hasOwnProperty":return r;case"toJSON":return i;case"toString":return l;case"valueOf":return u;default:let p=o(s);return p!==null?p:void 0}},set(a,s,c,p){return!1},ownKeys(a){if(api===null)return[];let s=Memory.alloc(pointerSize),c=api.objc_copyProtocolList(s);try{let p=s.readUInt();if(p!==t){e={};for(let h=0;h!==p;h++){let g=c.add(h*pointerSize).readPointer(),_=api.protocol_getName(g).readUtf8String();e[_]=g}t=p}}finally{api.free(c)}return Object.keys(e)},getOwnPropertyDescriptor(a,s){return{writable:!1,configurable:!0,enumerable:!0}}});function r(a){return registryBuiltins.has(a)?!0:o(a)!==null}function o(a){let s=e[a];if(s===void 0){if(s=api.objc_getProtocol(Memory.allocUtf8String(a)),s.isNull())return null;e[a]=s,t++}return new ObjCProtocol(s)}function i(){return Object.keys(n).reduce(function(a,s){return a[s]={handle:e[s]},a},{})}function l(){return"ProtocolRegistry"}function u(){return"ProtocolRegistry"}return n}let objCObjectBuiltins=new Set(["prototype","constructor","handle","hasOwnProperty","toJSON","toString","valueOf","equals","$kind","$super","$superClass","$class","$className","$moduleName","$protocols","$methods","$ownMethods","$ivars"]);function ObjCObject(e,t,n,r){let o=null,i=null,l=null,u=null,a=null,s=null,c=null,p=null,h=null,g=null,_=null,S={},w=null,k=null,P=null;if(e=getHandle(e),n===void 0){let y=api.object_getClass(e),d=y.toString();realizedClasses.has(d)||(api.objc_lookUpClass(api.class_getName(y)),realizedClasses.add(d))}let z=new Proxy(this,{has(y,d){return x(d)},get(y,d,N){switch(d){case"handle":return e;case"prototype":return y.prototype;case"constructor":return y.constructor;case"hasOwnProperty":return x;case"toJSON":return ie;case"toString":case"valueOf":let v=N.description;if(v!==void 0){let b=v.call(N);if(b!==null)return b.UTF8String.bind(b)}return function(){return N.$className};case"equals":return ae;case"$kind":return i===null&&(M()?i=api.class_isMetaClass(e)?"meta-class":"class":i="instance"),i;case"$super":if(l===null){let b=api.class_getSuperclass(I());if(b.isNull())l=[null];else{let O=Memory.alloc(2*pointerSize);O.writePointer(e),O.add(pointerSize).writePointer(b),l=[new ObjCObject(e,void 0,n,O)]}}return l[0];case"$superClass":if(u===null){let b=api.class_getSuperclass(I());b.isNull()?u=[null]:u=[new ObjCObject(b)]}return u[0];case"$class":return a===null&&(a=new ObjCObject(api.object_getClass(e),void 0,!0)),a;case"$className":return s===null&&(r?s=api.class_getName(r.add(pointerSize).readPointer()).readUtf8String():M()?s=api.class_getName(e).readUtf8String():s=api.object_getClassName(e).readUtf8String()),s;case"$moduleName":return c===null&&(c=api.class_getImageName(I()).readUtf8String()),c;case"$protocols":if(p===null){p={};let b=Memory.alloc(pointerSize),O=api.class_copyProtocolList(I(),b);if(!O.isNull())try{let L=b.readUInt();for(let C=0;C!==L;C++){let E=O.add(C*pointerSize).readPointer(),U=new ObjCProtocol(E);p[U.name]=U}}finally{api.free(O)}}return p;case"$methods":if(w===null){let b=r?r.add(pointerSize).readPointer():I(),O=api.object_getClass(b),L=new Set,C=O;do{for(let E of collectMethodNames(C,"+ "))L.add(E);C=api.class_getSuperclass(C)}while(!C.isNull());C=b;do{for(let E of collectMethodNames(C,"- "))L.add(E);C=api.class_getSuperclass(C)}while(!C.isNull());w=Array.from(L)}return w;case"$ownMethods":if(k===null){let b=r?r.add(pointerSize).readPointer():I(),O=api.object_getClass(b),L=collectMethodNames(O,"+ "),C=collectMethodNames(b,"- ");k=L.concat(C)}return k;case"$ivars":return P===null&&(M()?P={}:P=new ObjCIvars(z,I())),P;default:if(typeof d=="symbol")return y[d];if(t){let b=V(d);if(b===null||!b.implemented)return}let j=Z(d);return j===null?void 0:j}},set(y,d,N,v){return!1},ownKeys(y){if(h===null)if(t){let d=[],N=Y();Object.keys(N).forEach(function(v){v[0]!=="+"&&v[0]!=="-"&&N[v].implemented&&d.push(v)}),h=d}else{let d={},N={},v=api.object_getClass(e);do{let j=Memory.alloc(pointerSize),b=api.class_copyMethodList(v,j),O=M()?"+ ":"- ";try{let L=j.readUInt();for(let C=0;C!==L;C++){let E=b.add(C*pointerSize).readPointer(),U=api.method_getName(E),T=api.sel_getName(U).readUtf8String();if(N[T]!==void 0)continue;N[T]=T;let A=jsMethodName(T),X=2,$=A;for(;d[$]!==void 0;)X++,$=A+X;d[$]=!0;let ee=O+T;if(S[ee]===void 0){let te={sel:U,handle:E,wrapper:null};S[ee]=te,S[$]=te}}}finally{api.free(b)}v=api.class_getSuperclass(v)}while(!v.isNull());h=Object.keys(d)}return["handle"].concat(h)},getOwnPropertyDescriptor(y,d){return{writable:!1,configurable:!0,enumerable:!0}}});return t&&(_=M()?null:Z("- respondsToSelector:")),z;function x(y){if(objCObjectBuiltins.has(y))return!0;if(t){let d=V(y);return!!(d!==null&&d.implemented)}return B(y)!==null}function I(){return o===null&&(o=M()?e:api.object_getClass(e)),o}function M(){return n===void 0&&(api.object_isClass?n=!!api.object_isClass(e):n=!!api.class_isMetaClass(api.object_getClass(e))),n}function B(y){let d=S[y];if(d!==void 0)return d;let N=se(y),v=N[2];if(d=S[v],d!==void 0)return S[y]=d,d;let j=N[0],b=N[1],O=selector(b),L=M()?"+":"-";if(t){let C=V(v);C!==null&&(d={sel:O,types:C.types,wrapper:null,kind:j})}if(d===void 0){let C=j==="+"?api.class_getClassMethod(I(),O):api.class_getInstanceMethod(I(),O);if(!C.isNull())d={sel:O,handle:C,wrapper:null,kind:j};else{if(M()||j!=="-"||b==="forwardingTargetForSelector:"||b==="methodSignatureForSelector:")return null;let E=z;if("- forwardingTargetForSelector:"in z){let A=z.forwardingTargetForSelector_(O);if(A!==null&&A.$kind==="instance")E=A;else return null}else return null;let U=api.class_getInstanceMethod(api.object_getClass(E.handle),O);if(U.isNull())return null;let T=api.method_getTypeEncoding(U).readUtf8String();if((T===null||T==="")&&(T=F(E,v),T===null&&(T=F(z,v)),T===null))return null;d={sel:O,types:T,wrapper:null,kind:j}}}return S[v]=d,S[y]=d,j===L&&(S[jsMethodName(b)]=d),d}function F(y,d){let v=Object.keys(y.$protocols).map(j=>Q({},y.$protocols[j])).reduce((j,b)=>(Object.assign(j,b),j),{})[d];return v===void 0?null:v.types}function Q(y,d){return d.methods!==void 0&&Object.assign(y,d.methods),d.protocol!==void 0&&Q(y,d.protocol),y}function V(y){let N=Y()[y];return N!==void 0?N:null}function Y(){if(g===null){let y={},d=collectProtocols(t),N=M()?"+":"-";Object.keys(d).forEach(function(v){let b=d[v].methods;Object.keys(b).forEach(function(O){let L=b[O],C=O.substr(2),E=O[0],U=!1,T=!1,A={types:L.types};Object.defineProperty(A,"implemented",{get(){return U||(L.required?T=!0:T=_!==null&&_.call(z,selector(C)),U=!0),T}}),y[O]=A,E===N&&(y[jsMethodName(C)]=A)})}),g=y}return g}function Z(y){let d=B(y);if(d===null)return null;let N=d.wrapper;return N===null&&(N=makeMethodInvocationWrapper(d,z,r,H),d.wrapper=N),N}function se(y){let d=/([+\-])\s(\S+)/.exec(y),N,v;d===null?(v=M()?"+":"-",N=objcMethodName(y)):(v=d[1],N=d[2]);let j=[v,N].join(" ");return[v,N,j]}function ie(){return{handle:e.toString()}}function ae(y){return e.equals(getHandle(y))}}function getReplacementMethodImplementation(e){let t=replacedMethods.get(e.toString());if(t===void 0)return null;let[,n]=t;return n}function replaceMethodImplementation(e,t){let n=e.toString(),r,o=replacedMethods.get(n);o!==void 0?[r]=o:r=api.method_getImplementation(e),t.equals(r)?replacedMethods.delete(n):replacedMethods.set(n,[r,t]),api.method_setImplementation(e,t)}function collectMethodNames(e,t){let n=[],r=Memory.alloc(pointerSize),o=api.class_copyMethodList(e,r);try{let i=r.readUInt();for(let l=0;l!==i;l++){let u=o.add(l*pointerSize).readPointer(),a=api.method_getName(u),s=api.sel_getName(a).readUtf8String();n.push(t+s)}}finally{api.free(o)}return n}function ObjCProtocol(e){let t=null,n=null,r=null,o=null;Object.defineProperty(this,"handle",{value:e,enumerable:!0}),Object.defineProperty(this,"name",{get(){return t===null&&(t=api.protocol_getName(e).readUtf8String()),t},enumerable:!0}),Object.defineProperty(this,"protocols",{get(){if(n===null){n={};let l=Memory.alloc(pointerSize),u=api.protocol_copyProtocolList(e,l);if(!u.isNull())try{let a=l.readUInt();for(let s=0;s!==a;s++){let c=u.add(s*pointerSize).readPointer(),p=new ObjCProtocol(c);n[p.name]=p}}finally{api.free(u)}}return n},enumerable:!0}),Object.defineProperty(this,"properties",{get(){if(r===null){r={};let l=Memory.alloc(pointerSize),u=api.protocol_copyPropertyList(e,l);if(!u.isNull())try{let a=l.readUInt();for(let s=0;s!==a;s++){let c=u.add(s*pointerSize).readPointer(),p=api.property_getName(c).readUtf8String(),h={},g=api.property_copyAttributeList(c,l);if(!g.isNull())try{let _=l.readUInt();for(let S=0;S!==_;S++){let w=g.add(S*(2*pointerSize)),k=w.readPointer().readUtf8String(),P=w.add(pointerSize).readPointer().readUtf8String();h[k]=P}}finally{api.free(g)}r[p]=h}}finally{api.free(u)}}return r},enumerable:!0}),Object.defineProperty(this,"methods",{get(){if(o===null){o={};let l=Memory.alloc(pointerSize);i(o,l,{required:!0,instance:!1}),i(o,l,{required:!1,instance:!1}),i(o,l,{required:!0,instance:!0}),i(o,l,{required:!1,instance:!0})}return o},enumerable:!0});function i(l,u,a){let s=api.protocol_copyMethodDescriptionList(e,a.required?1:0,a.instance?1:0,u);if(!s.isNull())try{let c=u.readUInt();for(let p=0;p!==c;p++){let h=s.add(p*(2*pointerSize)),g=(a.instance?"- ":"+ ")+selectorAsString(h.readPointer()),_=h.add(pointerSize).readPointer().readUtf8String();l[g]={required:a.required,types:_}}}finally{api.free(s)}}}let objCIvarsBuiltins=new Set(["prototype","constructor","hasOwnProperty","toJSON","toString","valueOf"]);function ObjCIvars(e,t){let n={},r=null,o=[],i=t;do o.unshift(i),i=api.class_getSuperclass(i);while(!i.isNull());let l=Memory.alloc(pointerSize);o.forEach(g=>{let _=api.class_copyIvarList(g,l);try{let S=l.readUInt();for(let w=0;w!==S;w++){let k=_.add(w*pointerSize).readPointer(),P=api.ivar_getName(k).readUtf8String();n[P]=[k,null]}}finally{api.free(_)}});let u=new Proxy(this,{has(g,_){return s(_)},get(g,_,S){switch(_){case"prototype":return g.prototype;case"constructor":return g.constructor;case"hasOwnProperty":return s;case"toJSON":return c;case"toString":return p;case"valueOf":return h;default:let w=a(_);return w===null?void 0:w.get()}},set(g,_,S,w){let k=a(_);if(k===null)throw new Error("Unknown ivar");return k.set(S),!0},ownKeys(g){return r===null&&(r=Object.keys(n)),r},getOwnPropertyDescriptor(g,_){return{writable:!0,configurable:!0,enumerable:!0}}});return u;function a(g){let _=n[g];if(_===void 0)return null;let S=_[1];if(S===null){let w=_[0],k=api.ivar_getOffset(w).toInt32(),P=e.handle.add(k),z=parseType(api.ivar_getTypeEncoding(w).readUtf8String()),x=z.fromNative||identityTransform,I=z.toNative||identityTransform,M,B;g==="isa"?(M=readObjectIsa,B=function(){throw new Error("Unable to set the isa instance variable")}):(M=z.read,B=z.write),S={get(){return x.call(e,M(P))},set(F){B(P,I.call(e,F))}},_[1]=S}return S}function s(g){return objCIvarsBuiltins.has(g)?!0:n.hasOwnProperty(g)}function c(){return Object.keys(u).reduce(function(g,_){return g[_]=u[_],g},{})}function p(){return"ObjCIvars"}function h(){return"ObjCIvars"}}let blockDescriptorAllocSize,blockDescriptorDeclaredSize,blockDescriptorOffsets,blockSize,blockOffsets;pointerSize===4?(blockDescriptorAllocSize=16,blockDescriptorDeclaredSize=20,blockDescriptorOffsets={reserved:0,size:4,rest:8},blockSize=20,blockOffsets={isa:0,flags:4,reserved:8,invoke:12,descriptor:16}):(blockDescriptorAllocSize=32,blockDescriptorDeclaredSize=32,blockDescriptorOffsets={reserved:0,size:8,rest:16},blockSize=32,blockOffsets={isa:0,flags:8,reserved:12,invoke:16,descriptor:24});let BLOCK_HAS_COPY_DISPOSE=1<<25,BLOCK_HAS_CTOR=1<<26,BLOCK_IS_GLOBAL=1<<28,BLOCK_HAS_STRET=1<<29,BLOCK_HAS_SIGNATURE=1<<30;function Block(e,t=H){if(this._options=t,e instanceof NativePointer){let n=e.add(blockOffsets.descriptor).readPointer();this.handle=e;let r=e.add(blockOffsets.flags).readU32();if((r&BLOCK_HAS_SIGNATURE)!==0){let o=(r&BLOCK_HAS_COPY_DISPOSE)!==0?2:0;this.types=n.add(blockDescriptorOffsets.rest+o*pointerSize).readPointer().readCString(),this._signature=parseSignature(this.types)}else this._signature=null}else{this.declare(e);let n=Memory.alloc(blockDescriptorAllocSize+blockSize),r=n.add(blockDescriptorAllocSize),o=Memory.allocUtf8String(this.types);n.add(blockDescriptorOffsets.reserved).writeULong(0),n.add(blockDescriptorOffsets.size).writeULong(blockDescriptorDeclaredSize),n.add(blockDescriptorOffsets.rest).writePointer(o),r.add(blockOffsets.isa).writePointer(classRegistry.__NSGlobalBlock__),r.add(blockOffsets.flags).writeU32(BLOCK_HAS_SIGNATURE|BLOCK_IS_GLOBAL),r.add(blockOffsets.reserved).writeU32(0),r.add(blockOffsets.descriptor).writePointer(n),this.handle=r,this._storage=[n,o],this.implementation=e.implementation}}Object.defineProperties(Block.prototype,{implementation:{enumerable:!0,get(){let e=this.handle.add(blockOffsets.invoke).readPointer().strip(),t=this._getSignature();return makeBlockInvocationWrapper(this,t,new NativeFunction(e.sign(),t.retType.type,t.argTypes.map(function(n){return n.type}),this._options))},set(e){let t=this._getSignature(),n=new NativeCallback(makeBlockImplementationWrapper(this,t,e),t.retType.type,t.argTypes.map(function(l){return l.type}));this._callback=n;let r=this.handle.add(blockOffsets.invoke),o=Memory.queryProtection(r),i=o.includes("w");i||Memory.protect(r,Process.pointerSize,"rw-"),r.writePointer(n.strip().sign("ia",r)),i||Memory.protect(r,Process.pointerSize,o)}},declare:{value(e){let t=e.types;t===void 0&&(t=unparseSignature(e.retType,["block"].concat(e.argTypes))),this.types=t,this._signature=parseSignature(t)}},_getSignature:{value(){let e=this._signature;if(e===null)throw new Error("block is missing signature; call declare()");return e}}});function collectProtocols(e,t){t=t||{},t[e.name]=e;let n=e.protocols;return Object.keys(n).forEach(function(r){collectProtocols(n[r],t)}),t}function registerProxy(e){let t=e.protocols||[],n=e.methods||{},r=e.events||{},o=new Set(Object.keys(n).filter(a=>/([+\-])\s(\S+)/.exec(a)!==null).map(a=>a.split(" ")[1])),i={"- dealloc":function(){let a=this.data.target;"- release"in a&&a.release(),unbind(this.self),this.super.dealloc();let s=this.data.events.dealloc;s!==void 0&&s.call(this)},"- respondsToSelector:":function(a){let s=selectorAsString(a);return o.has(s)?!0:this.data.target.respondsToSelector_(a)},"- forwardingTargetForSelector:":function(a){let s=this.data.events.forward;return s!==void 0&&s.call(this,selectorAsString(a)),this.data.target},"- methodSignatureForSelector:":function(a){return this.data.target.methodSignatureForSelector_(a)},"- forwardInvocation:":function(a){a.invokeWithTarget_(this.data.target)}};for(var l in n)if(n.hasOwnProperty(l)){if(i.hasOwnProperty(l))throw new Error("The '"+l+"' method is reserved");i[l]=n[l]}let u=registerClass({name:e.name,super:classRegistry.NSProxy,protocols:t,methods:i});return function(a,s){a=a instanceof NativePointer?new ObjCObject(a):a,s=s||{};let c=u.alloc().autorelease(),p=getBoundData(c);p.target="- retain"in a?a.retain():a,p.events=r;for(var h in s)if(s.hasOwnProperty(h)){if(p.hasOwnProperty(h))throw new Error("The '"+h+"' property is reserved");p[h]=s[h]}this.handle=c.handle}}function registerClass(e){let t=e.name;t===void 0&&(t=makeClassName());let n=e.super!==void 0?e.super:classRegistry.NSObject,r=e.protocols||[],o=e.methods||{},i=[],l=api.objc_allocateClassPair(n!==null?n.handle:NULL,Memory.allocUtf8String(t),ptr("0"));if(l.isNull())throw new Error("Unable to register already registered class '"+t+"'");let u=api.object_getClass(l);try{r.forEach(function(a){api.class_addProtocol(l,a.handle)}),Object.keys(o).forEach(function(a){let s=/([+\-])\s(\S+)/.exec(a);if(s===null)throw new Error("Invalid method name");let c=s[1],p=s[2],h,g=o[a];if(typeof g=="function"){let P=null;if(a in n)P=n[a].types;else for(let z of r){let x=z.methods[a];if(x!==void 0){P=x.types;break}}if(P===null)throw new Error("Unable to find '"+a+"' in super-class or any of its protocols");h={types:P,implementation:g}}else h=g;let _=c==="+"?u:l,S=h.types;S===void 0&&(S=unparseSignature(h.retType,[c==="+"?"class":"object","selector"].concat(h.argTypes)));let w=parseSignature(S),k=new NativeCallback(makeMethodImplementationWrapper(w,h.implementation),w.retType.type,w.argTypes.map(function(P){return P.type}));i.push(k),api.class_addMethod(_,selector(p),k,Memory.allocUtf8String(S))})}catch(a){throw api.objc_disposeClassPair(l),a}return api.objc_registerClassPair(l),l._methodCallbacks=i,Script.bindWeak(l,makeClassDestructor(ptr(l))),new ObjCObject(l)}function makeClassDestructor(e){return function(){api.objc_disposeClassPair(e)}}function registerProtocol(e){let t=e.name;t===void 0&&(t=makeProtocolName());let n=e.protocols||[],r=e.methods||{};n.forEach(function(l){if(!(l instanceof ObjCProtocol))throw new Error("Expected protocol")});let o=Object.keys(r).map(function(l){let u=r[l],a=/([+\-])\s(\S+)/.exec(l);if(a===null)throw new Error("Invalid method name");let s=a[1],c=a[2],p=u.types;return p===void 0&&(p=unparseSignature(u.retType,[s==="+"?"class":"object","selector"].concat(u.argTypes))),{kind:s,name:c,types:p,optional:u.optional}}),i=api.objc_allocateProtocol(Memory.allocUtf8String(t));if(i.isNull())throw new Error("Unable to register already registered protocol '"+t+"'");return n.forEach(function(l){api.protocol_addProtocol(i,l.handle)}),o.forEach(function(l){let u=l.optional?0:1,a=l.kind==="-"?1:0;api.protocol_addMethodDescription(i,selector(l.name),Memory.allocUtf8String(l.types),u,a)}),api.objc_registerProtocol(i),new ObjCProtocol(i)}function getHandle(e){if(e instanceof NativePointer)return e;if(typeof e=="object"&&e.hasOwnProperty("handle"))return e.handle;throw new Error("Expected NativePointer or ObjC.Object instance")}function bind(e,t){let n=getHandle(e),r=e instanceof ObjCObject?e:new ObjCObject(n);bindings.set(n.toString(),{self:r,super:r.$super,data:t})}function unbind(e){let t=getHandle(e);bindings.delete(t.toString())}function getBoundData(e){return getBinding(e).data}function getBinding(e){let t=getHandle(e),n=t.toString(),r=bindings.get(n);if(r===void 0){let o=e instanceof ObjCObject?e:new ObjCObject(t);r={self:o,super:o.$super,data:{}},bindings.set(n,r)}return r}function enumerateLoadedClasses(...e){let t=new ModuleMap,n=!1,r,o;e.length===1?r=e[0]:(r=e[1],o=e[0].ownedBy),o===void 0&&(o=t,n=!0);let i=api.class_getName,l=r.onMatch.bind(r),u=(pointerSize===8?8:11)*pointerSize,a=api.objc_getClassList(NULL,0),s=Memory.alloc(a*pointerSize);api.objc_getClassList(s,a);for(let c=0;c!==a;c++){let p=s.add(c*pointerSize).readPointer(),h=i(p),g=null,_=o.findPath(h);if(_===null&&(n||t.findPath(h)===null)&&(g=h.readCString(),g.indexOf(".")!==-1)){let k=p.add(u).readPointer();_=o.findPath(k)}_!==null&&(g===null&&(g=h.readUtf8String()),l(g,_))}r.onComplete()}function enumerateLoadedClassesSync(e={}){let t={};return enumerateLoadedClasses(e,{onMatch(n,r){let o=t[r];o===void 0&&(o=[],t[r]=o),o.push(n)},onComplete(){}}),t}function choose(e,t){let n=e,r=!0;if(!(e instanceof ObjCObject)&&typeof e=="object"&&(n=e.class,e.hasOwnProperty("subclasses")&&(r=e.subclasses)),!(n instanceof ObjCObject&&(n.$kind==="class"||n.$kind==="meta-class")))throw new Error("Expected an ObjC.Object for a class or meta-class");let o=re().choose(n,r).map(i=>new ObjCObject(i));for(let i of o)if(t.onMatch(i)==="stop")break;t.onComplete()}function makeMethodInvocationWrapper(method,owner,superSpecifier,invocationOptions){let sel=method.sel,handle=method.handle,types;handle===void 0?(handle=null,types=method.types):types=api.method_getTypeEncoding(handle).readUtf8String();let signature=parseSignature(types),retType=signature.retType,argTypes=signature.argTypes.slice(2),objc_msgSend=superSpecifier?getMsgSendSuperImpl(signature,invocationOptions):getMsgSendImpl(signature,invocationOptions),argVariableNames=argTypes.map(function(e,t){return"a"+(t+1)}),callArgs=[superSpecifier?"superSpecifier":"this","sel"].concat(argTypes.map(function(e,t){return e.toNative?"argTypes["+t+"].toNative.call(this, "+argVariableNames[t]+")":argVariableNames[t]})),returnCaptureLeft,returnCaptureRight;retType.type==="void"?(returnCaptureLeft="",returnCaptureRight=""):retType.fromNative?(returnCaptureLeft="return retType.fromNative.call(this, ",returnCaptureRight=")"):(returnCaptureLeft="return ",returnCaptureRight="");let m=eval("var m = function ("+argVariableNames.join(", ")+") { "+returnCaptureLeft+"objc_msgSend("+callArgs.join(", ")+")"+returnCaptureRight+"; }; m;");Object.defineProperty(m,"handle",{enumerable:!0,get:getMethodHandle}),m.selector=sel,Object.defineProperty(m,"implementation",{enumerable:!0,get(){let e=getMethodHandle(),t=new NativeFunction(api.method_getImplementation(e),m.returnType,m.argumentTypes,invocationOptions),n=getReplacementMethodImplementation(e);return n!==null&&(t._callback=n),t},set(e){replaceMethodImplementation(getMethodHandle(),e)}}),m.returnType=retType.type,m.argumentTypes=signature.argTypes.map(e=>e.type),m.types=types,Object.defineProperty(m,"symbol",{enumerable:!0,get(){return`${method.kind}[${owner.$className} ${selectorAsString(sel)}]`}}),m.clone=function(e){return makeMethodInvocationWrapper(method,owner,superSpecifier,e)};function getMethodHandle(){if(handle===null){if(owner.$kind==="instance"){let e=owner;do if("- forwardingTargetForSelector:"in e){let t=e.forwardingTargetForSelector_(sel);if(t===null||t.$kind!=="instance")break;let n=api.class_getInstanceMethod(t.$class.handle,sel);n.isNull()?e=t:handle=n}else break;while(handle===null)}if(handle===null)throw new Error("Unable to find method handle of proxied function")}return handle}return m}function makeMethodImplementationWrapper(signature,implementation){let retType=signature.retType,argTypes=signature.argTypes,argVariableNames=argTypes.map(function(e,t){return t===0?"handle":t===1?"sel":"a"+(t-1)}),callArgs=argTypes.slice(2).map(function(e,t){let n=argVariableNames[2+t];return e.fromNative?"argTypes["+(2+t)+"].fromNative.call(self, "+n+")":n}),returnCaptureLeft,returnCaptureRight;retType.type==="void"?(returnCaptureLeft="",returnCaptureRight=""):retType.toNative?(returnCaptureLeft="return retType.toNative.call(self, ",returnCaptureRight=")"):(returnCaptureLeft="return ",returnCaptureRight="");let m=eval("var m = function ("+argVariableNames.join(", ")+") { var binding = getBinding(handle);var self = binding.self;"+returnCaptureLeft+"implementation.call(binding"+(callArgs.length>0?", ":"")+callArgs.join(", ")+")"+returnCaptureRight+"; }; m;");return m}function makeBlockInvocationWrapper(block,signature,implementation){let retType=signature.retType,argTypes=signature.argTypes.slice(1),argVariableNames=argTypes.map(function(e,t){return"a"+(t+1)}),callArgs=argTypes.map(function(e,t){return e.toNative?"argTypes["+t+"].toNative.call(this, "+argVariableNames[t]+")":argVariableNames[t]}),returnCaptureLeft,returnCaptureRight;retType.type==="void"?(returnCaptureLeft="",returnCaptureRight=""):retType.fromNative?(returnCaptureLeft="return retType.fromNative.call(this, ",returnCaptureRight=")"):(returnCaptureLeft="return ",returnCaptureRight="");let f=eval("var f = function ("+argVariableNames.join(", ")+") { "+returnCaptureLeft+"implementation(this"+(callArgs.length>0?", ":"")+callArgs.join(", ")+")"+returnCaptureRight+"; }; f;");return f.bind(block)}function makeBlockImplementationWrapper(block,signature,implementation){let retType=signature.retType,argTypes=signature.argTypes,argVariableNames=argTypes.map(function(e,t){return t===0?"handle":"a"+t}),callArgs=argTypes.slice(1).map(function(e,t){let n=argVariableNames[1+t];return e.fromNative?"argTypes["+(1+t)+"].fromNative.call(this, "+n+")":n}),returnCaptureLeft,returnCaptureRight;retType.type==="void"?(returnCaptureLeft="",returnCaptureRight=""):retType.toNative?(returnCaptureLeft="return retType.toNative.call(this, ",returnCaptureRight=")"):(returnCaptureLeft="return ",returnCaptureRight="");let f=eval("var f = function ("+argVariableNames.join(", ")+") { if (!this.handle.equals(handle))this.handle = handle;"+returnCaptureLeft+"implementation.call(block"+(callArgs.length>0?", ":"")+callArgs.join(", ")+")"+returnCaptureRight+"; }; f;");return f.bind(block)}function rawFridaType(e){return e==="object"?"pointer":e}function makeClassName(){for(let e=1;;e++){let t="FridaAnonymousClass"+e;if(!(t in classRegistry))return t}}function makeProtocolName(){for(let e=1;;e++){let t="FridaAnonymousProtocol"+e;if(!(t in protocolRegistry))return t}}function objcMethodName(e){return e.replace(/_/g,":")}function jsMethodName(e){let t=e.replace(/:/g,"_");return objCObjectBuiltins.has(t)&&(t+="2"),t}let isaMasks={x64:"0x7ffffffffff8",arm64:"0xffffffff8"},rawMask=isaMasks[Process.arch];if(rawMask!==void 0){let e=ptr(rawMask);readObjectIsa=function(t){return t.readPointer().and(e)}}else readObjectIsa=function(e){return e.readPointer()};function getMsgSendImpl(e,t){return resolveMsgSendImpl(msgSendBySignatureId,e,t,!1)}function getMsgSendSuperImpl(e,t){return resolveMsgSendImpl(msgSendSuperBySignatureId,e,t,!0)}function resolveMsgSendImpl(e,t,n,r){if(n!==H)return makeMsgSendImpl(t,n,r);let{id:o}=t,i=e.get(o);return i===void 0&&(i=makeMsgSendImpl(t,n,r),e.set(o,i)),i}function makeMsgSendImpl(e,t,n){let r=e.retType.type,o=e.argTypes.map(function(a){return a.type}),i=["objc_msgSend"];n&&i.push("Super"),r instanceof Array&&!typeFitsInRegisters(r)?i.push("_stret"):(r==="float"||r==="double")&&i.push("_fpret");let u=i.join("");return new NativeFunction(api[u],r,o,t)}function typeFitsInRegisters(e){return Process.arch!=="x64"?!1:sizeOfTypeOnX64(e)<=16}function sizeOfTypeOnX64(e){if(e instanceof Array)return e.reduce((t,n)=>t+sizeOfTypeOnX64(n),0);switch(e){case"bool":case"char":case"uchar":return 1;case"int16":case"uint16":return 2;case"int":case"int32":case"uint":case"uint32":case"float":return 4;default:return 8}}function unparseSignature(e,t){let n=typeIdFromAlias(e),r=t.map(typeIdFromAlias),o=r.map(u=>singularTypeById[u].size),i=o.reduce((u,a)=>u+a,0),l=0;return n+i+r.map((u,a)=>{let s=u+l;return l+=o[a],s}).join("")}function parseSignature(e){let t=[e,0];parseQualifiers(t);let n=readType(t);readNumber(t);let r=[],o=JSON.stringify(n.type);for(;dataAvailable(t);){parseQualifiers(t);let i=readType(t);readNumber(t),r.push(i),o+=JSON.stringify(i.type)}return{id:o,retType:n,argTypes:r}}function parseType(e){return readType([e,0])}function readType(e){let t=readChar(e);if(t==="@"){let r=peekChar(e);r==="?"?(t+=r,skipChar(e),peekChar(e)==="<"&&skipExtendedBlock(e)):r==='"'&&(skipChar(e),readUntil('"',e))}else if(t==="^"){let r=peekChar(e);r==="@"&&(t+=r,skipChar(e))}let n=singularTypeById[t];if(n!==void 0)return n;if(t==="["){let r=readNumber(e),o=readType(e);return skipChar(e),arrayType(r,o)}else if(t==="{"){if(!tokenExistsAhead("=","}",e))return readUntil("}",e),structType([]);readUntil("=",e);let r=[],o;for(;(o=peekChar(e))!=="}";)o==='"'&&(skipChar(e),readUntil('"',e)),r.push(readType(e));return skipChar(e),structType(r)}else if(t==="("){readUntil("=",e);let r=[];for(;peekChar(e)!==")";)r.push(readType(e));return skipChar(e),unionType(r)}else{if(t==="b")return readNumber(e),singularTypeById.i;if(t==="^")return readType(e),singularTypeById["?"];if(modifiers.has(t))return readType(e);throw new Error("Unable to handle type "+t)}}function skipExtendedBlock(e){let t;for(skipChar(e);(t=peekChar(e))!==">";)peekChar(e)==="<"?skipExtendedBlock(e):(skipChar(e),t==='"'&&readUntil('"',e));skipChar(e)}function readNumber(e){let t="";for(;dataAvailable(e);){let n=peekChar(e),r=n.charCodeAt(0);if(r>=48&&r<=57)t+=n,skipChar(e);else break}return parseInt(t)}function readUntil(e,t){let n=t[0],r=t[1],o=n.indexOf(e,r);if(o===-1)throw new Error("Expected token '"+e+"' not found");let i=n.substring(r,o);return t[1]=o+1,i}function readChar(e){return e[0][e[1]++]}function peekChar(e){return e[0][e[1]]}function tokenExistsAhead(e,t,n){let[r,o]=n,i=r.indexOf(e,o);if(i===-1)return!1;let l=r.indexOf(t,o);if(l===-1)throw new Error("Expected to find terminator: "+t);return i<l}function skipChar(e){e[1]++}function dataAvailable(e){return e[1]!==e[0].length}let qualifierById={r:"const",n:"in",N:"inout",o:"out",O:"bycopy",R:"byref",V:"oneway"};function parseQualifiers(e){let t=[];for(;;){let n=qualifierById[peekChar(e)];if(n===void 0)break;t.push(n),skipChar(e)}return t}let idByAlias={char:"c",int:"i",int16:"s",int32:"i",int64:"q",uchar:"C",uint:"I",uint16:"S",uint32:"I",uint64:"Q",float:"f",double:"d",bool:"B",void:"v",string:"*",object:"@",block:"@?",class:"#",selector:":",pointer:"^v"};function typeIdFromAlias(e){if(typeof e=="object"&&e!==null)return`@"${e.type}"`;let t=idByAlias[e];if(t===void 0)throw new Error("No known encoding for type "+e);return t}let fromNativeId=function(e){return e.isNull()?null:e.toString(16)===this.handle.toString(16)?this:new ObjCObject(e)},toNativeId=function(e){if(e===null)return NULL;let t=typeof e;return t==="string"?(cachedNSStringCtor===null&&(cachedNSString=classRegistry.NSString,cachedNSStringCtor=cachedNSString.stringWithUTF8String_),cachedNSStringCtor.call(cachedNSString,Memory.allocUtf8String(e))):t==="number"?(cachedNSNumberCtor===null&&(cachedNSNumber=classRegistry.NSNumber,cachedNSNumberCtor=cachedNSNumber.numberWithDouble_),cachedNSNumberCtor.call(cachedNSNumber,e)):e},fromNativeBlock=function(e){return e.isNull()?null:e.toString(16)===this.handle.toString(16)?this:new Block(e)},toNativeBlock=function(e){return e!==null?e:NULL},toNativeObjectArray=function(e){if(e instanceof Array){let t=e.length,n=Memory.alloc(t*pointerSize);for(let r=0;r!==t;r++)n.add(r*pointerSize).writePointer(toNativeId(e[r]));return n}return e};function arrayType(e,t){return{type:"pointer",read(n){let r=[],o=t.size;for(let i=0;i!==e;i++)r.push(t.read(n.add(i*o)));return r},write(n,r){let o=t.size;r.forEach((i,l)=>{t.write(n.add(l*o),i)})}}}function structType(e){let t,n;if(e.some(function(i){return!!i.fromNative})){let i=e.map(function(l){return l.fromNative?l.fromNative:identityTransform});t=function(l){return l.map(function(u,a){return i[a].call(this,u)})}}else t=identityTransform;if(e.some(function(i){return!!i.toNative})){let i=e.map(function(l){return l.toNative?l.toNative:identityTransform});n=function(l){return l.map(function(u,a){return i[a].call(this,u)})}}else n=identityTransform;let[r,o]=e.reduce(function(i,l){let[u,a]=i,{size:s}=l,c=align(u,s);return a.push(c),[c+s,a]},[0,[]]);return{type:e.map(i=>i.type),size:r,read(i){return e.map((l,u)=>l.read(i.add(o[u])))},write(i,l){l.forEach((u,a)=>{e[a].write(i.add(o[a]),u)})},fromNative:t,toNative:n}}function unionType(e){let t=e.reduce(function(o,i){return i.size>o.size?i:o},e[0]),n,r;if(t.fromNative){let o=t.fromNative;n=function(i){return o.call(this,i[0])}}else n=function(o){return o[0]};if(t.toNative){let o=t.toNative;r=function(i){return[o.call(this,i)]}}else r=function(o){return[o]};return{type:[t.type],size:t.size,read:t.read,write:t.write,fromNative:n,toNative:r}}let longBits=pointerSize==8&&Process.platform!=="windows"?64:32;modifiers=new Set(["j","A","r","n","N","o","O","R","V","+"]),singularTypeById={c:{type:"char",size:1,read:e=>e.readS8(),write:(e,t)=>{e.writeS8(t)},toNative(e){return typeof e=="boolean"?e?1:0:e}},i:{type:"int",size:4,read:e=>e.readInt(),write:(e,t)=>{e.writeInt(t)}},s:{type:"int16",size:2,read:e=>e.readS16(),write:(e,t)=>{e.writeS16(t)}},l:{type:"int32",size:4,read:e=>e.readS32(),write:(e,t)=>{e.writeS32(t)}},q:{type:"int64",size:8,read:e=>e.readS64(),write:(e,t)=>{e.writeS64(t)}},C:{type:"uchar",size:1,read:e=>e.readU8(),write:(e,t)=>{e.writeU8(t)}},I:{type:"uint",size:4,read:e=>e.readUInt(),write:(e,t)=>{e.writeUInt(t)}},S:{type:"uint16",size:2,read:e=>e.readU16(),write:(e,t)=>{e.writeU16(t)}},L:{type:"uint"+longBits,size:longBits/8,read:e=>e.readULong(),write:(e,t)=>{e.writeULong(t)}},Q:{type:"uint64",size:8,read:e=>e.readU64(),write:(e,t)=>{e.writeU64(t)}},f:{type:"float",size:4,read:e=>e.readFloat(),write:(e,t)=>{e.writeFloat(t)}},d:{type:"double",size:8,read:e=>e.readDouble(),write:(e,t)=>{e.writeDouble(t)}},B:{type:"bool",size:1,read:e=>e.readU8(),write:(e,t)=>{e.writeU8(t)},fromNative(e){return!!e},toNative(e){return e?1:0}},v:{type:"void",size:0},"*":{type:"pointer",size:pointerSize,read:e=>e.readPointer(),write:(e,t)=>{e.writePointer(t)},fromNative(e){return e.readUtf8String()}},"@":{type:"pointer",size:pointerSize,read:e=>e.readPointer(),write:(e,t)=>{e.writePointer(t)},fromNative:fromNativeId,toNative:toNativeId},"@?":{type:"pointer",size:pointerSize,read:e=>e.readPointer(),write:(e,t)=>{e.writePointer(t)},fromNative:fromNativeBlock,toNative:toNativeBlock},"^@":{type:"pointer",size:pointerSize,read:e=>e.readPointer(),write:(e,t)=>{e.writePointer(t)},toNative:toNativeObjectArray},"^v":{type:"pointer",size:pointerSize,read:e=>e.readPointer(),write:(e,t)=>{e.writePointer(t)}},"#":{type:"pointer",size:pointerSize,read:e=>e.readPointer(),write:(e,t)=>{e.writePointer(t)},fromNative:fromNativeId,toNative:toNativeId},":":{type:"pointer",size:pointerSize,read:e=>e.readPointer(),write:(e,t)=>{e.writePointer(t)}},"?":{type:"pointer",size:pointerSize,read:e=>e.readPointer(),write:(e,t)=>{e.writePointer(t)}}};function identityTransform(e){return e}function align(e,t){let n=e%t;return n===0?e:e+(t-n)}}var fe=new pe,R=fe;var K=null;function ne(){return K||(K={open:new NativeFunction(Module.getGlobalExportByName("open"),"int",["pointer","int"]),close:new NativeFunction(Module.getGlobalExportByName("close"),"int",["int"]),read:new NativeFunction(Module.getGlobalExportByName("read"),"long",["int","pointer","long"]),pwrite:new NativeFunction(Module.getGlobalExportByName("pwrite"),"long",["int","pointer","long","long"]),exit:new NativeFunction(Module.getGlobalExportByName("exit"),"void",["int"])},K)}var me=1024*1024,ge=2,he=["libxpc.dylib`xpc_main","Foundation`NSExtensionMain","ExtensionFoundation`EXExtensionMain"],_e=["UIKitCore`UIApplicationMain","AppKit`NSApplicationMain"];function oe(e){let t=Process.getModuleByName("CoreFoundation").getExportByName("CFRunLoopRun");for(let n of e){let[r,o]=n.split("`");try{let i=Process.getModuleByName(r).getExportByName(o);console.log("replace function",n,i),Interceptor.replace(i,t)}catch(i){console.log("skip",n,i.message)}}R.schedule(R.mainQueue,()=>{console.log("mainQueue scheduled")})}rpc.exports={hookAppMain(){oe(_e)},hookExtensionMain(){oe(he)},dump(e,t,n,r=!1){let{open:o,close:i,pwrite:l,exit:u}=ne();for(let[a,s]of Object.entries(n)){console.log("decrypt",a);let{offset:c,size:p}=s.encrypt,h=e+"/"+a,g=t+"/"+a,_=Module.load(h),S=Process.findRangeByAddress(_.base).file.offset;console.log("module =>",_.name,_.base,_.size),console.log("encrypted =>",c,p,"fatOffset =>",S);let w=o(Memory.allocUtf8String(g),ge);if(w<0){console.error("Failed to open",g);continue}let k=_.base.add(c),P=c+S,z=p;for(;z>0;){let I=Math.min(me,z);l(w,k,I,P),k=k.add(I),P+=I,z-=I}let x=Memory.alloc(12);l(w,x,12,s.offset+8+S),i(w),send({event:"patch",name:a}),recv("ack",()=>{}).wait()}return r&&R.schedule(R.mainQueue,()=>{u(0)}),!0}};
