flat assembler
Message board for the users of flat assembler.

Index > Windows > How Can I use the C runtime library with FASM like memcpy?

Author
Thread Post new topic Reply to topic
mikawawa



Joined: 22 May 2012
Posts: 5
mikawawa
I love FASM, but unfortunately I'm newb. So here is my first question:
How Can I use the C runtime library with FASM like memcpy and strlen etc?

I need help, Please
Post 02 May 2014, 03:15
View user's profile Send private message Reply with quote
Walter



Joined: 26 Jan 2013
Posts: 143
Walter
Here is one way:

Code:
;***************
;*mikawawa.asm *
;***************

format pe console
entry start

include 'win32ax.inc'

section '.data' data readable writeable

strName1 db 'mikawawa',0
strName2 rb 32

section '.code' code readable executable

start:

    cinvoke memcpy,strName2,strName1,3
    cinvoke memcpy,strName2+3,strName1+3,6
    cinvoke printf,'%s%c%c',strName2,0x0d,0x0a

    cinvoke strlen,strName2
    cinvoke printf,'Length of string is: %d',eax

    invoke  ExitProcess,0
         
section '.idata' import data readable

    library kernel32,'KERNEL32.DLL',\
            msvcrt,'MSVCRT.DLL'
         
    import kernel32,\
           ExitProcess,'ExitProcess'

    import msvcrt,\
           memcpy,'memcpy',\
           strlen,'strlen',\
           printf,'printf'
    
Post 02 May 2014, 04:29
View user's profile Send private message Reply with quote
mikawawa



Joined: 22 May 2012
Posts: 5
mikawawa
Walter wrote:
Here is one way:

Code:
;***************
;*mikawawa.asm *
;***************

format pe console
entry start

include 'win32ax.inc'

section '.data' data readable writeable

strName1 db 'mikawawa',0
strName2 rb 32

section '.code' code readable executable

start:

    cinvoke memcpy,strName2,strName1,3
    cinvoke memcpy,strName2+3,strName1+3,6
    cinvoke printf,'%s%c%c',strName2,0x0d,0x0a

    cinvoke strlen,strName2
    cinvoke printf,'Length of string is: %d',eax

    invoke  ExitProcess,0
         
section '.idata' import data readable

    library kernel32,'KERNEL32.DLL',\
            msvcrt,'MSVCRT.DLL'
         
    import kernel32,\
           ExitProcess,'ExitProcess'

    import msvcrt,\
           memcpy,'memcpy',\
           strlen,'strlen',\
           printf,'printf'
    


thank you very much, bro. I checked the FASM api directory and I didnt find the msvcrt.inc, so I thought I couldnt import the CRT functions directly. thanks again
Post 02 May 2014, 05:06
View user's profile Send private message Reply with quote
mikawawa



Joined: 22 May 2012
Posts: 5
mikawawa
BTW, in msdn there is a function called CopyMemory, but it is not imported from any library, if I want to use it with FASM, what should I do?
Post 02 May 2014, 05:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
mikawawa wrote:
BTW, in msdn there is a function called CopyMemory, but it is not imported from any library, if I want to use it with FASM, what should I do?
Code:
rep movsb ;<--- copy memory    
Post 02 May 2014, 06:03
View user's profile Send private message Visit poster's website Reply with quote
mikawawa



Joined: 22 May 2012
Posts: 5
mikawawa
revolution wrote:
mikawawa wrote:
BTW, in msdn there is a function called CopyMemory, but it is not imported from any library, if I want to use it with FASM, what should I do?
Code:
rep movsb ;<--- copy memory    


OK, I knew that. thanks all the same.
Post 02 May 2014, 06:36
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
mikawawa wrote:
OK, I knew that. thanks all the same.


Using external functions is of course important, for example for interfacing with the OS, but it should not be overused. Try to make the simple tasks in assembly way. It will be simpler, smaller and more readable. As always, the balance is important.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 02 May 2014, 07:13
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
I think CopyMemory is a macro... I may be wrong, however.
Post 02 May 2014, 14:20
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
AsmGuru62 wrote:
I think CopyMemory is a macro... I may be wrong, however.
This link suggests that it is implemented in Kernel32.dll

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366535%28v=vs.85%29.aspx
Post 02 May 2014, 14:25
View user's profile Send private message Visit poster's website Reply with quote
mikawawa



Joined: 22 May 2012
Posts: 5
mikawawa
revolution wrote:
AsmGuru62 wrote:
I think CopyMemory is a macro... I may be wrong, however.
This link suggests that it is implemented in Kernel32.dll

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366535%28v=vs.85%29.aspx


Oh, damn it! I didn't check it online, because I have a local msdn, although it is a little older, but I thought it might not be much more different. Well, seems I was totally wrong, thank you, bro. I really appreciate it!
Post 03 May 2014, 01:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
mikawawa wrote:
... bro ...
Or sis. Hehe Razz
Post 03 May 2014, 01:26
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


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

Website powered by rwasa.