{"id":823,"date":"2018-02-19T10:03:11","date_gmt":"2018-02-19T18:03:11","guid":{"rendered":"https:\/\/www.pnfsoftware.com\/blog\/?p=823"},"modified":"2018-02-19T10:50:42","modified_gmt":"2018-02-19T18:50:42","slug":"dex-version-39-new-dalvik-opcodes","status":"publish","type":"post","link":"https:\/\/www.pnfsoftware.com\/blog\/dex-version-39-new-dalvik-opcodes\/","title":{"rendered":"DEX Version 39, Dalvik and ART Opcode Overlaps, and JEB 2.3.11"},"content":{"rendered":"<p><strong>JEB 2.3.11 is <a href=\"https:\/\/www.pnfsoftware.com\/\">out<\/a> &#8211;<\/strong>\u00a0We&#8217;re getting close to completion on our 2.3 branch! <sup class='footnote'><a href='#fn-823-1' id='fnref-823-1' onclick='return fdfootnote_show(823)'>1<\/a><\/sup><\/p>\n<p>Before we get into the matter of this blog post, a couple of\u00a0noteworthy changes in terms of licensing:<\/p>\n<ul>\n<li>The Android Basic builds require an active Internet connection; however, <strong>if the JEB license is current, we allow a much longer grace period<\/strong> before requesting a connection with our licensing server. This is to take care of scenarios where the connectivity would drop for a relatively extended period of time on either end.<\/li>\n<li>Most interestingly, <strong>expired licenses of all types may now be used past their expiration date to reload and work on existing JDB2<\/strong>. New projects cannot be created with expired licenses though.<\/li>\n<\/ul>\n<p>In terms of features, JEB 2.3.11 includes upgrades to our ARM64, MIPS64 and x86-64 parsers <sup class='footnote'><a href='#fn-823-2' id='fnref-823-2' onclick='return fdfootnote_show(823)'>2<\/a><\/sup>, as well as fixes and additions to the DEX parser. One interesting update, which prompted writing this blog post, is the support of DEX 39 opcodes.<\/p>\n<h2>DEX 39 Opcodes<\/h2>\n<p>Here they are, per <a href=\"https:\/\/source.android.com\/devices\/tech\/dalvik\/dalvik-bytecode\">the official documentation<\/a>:<\/p>\n<ul>\n<li><strong>const-method-handle<\/strong> vAA, method_handle@BBBB<\/li>\n<li><strong>const-method-type<\/strong> vAA, proto@BBBB<\/li>\n<\/ul>\n<p>Version 39 of the DEX format will be supported with the release of Android P <sup class='footnote'><a href='#fn-823-3' id='fnref-823-3' onclick='return fdfootnote_show(823)'>3<\/a><\/sup>. DEX 38 had been introduced to support Oreo&#8217;s new opcodes related to dynamic programming. We wrote <a href=\"https:\/\/www.pnfsoftware.com\/blog\/android-o-and-dex-version-38-new-dalvik-opcodes-to-support-dynamic-invocation\/\">a lengthy post about them on this very blog<\/a>.<\/p>\n<p>The new instructions\u00a0<em>const-method-handle<\/em> and <em>const-method-types<\/em> are natural additions to retrieve method handles (basically, the same as a function pointer in C, a concept foreign to the JVM until lambdas and functional-style programming made its way into the language) and method prototypes. Those opcodes simply query into the prototypes and handles pools.<\/p>\n<p>In fact, support for those two opcodes was added in JEB months ago,\u00a0 right after their introduction in ART, which dates back to September 2017 (<a href=\"https:\/\/android.googlesource.com\/platform\/art\/+\/2e59994c3c586d8b753e4b14a94c81bce3dba1a9\">AOSP commit<\/a>). Now, if you&#8217;ve been following through the Dalvik, DEX and ART intricacies, you may know that we are facing opcode overlaps:<\/p>\n<ul>\n<li>The original non-optimized DEX instruction set spans from 0 to 0xFF, with undefined ranges (inclusive brackets omitted for clarity): 3E-43, 73, 79-7A, E3-FF\n<ul>\n<li>DEX 38 defines the range FA-FD (4x new invoke-xxx)<\/li>\n<li>DEX 39 defines the range FE-FE for the aforementioned new opcodes (2x new const-method-xxx)<\/li>\n<\/ul>\n<\/li>\n<li>The now defunct optimized DEX (ODEX) set, predating ART, used the reserved sub-range E3-FE<\/li>\n<li>The deadborn extended set used FF as an extension code to address 2-byte opcodes (FFxx); they were defined but unimplemented in Ice Cream Sandwich, and removed soon after in Jelly Bean.<\/li>\n<li>Finally, ART opcodes: also used for optimizing DEX execution, those opcodes use the 73 and E3-FF ranges<\/li>\n<\/ul>\n<p>ART opcodes in E3-FE are not necessarily the same as the original ODEX&#8217;s! The following table recaps the differences between ODEX and OART:<\/p>\n<figure style=\"width: 873px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/docs.google.com\/spreadsheets\/d\/1TNDVE57PtosvRw7gvPosdHXRu5PPFTt22YWKdJu-nV4\/\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2018\/02\/2d06b5ebd502de076490342b566f4c4b.png\" alt=\"\" width=\"873\" height=\"726\" \/><\/a><figcaption class=\"wp-caption-text\">legend: red= removed in ART, orange= moved, green= added in ART<\/figcaption><\/figure>\n<p>When you feed a piece of optimized DEX file to JEB, it may not know which instruction set to use. Normally, the following rules apply:<\/p>\n<ul>\n<li>For stand-alone (within or outside an APK) DEX files advertising a version code less than or equal to 37, the legacy ODEX set would be used if any opcodes within that range are encountered;<\/li>\n<li>For DEX files with version 38 or above, or that are part of an OAT ELF file, the newer ART set will be used.<\/li>\n<\/ul>\n<p>However, if the determination is incorrect (eg, you are opening a stand-alone DEX 37 file using ART opcodes), you may manually specify which optimized opcodes set the Dalvik parser should use by opening the project&#8217;s settings (<em>Edit\/Options, Advanced&#8230;<\/em>), and setting the property\u00a0<strong>DalvikParserMode<\/strong>\u00a0<sup class='footnote'><a href='#fn-823-4' id='fnref-823-4' onclick='return fdfootnote_show(823)'>4<\/a><\/sup> to:<\/p>\n<ul>\n<li>0: legacy DEX (default value)<\/li>\n<li>50: ART<\/li>\n<li>100: DEX 38<\/li>\n<li>110: DEX 39<\/li>\n<li>1000: latest<\/li>\n<\/ul>\n<p>That&#8217;s it for today&#8217;s DEX clarifications. Remember to upgrade to JEB 2.3.11. On a side-note, let us know if you&#8217;d like to be part of our group of early testers: those users receive beta builds ahead of time (eg, JEB 2.3.12-beta this week).<\/p>\n<p>Thank you.<\/p>\n<p>&#8212;<\/p>\n<div class='footnotes' id='footnotes-823'>\n<div class='footnotedivider'><\/div>\n<ol>\n<li id='fn-823-1'> A couple more updates are in the pipe before we start publishing betas of JEB 3. <span class='footnotereverse'><a href='#fnref-823-1'>&#8617;<\/a><\/span><\/li>\n<li id='fn-823-2'> The x86 modules now support the newest AVX-512 instruction set, although we do not decompile it <span class='footnotereverse'><a href='#fnref-823-2'>&#8617;<\/a><\/span><\/li>\n<li id='fn-823-3'> Per Google&#8217;s habits, we may expect a beta of Android P with API level 28 this Spring <span class='footnotereverse'><a href='#fnref-823-3'>&#8617;<\/a><\/span><\/li>\n<li id='fn-823-4'> That property is not as accessible as we&#8217;d like; an upcoming update will clarify and improve the UX around that. <span class='footnotereverse'><a href='#fnref-823-4'>&#8617;<\/a><\/span><\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>JEB 2.3.11 is out &#8211;\u00a0We&#8217;re getting close to completion on our 2.3 branch! 1 Before we get into the matter of this blog post, a couple of\u00a0noteworthy changes in terms of licensing: The Android Basic builds require an active Internet connection; however, if the JEB license is current, we allow a much longer grace period &hellip; <a href=\"https:\/\/www.pnfsoftware.com\/blog\/dex-version-39-new-dalvik-opcodes\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">DEX Version 39, Dalvik and ART Opcode Overlaps, and JEB 2.3.11<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,8],"tags":[],"class_list":["post-823","post","type-post","status-publish","format-standard","hentry","category-android","category-jeb2"],"_links":{"self":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts\/823","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/comments?post=823"}],"version-history":[{"count":0,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts\/823\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/media?parent=823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/categories?post=823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/tags?post=823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}