{"action":"created","issue":{"url":"https://api.github.com/repos/frida/frida-java/issues/63","repository_url":"https://api.github.com/repos/frida/frida-java","labels_url":"https://api.github.com/repos/frida/frida-java/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/frida/frida-java/issues/63/comments","events_url":"https://api.github.com/repos/frida/frida-java/issues/63/events","html_url":"https://github.com/frida/frida-java/issues/63","id":303458432,"number":63,"title":"Hook System.loadLibrary","user":{"login":"awakened1712","id":628212,"avatar_url":"https://avatars3.githubusercontent.com/u/628212?v=4","gravatar_id":"","url":"https://api.github.com/users/awakened1712","html_url":"https://github.com/awakened1712","followers_url":"https://api.github.com/users/awakened1712/followers","following_url":"https://api.github.com/users/awakened1712/following{/other_user}","gists_url":"https://api.github.com/users/awakened1712/gists{/gist_id}","starred_url":"https://api.github.com/users/awakened1712/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awakened1712/subscriptions","organizations_url":"https://api.github.com/users/awakened1712/orgs","repos_url":"https://api.github.com/users/awakened1712/repos","events_url":"https://api.github.com/users/awakened1712/events{/privacy}","received_events_url":"https://api.github.com/users/awakened1712/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2018-03-08T12:11:05Z","updated_at":"2018-04-26T12:49:47Z","closed_at":"2018-03-13T12:36:53Z","author_association":"NONE","body":"I have the below code to hook System.loadLibrary()\r\n```javascript\r\nvar System = Java.use.('java.lang.System');\r\nSystem.loadLibrary.implementation = function(name) {\r\n    console.log(\"System.loadLibrary \" + name); // it is ok until this point\r\n    this.loadLibrary(name);\r\n    console.log(\"loadLibrary\"); // <== this does not get printed out\r\n    // code to hook \r\n};\r\n```\r\nI want to hook some C native function after the library is loaded. So I must have some code after the original loadLibrary is called. However, as can be seen from my snippet, codes starting from `console.log(\"loadLibrary\"); ` does not get executed.\r\n\r\nDid I do anything wrong?"},"comment":{"url":"https://api.github.com/repos/frida/frida-java/issues/comments/384629231","html_url":"https://github.com/frida/frida-java/issues/63#issuecomment-384629231","issue_url":"https://api.github.com/repos/frida/frida-java/issues/63","id":384629231,"user":{"login":"jeanbmar","id":12987993,"avatar_url":"https://avatars2.githubusercontent.com/u/12987993?v=4","gravatar_id":"","url":"https://api.github.com/users/jeanbmar","html_url":"https://github.com/jeanbmar","followers_url":"https://api.github.com/users/jeanbmar/followers","following_url":"https://api.github.com/users/jeanbmar/following{/other_user}","gists_url":"https://api.github.com/users/jeanbmar/gists{/gist_id}","starred_url":"https://api.github.com/users/jeanbmar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeanbmar/subscriptions","organizations_url":"https://api.github.com/users/jeanbmar/orgs","repos_url":"https://api.github.com/users/jeanbmar/repos","events_url":"https://api.github.com/users/jeanbmar/events{/privacy}","received_events_url":"https://api.github.com/users/jeanbmar/received_events","type":"User","site_admin":false},"created_at":"2018-04-26T12:49:47Z","updated_at":"2018-04-26T12:49:47Z","author_association":"NONE","body":"You can actually hook System.loadLibrary doing this:\r\n```\r\nJava.perform(function() {\r\n    const SystemDef = Java.use('java.lang.System');\r\n    const RuntimeDef = Java.use('java.lang.Runtime');\r\n    const SystemLoad_2 = SystemDef.loadLibrary.overload('java.lang.String');\r\n    const VMStackDef = Java.use('dalvik.system.VMStack');\r\n\r\n    SystemLoad_2.implementation = function(library) {\r\n        send(\"Loading dynamic library => \" + library);\r\n        try {\r\n            let loaded = RuntimeDef.getRuntime().loadLibrary0(VMStackDef.getCallingClassLoader(), library);\r\n            if(library === 'myLib') {\r\n                //do my stuff\r\n            }\r\n            return loaded;\r\n        } catch(ex) {\r\n            console.log(ex);\r\n        }\r\n    };\r\n});\r\n```\r\n"}}
{"actor":{"display_login":"jeanbmar"}}