Skip to content

Commit

Permalink
Revert "Merge pull request #33 from zed-0xff/master"
Browse files Browse the repository at this point in the history
This reverts commit 3df3779, reversing
changes made to 6b56232.
  • Loading branch information
axhlzy committed Jan 17, 2024
1 parent 3df3779 commit be44677
Show file tree
Hide file tree
Showing 26 changed files with 93 additions and 165 deletions.
40 changes: 20 additions & 20 deletions Il2cppHook/agent/base/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class HookerBase {

@cache
static get _list_assemblies(): Il2Cpp.Assembly[] {
return Il2Cpp.domain.assemblies
return Il2Cpp.Domain.assemblies
}

@cache
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
* ===
Expand All @@ -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}`)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -710,4 +710,4 @@ declare global {
var fakeGCInstance: (inputClass: string | NativePointer | Il2Cpp.Class, mapFunction?: (item: Il2Cpp.Object) => string) => void

var soAddr: NativePointerValue
}
}
16 changes: 8 additions & 8 deletions Il2cppHook/agent/base/breaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

/**
Expand Down Expand Up @@ -638,4 +638,4 @@ declare global {
var attathing: boolean
var printDesertedMethods: (filterName?: string) => void
var printCurrentMethods: () => void
}
}
2 changes: 1 addition & 1 deletion Il2cppHook/agent/base/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
6 changes: 3 additions & 3 deletions Il2cppHook/agent/base/valueResolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ValueResolve {
public constructor(cacheID: string, methodInfo: Il2Cpp.Method) {
this.cacheId = cacheID
this.method = methodInfo
this.args = new Array<NativePointer>(methodInfo.generics.length)
this.args = new Array<NativePointer>(methodInfo.genericParameterCount)
}

public getCacheId(): string {
Expand All @@ -34,7 +34,7 @@ export class ValueResolve {

public setMethod(method: Il2Cpp.Method): ValueResolve {
this.method = method
this.args = new Array<NativePointer>(method.generics.length)
this.args = new Array<NativePointer>(method.genericParameterCount)
return this
}

Expand Down Expand Up @@ -251,4 +251,4 @@ export function FakeCommonType(type: Il2Cpp.Type, mPtr: NativePointer): string {
return mPtr.toString()
}
}
}
}
6 changes: 3 additions & 3 deletions Il2cppHook/agent/bridge/fix/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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!`);
// }
// }
3 changes: 2 additions & 1 deletion Il2cppHook/agent/bridge/fix/packer/packList.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MessagePort } from "worker_threads"
import { PackArray } from "./packArray"

interface list_impl {
Expand Down Expand Up @@ -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))
8 changes: 4 additions & 4 deletions Il2cppHook/agent/bridge/fix/parseFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -167,7 +167,7 @@ globalThis.lfp = (mPtr: NativePointer) => {
let classType: Array<mscorlib.Type> = (getTypeParent(mPtr) as Array<mscorlib.Type>).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
Expand Down Expand Up @@ -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)
3 changes: 1 addition & 2 deletions Il2cppHook/agent/expand/TypeExtends/apiExtends/apiExtends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function overloadTransfromStrToFunction<R extends NativeFunctionReturnType, A ex
return new NativeFunction<R, A>(exportPointer, retType, argTypes);
}

Il2Cpp.Api = Il2Cpp.Api || {}
Il2Cpp.Api.e = transfromStrToFunction
Il2Cpp.Api.t = transfromStrToWithTryCatchFunction
Il2Cpp.Api.o = overloadTransfromStrToFunction
Expand All @@ -50,4 +49,4 @@ declare global {
}
}

export { }
export { }
6 changes: 3 additions & 3 deletions Il2cppHook/agent/expand/TypeExtends/apiExtends/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -454,4 +454,4 @@ globalThis.generateInterface = generateInterface
globalThis.generateClassCxxH = generateClassCxxH
globalThis.generateClassCxxCPP = generateClassCxxCPP

export { }
export { }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const getEventUpdate = <T>(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
// })
Expand Down
Loading

0 comments on commit be44677

Please sign in to comment.