PLease help me with ASM

Just starting out? Need help? Post your questions and find answers here.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

PLease help me with ASM

Post by josku_x »

Hello!

I am trying to convert this API code to ASM:

Code: Select all

MessageBox_(0, "Message", "Title", 0)
The PureBasic.asm output looks like the following:

Code: Select all

; 
; PureBasic v4.00 (Windows - x86) generated code
; 
; © 2006 Fantaisie Software
; 
; The header must remain intact for Re-Assembly
; 
; 
format MS COFF
; 
extrn _ExitProcess@4
extrn _GetModuleHandleA@4
extrn _HeapCreate@12
extrn _HeapDestroy@4
extrn _MessageBoxA@16
; 
extrn _memset
extrn _PB_StringBase
extrn  PB_StringBase
extrn _SYS_InitString@0
; 
extrn _PB_StringBasePosition
public _PB_Instance
public _PB_ExecutableType
public _PB_MemoryBase
public PB_Instance
public PB_MemoryBase
public _PB_EndFunctions
public _PB_DEBUGGER_LineNumber
public _PB_DEBUGGER_IncludedFiles

macro pb_public symbol
{
  public  _#symbol
  public symbol
_#symbol:
symbol:
}

macro    align value { rb (value-1) - ($-_PB_DataSection + value-1) mod value }
macro bssalign value { rb (value-1) - ($-_PB_BSSSection  + value-1) mod value }
public PureBasicStart
; 
section '.code' code readable executable
; 
; 
PureBasicStart:
; 
  PUSH   dword I_BSSEnd-I_BSSStart
  PUSH   dword 0
  PUSH   dword I_BSSStart
  CALL  _memset
  ADD    esp,12
  PUSH   dword 0
  CALL  _GetModuleHandleA@4
  MOV    [_PB_Instance],eax
  PUSH   dword 0
  PUSH   dword 4096
  PUSH   dword 0
  CALL  _HeapCreate@12
  MOV    [PB_MemoryBase],eax
  CALL  _SYS_InitString@0
; :
; MessageBox_(0, "Message", "Title", 0)
  PUSH   dword 0
  PUSH   dword _S1
  PUSH   dword _S2
  PUSH   dword 0
  CALL  _MessageBoxA@16
_PB_EOP_NoValue:
  PUSH   dword 0
_PB_EOP:
  CALL  _PB_EndFunctions
  PUSH   dword [PB_MemoryBase]
  CALL  _HeapDestroy@4
  CALL  _ExitProcess@4
_PB_EndFunctions:
  RET
; 
; 
section '.data' data readable writeable
; 
_PB_DataSection:
_PB_DEBUGGER_LineNumber: dd -1
_PB_DEBUGGER_IncludedFiles: dd 0
_PB_ExecutableType: dd 0
public _SYS_StaticStringStart
_SYS_StaticStringStart:
_S1: db "Title",0
_S2: db "Message",0
pb_public PB_NullString
  db     0
public _SYS_StaticStringEnd
_SYS_StaticStringEnd:
align 4
align 4
s_s:
  dd     0
  dd     -1
align 4
; 
section '.bss' readable writeable
_PB_BSSSection:
bssalign 4
; 
I_BSSStart:
_PB_MemoryBase:
PB_MemoryBase: rd 1
_PB_Instance:
PB_Instance: rd 1
; 
bssalign 4
PB_DataPointer rd 1
bssalign 4
bssalign 4
bssalign 4
bssalign 4
I_BSSEnd:
section '.data' data readable writeable
SYS_EndDataSection:
And that looks like big code to me. I am wanting to create a very small 'messagebox' application with a very very small footprint.

Could someone help me strip out all the PB related stuff and have only the MessageBox part and the needed headers/stuff?

Thanks!
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

I think it's this stuff:

Code: Select all

  PUSH   dword 0
  PUSH   dword _S1
  PUSH   dword _S2
  PUSH   dword 0
  CALL  _MessageBoxA@16 
But I don't have a clue! :lol:

Take a look at the FASM page, I think they have examples like that!
I like logic, hence I dislike humans but love computers.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Joakim, I know what part is needed, I just want help to strip out the PB related stuff, to have only the really needed stuff.

EDIT: I looked the FASM page and downloaded all the examples they had there, but when I looked the ASM files, I didn't understand a bit!

Oh yes, I forgot to say, the 'cleaned' ASM should be compileable with FASM, I don't want code where FASM throws an error :wink:

Really much thanks!
Any help is very appreciated!
DarkDragon
Addict
Addict
Posts: 2347
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Look into the fasm examples after you've downloaded the 32 bit Windows edition(they are like in purebasic in the fasm directory): http://www.flatassembler.net/
bye,
Daniel
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

DarkDragon wrote:Look into the fasm examples after you've downloaded the 32 bit Windows edition(they are like in purebasic in the fasm directory): http://www.flatassembler.net/
I already have the FASM standalone, but I just don't know what I should strip out of the ASM files.

If someone could just help me with the PureBasic.asm file, it would help me a lot.

EDIT: I just noticed the MSCOFF example.
This code was what I was looking for:

Code: Select all

; example of making Win32 COFF object file

format MS COFF

extrn '__imp__MessageBoxA@16' as MessageBox:dword

section '.text' code readable executable

 public _demo

 _demo:
        push    0
        push    _caption
        push    _message
        push    0
        call    [MessageBox]
        ret

section '.data' data readable writeable

 _caption db 'Win32 assembly',0
 _message db 'Coffee time!',0        
Thanks anyway!
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

Look the problem with 'just a messagebox' is the following. For a messagebox PB need the following things: Routines to call a dll and the whle String system. I guess u could try to blow the Stringsystem away and Just give the Pointer to a Include Binary.
Apart from that Mrs Lincoln, how was the show?
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Konne wrote:Look the problem with 'just a messagebox' is the following. For a messagebox PB need the following things: Routines to call a dll and the whle String system. I guess u could try to blow the Stringsystem away and Just give the Pointer to a Include Binary.
I think you didn't get it. I got the solution which was the example source I posted above. And I know how ASM works, but I tried multiple times to remove all PB-related but without luck.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Code: Select all

format PE GUI 4.0
include '../INCLUDE/win32a.inc'     ; make sure you define the right path.
     ;call the function...
     invoke   MessageRequester,0,_msg,_title,MB_ICONEXCLAMATION+MB_OK
     cmp     eax,IDYES
     jne     exit ;after the newbie clicks on YES we "jump" to our exit label.

exit:
    invoke  ExitProcess,0   ;we end.

;our strings
_msg db 'Hi newbie!',0
_title db 'Title',0

data import ;lets import from kernel32 and user32.
    library kernel32,'KERNEL32.DLL',\
            user32,'USER32.DLL';

    import kernel32,\
        ExitProcess,'ExitProcess'

    import user32,\
        MessageRequester,'MessageBoxA'

end data
;eof               
Is that what you wanted; Professional programmer alias Josku_x?


I think you didn't get it. I got the solution which was the example source I posted above. And I know how ASM works, but I tried multiple times to remove all PB-related but without luck.
1) He did get it, not his problem you're a newbie on this.
2) The solution was not the source you posted above (PB "compiler's ASM output").
3) You don't know how ASM works, else, you'll knew how to write such a simple program on FASM.
4) Its not just removing "pb related lines"...
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

1) I was unsure if he got it; It seems that he got it. I am at novice level of FASM, I'm not a n00b, and I'm not pr0.
2) The source I meant was not the PureBasic.asm source, I meant this:

Code: Select all

; example of making Win32 COFF object file 

format MS COFF 

extrn '__imp__MessageBoxA@16' as MessageBox:dword 

section '.text' code readable executable 

 public _demo 

 _demo: 
        push    0 
        push    _caption 
        push    _message 
        push    0 
        call    [MessageBox] 
        ret 

section '.data' data readable writeable 

 _caption db 'Win32 assembly',0 
 _message db 'Coffee time!',0 
3) I know how ASM works, until now I have only played with the registers and done CPU related stuff, nothing with GUI.
4) I also said to have the needed headers/stuff

5) Yes, my professional programmer alias IS Josku_X :wink:
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Obviously, you're still quite a beginner in assembly so it would be a good idea to be cool with the guys which spend some time to help you, and answer in a more constructive way.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

1) Well, he did.

2) And why the .... do you want to make an object file?? You cant just
strip the thing out of pb's output.

Dagcracks example is very cool, better take a closer look at that..

3) So you say that you are a complete beginner who tried to put a number in eax? :wink:

4) again look at dagcracks example.

The fasm example:

Code: Select all

include 'win32ax.inc'

.code

  start:
        invoke  MessageBox,HWND_DESKTOP,"Hi! I'm the example program!","Win32 Assembly",MB_OK
        invoke  ExitProcess,0

.end start
                                
uses win32ax as it says, wich is an include that will help you around many imports and so on (wich dagcrack does more "by hand" in his example.)
Post Reply