News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Accessing Union elements inside a Structure in MASM64

Started by bluedevil, September 27, 2022, 12:57:21 AM

Previous topic - Next topic

bluedevil

But I still know the entry point right? And what about 'esp' before main? It seem to me like I still can learn how much you changed esp?
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

NoCforMe

So you're basically relocating the entire stack to a new place, right? How do you figure out where to relocate it? Can't just plop it anywhere ...
Assembly language programming should be fun. That's why I do it.

jj2007

Well, almost everywhere... but it must be downwards, and you need to probe the stack

hutch--

It must be done directly AFTER the program entry point, set a range of plus and minus 1k for a random algo and then add that to ESP.

After that, just run the normal app code.

jj2007


hutch--

With a default 1 meg stack, twiddling it in either direction by up to 1k is no big deal.

jj2007

Quote from: hutch-- on October 09, 2022, 09:43:32 AM
With a default 1 meg stack, twiddling it in either direction by up to 1k is no big deal.

Now I am curious, Hutch. Attached is a minimal window application, 38 lines of plain simple Masm64 SDK code. Where would you insert an add rsp, 1000h?

Subtracting works fine:
WinMain proc
LOCAL msg:MSG
  sub rsp, 1000h

hutch--

 :biggrin:

It Verx !

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm64\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    sub rsp, 512

    conout "How D",lf

    waitkey

    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

jj2007

Quote from: hutch-- on October 09, 2022, 02:34:24 PM
:biggrin:

It Verx !
entry_point proc

    sub rsp, 512


I know. Now what about add rsp, 512?

Quote from: hutch-- on October 09, 2022, 09:43:32 AM
With a default 1 meg stack, twiddling it in either direction by up to 1k is no big deal.

hutch--

 :biggrin:

Well, thats simple, change the example to ADD rather than SUB.

jj2007


NoCforMe

You raise a much more than trivial point here.

Correct me if I'm wrong, but it's always been my understanding that the stack starts at the end ("top" as in highest address) of what used to be called a "segment" in DOS days, and grows downwards. So that would mean that if you add to the stack you'll be in trouble, as you'll be addressing out-of-bounds memory. Correct? In other words, the stack pointer doesn't start out in the middle of the field, where it can be either added to or subtracted from, right? (There might be a little bit of padding on the bottom, but I'm guessing not much, much less than a K.)
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on October 09, 2022, 09:39:31 PMif you add to the stack you'll be in trouble, as you'll be addressing out-of-bounds memory. Correct?

Correct.

Quote from: jj2007 on October 09, 2022, 07:48:10 AM
it must be downwards, and you need to probe the stack

Please find attached Hutch' marginally modified code. Here are the changes:

entry_point proc
   mov ecx, 800      ; 800kBytes
@@:   sub rsp, 1024
   mov al, [rsp]
   dec ecx
   jge @B

    conout "How D",lf

hutch--

This is basically the tests I did years ago but now in 64 bit.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm64\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    rcall GetTickCount                  ; get a seed
    bswap rax                           ; invert bytes for fastest changing
    rcall seed_rrand,rax                ; use it as a random seed
    mov rax, rvcall(rrand,1,16)         ; call the range random algo
    shl rax, 3                          ; mul by 8, keep stack aligned

    sub rsp, rax                        ; sub rax from rsp

    conout "RSP = ",str$(rsp),lf,lf     ; display rsp
    conout "How D",lf                   ; a text message

    waitkey                             ; wait for result

    .exit                               ; bye

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

jj2007

Yep, looks good :thumbsup:

Here is a simple variant, tested only on Win7:

entry_point proc
mov ecx, 1000 ; 1000kBytes
@@: sub rsp, 1024
mov al, [rsp]
dec ecx
jge @B

    conout "Stack is stuck at ", hex$(rsp), "h", lf

    waitkey


Output: Stack is stuck at 35A70h :tongue: