Creating a Console Mode Messagebox with Newt and Gas In assembly

Wednesday, December 28 2005 @ 02:13 PM CET

Contributed by: stingduk

Level : newbie

OS : linux
Language : asm

i was wanting to test my invoke macro a little further
for those who arent aware take a look at my earlier articles
about using gas with intel sysntax and also using masm like
invoke style

so what better way than to program a simple message box in assembly
exactly like iczelions starter tutorial :)

so to do console user interfaces some libraries are available
like ncurses ,newt,cdk, etc

i experimented with ncurses and found it to be too longwinded
it has subroutines where we have to assemble every part and make a 1000 line
code to make a simple message box

rant against ncurses skip the paragraph to get to the point directly
to expand what i said above
first you need to know what is the size of the terminal
viz how many lines how many cols
then you have to know what is the size of string you have
then you have to decide what would be the size of your message box
then depending upon your size of message box you have to calculate
where you have to move your cursor for dispalying the message box
once you have done that then you have to code to place the
title,text ,button etc within the above message box
then you have to code a callback routine that waits for button press
and then clear the window and reset the terminal
well that kinda sucks for a newbie tutorial
especially who habitually gone through
invoke MessageBoxA,NULL,offset Title,Offset Text,NULL
invoke ExitProcess masm code
to create a simple Message box()

some rant about cdk (curses development kit)

i also tried mike glovers cdk (curses development kit ) but since it basically sits
above ncurses i found it to be too drab and colour less
he himself hasnt coded a single window sample with background color
in his example codes which is what i was really aiming to see
rant end here

i chose newt because it lives upto its name nifty erik's windowing tool

so now its enough introduction lets get to the code

copy paste the code below as messagebox.s

.intel_syntax noprefix   
.include "macro.mac"  
.data
title: .asciz "Sample Window\n"
buttontext: .asciz "OK\n"
instext:  .asciz  "linux asm is great\n"

.text

.global start
start:
        invoke newtInit
        invoke newtWinMessage,"offset title","offset buttontext","offset instext"
        invoke newtFinished
        invoke exit ,1

assemble and link with the commandline below

as -o messagebox.o messagebox.s
ld -o messagebox messagebox.o -s -defsym _start=start 
--dynamic-linker=/lib/ld-linux.so.2 /usr/lib/libc.so /usr/lib/libnewt.so

well thats all lets run it and see the out put : oops we need visual isnt it :)
below is a screen shot

the source is attached here

thanks to Detten for taking time to install newt and newt devel that wasnt
installed by default on his server
thanks to you all for reading through to here

stingduk

0 comments



http://www.reversing.be/article.php?story=2005122814133523