{"id":13484607,"url":"https://github.com/chame1eon/jnitrace-engine","last_synced_at":"2025-04-07T16:18:17.006Z","repository":{"id":36752250,"uuid":"226689146","full_name":"chame1eon/jnitrace-engine","owner":"chame1eon","description":"Engine used by jnitrace to intercept JNI API calls.","archived":false,"fork":false,"pushed_at":"2023-07-18T20:19:35.000Z","size":588,"stargazers_count":264,"open_issues_count":2,"forks_count":50,"subscribers_count":12,"default_branch":"master","last_synced_at":"2023-12-16T14:39:23.531Z","etag":null,"topics":["android","frida","jni","jni-api","reverse-engineering","sre","tracer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chame1eon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-12-08T15:31:57.000Z","updated_at":"2023-12-20T16:12:16.100Z","dependencies_parsed_at":"2023-12-20T16:26:00.705Z","dependency_job_id":null,"html_url":"https://github.com/chame1eon/jnitrace-engine","commit_stats":{"total_commits":41,"total_committers":4,"mean_commits":10.25,"dds":0.3902439024390244,"last_synced_commit":"1d1233c4c9f2bf197b94406dd4fa64a7adadb717"},"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chame1eon%2Fjnitrace-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chame1eon%2Fjnitrace-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chame1eon%2Fjnitrace-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chame1eon%2Fjnitrace-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chame1eon","download_url":"https://codeload.github.com/chame1eon/jnitrace-engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247685628,"owners_count":20979085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","frida","jni","jni-api","reverse-engineering","sre","tracer"],"created_at":"2024-07-31T17:01:27.017Z","updated_at":"2025-04-07T16:18:16.984Z","avatar_url":"https://github.com/chame1eon.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# jnitrace-engine\n\n_Engine used by jnitrace to intercept JNI API calls._\n\n`jnitrace-engine` is the project used by jnitrace to intercept and trace JNI API calls. It has been exposed as a separate project to allow Frida module developers to use the same engine to intercept and modify JNI API calls made by Android applications.\n\n## Installation:\n\nThe easiest way to get running with `jnitrace-engine` is using npm:\n\n`npm install jnitrace-engine`\n\n## Simple Usage:\n\n`jnitrace-engine` tries to mirror as much of the Frida API as possible. `JNIInterceptor` provides an API to attach to JNI API calls in a very similar way to the Frida `Interceptor`. The idea is to make using the library simple to use for those already familiar with Frida. The examples below are JavaScript but the module also supports TypeScript.\n\n```javascript\nimport { JNIInterceptor } from \"jnitrace-engine\";\n\n// Attach to the JNI FindClass method\nJNIInterceptor.attach(\"FindClass\", {\n    onEnter(args) {\n        // called whenever the FindClass is about to be called\n        console.log(\"FindClass method called\");\n        this.className = Memory.readCString(args[1]);\n    },\n    onLeave(retval) {\n        // called whenever the FindClass method has finished executing\n        console.log(\"\\tLoading Class:\", this.className);\n        console.log(\"\\tClass ID:\", retval.get());\n    }\n});\n\n```\n\n## Advanced Usage:\n\n```TypeScript\nimport { JNIInterceptor } from \"jnitrace-engine\";\nimport { JNILibraryWatcher } from \"jnitrace-engine\";\nimport { JNINativeReturnValue } from \"jnitrace-engine\";\nimport { ConfigBuilder } from \"jnitrace-engine\";\n\n// configure the jnitrace-engine to limit what libraries to traces\nconst builder : ConfigBuilder = new ConfigBuilder();\n\nbuilder.libraries = [ \"libnative-lib.so\" ]; // set a list of libraries to track\nbuilder.backtrace = \"fuzzy\"; // choose the backtracer type to use [accurate/fuzzy/none]\nbuilder.includeExports = [ \"Java_com_nativetest_MainActivity_stringFromJNI\" ]; // provide a list of library exports to track\nbuilder.excludeExports = []; // provide a list of library exports to ignore\nbuilder.env = true; // set whether to trace the JNIEnv struct or ignore all of it\nbuilder.vm = false; // set whether to trace the JavaVM struct or ignore all of it\n\nconst config = builder.build(); //initialise the config - this makes it available to the engine\n\n// An additional callback that can be used for listening to new libraries being loaded by an application\n// Note this callback will be called for all libraries, not just the ones in the config\n// libraries list\nJNILibraryWatcher.setCallback({\n    onLoaded(path : string) {\n        console.log(\"Library Loaded \" + path);\n        console.log(\"Currently Traced Libraries\", JSON.stringify(config.libraries));\n    }\n});\n\nconst findClassIntercept = JNIInterceptor.attach(\"FindClass\", {\n    onEnter(args: NativeArgumentValue[]) {\n        console.log(\"Find Class called\");\n        args[1] = NULL; // Change the arguments to the FindClass function\n        console.log(\"ThreadId\", this.threadId);\n        console.log(\"Address of FindClass method\", this.jniAddress);\n        this.backtrace.forEach((element: NativePointer) =\u003e {\n            console.log(\"backtrace\", element);\n        });\n    },\n    onLeave(retval: JNINativeReturnValue) {\n        // Change the retval to be returned to the caller of FindClass\n        retval.replace(NULL);\n        // Detach all JNI intercepts\n        JNIInterceptor.detatchAll();\n    }\n});\n\nJNIInterceptor.attach(\"CallDoubleMethodV\", {\n    onLeave(retval : JNINativeReturnValue) {\n        // Log the method params of the Java method the JNI API is calling.\n        // this.javaMethod will only exist if a Java method has been called.\n        console.log(\"Java Method Args\", JSON.stringify(this.javaMethod.params));\n        // Detach from the FindClass intercept\n        findClassIntercept.detach();\n    }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchame1eon%2Fjnitrace-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchame1eon%2Fjnitrace-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchame1eon%2Fjnitrace-engine/lists"}