flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > include 'win32axp.inc' + library

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 19
include 'win32axp.inc' + library
Hi.
I want to use win32axp macros and want to add some winapi functions. But I can't use library and import macros (upd: because it will cause an error).
How can I do in this case?

E.g. if I want to rewrite beer.asm I'll write:

Code:
format PE GUI 4.0
include 'win32axp.inc'
.code
start:  invoke  MessageBoxA,0,'Do you need additional place for the beer?','Desktop configuration',MB_ICONQUESTION+MB_YESNO
        .if eax=IDYES
                invoke  mciSendString,'open cdaudio',0,0,0
                invoke  mciSendString,'set cdaudio door open',0,0,0
                invoke  mciSendString,'close cdaudio',0,0,0
        .endif
        invoke  ExitProcess,0
.end start



But how to include:

Code:
library winmm,'WINMM.DLL'
import winmm,mciSendString,'mciSendStringA'


to code???


Last edited by Jin X on 24 Jul 2017, 12:00; edited 2 times in total
Post 20 Jul 2017, 10:08
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 19
Really nobody knows??? Sad
Post 22 Jul 2017, 15:42
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 80
Location: Russian Federation, Sochi
format of ypur import section:

Code:
section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,RVA winmm_name,RVA winmm_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dd RVA _ExitProcess
    dd 0
  user_table:
    MessageBoxA dd RVA _MessageBoxA
    dd 0
  winmm_table:
    mciSendString dd RVA _mciSendString
    dd 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0
  winmm_name db 'WINMM.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0
  __mciSendString dw 0
    db '_mciSendStringA',0  0



if you russion-speaking look in internet for "issledovanieprogramm2004.djvu" - nice source about PE internals. or/and see fasm/fasmg macros that realize different aspects of PE formatting.
Post 22 Jul 2017, 18:13
View user's profile Send private message Send e-mail Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 19
It's invention of bicycles and crutches (костылей)...
I thought that fasm has something for such cases...
Post 23 Jul 2017, 12:03
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 556
It does have, it's called the macro you don't want to use.

You can also write your own macro.
Post 23 Jul 2017, 12:29
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 19
What macro don't I want to use?
I didn't write that I don't want to use something... Smile

I mean that library macro will cause an error if 'win32axp.inc' file is included.
Post 24 Jul 2017, 11:59
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6435
Location: Kraków, Poland
It is the ".end" macro that creates the non-configurable import section. If you need to customize it, you have to either alter the ".end" macro or not use it:

Code:
format PE GUI 4.0
include 'win32axp.inc' 
.code 
start:  invoke  MessageBoxA,0,'Do you need additional place for the beer?','Desktop configuration',MB_ICONQUESTION+MB_YESNO 
        .if eax=IDYES 
                invoke  mciSendString,'open cdaudio',0,0,0 
                invoke  mciSendString,'set cdaudio door open',0,0,0 
                invoke  mciSendString,'close cdaudio',0,0,0 
        .endif 
        invoke  ExitProcess,0

entry start

section '.idata' import data readable writeable

 library kernel32,'KERNEL32.DLL',\
         user32,'USER32.DLL',\
         winmm,'WINMM.DLL'

 import kernel32,\
        ExitProcess,'ExitProcess'

 import user32,\
        MessageBoxA,'MessageBoxA'

 import winmm,\
        mciSendString,'mciSendStringA'

Post 24 Jul 2017, 13:02
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 19
Tomasz, it's almost the same as BEER.ASM in examples.
My idea is:
1. to use macros such .if, .code and strings in invoke
2. to don't use import macro for each WinAPI function

It's sad if it's impossible to do that...
I need to build this library/import comstruction just to include 1 WinAPI function. Imagine the program that uses 100 WinAPI function defined in INCLUDE/API/... and 1 not defined.

It's would be good to be able to use library and import (with the same libname) macro more than once.
Or additional macros like .library and .import that defines some constants that used in .end when calling library macros (and import in INCLUDE/API/...) Smile

The final code could be:

Code:
format PE GUI 4.0 
include 'win32axp.inc' 
.code 
start:  invoke  MessageBoxA,0,'Do you need additional place for the beer?','Desktop configuration',MB_ICONQUESTION+MB_YESNO 
        .if eax=IDYES 
                invoke  mciSendString,'open cdaudio',0,0,0 
                invoke  mciSendString,'set cdaudio door open',0,0,0 
                invoke  mciSendString,'close cdaudio',0,0,0 
        .endif 
        invoke  ExitProcess,0

.library wimnn,'WINMM.DLL'
.import winmm,mciSendString,'mciSendStringA'
.end start

It's much more good-looking and simple code...
Post 24 Jul 2017, 13:57
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6435
Location: Kraków, Poland
That's a good example of what an alteration of ".end" macro could accomplish. I cannot promise I would extend the macro myself, as I have mostly moved to fasmg with my "macro work". I could suggest working on it in the community-developed package but as far as I know these projects are no longer active.
Post 24 Jul 2017, 15:04
View user's profile Send private message Visit poster's website 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.