flat assembler
Message board for the users of flat assembler.

Index > Windows > API problems in FASM (n00be)

Author
Thread Post new topic Reply to topic
Stcherbatchenko



Joined: 20 Apr 2004
Posts: 13
Stcherbatchenko
hey everyone firdt i would like to thank tomasz for creating FASM (keep up the good work) first am new to asm read alot about it but still got problems anyway i searched for some examples in FASM but didnt find any if anyone can help it would be really appreciaited so what i want is some examples of varioous API used in FASM just eome examples so i can read them and understand them nothing complicated and any other usefull examples too thanks anyway and please try to help Smile
Post 20 Apr 2004, 11:18
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
You can download FASMW package. It come with very handy editor and some base Windows examples. After that you can search the board for posts of Imagineer - He post Iczelion's tutorials, translated to FASM syntax.

Regards.
Post 20 Apr 2004, 11:38
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Stcherbatchenko



Joined: 20 Apr 2004
Posts: 13
Stcherbatchenko
actually i read alot about it actually i know abuot asm but i wanted to get some specific samples that will help me alot if you have any please let me know, and i do have FASM and Fresh, if i didn't have it would i be posting here after all its the official FASM board and i like it and see that FASM is really great much better thatn others.
Post 20 Apr 2004, 12:35
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Hm-m-m-m. Well, actually I missed something. What kind of examples you need? These in FASMW package are actually are very basic for beginers. Maybe some more advanced? Maybe you have to describe it more detailed. But in all cases searching the board should be helpful.

Regards.
Post 20 Apr 2004, 13:01
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Stcherbatchenko



Joined: 20 Apr 2004
Posts: 13
Stcherbatchenko
thanks for the fast reply but what i want to see is how to use API's as the examples i downloaded for FASM are not very getting into all what i need, and i do surf the board but i dont find what i want maybe if you can help me with those samples i would be very glad here are more exmaples that i wanted to see:
1) how to use api's and write them in the code
2) some samples to demonastrate them
thats all
thanks again
Post 20 Apr 2004, 13:36
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
that IS shown in examples.

example of using api is
Code:
invoke MessageBox, 0, "text", "caption", MB_OK
    

but you must have imported all APIs (or better API procedures) you use. To import API procedure you must know in which DLL is it located. For example MessageBox is in USER32.dll, so importing it is
Code:
data import
  library user32,'USER32.DLL'
  import user32,MessageBox,'MessageBoxA'
end data
    

look at examples if windows FASM distribution, it's there.
Post 20 Apr 2004, 18:37
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Stcherbatchenko



Joined: 20 Apr 2004
Posts: 13
Stcherbatchenko
thanks very much for your fast reply and for keeping up with me anyway that was an easy one but i was looking for someinth like www.allapi.net has like they show you the api's and gives you a working demo examples so you can get to know what is happening but anyway thanks
Post 20 Apr 2004, 18:50
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
translating VB and C code to assembly is not hard - for example, setting caption of a window can be done like so:

Code:
invoke SendMessage,WM_SETTEXT,[hwnd],0,_text
    


where [hwnd] holds the window handle, and _text is the caption. if you need help translating a specific example from allapi.net, just post it here, we'll be glad to help


Last edited by coconut on 21 Apr 2004, 02:43; edited 1 time in total
Post 20 Apr 2004, 20:53
View user's profile Send private message Reply with quote
Stcherbatchenko



Joined: 20 Apr 2004
Posts: 13
Stcherbatchenko
thanks coconut for your reply and your help but i was asking generally coz actually i kinda wanted to know how to use all api's and to know how to write em in ASM as am new to it only been reading alot about it for along time, anyway it would be nice to know why the '[]' in the 'hwnd' like if i wrote that in C/C++ i dont have to use any pointers please correct me if am wrong and it yould be appreciated to see some examples or prorams of your own to learn from. Smile
Post 20 Apr 2004, 20:57
View user's profile Send private message Reply with quote
Stcherbatchenko



Joined: 20 Apr 2004
Posts: 13
Stcherbatchenko
heh another question, am not a complete idiot but ASM is really big so i have to use your help Smile so i have noticed in calling API's we use 'INVOKE' which i know is a macro anyway and i know something abuot asm too but not good in coding really
so what i wanted to know if i can use the pure old ASM style coding but in win32asm coz i like to learn it from the begining not search for an easy solution, i dont know but i like to llearn things well so i can then actually learn something better than not learn at all so if you can guide me to stuff like this you can really help also can you help me with doing the hex numbers as i only grab the calculaotr and use it i wanna know how to convert hex to deciman and vice vers in the old fashioned way "BRAIN POWER" thats enough for now i think i have been such a pain for now.
Post 20 Apr 2004, 21:07
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
take a look at this post, he asked the same thing: http://board.flatassembler.net/topic.php?t=1449

in fasm syntax, when we create a variable, example,

Code:
num dd ?
    


we access the value of the variable by enclosing it in brackets: [num]. if we wanted to send the memory location, a pointer, we wouldnt write the [] just num. you may see in other assemblers they use ADDR or OFFSET keywords to achieve this

Code:
num dd ?

mov     eax,72
mov     [num],eax ;num = 72
...
...
...
invoke  SomeProc,num ;pointer to num
    


i dont have any examples yet, i just started learning too Razz im trying to translate some vb programs i had made long ago, its going pretty well so far. ill post it here when im done
Post 21 Apr 2004, 02:55
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
There is no API reference for FASM, but you can use any API reference. Every argument is dword, not depending on what type is it in documentation.

You push argument in reversed order, last in documentation is pushed first, like:

int MessageBox(
HWND hWnd, // handle of owner window
LPCTSTR lpText, // address of text in message box
LPCTSTR lpCaption, // address of title of message box
UINT uType // style of message box
);

in C called as

MessageBox(0,"text","caption",MB_OK);

is in pure asm

push MB_OK
push "caption"
push "text"
push dword 0
call [MessageBox]
Post 21 Apr 2004, 18:23
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Stcherbatchenko



Joined: 20 Apr 2004
Posts: 13
Stcherbatchenko
oh okay that helped really but i wwondered when to use thos DWORDS and when not to use them and why do i call the API with '[] before it and stuff like that and ?
Post 21 Apr 2004, 19:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
DLL means "dynamic link library". That means it is loaded when it is needed and unloaded when not needed. So address of procedures in memory can change. For that, you can't call static location, like
Code:
  call MessageBox
    

Instead of that, in your program you declare table of procedures which you want to use. That is that import section, and stuff like
Code:
  library kernel32,'KERNEL32.DLL'
  import kernel32,\
    ExitProcess,'ExitProcess'
    

etc.
First, you list which dlls are you using with "library" macro. For each library, there are 2 macro arguments, first is symbol that remepresents library (used for "import" macro) and second is string holding name of library.
Then, for each DLL, you list procedures from it using "import" macro. First argument is symbol asociated to DLL with "library", then following groups of two macro arguments identify one procedure. First of two arguments is name of dword variable that will be filled with address of procedure, second is string holding name of procedure. For example, when you use
Code:
  library user32,'USER32.DLL'
  import user32, 
    MessageBox,'MessageBoxA'
    

you get declared dword variable "MessageBox" which holds address of procedure "MessageBoxA" from "USER32.DLL". For that reason, to call
it, you must use
Code:
  call [MessageBox]
    

btw: These macros are declared in "%FASMINC%\macro\import.inc", you have to include it to use them.
Code:
  include "%FASMINC%\macro\import.inc"
    


Last edited by vid on 22 Apr 2004, 08:38; edited 1 time in total
Post 22 Apr 2004, 08:26
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Stcherbatchenko



Joined: 20 Apr 2004
Posts: 13
Stcherbatchenko
well thanks for your help vod that really haelped me out now i know what is it used for thanks, but i want to know abuot those sections like '.code' '.import' and the other code you write in the same line like readble writable etc...
how can i make my own sections if possible and how to use them etc.. stuff like that would help me more
Post 22 Apr 2004, 08:33
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
only meaning of section is to restrict access to parts of memory.
For example, if you have some data that needs only to be read (like strings), you put then into section marked as "readable", not as "writable", so if you mistakenly, because of some bug, write to it, you will get error (general protection failure, GPF).

import table (table of pointers to procedures imported from DLLs) is usually stored in own section marked with "import". But it can as well be in any section, just marked with "data import" and "end data". Sections are just some standard, in my opinion not very useful.

FASM allows you to create file with only one section, on that all operations can be performed (writable readable executable), where you have everything you need. Such file is created if you dont' use any "section" directive in whole file.

You can also use "%FASMINC%\win32axp.inc" that contains macro which create section for you: ".data", ".code", ".end <entry label>"

I suggest using only one section, and using "data import" for import table
Post 22 Apr 2004, 08:45
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
What do you mean by making your own sections?
Post 22 Apr 2004, 08:45
View user's profile Send private message Visit poster's website MSN Messenger 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.