In my specific case, I want to use it to dump what I echo
.
I don't want to involve any file...
Is there a way to make objdump
read from STDIN
instead?
4 Answers
You can't. There is no way around that, you will have to use the temporary file.
Source file readelf.c has this unconditional check (in binutils 2.22-8 at least) before even attempting to open the file:
if (! S_ISREG (statbuf.st_mode))
{
error (_("'%s' is not an ordinary file\n"), file_name);
return 1;
}
So if the file is anything but regular file (like symlink, or char device as in case of /dev/stdin
, /proc/self/fd/*
, etc.) it won't work.
Alternatively, you could modify the source and use modified objdump, but there goes your portability.
- 2,409
- 23
- 37
you can always do
objdump -d /dev/stdin < t2.o
or
cat t2.o | objdump -d /dev/stdin
sample
[root@myhost cc]# objdump -h /dev/stdin < t2.o
/dev/stdin: file format elf64-x86-64
Sections: Idx Name Size VMA LMA
File off Algn 0 .group 00000008 0000000000000000 0000000000000000 00000040 2**2 CONTENTS, READONLY, EXCLUDE, GROUP, LINK_ONCE_DISCARD
- 1,663
- 8
- 8
-
1`cat t2.o | objdump -d /dev/stdin` does not work. `/dev/stdin` only works when it corresponds to a real file. Since your solution requires the presence of that file, this does not answer the OP. – dragonroot Nov 09 '12 at 05:04
-
This may work for this invocation of `objdump` in particular, but it might fail for others in case it does `seek` operations on the file. When tools don't have `-` for stdin, that is often the case. – Ciro Santilli OurBigBook.com Aug 28 '15 at 09:18
I used ndisasm -b 64 -
as a workaround.
e.g. I wanted:
echo 41 89 1b | xxd -r -p | objdump -d -
But the above doesn't work. This does work though:
echo 41 89 1b | xxd -r -p | ndisasm -b 64 -
- 1
- 1
-
I bit more of explanation would be great to understand what are you doing – djdomi Jul 22 '21 at 05:24
A kind of workaround is using tee
. So to disassemble a file named input
use
cat input | tee a.out | objdump -d
And, to give an example for passing some bytes with the echo
command, the following should be a good example (The parameters are described in this good SO answer):
To disassemble the x86 code byte sequence
b8 01 00 00 00 bb 0a 00 00 00 cd 80
prefix it with 0:
and use the command
echo "0: b8 01 00 00 00 bb 0a 00 00 00 cd 80" | xxd -r | tee a.out | objdump -D -Mintel,i386 -b binary -m i386
Its output is:
a.out: file format binary
Disassembly of section .data:
00000000 <.data>:
0: b8 01 00 00 00 mov eax,0x1
5: bb 0a 00 00 00 mov ebx,0xa
a: cd 80 int 0x80
which is just the assembly code for exiting an i386 linux program with the exit code 0xA.
- 101
- 4