Re: Disassembler questions



thiesd wrote:
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
so i thought hmm that wasn't right

:)

Linked with the "--static" switch? Well, anyway, there's a lot of "cruft" in a C-generated file (IME). Giving ndisasm a long and complicated command line may help (RTFM)... "gcc -S" or "objdump -s" may produce more useful results (although not in Nasm syntax).

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

Say what???

mov eax,1
mov ebx,0
int 21h

I suppose this is a "posto", and the real file is int 80h? If not... I have *no* idea! :)

also returned code with several thousands of line (mostly 'add [eax], al')

Lots of zero-padding... (giving ld the "-s" switch, or better yet, "strip -R.comment myfile" will help some)

any way i was wondering if there was a disassembler that if you reassemble
it it works like the first program

Try Jeff Owens' "asmsrc":

http://linuxasmtools.net/

No promises - a "perfect" disassembly (of "any arbitrary file") is theoretically "impossible", but at least "asmsrc" is intended to do what you want. It *does* work (imperfectly) on your example file (with the int 21h's "promoted" to int 80h)...

;Input file: hw.src

(no, Jeff, the input file was "hw", *this* file is "hw.src"... Close enough for asm :)

;Dynamic Libraries found: no
;Lib startup code wrapper found: no
;Symbol table found: yes
;Debug symbols found: no

;static load file
; Compile with: nasm -felf xxxx.asm -o xxxx.o
; ld xxxx.o -o xxxx
; (xxxx = filename)


global _start

[section .text]
_start:
mov eax,04H
mov ebx,01H
mov ecx,msg
mov edx,0DH
int byte 080H
mov eax,01H
int byte 080H
msg:
dec eax
db "ello, world"
db 00Ah


Dunno where the "dec eax" came from - asmsrc *does* seem to understand that it's doing data (my error - I put "msg in .text - works right with it in .data)... Works as intended anyway. Good Luck!!!

Best,
Frank

.



Relevant Pages