flat assembler
Message board for the users of flat assembler.

Index > Windows > Location of windows function return

Author
Thread Post new topic Reply to topic
Ariiio



Joined: 03 Feb 2024
Posts: 5
Location: Germany
Ariiio 03 Feb 2024, 18:45
I'm trying to get the cursor position with the windows function "GetCursorPos". As far as I know it takes in a POINT, puts the coordinates in that point and returns 1 if successful. I put 0 into ecx as that is supposed to be the POINT, and since POINT is just a x and y coordinate it should work.

Problem 1:
The function doesnt seem to return 1 into eax, so either it doesnt work for some reason or I did something wrong with passing the arguments

Problem 2:
Since the function is supposed to put the coordinates into the POINT (ecx) it should do just that. ecx does change, but it doesnt look anythingl like ax and y coordinates. When I put my mouse into the upper left corner of my screen (0x0) ecx isnt 0 which doesnt make sense?


Description:
Download
Filename: a.asm
Filesize: 461 Bytes
Downloaded: 44 Time(s)


_________________
🔨
Post 03 Feb 2024, 18:45
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2441
Furs 03 Feb 2024, 19:00
The argument is a pointer (i.e. the address) of the POINT structure. Also, it needs to be pushed on the stack since you're using 32-bit?
Post 03 Feb 2024, 19:00
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 913
Location: Russia
macomics 03 Feb 2024, 19:55
Code:
format PE
entry start

include 'win32a.inc'

section '.text' code readable writeable
start:
    sub esp, 8 ; 0x4
    ; mov ecx, 0x0
    ; xor eax, eax
    push esp
    call [GetCursorPos]
    pop eax ; x
    pop edx ; y

    push 0
    call [ExitProcess]

section '.idata' import data readable writeable
    library kernel, 'KERNEL32.DLL',\
        user, 'USER32.DLL'

    import kernel,\
        ExitProcess, 'ExitProcess'
        
    import user,\
        GetCursorPos, 'GetCursorPos'    
Post 03 Feb 2024, 19:55
View user's profile Send private message Reply with quote
Ariiio



Joined: 03 Feb 2024
Posts: 5
Location: Germany
Ariiio 03 Feb 2024, 20:09
Furs wrote:
The argument is a pointer (i.e. the address) of the POINT structure. Also, it needs to be pushed on the stack since you're using 32-bit?


You are right, completely forgot it took in a pointer. Thanks for mentioning the arguments having to get pushed on the stack in x86, probably got it confused with x64

_________________
🔨
Post 03 Feb 2024, 20:09
View user's profile Send private message Reply with quote
Ariiio



Joined: 03 Feb 2024
Posts: 5
Location: Germany
Ariiio 03 Feb 2024, 20:10
macomics wrote:
Code:
format PE
entry start

include 'win32a.inc'

section '.text' code readable writeable
start:
    sub esp, 8 ; 0x4
    ; mov ecx, 0x0
    ; xor eax, eax
    push esp
    call [GetCursorPos]
    pop eax ; x
    pop edx ; y

    push 0
    call [ExitProcess]

section '.idata' import data readable writeable
    library kernel, 'KERNEL32.DLL',\
        user, 'USER32.DLL'

    import kernel,\
        ExitProcess, 'ExitProcess'
        
    import user,\
        GetCursorPos, 'GetCursorPos'    


thanks, works perfectly

_________________
🔨
Post 03 Feb 2024, 20:10
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.