{"id":8748,"date":"2023-09-27T22:38:17","date_gmt":"2023-09-27T22:38:17","guid":{"rendered":"https:\/\/www.hexacorn.com\/blog\/?p=8748"},"modified":"2023-09-28T10:07:44","modified_gmt":"2023-09-28T10:07:44","slug":"zydisinfo-the-disassembler-that-breaks-the-code-twice","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2023\/09\/27\/zydisinfo-the-disassembler-that-breaks-the-code-twice\/","title":{"rendered":"ZydisInfo &#8211; the disassembler that breaks the code, twice"},"content":{"rendered":"\n<p>The moment I heard of machine code and its opcodes&#8230; I fell in love. Being able to understand machine code from just looking at the binary (okay, mostly its hexadecimal representation) felt like magic. And since many simple x86 assembly instructions are quite easy to decipher, I really liked the fact I could not only &#8216;read some of the code&#8217; by just looking at binary, but also use that knowledge to patch code here and there, too. <\/p>\n\n\n\n<p>Of course, today everyone knows about nopping code with 0x90, or changing the conditional jumps from 0x74, 0x75 to 0xEB, but back then it was something special. Unfortunately, once you learn the basics, this feeling doesn&#8217;t last for too long, because the opcodes got &#8230; complicated, and they did so, pretty quickly, too. The FPU, MMX, SSEn, AVXn instructions are not for the faint-hearted, and it takes a lot effort to understand them on a mathematical level, let alone memorizing their opcodes. And on top of that, the new CPUs arrived, bytecode in many different forms is a thing, and on top of that we have code virtualizers, so now it&#8217;s really prohibitive to even think of learning any of it&#8230; unless you are a dedicated low-level code fan.<\/p>\n\n\n\n<p>Still, even in 2023 it really helps to know some of the most important opcodes, at least in the x86\/x64 world. Malware uses many tricks to obfuscate code, use opcodes to enforce incorrect disassembly, or trigger exceptions on undocumented instructions. Patching is also still a thing, and knowing at least a subset of most popular opcodes helps to quickly understand what is going on. For example, if some random routine is looking for some specific byte values that correspond to known opcodes it&#8217;s really handy to know some of them to quickly make an educated guess that we are looking at some sort of length disassembler, or a hooking\/unhooking routine&#8230;<\/p>\n\n\n\n<p>Let&#8217;s admit it though &#8211; we can&#8217;t learn it all, so, it&#8217;s time to cheat a bit and then hopefully win some&#8230;<\/p>\n\n\n\n<p>Knowing how complicated all of this became, for a long time I dreamed of a tool that takes a series of bytes, interprets it as code, and breaks it down into smaller chunks where the respective parts of the alleged machine instruction are clearly deconstructed, described, and represented; that is, the prefixes, the opcode itself, the operation direction, the size of the argument, the R\/M, MOD, REG, SIB, and IMM and DISP parts, etc. and all are extracted and presented in a nice way to the user&#8230;<\/p>\n\n\n\n<p>And after thinking of it for a long time I only last week <a href=\"https:\/\/x.com\/Hexacorn\/status\/1704521189857640814?s=20\">asked<\/a> about a tool like this&#8230;<\/p>\n\n\n\n<p>Thanks to <a href=\"https:\/\/x.com\/stevemk14ebr\">Steve Eckels<\/a>, we now <a href=\"https:\/\/x.com\/stevemk14ebr\/status\/1706505479780798611?s=20\">know<\/a> that such tool does exist! It&#8217;s called <a href=\"https:\/\/doc.zydis.re\/v2.0.2\/html\/\">Zydisinfo<\/a>, and It was created by <a href=\"https:\/\/twitter.com\/athre0z\">Joel H\u00f6ner<\/a> et al (with Florian Bernd creating most of Zydisinfo, as per this <a href=\"https:\/\/x.com\/athre0z\/status\/1707332881268301929?s=20\">twit<\/a>). <\/p>\n\n\n\n<p>Over last few days I spent some time playing around with Zydisinfo and I am really impressed. This is a fantastic educational tool that many students and assembler lovers will find absolutely delightful to work with.<\/p>\n\n\n\n<p>Let&#8217;s see a few examples:<\/p>\n\n\n\n<p><strong>ZydisInfo -64 &#8220;90&#8221;<\/strong> (NOP)<\/p>\n\n\n\n<p>no surprise here&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo1.png\"><img decoding=\"async\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo1.png\" alt=\"\" class=\"wp-image-8749\" width=\"600\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo1.png 980w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo1-300x122.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo1-768x311.png 768w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo1-500x203.png 500w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/a><\/figure>\n\n\n\n<p><strong>ZydisInfo -64 &#8220;74 01&#8221;<\/strong> (short jump)<\/p>\n\n\n\n<p>no surprise here either&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo2.png\"><img decoding=\"async\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo2.png\" alt=\"\" class=\"wp-image-8750\" width=\"600\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo2.png 987w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo2-300x209.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo2-768x536.png 768w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo2-430x300.png 430w\" sizes=\"(max-width: 987px) 100vw, 987px\" \/><\/a><\/figure>\n\n\n\n<p><strong>ZydisInfo -64 &#8220;67 8B 04 C1&#8221;<\/strong> (mov eax, dword ptr ds:[ecx+eax*8])<\/p>\n\n\n\n<p>a more complicated example and it still works like a charm&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo3.png\"><img decoding=\"async\" loading=\"lazy\" width=\"1006\" height=\"686\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo3.png\" alt=\"\" class=\"wp-image-8751\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo3.png 1006w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo3-300x205.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo3-768x524.png 768w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/09\/zydinfo3-440x300.png 440w\" sizes=\"(max-width: 1006px) 100vw, 1006px\" \/><\/a><\/figure>\n\n\n\n<p>Isn&#8217;t that cool? <\/p>\n\n\n\n<p>Joel et al, you really killed it! Touche!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The moment I heard of machine code and its opcodes&#8230; I fell in love. Being able to understand machine code from just looking at the binary (okay, mostly its hexadecimal representation) felt like magic. And since many simple x86 assembly &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2023\/09\/27\/zydisinfo-the-disassembler-that-breaks-the-code-twice\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[53,16],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8748"}],"collection":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/comments?post=8748"}],"version-history":[{"count":2,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8748\/revisions"}],"predecessor-version":[{"id":8761,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8748\/revisions\/8761"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=8748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=8748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=8748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}