frida / frida-core

Frida core library intended for static linking into bindings
https://frida.re
Other
592 stars 187 forks source link

Memory leak detection #495

Open nmweizi opened 7 months ago

nmweizi commented 7 months ago

hi, Use the frida-gadget.dylib hook macos program to execute the javascript script. After running for a long time, the memory keeps growing. It seems that the written script has a memory leak.

In this injection environment, how to detect memory usage and leakage?

When not hooked, the memory is normal. frida-gadget.dylib 16.1.8 macos 14.1 intel

const NSNumber = ObjC.classes.NSNumber;
const NSNumber_0 = NSNumber.alloc().initWithInt_(0);

var get_item = {"bb":NSNumber_0};

var objectForKeyedSubscript = ObjC.classes.NSDictionary["- objectForKeyedSubscript:"];

Interceptor.attach(objectForKeyedSubscript.implementation, {
    onEnter(args) {
        this.key = new ObjC.Object(ptr(args[2])).toString();
    },
    onLeave: function (retval) {
        var result = get_item[this.key];
        if (result) {
            retval.replace(result);
        }
        this.key = null;
    }
})