flat assembler
Message board for the users of flat assembler.

Index > Windows > Step_2_Fasm

Author
Thread Post new topic Reply to topic
F9



Joined: 29 Sep 2006
Posts: 17
F9 04 Oct 2006, 06:00
About me: I am new to FASM. I have use MASM in my spare time over the pass year plus. Other than that I never tried anything else since I got interested in programming for Windows for my own personal use. Compaq (Intel P3) . Reading doc's all over the web don't really sink in unless you got time to assemble and test everything as you go. It do make you think. Now i want to start over again and write a useful program and i want to do it Steping_with_Fasm.

Problem 1: Last week when I finally came and join FASM board. I read thru tons of old threads to get some understanding, came back and got locked on this one. http://board.flatassembler.net/topic.php?t=5616 . Writing from ground up (PE) would be where I want to start with FASM. There is much much more that sold me to start using FASM but this took the cake.

Since than I been including various code to make FASM assemble a real window (wc) with this template and had no luck to date. I even threw in the kitchen sink, curse my dog and was late for work two days in one week. (Could not sleep) I tried everything...

Does anyone have an example of displaying a real window using this template or similar?
Post 04 Oct 2006, 06:00
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 04 Oct 2006, 06:28
i suggest you to first write normal PE file that creates real window (you have something like that in examples).

And before you will try PE from scratch, you must understand how it works - this is not thing to begin with
Post 04 Oct 2006, 06:28
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
F9



Joined: 29 Sep 2006
Posts: 17
F9 04 Oct 2006, 10:26
Thanks for the reply vid but advice is not what's is needed here. I don't like asking for help. I try hard on my own and seek help if I cannot figure things out. How would you feel if someone seems to end your thread with unneeded advice. I did not say I know absolutely nothing about programming for windows or the PE format.

There is a few things I have to understand when writing a program with FASM simply because it does thing differently, but when it comes down to it, it is an assembler just like MASM. Because MASM cannot assembler that PE program, says a lot for FASM and my new founded interest in it.

I got lots of questions about FASM standard PE format, but right now I read hoping to find answers instead of wasting server space.

I have written hundreds of small programs with MASM just behind following examples and have a decent understanding of how things works.

As far as PE from scratch, the author of the template wrote the book already for us to use. Not many knew it was even possible with FASM or anything else . I tried something in the pass with MASM but gave up.

A real window with a simple button is all i need to get started and i can figure the rest out from there. As I said I tried on my own ?
Post 04 Oct 2006, 10:26
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 04 Oct 2006, 10:33
do you consider MessageBox a real window? Smile

i bet nobody was doing this.. there just in 99.9% cases isn't reason to do manually something that computer can do for you
Post 04 Oct 2006, 10:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
F9



Joined: 29 Sep 2006
Posts: 17
F9 04 Oct 2006, 11:28
Viv

I do everything possible manually just for the know-how and to say i can see and understand what makes something work.

Out of 60 millions programmers in the world there may be under 500 fools like us using 100% assembler. Out that 500 at lease 25% wonder about or tinker with the PE format. We live for speed and to save a byte or two. That's all it's all about. Just search other forum and see for yourself.

Message and Dialog boxes are subsystem windows. If you don't know how or even care just give someone else a chance to post an answer or pitch a bi#ch. If you are trying to discourage me and my thread you are doing a darn good job my friend.
Post 04 Oct 2006, 11:28
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 04 Oct 2006, 12:33
and how many of those 125 programmers who tinkered with PE from scratch did exactly window template? You want one very specific thing which probably wasn't done by anyone yet, and you do not accept more general advice.

maybe you can post your code that is not working and we can find error there.
Post 04 Oct 2006, 12:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20295
Location: In your JS exploiting you and your system
revolution 04 Oct 2006, 12:59
F9: write a video driver using your manual PE. That way you can put anything you want on the screen. Otherwise under the windows OS you are forced to use API calls to do the video rendering. It is a ring0/ring3 thing that will prevent you having direct access to any hardware. I hope I am understanding your question correctly.

vid was trying to be helpful and I think your response was not called for. Try to benefit from the advice of expereinced people like vid, it will serve you well in the long term, don't discount it as discouragement. We all have to start with crawling before we can run.
Post 04 Oct 2006, 12:59
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 04 Oct 2006, 13:07
but you can import APIs in manual PE...
Post 04 Oct 2006, 13:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl 04 Oct 2006, 13:38
F9: check out my recent post here (smallest flexible PE)
Post 04 Oct 2006, 13:38
View user's profile Send private message Reply with quote
F9



Joined: 29 Sep 2006
Posts: 17
F9 04 Oct 2006, 22:58
Quote:
write a video driver using your manual PE. That way you can put anything you want on the screen. Otherwise under the windows OS you are forced to use API calls to do the video rendering.


I did'nt know that. Btw: the manual PE does not belong to me.

Your up to date facts on the subject is all I was fishing for Thanks revolution now I see things a little more clearer.

Quote:
vid was trying to be helpful and I think your response was not called for.


I know that. But he did crack on me about the word *real* that he even used himself before the crack. As far as advice not needed right now ... it's was the truth. I think he's a good person. He has thick skin. He must be a male. We are all Psychiatrists when the sh#t hit the fan and will do battle..
No way would I say Thank you, I"ll do that, have a great day... bye bye raw PE ...

Quote:
check out my recent post here (smallest flexible PE)


Never saw these threads. I did not search properly or got distracted a few days ago. I did see the one about HTML, JAVA and COM files done in Fasm raw PE. So when i posted I did expect bad news which is better than no news at all. Stupit me, I came along thinking I struck gold so I'm bashing myself Sad

Thanks karl ... now I will read the pe.pdf again but more thoroughly. It's all make so much more since when you finally see example and the writers discussing it as you read thru those once confusing documentation. I could not do it but I will learn quicker now.

Quote:
.. probably wasn't done by anyone yet,


On that note viv, now i can move on to FASM PE and study raw PE in my spare time ... As you know I like the hard way (doing things manually) Alway have...

I forgot to mention one of the main reasons I'm checking out FASM... I think I read on the download page somewhere that once you write code for Windows it's not hard to make it work for other OS. And as far as doing things manually, I never want my program to be dependent on one assembler only. Just like what FASM do for other OS I try to keep my code in focus of other Assemblers also.

Bouncing back and forth as I see fit makes you see a lot of things that can shock you at times. What one won't do the other will, so i change my code to meet both standards when possible.

There will always be room to use those fancy FASM macros and MASM inc files only after the bulk of the program stay simple and comply with RAW fasm and masm with the slightest of modification. Everything else stays small and will get linked. Hope I am painting a clear enough picture of what I am trying to do.

OK, I want to use the PUSH directive and not the Invoke macro or stdcall in the code below. It will crash after closing the program on XP Pro no service pack. I get the Contact Bill Message.

How do I do this and why is Push allowed under procedures and not at the beginning of the code section during Window creation ? ? ? Check out comma meted lines...


Code:
;===========================================================================================
; Button_2.asm  Fasm Flat assembler
; Boutons: bitmap/icones
; Programmé par AsmGges France
;===========================================================================================

format PE GUI 4.0
entry start

  include 'include/win32a.inc'
  include 'include/macro\if.inc'

  FLOODFILLSURFACE = 01h

section '.code' code readable executable

start:
:############################################## PUSH  Don't work  INVOKE WILL
:############################################## PUSH  Don't work  INVOKE WILL
:############################################## PUSH  Don't work  INVOKE WILL

    invoke GetModuleHandle,0

;PUSH 0
;CALL GetModuleHandle
    mov [wc.hInstance],eax

:##############################################
:##############################################
:##############################################

    invoke LoadIcon,[wc.hInstance],ID_FRANCE
    mov [wc.hIcon],eax

    invoke LoadCursor,0,IDC_ARROW
    mov [wc.hCursor],eax

    invoke GetSystemMetrics,SM_CXSCREEN
    sub eax,[WinW]
    shr eax,1
    mov [WinX],eax

    invoke GetSystemMetrics,SM_CYSCREEN
    sub eax,[WinH]
    shr eax,1
    mov [WinY],eax
    sub [WinY],130

    invoke RegisterClass,wc

    invoke CreateWindowEx,WS_EX_LEFT,ClassName,Titre,WS_OVERLAPPED+WS_SYSMENU,\
                          [WinX],[WinY],[WinW],[WinH],0,0,[wc.hInstance],0
    mov [hWnd],eax

 
    invoke ShowWindow,[hWnd],SW_SHOWDEFAULT
    invoke UpdateWindow,[hWnd]

 MessageLoop:
    invoke GetMessage,msg,0,0,0
    or eax,eax
    jz ExitProgram

    invoke TranslateMessage,msg

    invoke DispatchMessage,msg

    jmp MessageLoop

 ExitProgram:

    invoke ExitProcess,[msg.wParam]


proc WindowProc uses ebx esi edi, @hWnd, @uMsg, @wParam, @lParam

    .if [@uMsg] = WM_CLOSE
        invoke MessageBox,[@hWnd],MsgEnd,ClassName,MB_OK+MB_ICONINFORMATION

        invoke PostQuitMessage,0

    .elseif [@uMsg] = WM_COMMAND
        .if [@wParam] = BN_CLICKED shl 16+ID_BUTTON_ICON1
            invoke MessageBox,[@hWnd],icoMsg1,ClassName,MB_OK

        .elseif [@wParam] = BN_CLICKED shl 16+ID_BUTTON_ICON2
            invoke MessageBox,[@hWnd],icoMsg2,ClassName,MB_OK

        .elseif [@wParam] = BN_CLICKED shl 16+ID_BUTTON_BMP1
            invoke MessageBox,[@hWnd],bmpMsg1,ClassName,MB_OK

        .elseif [@wParam] = BN_CLICKED shl 16+ID_BUTTON_BMP2
            invoke MessageBox,[@hWnd],bmpMsg2,ClassName,MB_OK

        .endif

    .elseif [@uMsg] = WM_CREATE
        stdcall DrawButton,[@hWnd],20,20,36,36,ID_BUTTON_ICON1,BS_ICON
        mov [hWndBtn1],eax

        invoke LoadIcon,[wc.hInstance],ID_ICON1

        invoke SendMessage,[hWndBtn1],BM_SETIMAGE,1,eax

        stdcall DrawButton,[@hWnd],20,70,36,36,ID_BUTTON_ICON2,BS_ICON
        mov [hWndBtn2],eax

        invoke SetWindowLong,[hWndBtn2],GWL_WNDPROC,BtnProc
        mov [lpBtnProc],eax

        invoke LoadIcon,[wc.hInstance],ID_ICON1

        invoke SendMessage,[hWndBtn2],BM_SETIMAGE,1,eax

        invoke LoadBitmap,[wc.hInstance],ID_BMP1
        mov [hBmp1],eax
:############################################### A-OK
:############################################### A-OK
:############################################### A-OK
PUSH [hBmp1]
CALL SetBmpColor

;       stdcall SetBmpColor,[hBmp1]
;       mov [hBmp1],eax
:##############################################
:##############################################
:##############################################

        invoke LoadBitmap,[wc.hInstance],ID_BMP2
        mov [hBmp2],eax

        stdcall SetBmpColor,[hBmp2]
        mov [hBmp2],eax

        stdcall DrawButton,[@hWnd],120,20,100,36,ID_BUTTON_BMP1,BS_BITMAP
        mov [hWndBtn3],eax

        invoke SendMessage,[hWndBtn3],BM_SETIMAGE,0,[hBmp1]

        stdcall DrawButton,[@hWnd],120,70,100,36,ID_BUTTON_BMP2,BS_BITMAP
        mov [hWndBtn4],eax

        invoke SendMessage,[hWndBtn4],BM_SETIMAGE,0,[hBmp1]

        invoke SetWindowLong,[hWndBtn4],GWL_WNDPROC,bmpProc
        mov [lpfnbmpProc], eax

    .elseif [@uMsg] = WM_PAINT
        invoke BeginPaint,[@hWnd],ps
        mov [ps.hdc],eax

        stdcall PaintProc,[@hWnd],[ps.hdc]

        invoke EndPaint,[@hWnd],ps

    .else

        invoke DefWindowProc,[@hWnd],[@uMsg],[@wParam],[@lParam]
        ret

    .endif

    mov eax,0
    ret
endp

;===========================================================================================
proc PaintProc @hWnd, @hDC
    local .btn_hi:DWORD, .btn_lo:DWORD

    invoke GetSysColor,COLOR_BTNHIGHLIGHT
    mov [.btn_hi],eax

    invoke GetSysColor,COLOR_BTNSHADOW
    mov [.btn_lo],eax

    mov eax,0
    ret
endp

;===========================================================================================
proc BtnProc @hCtl, @uMsg, @wParam, @lParam

    .if [@uMsg] = WM_LBUTTONDOWN | [@uMsg] = WM_KEYDOWN
        invoke LoadIcon,[wc.hInstance],ID_ICON2
        invoke SendMessage,[hWndBtn2],BM_SETIMAGE,1,eax

    .elseif [@uMsg] = WM_LBUTTONUP | [@uMsg] = WM_KEYUP
        invoke LoadIcon,[wc.hInstance],ID_ICON1
        invoke SendMessage,[hWndBtn2],BM_SETIMAGE,1,eax

    .endif

    invoke CallWindowProc,[lpBtnProc],[@hCtl],[@uMsg],[@wParam],[@lParam]

    ret
endp

;===========================================================================================
proc bmpProc @hCtl, @uMsg, @wParam, @lParam

    .if [@uMsg] = WM_LBUTTONDOWN | [@uMsg] = WM_KEYDOWN
        invoke SendMessage,[hWndBtn4],BM_SETIMAGE,0,[hBmp2]

    .elseif [@uMsg] = WM_LBUTTONUP | [@uMsg] = WM_KEYUP
        invoke SendMessage,[hWndBtn4],BM_SETIMAGE,0,[hBmp1]

    .endif

    invoke CallWindowProc,[lpfnbmpProc],[@hCtl],[@uMsg],[@wParam],[@lParam]

    ret
endp


proc DrawButton @hParent, @X, @Y, @wX, @hY, @Id, @ButtonStyle

    mov eax,WS_CHILD+WS_VISIBLE
    add eax,[@ButtonStyle]
    invoke CreateWindowEx,0,Button,noTitre,eax,[@X],[@Y],[@wX],[@hY],\
                                [@hParent],[@Id],[wc.hInstance],NULL
    ret
endp


proc SetBmpColor @hBitmap
    local .hMemDC:DWORD, .hBrush:DWORD, .hOldBmp:DWORD, .hReturn:DWORD, .hOldBrush:DWORD

    invoke CreateCompatibleDC,NULL
    mov [.hMemDC],eax

    invoke SelectObject,[.hMemDC],[@hBitmap]
    mov [.hOldBmp],eax

    invoke GetSysColor,COLOR_BTNFACE
    invoke CreateSolidBrush,eax
    mov [.hBrush],eax

    invoke SelectObject,[.hMemDC],[.hBrush]
    mov [.hOldBrush],eax

    invoke GetPixel,[.hMemDC],1,1
    invoke ExtFloodFill,[.hMemDC],1,1,eax,FLOODFILLSURFACE

    invoke SelectObject,[.hMemDC],[.hOldBrush]
    invoke DeleteObject,[.hBrush]

    invoke SelectObject,[.hMemDC],[@hBitmap]
    mov [.hReturn],eax

    invoke DeleteDC,[.hMemDC]

    mov eax,[.hReturn]

    ret
endp


section '.data' data readable writeable

  Titre       db ' Boutons: Bitmap / Icône ',0
  ClassName   db ' AsmGges Win32',0
  MsgEnd      db ' AsmGges France @2006  ',0
  Button      db 'BUTTON',0
  noTitre     db '',0

  icoMsg1     db 'Bouton: 1 icône ',0
  icoMsg2     db 'Bouton: 2 icônes ',0
  bmpMsg1     db 'Bouton: 1 bitmap ',0
  bmpMsg2     db 'Bouton: 2 Bitmap ',0
  align 4

  WinX        dd 0
  WinY        dd 0
  WinW        dd 248
  WinH        dd 156

  hWnd        dd ?
  hWndBtn1    dd ?
  hWndBtn2    dd ?
  hWndBtn3    dd ?
  hWndBtn4    dd ?
  hBmp1       dd ?
  hBmp2       dd ?
  lpBtnProc   dd ?
  lpfnbmpProc dd ?

  wc          WNDCLASS  0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,0,ClassName
  msg         MSG
  ps          PAINTSTRUCT


section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
            user32,'USER32.DLL',\
             gdi32,'GDI32.DLL'

  ; -------------------------------
  include 'include/apia\kernel32.inc'
  include 'include/apia\user32.inc'
  include 'include/apia\gdi32.inc'


section '.rsrc' resource data readable

  directory RT_ICON,icons,\
            RT_GROUP_ICON,group_icons,\
            RT_BITMAP,appBmp

  ID_FRANCE = 1
  ID_ICON1  = 2
  ID_ICON2  = 3
  ID_BMP1   = 10
 ID_BMP2   = 11

  ID_BUTTON_ICON1 = 400
  ID_BUTTON_ICON2 = 401
  ID_BUTTON_BMP1  = 402
  ID_BUTTON_BMP2  = 403

  resource icons,\
           1,LANG_NEUTRAL,france_data,\
           2,LANG_NEUTRAL,icon1_data,\
           3,LANG_NEUTRAL,icon2_data

  resource group_icons,\
           ID_FRANCE,LANG_NEUTRAL,france,\
           ID_ICON1, LANG_NEUTRAL,icon1,\
           ID_ICON2, LANG_NEUTRAL,icon2
  resource appBmp,\
           ID_BMP1,LANG_NEUTRAL,bmp1,\
           ID_BMP2,LANG_NEUTRAL,bmp2

  icon france,france_data,'res\france.ico'
  icon icon1, icon1_data, 'res\icon1.ico'
  icon icon2, icon2_data, 'res\icon2.ico'

  bitmap bmp1,'res\bmp1.bmp'
  bitmap bmp2,'res\bmp2.bmp'
    


I'll keep it short next time around

Thanks you ALL
Post 04 Oct 2006, 22:58
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 05 Oct 2006, 07:39
Quote:
On that note viv

it would be nice to have at least some respect and don't mistype nicks on purpose. I am not calling you F8, too Laughing

Quote:
I forgot to mention one of the main reasons I'm checking out FASM... I think I read on the download page somewhere that once you write code for Windows it's not hard to make it work for other OS. And as far as doing things manually, I never want my program to be dependent on one assembler only. Just like what FASM do for other OS I try to keep my code in focus of other Assemblers also.

maintainig platform-independent code inside PE-from-scratch is much harder than inside simple PE

Quote:
OK, I want to use the PUSH directive...

note: push is instruction, not directive. see http://board.flatassembler.net/topic.php?t=4740

Quote:
How do I do this and why is Push allowed under procedures and not at the beginning of the code section during Window creation ? ? ? Check out comma meted lines...

push is allowed everywhere, if it crashes, then it's because you are not using it properly. And, by the way, it's not PUSH that crashes, it's CALL

Maybe you got mislead by using MASM invoke, which beheaves differently than FASM's. again, see http://flatassembler.net/docs.php?article=win32#1.3
Post 05 Oct 2006, 07:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
F9



Joined: 29 Sep 2006
Posts: 17
F9 05 Oct 2006, 09:20
Quote:
it would be nice to have at least some respect and don't mistype nicks on purpose. I am not calling you F8, too

F8 -- LOL: Sorry about that vid. I would never do things like that on purpose.

Quote:
maintainig platform-independent code inside PE-from-scratch is much harder than inside simple PE

I thought it would be if i ever was to get to that point. Just got overly enthused seeing something like manual PE working for first time.

I would not risk that anyway. I'm trying something new that FASM all really possible. It be insane for someone like me to make it more difficult for myself. I enjoy coding but im not crazy yet...

Thanks for the info about my problem. I going read those threads and my fasm.pdf . I'll have things running in a few hours or days with more understanding of what's going on.

Thanks vid

Glad your not mad at me and sorry if i seemed to come off as mean.
Post 05 Oct 2006, 09:20
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 05 Oct 2006, 11:17
well... your problem was you was doing "call MessageBoxA" instead of "call [MessageBoxA]". But you should understand why this is a problem and why [] is needed, if you want to go "from scratch". That's why i discouraged you to go on with such advanced thing
Post 05 Oct 2006, 11:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
F9



Joined: 29 Sep 2006
Posts: 17
F9 07 Oct 2006, 06:36
I understand. I should have studied a little more other than just going gun-ho about something i was not really clear about.

Anyway, I'm going with dialog boxes. I should be able to make it work. I'm reading the doc's and trying things as I go.

Thank vid
Post 07 Oct 2006, 06:36
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 07 Oct 2006, 07:15
no problem
Post 07 Oct 2006, 07:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.