{"id":839,"date":"2011-08-09T21:07:27","date_gmt":"2011-08-09T19:07:27","guid":{"rendered":"http:\/\/cerezo.name\/blog\/?p=839"},"modified":"2024-10-14T14:13:52","modified_gmt":"2024-10-14T12:13:52","slug":"obfuscating-android-c-native-code","status":"publish","type":"post","link":"http:\/\/cerezo.name\/blog\/2011\/08\/09\/obfuscating-android-c-native-code\/","title":{"rendered":"Obfuscating Android C Native Code"},"content":{"rendered":"<p style=\"text-align: justify;\">I\u2019ve got way too many emails from this blog, but one has found my attention: a reader has emailed me asking for advice on Android Native Code obfuscation, in the same line of <a href=\"http:\/\/cerezo.name\/blog\/2011\/03\/03\/iphone-decompilation-obfuscation\/\" target=\"_blank\" rel=\"noopener\">previous<\/a> <a href=\"http:\/\/cerezo.name\/blog\/2011\/03\/23\/android-decompilation-obfuscation\/\" target=\"_blank\" rel=\"noopener\">posts<\/a>. It\u2019s pretty clear that <a href=\"http:\/\/proguard.sourceforge.net\" target=\"_blank\" rel=\"noopener\" class=\"broken_link\">ProGuard<\/a> it\u2019s an excellent solution for the main language of the Android platform, Java, but there is no clear alternative for native development in C\/C++ with <span class=\"caps\">ARM<\/span> binaries.<\/p>\n<p style=\"text-align: justify;\">The best way to frame this question is to start defining what would be the preferred tools to decompile\/disassemble the binary code by Mallory, our evil cracker. Many tools have existed over the years to decompile C code (<a href=\"http:\/\/www.backerstreet.com\/rec\/rec.htm\" target=\"_blank\" rel=\"noopener\"><span class=\"caps\">REC<\/span><\/a>, <a href=\"https:\/\/web.archive.org\/web\/20131209235003\/http:\/\/itee.uq.edu.au\/~cristina\/dcc.html\" target=\"_blank\" rel=\"noopener\"><span class=\"caps\">DCC<\/span><\/a>), <a href=\"http:\/\/www.hex-rays.com\" target=\"_blank\" rel=\"noopener\">Hex-Rays<\/a> being the latest and most powerful one ever, so it would be the first in her tool chest. Fixed the chosen scalpel, the most effective countermeasure against that, and any decompiler, is <a href=\"http:\/\/asm.sourceforge.net\/articles\/smc.html\" target=\"_blank\" rel=\"noopener\" class=\"broken_link\">self-modifying<\/a>\/<a href=\"http:\/\/cs.ecs.baylor.edu\/~maurer\/Metamorphic\" target=\"_blank\" rel=\"noopener\">metamorphic<\/a> code, since it breaks their over-reliance on static binary analysis. But the downside of it being that it\u2019s very difficult to create good, reliable self-modifying\/metamorphic code, especially in these times in which almost everyone abhors assembly programming, so protecting most parts of the binary and decrypting them at program load time it\u2019s a realistic substitute, much like <a href=\"http:\/\/upx.sourceforge.net\/\" target=\"_blank\" rel=\"noopener\" class=\"broken_link\"><span class=\"caps\">UPX<\/span><\/a> does (but no, it\u2019s no protection at&nbsp;all).<\/p>\n<p style=\"text-align: justify;\">Most people would recommend following the conventional route of code obfuscation (<a href=\"http:\/\/www.pcsentinelsoftware.com\/products\/mangleit\/mangler_cpp_new_proj.htm\" target=\"_blank\" rel=\"noopener\">Mangle-It<\/a>, <a href=\"http:\/\/freshmeat.net\/projects\/cxx-obfus\" target=\"_blank\" rel=\"noopener\" class=\"broken_link\">Stunnix C\/C++ Obfuscator<\/a>, <a href=\"http:\/\/www.plexaure.de\/cms\/index.php?id=cobf\" target=\"_blank\" rel=\"noopener\"><span class=\"caps\">COBF<\/span><\/a>, <a href=\"http:\/\/www.semdesigns.com\/Products\/Obfuscators\/index.html\" target=\"_blank\" rel=\"noopener\" class=\"broken_link\">Thicket<\/a>), but there also are some very creative approaches, vg: use the <span class=\"caps\">LLVM<\/span> compiler infrastructure with the C back-end to produce an intermediate C representation, to be recompiled with gcc; or my favorite one, try to use a virtual machine like <a href=\"http:\/\/oreans.com\/\" target=\"_blank\" rel=\"noopener\">Oreans<\/a> or <a href=\"http:\/\/www.python.org\" target=\"_blank\" rel=\"noopener\">Python<\/a> for the most critical parts of the program.<\/p>\n<p style=\"text-align: justify;\">For the sake of completeness, there has also been some very interesting papers on cryptographically-aided obfuscation, my favourite being the following one:<\/p>\n<p style=\"text-align: justify;\">\n<\/p><div class=\"gde-error\"><span class=\"caps\">GDE<\/span> Error: Error retrieving file \u2014 if necessary turn off error checking (404:Not Found)<\/div>\n\n<p style=\"text-align: justify;\">And remember, enabling full compiler optimizations will always help!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve got way too many emails from this blog, but one has found my attention: a reader has emailed me asking for advice on Android Native Code obfuscation, in the same line of previous posts. It\u2019s pretty clear that ProGuard it\u2019s an excellent solution for the main language of the Android platform, Java, but&nbsp;there&nbsp;[\u2026]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wp_typography_post_enhancements_disabled":false,"ngg_post_thumbnail":0},"categories":[12,6],"tags":[],"_links":{"self":[{"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/posts\/839"}],"collection":[{"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/comments?post=839"}],"version-history":[{"count":6,"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/posts\/839\/revisions"}],"predecessor-version":[{"id":1631,"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/posts\/839\/revisions\/1631"}],"wp:attachment":[{"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/media?parent=839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/categories?post=839"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cerezo.name\/blog\/wp-json\/wp\/v2\/tags?post=839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}