aboutsummaryrefslogtreecommitdiffhomepage
path: root/binary/objdump.html
diff options
context:
space:
mode:
Diffstat (limited to 'binary/objdump.html')
-rw-r--r--binary/objdump.html33
1 files changed, 33 insertions, 0 deletions
diff --git a/binary/objdump.html b/binary/objdump.html
index e61f55a..e97b853 100644
--- a/binary/objdump.html
+++ b/binary/objdump.html
@@ -158,6 +158,39 @@
<p>For example <code>.plt</code> section:</p>
<pre><code class="language-markdown"> objdump -j .plt -d &lt;elf&gt;
</code></pre>
+<h2 id="example-disassemble-raw-binary"><a class="header" href="#example-disassemble-raw-binary">Example: disassemble raw binary</a></h2>
+<p>This can be helpful for example as a cheap analysis tool when toying with JIT
+generating code. We could just write thee binary code buffer to a file and
+disassemble with <code>objdump</code>.</p>
+<p>To re-create that case, we just assemble and link some ELF file and then create
+a raw binary of the text section with <code>objcopy</code>.</p>
+<pre><code class="language-x86asm"># file: test.s
+.section .text, &quot;ax&quot;
+
+.global _start
+_start:
+ xor %rax, %rax
+ mov $0x8, %rax
+1:
+ cmp $0, %rax
+ je 2f
+ dec %rax
+ jmp 1b
+2:
+ # x86-64 exit(2) syscall
+ mov $0, %rdi
+ mov $60, %rax
+ syscall
+</code></pre>
+<pre><code class="language-bash"># Assemble &amp; link.
+as -o test.o test.s
+ld -o test test.o testc.o
+# ELF -&gt; binary (only take .text section).
+objcopy -O binary --only-section .text test test-bin
+
+# Disassemble raw binary.
+objdump -D -b binary -m i386:x86-64 test-bin
+</code></pre>
</main>