diff --git a/Il2cppHook/agent/base/base.ts b/Il2cppHook/agent/base/base.ts index 148a75f9..d660b2b7 100644 --- a/Il2cppHook/agent/base/base.ts +++ b/Il2cppHook/agent/base/base.ts @@ -10,7 +10,7 @@ export class HookerBase { @cache static get _list_assemblies(): Il2Cpp.Assembly[] { - return Il2Cpp.domain.assemblies + return Il2Cpp.Domain.assemblies } @cache @@ -42,7 +42,7 @@ export class HookerBase { @cache static get _list_classes(): Il2Cpp.Class[] { - return Il2Cpp.domain.assemblies.map((assembly: Il2Cpp.Assembly) => assembly.image).flatMap((image: Il2Cpp.Image) => image.classes) + return Il2Cpp.Domain.assemblies.map((assembly: Il2Cpp.Assembly) => assembly.image).flatMap((image: Il2Cpp.Image) => image.classes) } static showImages(filter: string = "", sort: boolean = true): void { @@ -72,7 +72,7 @@ export class HookerBase { image = new Il2Cpp.Image(ptr(imageOrName.trim())) } else { //传递ImageName的情况 - image = Il2Cpp.domain.assembly(imageOrName).image + image = Il2Cpp.Domain.assembly(imageOrName).image } } else if (typeof imageOrName == "number") { if (Process.arch == "arm64" && (imageOrName.toString().length > 15)) @@ -232,7 +232,7 @@ export class HookerBase { localMethods = localMethods.sort((first, secend) => first.relativeVirtualAddress.compare(secend.relativeVirtualAddress)) break case MethodSortType.ACCESS: - localMethods = localMethods.sort((first, second) => (second.modifier ?? '').localeCompare(first.modifier ?? '')) + localMethods = localMethods.sort((first, second) => second.modifier.localeCompare(first.modifier)) break case MethodSortType.MethodName: localMethods = localMethods.sort((first, second) => second.name.localeCompare(first.name)) @@ -303,7 +303,7 @@ export class HookerBase { let cache: Il2Cpp.Class | undefined = HookerBase.map_cache_class.get(searchClassName) if (cache != undefined) return cache.handle } - let assemblies = Il2Cpp.domain.assemblies + let assemblies = Il2Cpp.Domain.assemblies for (let index = 0; index < assemblies.length; index++) { if (fromAssebly.includes(assemblies[index].name)) { let ret = innerCall(assemblies[index].image.classes) @@ -335,7 +335,7 @@ export class HookerBase { * findMethod("LerpUnclamped") // 最慢 * * 以下三种写法等价: - * Il2Cpp.domain.assembly("UnityEngine.CoreModule").image.class("UnityEngine.Texture").method("get_width",1).virtualAddress + * Il2Cpp.Domain.assembly("UnityEngine.CoreModule").image.class("UnityEngine.Texture").method("get_width",1).virtualAddress * === * find_method("UnityEngine.CoreModule","Texture","get_width",0) * === @@ -352,7 +352,7 @@ export class HookerBase { let methodInfo: Il2Cpp.Method | undefined if (arguments[3] != undefined && typeof arguments[3] == "number") { try { - methodInfo = Il2Cpp.domain.assembly(assemblyName).image.class(className).method(methodName, argsCount) + methodInfo = Il2Cpp.Domain.assembly(assemblyName).image.class(className).method(methodName, argsCount) if (overload.length != 0) methodInfo = methodInfo?.overload(...overload) } catch { throw new Error(`findMethod failed: Not Found ${methodName}(argCount:${argsCount}) in ${className}`) @@ -398,12 +398,12 @@ export class HookerBase { let cachedPointer = HookerBase.findMethodsyncCacheMap.get(cacheKey) if (cachedPointer != undefined) return cachedPointer as NativePointer } - let currentlibPack = Il2Cpp.domain.assembly(imageName).image + let currentlibPack = Il2Cpp.Domain.assembly(imageName).image let currentlib: NativePointer = currentlibPack.handle - let klass = Il2Cpp.api.classFromName(currentlib, allocCStr(imageName), allocCStr(className)) + let klass = Il2Cpp.Api._classFromName(currentlib, allocCStr(imageName), allocCStr(className)) if (klass.isNull()) { - for (let j = 0; j < Il2Cpp.api.imageGetClassCount(currentlib); j++) { - let il2CppClass = new Il2Cpp.Class(Il2Cpp.api.imageGetClass(currentlib, j)) + for (let j = 0; j < Il2Cpp.Api._imageGetClassCount(currentlib); j++) { + let il2CppClass = new Il2Cpp.Class(Il2Cpp.Api._imageGetClass(currentlib, j)) if (il2CppClass.name == className) { klass = il2CppClass.handle break @@ -412,7 +412,7 @@ export class HookerBase { } if (klass.isNull()) return ptr(0) - let method = Il2Cpp.api.classGetMethodFromName(klass, allocCStr(functionName), argsCount) + let method = Il2Cpp.Api._classGetMethodFromName(klass, allocCStr(functionName), argsCount) if (method.isNull()) return ptr(0) if (arguments[5] != undefined && arguments[5] != 2) { return method @@ -443,8 +443,8 @@ export class HookerBase { LOGO(getLine(30)) let ShowMore = false LOG("Il2CppImage\t---->\t" + currentlib + (ShowMore ? " (" + currentlib.add(p_size).readPointer().readCString() + ")" : "")) - LOG("Il2CppClass\t---->\t" + klass + (ShowMore ? " (" + Il2Cpp.api.classGetName(klass) + ")" : "")) - LOG("MethodInfo\t---->\t" + method + (ShowMore ? " (" + Il2Cpp.api.classGetName(method) + ")" : "")) + LOG("Il2CppClass\t---->\t" + klass + (ShowMore ? " (" + Il2Cpp.Api._classGetName(klass) + ")" : "")) + LOG("MethodInfo\t---->\t" + method + (ShowMore ? " (" + Il2Cpp.Api._classGetName(method) + ")" : "")) LOGD("MethodPointer\t---->\t" + method.readPointer() + "\t===>\t" + method.readPointer().sub(soAddr)) LOGO(getLine(85)) } @@ -496,12 +496,12 @@ export class HookerBase { let maxlength = 0 let arrStr = new Array() let enumIndex = 0 - while (field = Il2Cpp.api.classGetFields(klass, iter)) { + while (field = Il2Cpp.Api._classGetFields(klass, iter)) { if (field.isNull()) break let fieldName = field.readPointer().readCString() let filedType = field.add(p_size).readPointer() let filedOffset = "0x" + field.add(3 * p_size).readInt().toString(16) - let field_class = Il2Cpp.api.typeGetClass(filedType) + let field_class = Il2Cpp.Api._classFromType(filedType) let fieldClassName = new Il2Cpp.Class(field_class).name let accessStr = fackAccess(filedType) accessStr = accessStr.substring(0, accessStr.length - 1) @@ -555,10 +555,10 @@ export class HookerBase { LOG("\t" + fRet + "\n", LogColor.C90) } else if (str.indexOf("static") != -1) { // console.warn(+ptr(mStr[3])+allocStr(mStr[4])+"\t"+mStr[4]) - let field = Il2Cpp.api.classGetFieldFromName(ptr(mStr[3]), allocCStr(mStr[4])) + let field = Il2Cpp.Api._classGetFieldFromName(ptr(mStr[3]), allocCStr(mStr[4])) if (!field.isNull()) { let addrOut = alloc() - Il2Cpp.api.fieldGetStaticValue(field, addrOut) + Il2Cpp.Api._fieldGetStaticValue(field, addrOut) let realP = addrOut.readPointer() LOG("\t" + addrOut + " ---> " + realP + " ---> " + FackKnownType(mName, realP, mStr[3]), LogColor.C90) } @@ -630,7 +630,7 @@ export const get_gc_instance = (inputClass: string | NativePointer | Il2Cpp.Clas } else { throw new Error(`inputClass type error`) } - return Il2Cpp.gc.choose(localClass) + return Il2Cpp.GC.choose(localClass) } export const show_gc_instance = (inputClass: string | NativePointer | Il2Cpp.Class): void => get_gc_instance(inputClass).forEach((item: Il2Cpp.Object) => { @@ -710,4 +710,4 @@ declare global { var fakeGCInstance: (inputClass: string | NativePointer | Il2Cpp.Class, mapFunction?: (item: Il2Cpp.Object) => string) => void var soAddr: NativePointerValue -} +} \ No newline at end of file diff --git a/Il2cppHook/agent/base/breaker.ts b/Il2cppHook/agent/base/breaker.ts index c855295a..8eeaec48 100644 --- a/Il2cppHook/agent/base/breaker.ts +++ b/Il2cppHook/agent/base/breaker.ts @@ -8,7 +8,7 @@ import { formartClass as FC } from "../utils/formart" import { closest } from "fastest-levenshtein" import { ValueResolve } from "./valueResolve" import { HookerBase } from "./base" -import { JSHOOKTYPE, LogColor } from "./enum" +import { JSHOOKTYPE } from "./enum" type SpecialClass = "CommonClass" | "JNI" | "AUI" | "Soon" const CommonClass = ["Assembly-CSharp", "MaxSdk.Scripts", "Game", "Zenject", "UniRx", "Purchasing.Common", "UnityEngine.Purchasing"] @@ -48,11 +48,11 @@ export class Breaker { } else { // ---> className case to Pointer let classNameStr: string = imgOrClsPtr - let classArray: Il2Cpp.Class[] = (findClasses(classNameStr, true, true) as Il2Cpp.Class[])! + let classArray: Il2Cpp.Class[] = findClasses(classNameStr, true, true)! let clsPtr: NativePointer = findClass(imgOrClsPtr) if (clsPtr.isNull()) { let imageName = closest(imgOrClsPtr, HookerBase._list_images_names) - LOGE(`You mean this ? ${imageName} @ ${Il2Cpp.domain.assemblies.filter(item => item.name.includes)[0].handle}`) + LOGE(`You mean this ? ${imageName} @ ${Il2Cpp.Domain.assemblies.filter(item => item.name.includes)[0].handle}`) throw new Error(`\n\tCan't find class ${classNameStr}\n`) } if (classArray.length == 1 && clsPtr.equals(classArray[0].handle)) innerImage(clsPtr) @@ -94,13 +94,13 @@ export class Breaker { } }) } else if (type == "JNI") { - let clsTmp = Il2Cpp.domain.assembly("UnityEngine.AndroidJNIModule").image.class("UnityEngine.AndroidJNI") + let clsTmp = Il2Cpp.Domain.assembly("UnityEngine.AndroidJNIModule").image.class("UnityEngine.AndroidJNI") if (clsTmp.isNull()) throw new Error("can't find class UnityEngine.AndroidJNI") FC.printTitile(`Found : ClassName: ${clsTmp.name} @ ${clsTmp.handle}`) innerImage(clsTmp.handle) - // innerImage(Il2Cpp.domain.assembly("UnityEngine.AndroidJNIModule").image.class("UnityEngine.AndroidJNIHelper").handle) + // innerImage(Il2Cpp.Domain.assembly("UnityEngine.AndroidJNIModule").image.class("UnityEngine.AndroidJNIHelper").handle) } else if ("AUI") { - innerImage(Il2Cpp.domain.assembly("Assembly-CSharp").image.handle) + innerImage(Il2Cpp.Domain.assembly("Assembly-CSharp").image.handle) setTimeout(() => h("Update"), 3000) } else if (type == "Soon") { //TODO others @@ -447,7 +447,7 @@ globalThis.breakMemRW = Breaker.breakMemRW globalThis.printDesertedMethods = Breaker.printDesertedMethods // 展示 已经被取消hook 或者 不显示的部分函数 globalThis.bt = (mPtr: NativePointer | number) => b(AddressToMethod(mPtr)) globalThis.BN = (namespace: string) => Breaker.addBreakPoint("", namespace) // <- alias B(`NameSpace`) -globalThis.getPlatform = (): "arm" | "arm64" => (Process.platform == "linux" && Process.pageSize == 0x4) ? "arm" : "arm64" +globalThis.getPlatform = (): string => (Process.platform == "linux" && Process.pageSize == 0x4) ? "arm" : "arm64" globalThis.getPlatformCtx = (ctx: CpuContext): ArmCpuContext | Arm64CpuContext => getPlatform() == "arm" ? ctx as ArmCpuContext : ctx as Arm64CpuContext /** @@ -638,4 +638,4 @@ declare global { var attathing: boolean var printDesertedMethods: (filterName?: string) => void var printCurrentMethods: () => void -} +} \ No newline at end of file diff --git a/Il2cppHook/agent/base/dynamic.ts b/Il2cppHook/agent/base/dynamic.ts index 0eb24fa7..85ea5f7e 100644 --- a/Il2cppHook/agent/base/dynamic.ts +++ b/Il2cppHook/agent/base/dynamic.ts @@ -21,7 +21,7 @@ const filter_assembly: string[] = ["Assembly"] Il2Cpp.perform(() => { if (!enable_dynamic) return - Il2Cpp.domain.assemblies.forEach(async (assembly: Il2Cpp.Assembly) => { + Il2Cpp.Domain.assemblies.forEach(async (assembly: Il2Cpp.Assembly) => { let key = repName(assembly.name) Reflect.set(Assembly, key, needPack(assembly) ? packAssembly(assembly) : assembly) }) diff --git a/Il2cppHook/agent/base/valueResolve.ts b/Il2cppHook/agent/base/valueResolve.ts index a3845f8e..f5fc1a7e 100644 --- a/Il2cppHook/agent/base/valueResolve.ts +++ b/Il2cppHook/agent/base/valueResolve.ts @@ -16,7 +16,7 @@ export class ValueResolve { public constructor(cacheID: string, methodInfo: Il2Cpp.Method) { this.cacheId = cacheID this.method = methodInfo - this.args = new Array(methodInfo.generics.length) + this.args = new Array(methodInfo.genericParameterCount) } public getCacheId(): string { @@ -34,7 +34,7 @@ export class ValueResolve { public setMethod(method: Il2Cpp.Method): ValueResolve { this.method = method - this.args = new Array(method.generics.length) + this.args = new Array(method.genericParameterCount) return this } @@ -251,4 +251,4 @@ export function FakeCommonType(type: Il2Cpp.Type, mPtr: NativePointer): string { return mPtr.toString() } } -} +} \ No newline at end of file diff --git a/Il2cppHook/agent/bridge/fix/enum.ts b/Il2cppHook/agent/bridge/fix/enum.ts index 7317c934..ad7e319c 100644 --- a/Il2cppHook/agent/bridge/fix/enum.ts +++ b/Il2cppHook/agent/bridge/fix/enum.ts @@ -19,12 +19,12 @@ export const enumForEach = (className: string, callback: (field: NativePointer, if (!local_clazz.isEnum) throw new Error("Not enum class") let iter_ptr = alloc() let field_ptr: NativePointer = ptr(0) - while (field_ptr = Il2Cpp.api.classGetFields(local_clazzPtr, iter_ptr)) { + while (field_ptr = Il2Cpp.Api._classGetFields(local_clazzPtr, iter_ptr)) { if (field_ptr.isNull()) break let fieldName: string = field_ptr.readPointer().readCString()! let value: NativePointer = alloc() try { - Il2Cpp.api.fieldGetStaticValue(field_ptr, value) + Il2Cpp.Api._fieldGetStaticValue(field_ptr, value) } catch { } callback(field_ptr, fieldName, value.readPointer().toInt32()) } @@ -109,4 +109,4 @@ declare global { // return new Il2Cpp.Array(pointer.readPointer()); // } // throw new Error(`read: "${type.name}" (${type.typeEnum}) has not been handled yet. Please file an issue!`); -// } +// } \ No newline at end of file diff --git a/Il2cppHook/agent/bridge/fix/packer/packList.ts b/Il2cppHook/agent/bridge/fix/packer/packList.ts index ec5df45f..4532682c 100644 --- a/Il2cppHook/agent/bridge/fix/packer/packList.ts +++ b/Il2cppHook/agent/bridge/fix/packer/packList.ts @@ -1,3 +1,4 @@ +import { MessagePort } from "worker_threads" import { PackArray } from "./packArray" interface list_impl { @@ -180,4 +181,4 @@ declare global { */ globalThis.showList = (mPtr: NativePointer, transformer?: (item: Il2Cpp.Object) => string) => { new PackList(checkCmdInput(mPtr)).showList(transformer) } -globalThis.packList = (mPtr: NativePointer) => new PackList(checkCmdInput(mPtr)) +globalThis.packList = (mPtr: NativePointer) => new PackList(checkCmdInput(mPtr)) \ No newline at end of file diff --git a/Il2cppHook/agent/bridge/fix/parseFields.ts b/Il2cppHook/agent/bridge/fix/parseFields.ts index c2eb42dc..60ae0413 100644 --- a/Il2cppHook/agent/bridge/fix/parseFields.ts +++ b/Il2cppHook/agent/bridge/fix/parseFields.ts @@ -27,7 +27,7 @@ export class FieldsParser { this.mClass = new Il2Cpp.Object(this.mPtr).class this.mClass.name // use to check if instance is valid } catch { - if (this.mPtr.isNull()) this.mClass = Il2Cpp.domain.assembly("mscorlib").image.class("System.Object") + if (this.mPtr.isNull()) this.mClass = Il2Cpp.Domain.assembly("mscorlib").image.class("System.Object") else this.mClass = new Il2Cpp.Class(this.mPtr) this.mPtr = ptr(0) // not instance need set it to null } @@ -130,7 +130,7 @@ const dealWithSpecialType = (field: Il2Cpp.Field, thisValueP: NativePointer): st function fakeStaticField(field: Il2Cpp.Field): NativePointer { try { let tmpOut: NativePointer = alloc() - Il2Cpp.api.fieldGetStaticValue(field.handle, tmpOut) + Il2Cpp.Api._fieldGetStaticValue(field.handle, tmpOut) return tmpOut } catch (error) { return ptr(0) @@ -167,7 +167,7 @@ globalThis.lfp = (mPtr: NativePointer) => { let classType: Array = (getTypeParent(mPtr) as Array).reverse().map((localType: mscorlib.Type) => { let localT = new Il2Cpp.Class(localType.handle) if (localT.isAbstract) { - let objT = Il2Cpp.corlib.class("System.Object") + let objT = Il2Cpp.Image.corlib.class("System.Object") return new mscorlib.Type(localT.inflate(objT).type.handle) } return localType @@ -196,4 +196,4 @@ globalThis.lfvt = (mPtr: NativePointer, fieldName: string, classHandle?: NativeP } } -globalThis.lms = (mPtr: NativePointer) => HookerBase.showMethods(new Il2Cpp.Object(checkCmdInput(mPtr)).class.handle) +globalThis.lms = (mPtr: NativePointer) => HookerBase.showMethods(new Il2Cpp.Object(checkCmdInput(mPtr)).class.handle) \ No newline at end of file diff --git a/Il2cppHook/agent/expand/TypeExtends/apiExtends/apiExtends.ts b/Il2cppHook/agent/expand/TypeExtends/apiExtends/apiExtends.ts index 09e1d13e..75b930af 100644 --- a/Il2cppHook/agent/expand/TypeExtends/apiExtends/apiExtends.ts +++ b/Il2cppHook/agent/expand/TypeExtends/apiExtends/apiExtends.ts @@ -28,7 +28,6 @@ function overloadTransfromStrToFunction(exportPointer, retType, argTypes); } -Il2Cpp.Api = Il2Cpp.Api || {} Il2Cpp.Api.e = transfromStrToFunction Il2Cpp.Api.t = transfromStrToWithTryCatchFunction Il2Cpp.Api.o = overloadTransfromStrToFunction @@ -50,4 +49,4 @@ declare global { } } -export { } +export { } \ No newline at end of file diff --git a/Il2cppHook/agent/expand/TypeExtends/apiExtends/generator.ts b/Il2cppHook/agent/expand/TypeExtends/apiExtends/generator.ts index 93ac018e..e77fbd44 100644 --- a/Il2cppHook/agent/expand/TypeExtends/apiExtends/generator.ts +++ b/Il2cppHook/agent/expand/TypeExtends/apiExtends/generator.ts @@ -112,7 +112,7 @@ const repStr = (str: string): string => { const incorLib = (name: string) => { let corLib: boolean = false - Il2Cpp.domain.assembly('mscorlib').image.classes.forEach((cls: Il2Cpp.Class) => { + Il2Cpp.Domain.assembly('mscorlib').image.classes.forEach((cls: Il2Cpp.Class) => { if (cls.name == name) corLib = true }) return corLib @@ -229,7 +229,7 @@ const generateFieldEnum = (className: string, classPtr: NativePointer = ptr(0)) LOGE(`export enum ${clsInstance.namespace.replace('.', '_')}_${clsInstance.name} {`) clsInstance.fields.forEach((field: Il2Cpp.Field) => { - Il2Cpp.api.typeGetTypeEnum + Il2Cpp.Api._typeGetTypeEnum LOGD(`\t${field.name} = ${field}`) }) LOGO(`}\n`) @@ -454,4 +454,4 @@ globalThis.generateInterface = generateInterface globalThis.generateClassCxxH = generateClassCxxH globalThis.generateClassCxxCPP = generateClassCxxCPP -export { } +export { } \ No newline at end of file diff --git a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/UIBehaviour/EventSystem/export.ts b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/UIBehaviour/EventSystem/export.ts index e115482e..5179a53b 100644 --- a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/UIBehaviour/EventSystem/export.ts +++ b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/UIBehaviour/EventSystem/export.ts @@ -1,5 +1,5 @@ export const getEventUpdate = (needMethod: boolean = false): T => { - let local_method: Il2Cpp.Method = Il2Cpp.domain.assembly("UnityEngine.UI").image.class("UnityEngine.EventSystems.EventSystem").method("Update"); + let local_method: Il2Cpp.Method = Il2Cpp.Domain.assembly("UnityEngine.UI").image.class("UnityEngine.EventSystems.EventSystem").method("Update"); if (needMethod == undefined || needMethod == false) { return local_method.virtualAddress as unknown as T } else { diff --git a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/UIBehaviour/Graphic/MaskableGraphic/Image/class.ts b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/UIBehaviour/Graphic/MaskableGraphic/Image/class.ts index ee4539d3..3837e31a 100644 --- a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/UIBehaviour/Graphic/MaskableGraphic/Image/class.ts +++ b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/UIBehaviour/Graphic/MaskableGraphic/Image/class.ts @@ -58,7 +58,7 @@ class UnityEngine_UI_Image_Impl extends UnityEngine_UI_MaskableGraphic_Impl { // 这里想尝试一下动态静态结合一下 // 静态的方法和属性:方便脚本的编写,多数时候UnityApi变化不大不会有啥问题,但是确实也有不同版本不准确的问题 // 动态的方法和属性:方便CMD直接使用,保管准确 var s = new Il2Cpp.UI_Image(ptr(0x911e5790));s._fields; - // let thisClass = Il2Cpp.domain.assembly('UnityEngine.UI').image.class('UnityEngine.UI.Image') + // let thisClass = Il2Cpp.Domain.assembly('UnityEngine.UI').image.class('UnityEngine.UI.Image') // thisClass.methods.forEach((method: Il2Cpp.Method) => { // Reflect.set(this._methods, method.name, method.invoke.apply(this.handle)) // }) diff --git a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/export.ts b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/export.ts index 7f343090..485c7149 100644 --- a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/export.ts +++ b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Component/Behavior/MonoBehaviour/export.ts @@ -173,7 +173,7 @@ const findAndHook = (methodName: string, callback?: (instancePtr: NativePointer, // [-]_RET_ | type: 0x7a21744c78 | @ class:0x790a972600 | UnityEngine.Texture2D globalThis.HookSprite = () => { Il2Cpp.perform(() => { - let class_Sprite = Il2Cpp.domain.assembly("UnityEngine.CoreModule").image.class("UnityEngine.Sprite") + let class_Sprite = Il2Cpp.Domain.assembly("UnityEngine.CoreModule").image.class("UnityEngine.Sprite") let method_get_texture = class_Sprite.method("get_texture", 0) Interceptor.attach(method_get_texture.virtualAddress, { onEnter(args) { @@ -204,7 +204,7 @@ const HookMonoStart = (callback?: (instancePtr: NativePointer, ctx: CpuContext) // [-]UnityEngine.UI.dll @ 0x7b4dbcb438 | C:202 // [-]Graphic @ 0x7b618ede00 | M:61 | F:23 | N:UnityEngine.UI // [-]protected virtual Void UpdateGeometry() @ MI: 0x7a14cce740 & MP: 0x7b6d83cda8 & RP: 0x213cda8 - const class_Graphic = Il2Cpp.domain.assembly("UnityEngine.UI").image.class("UnityEngine.UI.Graphic") + const class_Graphic = Il2Cpp.Domain.assembly("UnityEngine.UI").image.class("UnityEngine.UI.Graphic") const method_UpdateGeometry = class_Graphic.method("UpdateGeometry", 0) const src_function = new NativeFunction(method_UpdateGeometry.virtualAddress, "void", ["pointer"]) Interceptor.replace(method_UpdateGeometry.virtualAddress, new NativeCallback((instance: NativePointer) => { diff --git a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/GameObject/export.ts b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/GameObject/export.ts index f60852f6..ff7c73ae 100644 --- a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/GameObject/export.ts +++ b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/GameObject/export.ts @@ -11,7 +11,7 @@ enum activeStatus { all = -1 } -const HookSetActive = (defaltActive: activeStatus | boolean = activeStatus.active, PrintStackTrace: boolean = false, filterString: Array | string = "") => { +globalThis.HookSetActive = (defaltActive: activeStatus | boolean = activeStatus.active, PrintStackTrace: boolean = false, filterString: Array | string = "") => { let setActiveAddress = find_method("UnityEngine.CoreModule", "GameObject", "SetActive", 1) try { @@ -74,9 +74,8 @@ const HookSetActive = (defaltActive: activeStatus | boolean = activeStatus.activ } } } -globalThis.HookSetActive = HookSetActive -const HookSendMessage = () => { +globalThis.HookSendMessage = () => { // try { // var UnityPlayer = Java.use("com.unity3d.player.UnityPlayer") // UnityPlayer.UnitySendMessage.implementation = function (str0:string, str1:string, str2:string) { @@ -91,7 +90,6 @@ const HookSendMessage = () => { LOGD("UnitySendMessage => " + args[0].readCString() + " " + args[1].readCString() + " " + args[2].readCString()) }) } -globalThis.HookSendMessage = HookSendMessage export function GetGameObjectFromPtr(mPtr: NativePointer | Il2Cpp.GameObject | Il2Cpp.Component | Il2Cpp.Transform): Il2Cpp.GameObject | undefined { if (mPtr == undefined) throw new Error("mPtr is undefined") @@ -110,7 +108,7 @@ export function GetGameObjectFromPtr(mPtr: NativePointer | Il2Cpp.GameObject | I } else throw new Error("mPtr is not a valid instance of the specified type") } -const showGameObject = (mPtr: NativePointer | Il2Cpp.GameObject | Il2Cpp.Transform) => { +globalThis.showGameObject = (mPtr: NativePointer | Il2Cpp.GameObject | Il2Cpp.Transform) => { if (mPtr == undefined || (mPtr instanceof NativePointer && mPtr.isNull())) return let gameObject: Il2Cpp.GameObject = GetGameObjectFromPtr(mPtr)! LOGO("--------- GameObject ---------") @@ -130,12 +128,10 @@ const showGameObject = (mPtr: NativePointer | Il2Cpp.GameObject | Il2Cpp.Transfo } LOGD("hierarchy\t--->\t" + layerNames) } -globalThis.showGameObject = showGameObject -const getTransform = (mPtr: NativePointer) => { +globalThis.getTransform = (mPtr: NativePointer) => { return GetGameObjectFromPtr(mPtr)!.transform.handle } -globalThis.getTransform = getTransform globalThis.setActive = (mPtr: Il2Cpp.GameObject | Il2Cpp.Transform | string | number | NativePointer, active: boolean = false) => { mPtr = checkGT(mPtr) @@ -324,4 +320,4 @@ declare global { var s: (mPtr: NativePointer) => void } -export { showGameObject, HookSetActive, getTransform, HookSendMessage } +export { showGameObject, HookSetActive, getTransform, HookSendMessage } \ No newline at end of file diff --git a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Texture/Texture2D/export.ts b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Texture/Texture2D/export.ts index fe964d5e..ff4ca3a2 100644 --- a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Texture/Texture2D/export.ts +++ b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/Texture/Texture2D/export.ts @@ -1,4 +1,4 @@ -const B_Texture2D = () => { +globalThis.B_Texture2D = () => { setTimeout(() => { Il2Cpp.perform(() => { let libil2cpp = Module.findBaseAddress("libil2cpp.so")! @@ -21,7 +21,7 @@ const B_Texture2D = () => { // printExp("get_mainTexture",true) - let addr = Il2Cpp.domain.assembly("UnityEngine.UI").image.class("UnityEngine.UI.Image").method("get_mainTexture").virtualAddress + let addr = Il2Cpp.Domain.assembly("UnityEngine.UI").image.class("UnityEngine.UI.Image").method("get_mainTexture").virtualAddress LOGD("get_mainTexture => " + addr) let list_text2d = [] @@ -84,10 +84,9 @@ const B_Texture2D = () => { }) }, 200) } -globalThis.B_Texture2D = B_Texture2D declare global { var B_Texture2D: () => void } -export { B_Texture2D } +export { B_Texture2D } \ No newline at end of file diff --git a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/export.ts b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/export.ts index d2c2bdd0..b98ef39c 100644 --- a/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/export.ts +++ b/Il2cppHook/agent/expand/TypeExtends/mscorlibObj/Object/export.ts @@ -1,7 +1,9 @@ import { mscorlib_System_Object_impl } from "../class" import { UnityEngine_Object } from "./class" -const getObjName = (mPtr: NativePointer): string => { +export { getObjName, getObjClass } + +globalThis.getObjName = (mPtr: NativePointer): string => { try { if (mPtr instanceof NativePointer && !mPtr.isNull()) { return new mscorlib_System_Object_impl(mPtr).toString() @@ -13,14 +15,12 @@ const getObjName = (mPtr: NativePointer): string => { } return '' } -globalThis.getObjName = getObjName -const getObjClass = (mPtr: NativePointer): NativePointer => { +globalThis.getObjClass = (mPtr: NativePointer): NativePointer => { if (typeof mPtr == "number") mPtr = ptr(mPtr) let obj = new UnityEngine_Object(mPtr) return obj.class.handle } -globalThis.getObjClass = getObjClass globalThis.HookInstantiate = () => { @@ -84,6 +84,4 @@ declare global { var getObjName: (mPtr: NativePointer) => string var getObjClass: (mPtr: NativePointer) => NativePointer var HookInstantiate: () => void -} - -export { getObjName, getObjClass } +} \ No newline at end of file diff --git a/Il2cppHook/agent/expand/TypeExtends/thread/thread.ts b/Il2cppHook/agent/expand/TypeExtends/thread/thread.ts index 85147636..3b2104b7 100644 --- a/Il2cppHook/agent/expand/TypeExtends/thread/thread.ts +++ b/Il2cppHook/agent/expand/TypeExtends/thread/thread.ts @@ -1,10 +1,10 @@ const attachCurrentThread = () => { - let thread = Il2Cpp.api.threadGetCurrent() - if (thread.isNull()) Il2Cpp.domain.attach() + let thread = Il2Cpp.Api._threadCurrent() + if (thread.isNull()) Il2Cpp.Domain.attach() } const detachCurrentThread = () => { - let threadHandle = Il2Cpp.api.threadGetCurrent(); + let threadHandle = Il2Cpp.Api._threadCurrent(); if (!threadHandle.isNull()) new Il2Cpp.Thread(threadHandle).detach() } @@ -16,4 +16,4 @@ declare global { var detachCurrentThread: () => void } -export { } +export { } \ No newline at end of file diff --git a/Il2cppHook/agent/index.ts b/Il2cppHook/agent/index.ts index 24a391dd..10f64f6f 100644 --- a/Il2cppHook/agent/index.ts +++ b/Il2cppHook/agent/index.ts @@ -47,12 +47,12 @@ class PauseHelper { } public static getPauseAddress = () => { - let EventSystem = Il2Cpp.domain.assembly("UnityEngine.UI").image.tryClass("UnityEngine.EventSystems.EventSystem") + let EventSystem = Il2Cpp.Domain.assembly("UnityEngine.UI").image.tryClass("UnityEngine.EventSystems.EventSystem") if (EventSystem != null) { let method = EventSystem.tryMethod("Update") if (method != null) return method.virtualAddress } - let Image = Il2Cpp.domain.assembly("UnityEngine.UI").image.tryClass("UnityEngine.UI.Image") + let Image = Il2Cpp.Domain.assembly("UnityEngine.UI").image.tryClass("UnityEngine.UI.Image") if (Image != null) { let method = Image.tryMethod("UpdateMaterial") if (method != null) return method.virtualAddress @@ -97,7 +97,6 @@ class ExceptionTraceClass { // }); let CodeLength = 0x100 - CodeLength ??= 0x100 let retPC = details.context.pc let ins: NativePointer = ptr(ExceptionTraceClass.savedCode.get(retPC.toString())!) let trampoline = Memory.alloc(CodeLength) @@ -196,13 +195,13 @@ const HookExit = () => { Il2Cpp.perform(() => { // UnityEngine.CoreModule UnityEngine.Application Quit(Int32) : Void - R(Il2Cpp.domain.assembly("UnityEngine.CoreModule").image.class("UnityEngine.Application").method("Quit", 1).virtualAddress, (_srcCall: Function, arg0: NativePointer) => { + R(Il2Cpp.Domain.assembly("UnityEngine.CoreModule").image.class("UnityEngine.Application").method("Quit", 1).virtualAddress, (_srcCall: Function, arg0: NativePointer) => { // srcCall(arg0, arg1, arg2, arg3) LOGE("called UnityEngine.Application.Quit(" + arg0.toInt32() + ")") return ptr(0) }) // UnityEngine.CoreModule UnityEngine.Application Quit() : Void - R(Il2Cpp.domain.assembly("UnityEngine.CoreModule").image.class("UnityEngine.Application").method("Quit").virtualAddress, (_srcCall: Function) => { + R(Il2Cpp.Domain.assembly("UnityEngine.CoreModule").image.class("UnityEngine.Application").method("Quit").virtualAddress, (_srcCall: Function) => { // srcCall(arg0, arg1, arg2, arg3) LOGE("called UnityEngine.Application.Quit()") return ptr(0) @@ -219,7 +218,7 @@ function fixMoreVerison() { const UnityVersion = "2020.3.0f1c1" Il2Cpp.perform(() => { - if (Il2Cpp.api.resolveInternalCall(allocCStr('UnityEngine.Application::get_unityVersion')).isNull()) { + if (Il2Cpp.Api._resolveInternalCall(allocCStr('UnityEngine.Application::get_unityVersion')).isNull()) { LOGW(`Couldn't determine the Unity version, Schedule set to ${UnityVersion}`) setTimeout(() => { if (Reflect.has(Il2Cpp, "unityVersion")) { @@ -237,8 +236,8 @@ function fixMoreVerison() { // { // Il2Cpp.perform(() => { // setTimeout(() => { - // if (Il2Cpp.api.resolveInternalCall(allocCStr('UnityEngine.Application::get_unityVersion')).isNull()) { - // A(Il2Cpp.api.resolveInternalCall, (args: InvocationArguments, _ctx: CpuContext, passValue: Map) => { + // if (Il2Cpp.Api._resolveInternalCall(allocCStr('UnityEngine.Application::get_unityVersion')).isNull()) { + // A(Il2Cpp.Api._resolveInternalCall, (args: InvocationArguments, _ctx: CpuContext, passValue: Map) => { // if (args[0].readCString() == 'UnityEngine.Application::get_unityVersion') { // passValue.set("RET", allocCStr(UnityVersion)) // LOGE(`Can't get UnityVersion, set to ${UnityVersion}`) @@ -274,7 +273,7 @@ function fixMoreVerison() { // return local_offset // } // }) -// A(Il2Cpp.Api.fieldGetOffset, undefined, (ret) => { +// A(Il2Cpp.Api._fieldGetOffset, undefined, (ret) => { // let local_offset: number = ret.toInt32() // if (local_offset < 0) return -1 // if (Process.arch == "arm") local_offset = local_offset - 8 @@ -298,4 +297,4 @@ globalThis.resume = PauseHelper.Resume globalThis.setException = ExceptionTraceClass.setException globalThis.addBP = ExceptionTraceClass.writeBP globalThis.removeBP = ExceptionTraceClass.removeBP -globalThis.HookExit = HookExit +globalThis.HookExit = HookExit \ No newline at end of file diff --git a/Il2cppHook/agent/java/info.ts b/Il2cppHook/agent/java/info.ts index 8a57a34c..2f084f4a 100644 --- a/Il2cppHook/agent/java/info.ts +++ b/Il2cppHook/agent/java/info.ts @@ -118,7 +118,7 @@ const cacheMethods = (withLog: boolean = true) => { if (allMethodsCacheArray.length > 0) return if (withLog) LOGZ("Caching methods ...") let timeCurrent = Date.now() - Il2Cpp.domain.assemblies.forEach((assembly: Il2Cpp.Assembly) => { + Il2Cpp.Domain.assemblies.forEach((assembly: Il2Cpp.Assembly) => { assembly.image.classes.forEach((klass: Il2Cpp.Class) => allMethodsCacheArray = allMethodsCacheArray.concat(klass.methods)) }) allMethodsCacheArray = allMethodsCacheArray.sort((a: Il2Cpp.Method, b: Il2Cpp.Method) => a.virtualAddress.compare(b.virtualAddress)) diff --git a/Il2cppHook/agent/java/unity.ts b/Il2cppHook/agent/java/unity.ts index 1b805d1a..13fb70ea 100644 --- a/Il2cppHook/agent/java/unity.ts +++ b/Il2cppHook/agent/java/unity.ts @@ -1,6 +1,6 @@ export const HookCallstatic = () => { Il2Cpp.perform(() => { - let _CallStatic = Il2Cpp.domain.assembly("UnityEngine.AndroidJNIModule").image.class("UnityEngine.AndroidJavaObject").method("_CallStatic").virtualAddress + let _CallStatic = Il2Cpp.Domain.assembly("UnityEngine.AndroidJNIModule").image.class("UnityEngine.AndroidJavaObject").method("_CallStatic").virtualAddress if (_CallStatic.isNull()) throw new Error("CallStatic is null") /** * protected void _CallStatic(string methodName, params object[] args) diff --git a/Il2cppHook/agent/utils/alloc.ts b/Il2cppHook/agent/utils/alloc.ts index 367fea78..45a37a9e 100644 --- a/Il2cppHook/agent/utils/alloc.ts +++ b/Il2cppHook/agent/utils/alloc.ts @@ -1,6 +1,6 @@ import { TYPE_STR } from "../base/enum" -const allocStrInner = (str: string, type: TYPE_STR = TYPE_STR.C_STR): NativePointer => type == TYPE_STR.C_STR ? Memory.allocUtf8String(str) : Il2Cpp.api.stringNew(Memory.allocUtf8String(str)) +const allocStrInner = (str: string, type: TYPE_STR = TYPE_STR.C_STR): NativePointer => type == TYPE_STR.C_STR ? Memory.allocUtf8String(str) : Il2Cpp.Api._stringNew(Memory.allocUtf8String(str)) const allocCStr = (str: string): NativePointer => allocStrInner(str, TYPE_STR.C_STR) @@ -44,4 +44,4 @@ globalThis.allocCStr = allocCStr globalThis.allocUStr = allocUStr globalThis.allocVector = allocVector globalThis.alloc = alloc -globalThis.allocP = allocP +globalThis.allocP = allocP \ No newline at end of file diff --git a/Il2cppHook/agent/utils/common.ts b/Il2cppHook/agent/utils/common.ts index fa726603..31ab8232 100644 --- a/Il2cppHook/agent/utils/common.ts +++ b/Il2cppHook/agent/utils/common.ts @@ -315,15 +315,11 @@ const SendMessageImpl = (platform: string | "IronSource" | "MaxSdkCallbacks" | " globalThis.HookForwardEvent = () => { Il2Cpp.perform(() => { // MaxSdk.Scripts + MaxSdkCallbacks + ForwardEvent - let ass = Il2Cpp.domain.tryAssembly("MaxSdk.Scripts") + let ass = Il2Cpp.Domain.tryAssembly("MaxSdk.Scripts") if (ass) { - let method : Il2Cpp.Method = ass.image.class("MaxSdkCallbacks").method("ForwardEvent") - method.implementation = function (...parameters: Il2Cpp.Parameter.Type[]) { - const instance: NativePointer = parameters[0] as NativePointer; - const eventPropsStr: NativePointer = parameters[1] as NativePointer; - - LOGD(`ForwardEvent: ${instance} ${readU16(eventPropsStr)}`); - return this.method("ForwardEvent").invoke(...parameters); + ass.image.class("MaxSdkCallbacks").method("ForwardEvent").implementation = function (instance: NativePointer, eventPropsStr: NativePointer) { + LOGD(`ForwardEvent: ${instance} ${readU16(eventPropsStr)}`) + return this.method("ForwardEvent").invoke(...arguments) } } else { throw new Error("MaxSdk.Scripts not found") @@ -366,7 +362,7 @@ const watchFunction = (call: Function, interval: number = 1000) => { } const disWatchFuntion = () => { - if (intervalID != null) clearInterval(intervalID as NodeJS.Timeout) + if (intervalID != null) clearInterval(intervalID) } export { @@ -418,4 +414,4 @@ globalThis.watchFunction = watchFunction globalThis.w = globalThis.watchFunction globalThis.disWatchFuntion = disWatchFuntion globalThis.dd = disWatchFuntion -globalThis.P = (call: Function) => { return new Promise((resolve, _reject) => { resolve(call()) }) } +globalThis.P = (call: Function) => { return new Promise((resolve, _reject) => { resolve(call()) }) } \ No newline at end of file diff --git a/Il2cppHook/agent/utils/stdString.ts b/Il2cppHook/agent/utils/stdString.ts index 6d5fbc22..a108c65e 100644 --- a/Il2cppHook/agent/utils/stdString.ts +++ b/Il2cppHook/agent/utils/stdString.ts @@ -9,7 +9,7 @@ const get_PrettyMethod = () => { return PrettyMethod_func } -const readStdString = (pointers: NativePointer[]) => { +globalThis.readStdString = (pointers: NativePointer[]) => { let str = Memory.alloc(Process.pointerSize * 3) str.writePointer(pointers[0]) str.add(Process.pointerSize * 1).writePointer(pointers[1]) @@ -18,7 +18,6 @@ const readStdString = (pointers: NativePointer[]) => { if (isTiny) return str.add(1).readUtf8String() return str.add(2 * Process.pointerSize).readPointer().readUtf8String() } -globalThis.readStdString = readStdString export { readStdString, get_PrettyMethod } diff --git a/Il2cppHook/bin/fat.js b/Il2cppHook/bin/fat.js old mode 100755 new mode 100644 diff --git a/Il2cppHook/package.json b/Il2cppHook/package.json index 47586614..41a6e419 100644 --- a/Il2cppHook/package.json +++ b/Il2cppHook/package.json @@ -1,6 +1,6 @@ { "name": "@axhlzy/il2cpp-hooker", - "version": "1.0.7", + "version": "1.0.6", "description": "frida-based libil2cpp.so runtime parsing script", "homepage": "https://github.com/axhlzy/Il2CppHookScripts#readme", "author": "axhlzy (https://github.com/axhlzy/Il2CppHookScripts/)", @@ -17,7 +17,7 @@ ], "scripts": { "prepare": "npm run build", - "build": "tsc && frida-compile agent/index.ts -o _Ufunc.tmp && cat _Ufunc.tmp | ./postprocess.py > _Ufunc.js", + "build": "frida-compile agent/index.ts -c -o _Ufunc.js", "watch": "frida-compile agent/index.ts -w -o _Ufunc.js", "compress": "uglifyjs _Ufunc.js -m -c -o _Ufunc.js" }, @@ -30,10 +30,10 @@ "dependencies": { "babelify": "^10.0.0", "chalk": "^5.0.1", - "decorator-cache-getter": "github:zed-0xff/decorator-cache-getter", + "decorator-cache-getter": "^1.0.0", "fastest-levenshtein": "^1.0.12", - "frida-compile": "^13.0.1", - "frida-il2cpp-bridge": "^0.9.0", + "frida-compile": "^10.2.5", + "frida-il2cpp-bridge": "0.7.13", "minimist": "^1.2.8", "numbro": "^2.3.6", "prettier": "^2.6.2", diff --git a/Il2cppHook/postprocess.py b/Il2cppHook/postprocess.py deleted file mode 100755 index 33b4bbba..00000000 --- a/Il2cppHook/postprocess.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 - -# 1. convert empty objects to non-empty objects, because empty objects are not valid -# 2. convert imports to .js imports, because frida can't find them otherwise - -import re -import sys -import json - -data = sys.stdin.read() - -hdr, data = data.split('\n', 1) -if hdr != '📦': - raise ValueError("No package header in input") - -parts = data.split("✄") - -data_idx = -1 -index = [] -for line in parts[0].split('\n'): - if line == '': - continue - if line.startswith('↻'): - index.append({'literal': line}) - else: - size, pathname = line.split(' ', 2) - data_idx += 1 - index.append({'size': int(size), 'name': pathname, 'data_idx': data_idx}) - -datas = [part.strip() for part in parts[1:]] - -# Patch includes, add "js" suffix to names -pattern = re.compile(r'(import|from)\s*(["\'])\.[^\'"]+\2') -def add_js_suffix(match): - if not match.group(0).endswith('.js' + match.group(2)): - return match.group(0)[:-1] + '.js' + match.group(2) - return match.group(0) -datas = [pattern.sub(add_js_suffix, data) for data in datas] - -# Convert empty objects to non-empty objects and fix new lengths -for entry in index: - size = entry.get('size') - if size is not None: - if len(datas[entry['data_idx']]) == 0: - datas[entry['data_idx']] += ' ' - entry['size'] = len(datas[entry['data_idx']].encode()) - -# Write to stdout -sys.stdout.write(hdr + '\n') -for entry in index: - if 'literal' in entry: - sys.stdout.write(entry['literal'] + '\n') - else: - sys.stdout.write(f"{entry['size']} {entry['name']}\n") -for data in datas: - sys.stdout.write('✄\n') - sys.stdout.write(data + '\n') - diff --git a/Il2cppHook/tsconfig.json b/Il2cppHook/tsconfig.json index 664fba3b..8855384f 100644 --- a/Il2cppHook/tsconfig.json +++ b/Il2cppHook/tsconfig.json @@ -10,6 +10,5 @@ "esModuleInterop": true, "strict": true, "removeComments": true - }, - "exclude": ["_Ufunc.js"] -} + } +} \ No newline at end of file