NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Teol on July 25, 2016, 07:26:54 PM
-
Hello,
How can i dissassemble linux program and compile it back again using the disassembled code?
I know i can use ndisasm -b 32 [program] > file ,but the output is such that i cannot compile it back to what it was.
How could i compile it back?
-
Well, you can write yourself a little utility to remove the first 20(?) characters from each line. You might be able to reassemble this. Useless, since you can't modify it at all.
I would suggest you look at Agner Fog's "objconv". Jeff Owens has a utility that will convert to source also. In general, this is not a very practical thing to do. You want a program, write it.
Best,
Frank
-
Good to see you around. :-)
I have nasm installed in Ubuntu.
Will need a lot of help.
Am used to MASM which is GUI.
Every example in the forum yields this message ??
Label or instruction expected at start of line
-
Anyone home ?
-
Seems improbable that "every example" gives that message. What are you doing, exactly?
Best,
Frank
-
; nasm -fwin32 -oWinMain.obj WinMain.asm
; golink /entry start /fo WinMain.exe WinMain.obj kernel32.dll
;
; WinMain.asm
; 06/23/2014
;
; Assembler: NASM version 2.11.05 compiled on May 21 2014
; Linker: GoLink.Exe Version 1.0.0.0
;
; nasm -fwin32 -oWinMain.obj WinMain.asm
; golink /entry start /fo WinMain.exe WinMain.obj kernel32.dll
;
cpu 386
global start
extern GetCommandLineW
extern GetModuleHandleW
extern ExitProcess
[SECTION .code use64]
start:
push 3 ; nCmdShow SW_MAXIMIZE who needs this argument????????
call GetCommandLineW ; win32 API
push eax ; lpCmdLine
xor eax, eax
push eax ; hPrev nobody need this argument.
push eax
call GetModuleHandleW; win32 API
push eax ; hInst
call WinMain ; call WinMain with 4 arguments on the stack
exit:
push eax ; error code
call ExitProcess ; win32 API
; WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
WinMain:
; do some useful things here
xor eax, eax ; return 0, everything went well
ret 16 ; restore the stack, pop 4 arguments
-
Well...
[SECTION .code use64]
seems unlikely to play nicely with "-f win32"! In fact, "use64" may not assemble a "push" of a 32-bit register. Why is that there? ".code" is not one of the "known" section names in "-f win32", but I would not expect that to cause an error.
Given that you're getting errors in other examples(?), it might be a problem with your editor not producing ascii text. I should have thought of that in the first place - some 'doze editors are known to have this issue, but you should be able to tell it to produce ascii. I suggested this on c.l.a.x. the other day. Have you looked into it? (somewhere in the "properties" heirarchy, I suspect?)
Best,
Frank
-
I am using geany as my text editor and I believe it saves as ascii text.
-
I'm not familiar with geany, but I think it should be alright. I pasted your file into Linux and it assembled without a peep for me. (I tried it with -f win64 and it does complain about the 32-bit "push"s but -f win32 is fine) We don't have source code for "golink" so I can't try linking it - wouldn't run anyway. I have no clue what your problem might be. Hope a Windows user comes by and can help you with it.
Best,
Frank
-
Can you direct me to some nasm code that will run on Linux ?
-
That byte editor you were looking at is great! (just type "make") There's lots in the "examples" section (tho some dead links). I've got lots of 32-bit code. Here's something simple to start with...
; nasm -f elf hw2u.asm
; ld -o hw2u hw2u.o -melf_i386
global _start
MAXNAME equ 256
section .text
_start:
nop ; for the debuggers
commence: ; ditto
mov ecx, prompt
mov edx, prompt_len
call write_stdout
mov eax, 3 ; __NR_read
mov ebx, 0 ; stdin
mov ecx, namebuf ; buffer
mov edx, MAXNAME ; maximum to read
int 80h
dec eax ; length returned includes LF we don't want
push eax ; save it for later
mov ecx, greet
mov edx, greet_len
call write_stdout
mov ecx, namebuf
pop edx ; retrieve the length
call write_stdout
mov ecx, coda
mov edx, coda_len
call write_stdout
exit:
mov eax, 1 ; __NR_exit
int 80h
write_stdout:
push ebx
mov eax, 4 ; __NR_write
mov ebx, 1 ; stdout
int 80h
pop ebx
ret
section .data
prompt db "Please tell me your name? "
prompt_len equ $ - prompt
greet db "Hello, "
greet_len equ $ - greet
coda db "! Welcome to Linux Assembly!", 10
coda_len equ $ - coda
section .bss
namebuf resb MAXNAME
What sort of thing are you looking for?
Best,
Frank
-
Thanks.
How do i run hw2u in Linux ?
I am looking for GUI code.
-
You type "./hw2u". Then you type "uhClem" or whatever you claim your name is.
In Windows the GUI is part of the OS. In Linux, it is a separate program which functions as a server. At the lowest level we send it requests to do stuff on-screen through a socket - just as if we were talking to the internet. It is extremely tedious to do anything at this level. Something like "MessageBoxA" would be a big deal. We can use "libX" to take care of some of the housekeeping, but that's still too low-level and "helper" libs are used. "GTK" or so. We can call these libs from assembly, but there is no advantage to doing so. It is just as efficient and probably much easier (depending on your taste) to do it from C or higher. As such, I have very little Linux GUI code to share with you (can find some...). That's the sad story on that...
Best,
Frank
-
You type "./hw2u". Then you type "uhClem" or whatever you claim your name is.
In Windows the GUI is part of the OS. In Linux, it is a separate program which functions as a server. At the lowest level we send it requests to do stuff on-screen through a socket - just as if we were talking to the internet. It is extremely tedious to do anything at this level. Something like "MessageBoxA" would be a big deal. We can use "libX" to take care of some of the housekeeping, but that's still too low-level and "helper" libs are used. "GTK" or so. We can call these libs from assembly, but there is no advantage to doing so. It is just as efficient and probably much easier (depending on your taste) to do it from C or higher. As such, I have very little Linux GUI code to share with you (can find some...). That's the sad story on that...
Best,
Frank
My real name is Andy.
Your example compiled fine and ran.
Many thanks for your help. :-)
-
I am looking for GUI code.
Linux users tend to be more comfortable running programs from the command line than Windows users are. In general, it's an accepted practice to write a command line version of your program, then later on add a graphical wrapper in a scripting language like Python/Tk. That said, if you're determined to write GUI programs you could avoid a lot of the complication by using Gtk's Glade library. The development process with Gtk/Glade is to use the WYSIWYG form developer called GtkBuilder to develop your user interface, then write initialization routines and event handlers in your code. This is about as easy as VB.Net coding for GUI's.
Glade - A user interface designer (https://glade.gnome.org/)
Cross OS App For Linux/Windows Using GTK (http://www.dreamincode.net/forums/topic/292403-nasm-cross-os-app-for-linuxwindows-using-gtk/) <- with NASM
-
Thanks for the info.
-
Thanks.
I am confused by the example in your second link.
It does not use Glade to assemble the example.
Do I need to use wine from DOSBOX or assemble and link from a console ?
make
nasm -f elf cross_os.asm
cross_os.asm:5: error: symbol `gtk_init' undefined
cross_os.asm:8: error: symbol `gtk_builder_new' undefined
cross_os.asm:9: error: symbol `oBuilder' undefined
cross_os.asm:11: error: symbol `NULL' undefined
This is more complicated than running MASM32. :-)
-
Thanks.
I am confused by the example in your second link.
It does not use Glade to assemble the example.
Do I need to use wine from DOSBOX or assemble and link from a console ?
make
nasm -f elf cross_os.asm
cross_os.asm:5: error: symbol `gtk_init' undefined
cross_os.asm:8: error: symbol `gtk_builder_new' undefined
cross_os.asm:9: error: symbol `oBuilder' undefined
cross_os.asm:11: error: symbol `NULL' undefined
This is more complicated than running MASM32. :-)
Those errors are because you don't have a full copy of the source. The author only documented the code sections and left externs, constants, data sections, and the glade file itself in an attachment. Unfortunately, DreamInCode has since deleted the attachment... can't really find another decent example.