flat assembler
Message board for the users of flat assembler.

Index > Main > How to call memmove?

Author
Thread Post new topic Reply to topic
DSblizzard



Joined: 23 Oct 2019
Posts: 15
Location: Ryazan, Russia
DSblizzard 18 Nov 2019, 14:10
I tried all of commented and uncommented code, but nothing works.
Code:
format PE64 console
entry prog

include "win64ax.inc"

section '.idata' import data readable writeable

library kernel32, 'kernel32.dll', msvcrt, 'msvcrt.dll'

import kernel32, ExitProcess,'ExitProcess'
import msvcrt, memmove, 'memmove'

section '.text' code readable executable

prog:

;;mov rdx, 4
;;push rdx
;;mov rsi, temp_str
;;push rsi
;;mov rdi, temp_str1
;;push rdi
;;call memmove


;;sub   rsp, 24
;;mov   [rsp + 16], rdx
;;mov   [rsp + 8], rsi
;;mov   [rsp], rdi
;;call memmove
;;add rsp, 24


;;push rbp
;;mov rbp, rsp
;;push rdx
;;push rsi
;;push rdi
;;call memmove
;;mov rsp, rbp
;;pop rbp


sub rsp, 32
mov rcx, temp_str1
mov rdx, temp_str
mov r8, 3
call memmove
add rsp, 32

end_prog:
        invoke ExitProcess, 0

section '.data' data readable writeable
        temp_str db "abc", 0
        temp_str1 db "def", 0
    

Don't suggest cinvoke because it seems to have a bug. Some combinations of registers work, others don't.
Post 18 Nov 2019, 14:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 18 Nov 2019, 16:51
memmove is a pointer so you need to dereference it:
Code:
call [memmove]    
Post 18 Nov 2019, 16:51
View user's profile Send private message Visit poster's website Reply with quote
DSblizzard



Joined: 23 Oct 2019
Posts: 15
Location: Ryazan, Russia
DSblizzard 18 Nov 2019, 17:15
Thank you, now it works. But following code still crashes:
mov rdi, temp_str1
mov rsi, temp_str
mov rdx, 3
cinvoke memmove, rdi, rsi, rdx
Is cinvoke supposed to work only with certain registers? Seems like it is a bug.
Post 18 Nov 2019, 17:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 18 Nov 2019, 17:22
You need to be aware of the register allocation order that cinvoke uses. When you have an overlap like you do in your example then currently the only way to solve it is to manually set the registers.
Post 18 Nov 2019, 17:22
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.