A Simple Window in Console Mode

Friday, December 30 2005 @ 04:53 PM CET

Contributed by: stingduk

Level : newbie

OS : linux
Language : asm

in the last article Creating MessageBox in console mode it was a static in the
sense we couldnt move it around and it didnt have an interactiveness

lets see how we can create a small window and move it around the screen

you would need libnewt installed to assemble and link this code


.intel_syntax noprefix
.include "macro.mac"

.data
title:		 .asciz "Sample Window"
roottext:	 .asciz "Hit UP,DOWN,LEFT,RIGHT keys to move the window HIT DEL key to close and quit"

.bss
.lcomm keypressed,4
.lcomm upkey,4
.lcomm leftkey,4

.text
.global start

start:
	invoke newtInit
	invoke newtCls 
	mov dword ptr ds:[leftkey],11
	mov dword ptr ds:[upkey],11
	invoke newtOpenWindow,leftkey,upkey,50,10,"offset title"
	invoke newtDrawRootText,0,0,"offset roottext"
	invoke newtRefresh
loop_start:
	invoke newtGetKey
	mov keypressed,eax

keyup:
	cmp dword ptr ds:[keypressed], 0x8001
	jne keydown
	dec dword ptr ds:[upkey]
	invoke move_window
	jmp loop_start
keydown:
	cmp dword ptr ds:[keypressed], 0x8002
	jne keyleft
	inc dword ptr ds:[upkey]
	invoke move_window
	jmp loop_start
keyleft:
        cmp dword ptr ds:[keypressed],0x8004
	jne keyright
	dec dword ptr ds:[leftkey]
	invoke move_window
	jmp loop_start
keyright:
        cmp dword ptr ds:[keypressed],0x8005
	jne close_wind
	inc dword ptr ds:[leftkey]
	invoke move_window
	jmp loop_start
close_wind:
	cmp dword ptr ds:[keypressed],0x8007
	jne loop_start
	invoke newtFinished
	invoke exit ,1
move_window:
	invoke newtPopWindow
        invoke newtOpenWindow,leftkey,upkey,50,10,"offset title"
        invoke newtRefresh
	ret


assemble and link with

as -o simpwind.o simpwind.s 
ld -o simpwind simpwind.o -s -defsym _start=start 
--dynamic-linker=/lib/ld-linux.so.2 /usr/lib/libc.so /usr/lib/libnewt.so
source and precompiled binary attached
simpwind.tar.gz thanks to all of you
stingduk

0 comments



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