There are lot’s of situations which you can’t create new object to calling an method or changing an property. You need to finding existing instances and then manipulate them.

To achieve this goal you can use use Java.choose.

Example:

Java.perform(
    function(){
        Java.choose("com.example.package.player", {
            onMatch: function(instance){
                instance.increaseLives()
                send("[+] Player lives increased to: " + instance.lives.value)
            },
            onCompelet: function(){
                console.log("[+] Done")
            }
        })
    }
)

Passing an Object as Parameter

Java.perform(function(){
        var itemClassRef = Java.use("com.example.package.Item")
        var itemClassObj =  itemClassRef.$new(1000)

        var bossClassRef = Java.use("com.example.package.Boss")
        bossClassRef.$new(itemClassObj)
    
    })

<aside> 💡 You can use Java.choose to send an existing object as an parameter.

</aside>

Hooking Constructors

In order to hooking contractors we should use $init keyword.

let Player = Java.use("de.fgerbig.spacepeng.components.Player");
    Player.$init.implementation = function(){
        console.log("[+] Hooking constructors")
				this.$init()
    }

Tasks