Re: Disassembler questions
- From: "Benjamin David Lunt" <spamtrap@xxxxxxxxxx>
- Date: Sat, 26 Jul 2008 12:58:07 -0700
"thiesd" <spamtrap@xxxxxxxxxx> wrote in message
news:g6fn9h$f6o$1@xxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,
I have been recently trying to see how some simple c programs translate
into assembly but my efforts have led to endless segfaults after
reassembling them
so i started with a simple hello world program
int main(){
printf("Hello, World!\n");
}
which to my surprise "ndisasm -b 32" returned a asm file that was 30000+
lines long
Depending on the compiler, it will most likely add all of the startup code,
including the PE header (for Windows), etc. Also, see below for more.
so i thought hmm that wasn't right
so i did the simple hello world with nasm
section .data
msg db "Hello, World!","$"
len equ $ - msg
section .code
global _start
_start:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 21h
mov eax,1
mov ebx,0
int 21h
The code looks like Linux, but the int 21h looks like DOS.
I haven't done any Linux programming, so I may be wrong here,
but shouldn't the int 21h be int 80h?
also returned code with several thousands of line (mostly 'add [eax], al')
If you will notice, the binary form for add [eax],al is 00 00.
Most likely, nasm is adding padding to the end of the section. I don't
know much about nasm, but this would be my guess. Now, if a section
is 4096 bytes, and it takes 2 bytes per add [eax],al, then you would
have 2048 lines. Not several thousand, but a couple thousand non the less.
any way i was wondering if there was a disassembler that if you reassemble
it it works like the first program
A disassembler simply takes the binary bytes and translates them
to the corresponding mnemonics. It doesn't know the difference between
data or code.
a few debuggers that do a better job, but the better the job, the moreFrom your post, I get that you want a "smart" disassembler. There are
expensive the tool.
also i get stuff that doesn't work right like 'loopne 0x154f38'
What is wrong with loopne 0x154f38 ?
It is the same as loopnz 0x154f38, which loops if the zero flag
is clear and ecx != 0.
i also tried udis but that worked less than ndisasm
I have never tried udis, so I have no comment here. Maybe someone
else has and can comment.
Ben
.
- References:
- Disassembler questions
- From: thiesd
- Disassembler questions
- Prev by Date: Re: Problem Linking (win32)
- Next by Date: Re: Disassembler questions
- Previous by thread: Disassembler questions
- Next by thread: Re: Disassembler questions
- Index(es):
Relevant Pages
|