26276 total geeks with 3498 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
MaxMouse
It's Friday... That's good enough for me!
CodeX
non stop lolz here but thats soon to end thanks to uni, surely the rest of the world is going good?
stabat
how things are going guys? Here... boring...
CodeX
I must be going wrong on the password lengths then, as long as it was done on ECB
MaxMouse
lol... the key is in hex (MD5: of the string "doit" without the "'s) and is in lower case. Maybe i should have submitted this as a challenge!

Donate
Donate and help us fund new challenges
Donate!
Due Date: May 31
May Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
Google builds
crowdsourcing into
new Maps code stack
Google"s Native
Code browser tech
goes cross-platform
Yahoo! to "share
something special"
in New York on
Monday
Adobe"s Creative
Cloud fails at
being a cloud
NASA signs off on
sampling mission to
Earth-threatening
asteroid
US military
welcomes Apple iOS
6 kit onto its
networks
Jailed Romanian
hacker repents,
invents ATM
security scheme
Climate scientists
agree: Humans cause
global warming
MIT takes
battery-powered
robot cheetah for a
gallop
Google research
chief: "Emergent
artificial
intelligence?
Hogwash!"
Slashdot
NASA
Meteoroid-Spotting
Program Captures
Brightest-Yet Moon
Impact
Password Strength
Testers Work For
Important Accounts
Crowdsourced
Network Planning
For
Connection-Bridging
Startup
Cell Phones As a
Dirty Bomb
Detection Network
Linux Mint 15
"Olivia" Release
Candidate Is Out
Australian
Government Backdoor
Internet Filter
Shuts Down 1,000
Websites
Nintendo Hijacks Ad
Revenue From
Fan-Created YouTube
Playthroughs
9th Grade Science
Experiment: Garden
Cress Won"t
Germinate Near
Routers
Review: Star Trek:
Into Darkness
Congress Demands
Answers From Google
Over Google Glass
Privacy Concerns
Article viewer

Creating a skeleton application in Win32 ASM



Written by:dimport
Published by:sefo
Published on:2003-06-21 07:19:46
Topic:Assembly
Search OSI about Assembly.More articles by dimport.
 viewed 6183 times send this article printer friendly

Digg this!
    Rate this article :
Whilst last time i only showed you how to create a pop up box, today we will go the full hog and create a full window.

To create a window you need to use the RegisterClassEx function which accepts one parameter, a pointer to the WNDCLASSEX struct, which you can find more info here

 
 .386p ; 80386 instruction set.
.model flat, stdcall ; Memory model.
 ; API functions we’ll be using
extrn GetModuleHandle : PROC
extrn RegisterClassExA : PROC
 .DATA
 msg MSG
wc WNDCLASSEX
 ; handles
hMain dd 0 ; handle for the window
hInst dd 0 ; handle to the instance
 ; strings
szProgName db ''An OSI production'',0
szMainClass db ''ASMWINDOW'',0

All pretty self explanatory so far

 .CODE
start:
    call GetModuleHandleA, 0 ; retrieve the Instance handle
    mov hInst, eax ; save ot
     mov [wc.style], CS_HREDRAW + CS_VREDRAW
    mov [wc.lpfnWndProc], offset WndProc
    mov [wc.cbClsExtra], 0
    mov [wc.cbWndExtra], 0
     mov eax, [hInst]
    mov [wc.hInstance], eax
     ; Load the icon for my application
    call LoadIconA, 0, IDI_APPLICATION
    mov [wc.hIcon], eax ; save here
     ; Load the cursor for my application
    call LoadCursorA, 0, IDC_ARROW
    mov [wc.hCursor], eax ;save here
     mov [wc.hbrBackground], COLOR_WINDOW + 1
    mov dword ptr [wc.lpszMenuName], 0
    mov dword ptr [wc.lpszClassName], offset szMainClass
    push offset wc
    call RegisterClassExA

GetModuleHandle() as the comment says, retrieves the handle of our window, this is pretty important, a lot of win32 functions need the handle as a parameter to perform their task, RegisterClassExA() as previously mentioned, is needed to register a window class, once we’ve done this we can use the CreateWindowExA() function to actually create the window, it takes 12 params, MSDN defines it as;

HWND CreateWindowEx(
DWORD dwExStyle,
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);

In ASM this looks like;

             call CreateWindowExA, 0,
                    offset szMainClass,
                    offset szProgName,
                    WS_VISIBLE OR WS_CAPTION OR WS_SYSMENU,
                    100, ;X position
                    50, ;Y position
                
    300, ;width of the window
                    100, ;height of the window
                    0, ;handle to parent''s window if there is one
                    0, ;handle to the window''s menu
                    hInst, ;the instance handle
                    0 ;lparam
            mov hMain, eax ; store the handle

So now we have a window handle (stored in hMain), the window, by default, is hidden, we need to use the ShowWindow() function to make it visible, then the UpdateWindow() function whenever it needs redrawing

call ShowWindow, hMain, SW_SHOWNORMAL
call UpdateWindow, hMain

Now we have a visible, working window, we now need to implement a skeleton message handler for it.

 msg_loop:
        call GetMessageA, offset msg, 0, 0, 0
        cmp ax, 0
        je end_loop
        call TranslateMessage, offset msg
        call DispatchMessageA, offset msg
        jmp msg_loop
end_loop:
        call ExitProcess, 0
 WndProc proc Hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
        movzx eax, WORD PTR wmsg
        .if eax == WM_DESTROY
                jmp wmdestroy
        .else
                call DefWindowProcA, Hwnd, wmsg, wparam, lparam
                jmp @@End
        .endif
                xor eax, eax
        @@End:
                ret
wmdestroy:
        call PostQuitMessage, 0
        xor eax, eax
        ret
WndProc endp

public WndProc
This responds to each message the program gets sent, the DefWindowProcA() function discards anything irrelevant to the program, seeing as this is a skeleton app we only need to deal with the WM_DESTROY message, which is sent when an app is quitting.

This article was originally written by pigsbig78

Did you like this article? There are hundreds more.

Comments:
<none>
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Blogs: (People who have posted blogs on this subject..)
jackier
jackier on Mon 13th Oct 10am
111
sefo
Sneak - encryption on Fri 17th Nov 12pm
I'm developing the win32 version of sneak: http://snarkles.net/scripts/sneak/sneak. php The ASM source code is available on cyberarmy svn (for members only - free) Check the forum for details: http://www.cyberarmy.net/forum/sneak/mes sages/295244.
sefo
Geek Toolbar on Mon 13th Nov 8am
This a very simple and small toolbar I wrote in my spare time. I use the same set of tools very often and I find it very annoying to look for them in the start menu, on the desktop or in explorer. http://www.osix.net/modules/folder/index .php?tid=134
sefo
BinScan and Alternate Data Stream on Thu 27th Jul 9am
BinScan I created this tool to quickly identify modifications in the PE, use of a TLS callback and Alternate Data Streams. -> Some modifications done in the PE structure of an executable can prevent debuggers or other tools to open the executable.
sefo
Wmf Creator on Wed 26th Jul 7am
Now that the blog is online, I'll be able to share two or three tools I wrote. The first one I'd like to share is WMF Creator. I already put a link in the comments of my article: Wmf Exploit but I thought it would look nicer here. This tool will tak

Test Yourself: (why not try testing your skill on this subject? Clicking the link will start the test.)
Reverse Engineering by Geek_Freek

A test to check your assembly and reversing skills.
Assembly Language - non compiler specific by TroPe

You can test your assembly knowledge by taking this test. It starts out relatively easy, but gets progressively hards very quickly! If you know assembly, or just want to see what you DONT know about assembly, this test is for you. A more advanced assembly


     
Your Ad Here
 
Copyright Open Source Institute, 2006