flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] strange problem with EDX register in Win32 Api

Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1300
Location: Paradise Falls
Picnic
Hey everyone,

This is a piece of code from a procedure. The code works fine but if i replace eax with edx (and edx only) the program crashes. No other changes are made to the procedure.
Any idea why is this happening?


this works
Code:

    ; ... 

    mov ecx, dword [dwBufferSize]
    mov eax, [buffer]
    cmp word [eax], 0
    je .continue

    invoke WriteConsoleOutput, [hOut], eax, ecx, 0, addr lpWriteRegion

    ; ...
    


this fails
Code:

    ; ...

    mov ecx, dword [dwBufferSize]
    mov edx, [buffer]
    cmp word [edx], 0
    je .continue

    invoke WriteConsoleOutput, [hOut], edx, ecx, 0, addr lpWriteRegion

    ; ...
    
Post 11 Apr 2021, 10:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18589
Location: In your JS exploiting you and your system
revolution
The macro for addr uses edx as a temporary register.
Code:
lea edx, [lpWriteRegion]
push edx    
Post 11 Apr 2021, 11:04
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1300
Location: Paradise Falls
Picnic
oh, i see. Thanks revolution.
Post 11 Apr 2021, 11:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18589
Location: In your JS exploiting you and your system
revolution
You could change the macro to do this:
Code:
push edx
lea edx, [lpWriteRegion]
xchg edx, [esp]    
Post 11 Apr 2021, 15:43
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.