hook类的ctor返回空值
对于java代码
public final class C666190Q1w<A, B> {
public final A LIZ;
public final B LIZIZ;
...
public C666190Q1w(A a2, B b) {
this.LIZ = a2;
this.LIZIZ = b;
}
}
去hook了构造函数,最整代码是:
function hookDouyinClass_X_0Q1w(ThrowableCls) {
/******************** X.0Q1w ********************/
var clsName_0Q1w = "X.0Q1w"
// printClassAllMethodsFields(clsName_0Q1w)
var cls_0Q1w = Java.use(clsName_0Q1w)
console.log("cls_0Q1w=" + cls_0Q1w)
// public C666190Q1w(A a2, B b) {
// call: C666190Q1w<ByteBuffer, Long> c666190Q1w = new C666190Q1w<>(allocate5, Long.valueOf(j6))
var func_0Q1w_ctor = cls_0Q1w.$init
console.log("func_0Q1w_ctor=" + func_0Q1w_ctor)
if (func_0Q1w_ctor) {
func_0Q1w_ctor.implementation = function (a2, b) {
var funcName = "0Q1w(a2,b)"
var funcParaDict = {
"a2": a2,
"b": b,
}
printFunctionCallAndStack(funcName, funcParaDict, ThrowableCls)
// var new0Q1w = this.$init(a2, b)
// console.log("new0Q1w=" + new0Q1w)
this.$init(a2, b)
console.log("this=" + this)
console.log("this.LIZ=" + this.LIZ)
console.log("this.LIZIZ=" + this.LIZIZ)
// var new0Q1w = this
// return new0Q1w
return
}
}
}
而其中,之前的写法是:
var new0Q1w = this.$init(a2, b)
console.log("new0Q1w=" + new0Q1w)
但会输出:new0Q1w=undefined
是因为:
- 构造函数:并没有返回值
- 所以此时的值(始终)是:undefined
- 所以后续改为:直接return返回
- 效果也是一样的
而要想要: 去打印,初始还后(执行完毕构造函数后)的对应的实例(的属性值)
则是:
在运行完毕:this.$init(a2, b)
后,再去查看属性值:
console.log("this=" + this)
console.log("this.LIZ=" + this.LIZ)
console.log("this.LIZIZ=" + this.LIZIZ)
即可查看到:(内存中的)实例的相关的值:
this=X.0Q1w@e1993e0
this.LIZ=Java.Field{holder: X.0Q1w@e1993e0, fieldType: 2, fieldReturnType: [object Object], value: java.nio.HeapByteBuffer[pos=12288 lim=12288 cap=12288]}
this.LIZIZ=Java.Field{holder: X.0Q1w@e1993e0, fieldType: 2, fieldReturnType: [object Object], value: 236556288}
即可。
对了,进一步,查看属性的值,是加上:.value
console.log("this.LIZ.value=" + this.LIZ.value)
console.log("this.LIZIZ.value=" + this.LIZIZ.value)
输出:
this.LIZ.value=java.nio.HeapByteBuffer[pos=12288 lim=12288 cap=12288]
this.LIZIZ.value=236556288