frida / frida-core

Frida core library intended for static linking into bindings

Home Page:https://frida.re

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak detection

nmweizi opened this issue · comments

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;
    }
})