flat assembler
Message board for the users of flat assembler.

Index > Main > The examples section

Goto page 1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 13 Dec 2006, 12:09
As you all know, the official examples section of this website is terribly under-developed, though it already contains some nice sources.
At the same time some people may wonder why I haven't put some of the programs there, even though they were posted on board with such purpose in mind. The fact is: I just haven't found a time to prepare them to fulfill a set of rules I try to apply to all the packages I put there.

Thus, if anyone would like to share some program this way, I here give a set of rules/hints how the package should be prepared - if they're followed, the package will be put into Examples page as soon as possible.


  • The preferred format is a .zip archive for DOS/Windows/OSdev examples, and .tar.gz for Linux/Unix.
  • The package should contain all the sources but also the executable. The documentation is optional.
  • The name of author should be noted somewhere - in the documentation, if packages has one, or in the comment in the beginning of main source file
  • The sources should assemble correctly with the latest version of fasm. If you use any includes or macros other than the standard headers, please put all those includes into package. If you use standard headers, assume that the INCLUDE variable is set up, don't use absolute paths or other environment variables.
  • It's good when program is commented, but this is not a required condition. Use any formatting you wish - it may be good to show in the examples a wide range of possible programming styles.
  • When posting an example package, please provide a short description explaining what it demonstrates, and also an author name (see the already existing entries for a hint how it may look like).


Also if you notice any such problems with the examples already available in that section, please let me know.
Post 13 Dec 2006, 12:09
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 13 Dec 2006, 12:11
I also noticed another problem in the fact, that it is not clear from looking at the page in what operating systems some of the packages work. Perhaps I should divide examples into a categories?
Post 13 Dec 2006, 12:11
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 13 Dec 2006, 12:31
until we have enough examples, it's enough to mention OS in description.
Post 13 Dec 2006, 12:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 13 Dec 2006, 13:45
hi tomasz, i would like to add this example of creating custom windows and buttons

ps. there are you can find code to draw masked bitmaps
ps. rgn-file can be created with this utility http://www.codeproject.com/gdi/rgncreator.asp


Description:
Download
Filename: gg.rar
Filesize: 4.99 KB
Downloaded: 808 Time(s)


_________________
[not enough memory]
Post 13 Dec 2006, 13:45
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 13 Dec 2006, 13:46
Really, please follow my guidelines when preparing a package.
Post 13 Dec 2006, 13:46
View user's profile Send private message Visit poster's website Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf 13 Dec 2006, 13:56
Rules Broken Vasilev: Very Happy

-The package should contain all the sources but also the executable. The documentation is optional.

-The name of author should be noted somewhere - in the documentation, if packages has one, or in the comment in the beginning of main source file

-The sources should assemble correctly with the latest version of fasm. If you use any includes or macros other than the standard headers, please put all those includes into package. If you use standard headers, assume that the INCLUDE variable is set up, don't use absolute paths or other environment variables. (%fasminc% used not %include%)

-When posting an example package, please provide a short description explaining what it demonstrates, and also an author name (see the already existing entries for a hint how it may look like).

4/6 broken, only because 1 rule was optional lol (and you didn't comment)

I can only guess that Vasilev was making a package to show us how to make a wrong package! Very Happy

Cheers LOL, good laugh Smile

_________________
Raedwulf
Post 13 Dec 2006, 13:56
View user's profile Send private message MSN Messenger Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf 13 Dec 2006, 13:58
At least you didn't try and make an arj, zoo, ace, arc, lha package format!
Post 13 Dec 2006, 13:58
View user's profile Send private message MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 13 Dec 2006, 14:05
Raedwulf wrote:
(%fasminc% used not %include%)

You don't use INCLUDE variable this way (especially since it may contain more than one path), see the existing examples.
Post 13 Dec 2006, 14:05
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 13 Dec 2006, 14:59
Code:
        invoke  CreateRoundRectRgn,\
                0,\             ;// x-coordinate of the region's upper-left corner
                0,\             ;// y-coordinate of the region's upper-left corner
                WND_WIDTH,\     ;// x-coordinate of the region's lower-right corner
                WND_HEIGHT,\    ;// y-coordinate of the region's lower-right corner
                9,\             ;// height of ellipse for rounded corners
                9               ;// width of ellipse for rounded corners
        mov     edi, eax
        invoke  CreateRectRgn,\
                0,\              ;// x-coordinate of region's upper-left corner
                WND_HEIGHT/2,\   ;// y-coordinate of region's upper-left corner
                WND_WIDTH-1,\    ;// x-coordinate of region's lower-right corner ***
                WND_HEIGHT       ;// y-coordinate of region's lower-right corner
        ;*** I don't know why I have to use WND_WIDTH-1 but if I use just WND_WIDTH the window is one pixel wider in the lower half
        push    eax              ;*** PARAM FOR DELETEOBJECT!!
        invoke  CombineRgn,\
                edi,\            ;// handle to destination region
                edi,\            ;// handle to source region
                eax,\            ;// handle to source region
                RGN_OR           ;// region combining mode
        call   [DeleteObject]    


This chunk creates a GoogleTalk like region.
Post 13 Dec 2006, 14:59
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 13 Dec 2006, 16:40
Here is a Windows hooking (detouring) example with FASM. This example is very heavily commented, I also kept the source nice and aligned. It writes a detour to MessageBoxA with an insert_detour function I wrote. It shows maybe opcode modification during run-time and hooking an API for whatever reason. I remember looking for this way back in the day on the MASM forums and couldn't find any examples so I had to teach myself. I am very excited to be able to contribute to FASM.

Edit: Updated with disassembly after hook is inserted, added Windows 2000 compatibility.


Description:
Download
Filename: detour_example.zip
Filesize: 3.32 KB
Downloaded: 766 Time(s)


_________________
redghost.ca


Last edited by RedGhost on 14 Dec 2006, 05:38; edited 1 time in total
Post 13 Dec 2006, 16:40
View user's profile Send private message AIM Address MSN Messenger Reply with quote
MichaelH



Joined: 03 May 2005
Posts: 402
MichaelH 14 Dec 2006, 00:09
RedGhost, detour_example.exe crashes with access violations at both calls -

call [MessageBoxA]
call [oMessageBoxA]

on my winXP.

Edit:

After some more playing around with this example it appears it works fine on a freshly installed winXP with SP2.

The winXP it crashes on has no SP...... Hmmmmmm?


Last edited by MichaelH on 14 Dec 2006, 01:59; edited 1 time in total
Post 14 Dec 2006, 00:09
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 14 Dec 2006, 01:17
crashed on server 2003 no SP
Post 14 Dec 2006, 01:17
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 14 Dec 2006, 02:12
I have XP SP2 so it worked as with you. Do me a favour and post the disassembly of MessageBoxA from the non-service packed versions. It's possible the first $5 bytes are not identical, this is why I use an LDE (Reverend's or virxasm), but not for a basic example. The only two possibilities are A) Instruction corruption with MessageBoxA not having a perfect $5 bytes to hook, or B) VirtualProtectEx incompatibilities.

Edit: My suspicion was right, there is no "mov edi, edi", I am updating for compatibility with the other OS I was able to test (Win2000 SP4).
Edit: Updated first post.

_________________
redghost.ca
Post 14 Dec 2006, 02:12
View user's profile Send private message AIM Address MSN Messenger Reply with quote
arafel



Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
arafel 14 Dec 2006, 16:11
Hi,

Here is an example of USB devices enumeration. This is a port of a C example from the Windows DDK. (made it a while ago mostly as an exercise while studding the FASM syntax...) Not a well commented. But the main part responsible for enumeration is identical to the C version from the DDK, which is fully commented, so it can be looked up for a more detailed description of the process. Rolling Eyes


Description: USB devices enumeration example
Download
Filename: usbenum.zip
Filesize: 10.53 KB
Downloaded: 713 Time(s)

Post 14 Dec 2006, 16:11
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Dec 2006, 17:40
arafael: nice example. I thought of commenting it, but first i would need to understand it Very Happy

there is one problem though - it uses "WriteConsole" to write to stdout. This doesn't work with redirected output.

I believe we should spend some work on examples to make them all of some quality - not to teach newbies bad practices
Post 14 Dec 2006, 17:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Dec 2006, 18:04
Here is my try. It should be example of multiplatform 32bit programming with libc. However i didn't manage to link this 32bit object file on my 64bit linux, and i even don't know which is 32bit libc object file on gentoo.

Someone please try to link this on linux, and provide me binary and description how to link, i will finish this example.

I also plan to make same example for FASMLIB, and for 64bit code with libc.


Description:
Download
Filename: flibc.zip
Filesize: 31.6 KB
Downloaded: 622 Time(s)



Last edited by vid on 14 Dec 2006, 18:48; edited 1 time in total
Post 14 Dec 2006, 18:04
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
arafel



Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
arafel 14 Dec 2006, 18:26
vid wrote:
there is one problem though - it uses "WriteConsole" to write to stdout. This doesn't work with redirected output.

I believe we should spend some work on examples to make them all of some quality - not to teach newbies bad practices


Bad practice would be not freeing allocated resources or neglecting error checking.. WriteConsole does exactly what it is supposed to do - display the output. In the given context the support for alterative output method is not really the essence of the example. Smile

But I guess, it could be changed to WriteFile if it brings some inconvenience.
Post 14 Dec 2006, 18:26
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Dec 2006, 18:48
arafael: It does. When you run the program from GUI environment (not from console), window closes immediately as the program ends. Typical solution is to redirect to file "usbenum >abc.txt". This causes WriteConsole to return error, this error is unchecked, and so program just continues running. Really not a best way to do it.

I think it really should be changed to WriteFile.

arafael: could you please try to link my example on linux?
Post 14 Dec 2006, 18:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
arafel



Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
arafel 14 Dec 2006, 20:09
There was a slight issue with names decoration.
Here is a linked binnary.


Description:
Download
Filename: flibc.zip
Filesize: 32.29 KB
Downloaded: 612 Time(s)

Post 14 Dec 2006, 20:09
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Dec 2006, 21:23
thanks, i will repost it complete soon.

unfortunatelly, i am not sure if accessing "errno" can be done in portable way, without some "get_errno" macro Sad
Post 14 Dec 2006, 21:23
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:  
Goto page 1, 2, 3, 4  Next

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.