{"id":901,"date":"2018-10-08T09:45:30","date_gmt":"2018-10-08T17:45:30","guid":{"rendered":"https:\/\/www.pnfsoftware.com\/blog\/?p=901"},"modified":"2018-10-08T09:45:30","modified_gmt":"2018-10-08T17:45:30","slug":"android-ndk-libraries-signatures","status":"publish","type":"post","link":"https:\/\/www.pnfsoftware.com\/blog\/android-ndk-libraries-signatures\/","title":{"rendered":"Android NDK Libraries Signatures"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In this blog post, we present a new batch of native signatures released with JEB3 to identify Android <a href=\"https:\/\/developer.android.com\/ndk\/\">Native Development Kit (NDK)<\/a> libraries. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">First, let\u2019s briefly give some context. The Android NDK is a set of tools allowing developers to embed compiled C\/C++ code into their Android applications. Thus, developers can integrate existing native code libraries, develop performance-sensitive code in C\/C++ or obfuscate algorithms with native code protectors.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In practice, native code within Android applications comes in the form of ELF shared libraries (\u201c.so\u201d); the native methods can then be called from Java using Java Native Interface (JNI), which we described in a <a href=\"https:\/\/www.pnfsoftware.com\/blog\/dynamic-jni-detection-plugin\/\">previous blog post<\/a>.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">NDK Pre-Built Libraries<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Android NDK provides some <\/span><i><span style=\"font-weight: 400;\">pre-built<\/span><\/i><span style=\"font-weight: 400;\"> libraries that can be linked against. For example, there are several C++ Standard Template Library (STL) <sup class='footnote'><a href='#fn-901-1' id='fnref-901-1' onclick='return fdfootnote_show(901)'>1<\/a><\/sup> , or the <a href=\"http:\/\/www.zlib.net\/manual.html\">Zlib decompression library<\/a>.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As an example, let\u2019s compile a &#8220;hello world&#8221; Android NDK C++ library with NDK r17. By default, the C++ implementation will be <em>gnustl<\/em> &#8212; the default choice before NDK r18. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here is the C++ code:<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2018\/10\/56fca739f9c82d70a610e80d7b4a9870.png\" \/><\/p>\n<p>When compiled with Android Studio&#8217;s default settings, libraries are linked <i>dynamically<\/i>, and <em>libgnustl_shared.so<\/em>\u00a0is directly included in the application &#8212; because it is not a system library &#8211;, for each supported Application Binary Interface (ABI).<\/p>\n<figure style=\"width: 214px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2018\/10\/abcba6dbd963c489ee4cb1e1502dbfb3.png\" alt=\"\" width=\"214\" height=\"345\" \/><figcaption class=\"wp-caption-text\">Files hierarchy of the Android application containing our &#8220;hello world&#8221; native library<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">If we open the ARM library we can pretty easily understand the &#8212; already convoluted &#8212; logic of our &#8220;hello world&#8221; routine, thanks to the names of gnustl external API calls:<\/span><\/p>\n<figure style=\"width: 1018px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2018\/10\/ddf4a5e7f84ba75a04f4edb768f63ef5.png\" alt=\"\" width=\"1018\" height=\"815\" \/><figcaption class=\"wp-caption-text\">Control-flow graph of ARM &#8220;hello world&#8221; with gnustl dynamically linked. Note that JEB displays mangled names when API calls correspond to external routines.<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">Now, Android NDK also provides <\/span><i><span style=\"font-weight: 400;\">static<\/span><\/i><span style=\"font-weight: 400;\"> versions for most of the pre-built libraries. A developer &#8212; especially a malware developer wishing to hinder analysis &#8212; might prefer to use those. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">When compiled in static mode, gnustl library is now \u2018included\u2019 in our native library, and here is our &#8220;hello world&#8221; routine:<\/span><\/p>\n<figure style=\"width: 898px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2018\/10\/6d649faee14a9d17f681f762d24b69b3.png\" alt=\"\" width=\"898\" height=\"818\" \/><figcaption class=\"wp-caption-text\">Control-flow graph of ARM &#8220;hello world&#8221; with gnustl statically linked. Subroutines bear no specific names.<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">In this case, the analysis will be slowed down by the numerous routine calls with no specific names; each of this subroutine will need to be looked at to understand the whole purpose. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">This brings us to a common reverse-engineering problem: is there a way to automatically identify and rename static library code, such that the analyst can focus on the application code?<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">JEB3 NDK Signatures<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">That&#8217;s when JEB native signatures come to the rescue! Indeed JEB3 now provides signatures<\/span>\u00a0for the following Android NDK\u00a0 static libraries:<\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">gnustl<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">libc++<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">STLport<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">libc<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">libmath<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">zlib<\/span><\/li>\n<\/ul>\n<p>We provide signatures for ARM\/ARM64 ABIs (including all variants like arm-v7a, arm-v7a-hard, thumb or ARM mode, etc) of these libraries, from NDK r10 to NDK r18.<\/p>\n<p><span style=\"font-weight: 400;\">These signatures are built in a similar fashion to our x86\/x64 Visual Studio native signatures, and are intended to be \u201cfalse-positive free\u201d, which means a match should be blindly trustable. Note that <a href=\"https:\/\/www.pnfsoftware.com\/blog\/jeb3-auto-signing-mode\/\">JEB users can create their own signatures directly from the UI<\/a>.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So, within JEB, if we open our statically-linked library with the signatures loaded, gnustl library routines are identified and renamed:<\/span><\/p>\n<figure style=\"width: 913px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2018\/10\/31c46fabeff7a9c82647d4f93799be77.png\" alt=\"\" width=\"913\" height=\"817\" \/><figcaption class=\"wp-caption-text\">Control-flow graph of ARM &#8220;hello world&#8221; with gnustl statically linked and NDK signatures loaded. Subroutines have been renamed.<\/figcaption><\/figure>\n<p><em><span style=\"font-weight: 400;\">Note: the attentive reader might have noticed some \u201cunk_lib_subX\u201d routines in the previous image. Those names correspond to cases where several library routines match the routine. The user can then see the conflicting names in the target routine and use the most suitable one.<\/span><\/em><\/p>\n<p><span style=\"font-weight: 400;\">Due to the continuous evolution of compilers and libraries, it is not an easy task to provide up-to-date and useful signatures, but we hope this first NDK release will help our users. Nevertheless, more libraries should certainly be signed in the future, and we encourage users to comment on that\u00a0 (<a href=\"mailto:support@pnfsoftware.com\">email<\/a>, <a href=\"https:\/\/twitter.com\/jebdec\">Twitter<\/a>, <a href=\"https:\/\/jebdecompiler.slack.com\">Slack<\/a>).<\/span><\/p>\n<div class='footnotes' id='footnotes-901'>\n<div class='footnotedivider'><\/div>\n<ol>\n<li id='fn-901-1'>\u00a0NDK C++ support is a turbulent story, to say the least. Historically, different implementations of C++ have been provided with the NDK (gnustl, STLport, libc++,&#8230;), each of them coming with a different set of features (exceptions handling, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Run-time_type_information\">RTTI<\/a>\u2026). Since the very recent r18 version (released in september 2018)\u00a0<a href=\"https:\/\/github.com\/android-ndk\/ndk\/wiki\/Changelog-r18\">Android developers must now use only libc++<\/a><i>.<\/i> <span class='footnotereverse'><a href='#fnref-901-1'>&#8617;<\/a><\/span><\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post, we present a new batch of native signatures released with JEB3 to identify Android Native Development Kit (NDK) libraries. First, let\u2019s briefly give some context. The Android NDK is a set of tools allowing developers to embed compiled C\/C++ code into their Android applications. Thus, developers can integrate existing native code &hellip; <a href=\"https:\/\/www.pnfsoftware.com\/blog\/android-ndk-libraries-signatures\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Android NDK Libraries Signatures<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,13],"tags":[],"class_list":["post-901","post","type-post","status-publish","format-standard","hentry","category-jeb3","category-native-code"],"_links":{"self":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts\/901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/comments?post=901"}],"version-history":[{"count":0,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts\/901\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/media?parent=901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/categories?post=901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/tags?post=901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}