flat assembler
Message board for the users of flat assembler.

Index > Windows > Moving address of structure in FASM?

Author
Thread Post new topic Reply to topic
itsnobody



Joined: 01 Feb 2008
Posts: 93
Location: Silver Spring, MD
itsnobody 07 Oct 2008, 03:18
I need to move the address of a NMHDR structure to the pointer in lparam....how do you do this in FASM?
Post 07 Oct 2008, 03:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 07 Oct 2008, 04:05
Structures are just macros with the added requirement of needing a defining label. So the "address" of a structure is the address of the label that precedes it.
Code:
SomeLabel NMHDR ;<--- SomeLabel now points to a NMHDR structure    
Post 07 Oct 2008, 04:05
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 09 Oct 2008, 20:17
revolution,

"Address of the label" sounds funny. Labels are just constants with value equal to some value, usually current offset, aren't they? (They may have associated type info, I know) Wink

itsnobody,

To "move the address" you need this address. If it is static, just mov the appropriate constant (name it using label, if you wish) into lParam, as revolution suggested. For dynamic-allocated case (be it automatic stack-frame-based or heap-based variable) you will need to calculate the address (lea exx, [localNMHDR] for stack-based or simply mov exx, [pheapNMHDR] will be enough in most cases) beforehand.
Post 09 Oct 2008, 20:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 10 Oct 2008, 01:18
baldr wrote:
"Address of the label" sounds funny. Labels are just constants with value equal to some value, usually current offset, aren't they? (They may have associated type info, I know)
What is wrong with address of label? How else do you state what address the assembler assigned to the label?
Post 10 Oct 2008, 01:18
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 10 Oct 2008, 03:36
The address of the label is the present position of the envelope apon which the address label(s) is/are affixed. Can you imagine trying to use relative addressing on a postal letter. Laughing

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Oct 2008, 03:36
View user's profile Send private message Visit poster's website Reply with quote
itsnobody



Joined: 01 Feb 2008
Posts: 93
Location: Silver Spring, MD
itsnobody 10 Oct 2008, 15:15
But it doesn't work, I've tried everything, I can't just do mov [structureName],eax or anything like that...I don't need to get the address of the structure...I just need the structureName to point to whats in lparam

So how I can make the structureName point to what's in lparam?
Post 10 Oct 2008, 15:15
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 10 Oct 2008, 15:19
label StructureName at lparam ?

I have a feeling you are going to need to show us some code to get to the bottom of this. If the address of the structure is in lparam then just load it into a register to use it.

mov eax,[lparam]
mov ecx,[eax + MyStruct.MyItem]

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Oct 2008, 15:19
View user's profile Send private message Visit poster's website Reply with quote
itsnobody



Joined: 01 Feb 2008
Posts: 93
Location: Silver Spring, MD
itsnobody 10 Oct 2008, 15:32
For some reason when I did [eax+MyStruct.MyItem] it didn't work...but when I counted where it was and did [eax+8] it did work

Oh well that works for me for now
Post 10 Oct 2008, 15:32
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 10 Oct 2008, 15:41
Code:
proc WindowProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi

        cmp     [wmsg],WM_NOTIFY
        je      .wmnotify

        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        pop     edi esi ebx
        ret

  .wmnotify:
        mov     eax, [lparam]
        mov     eax, [eax+NMHDR.code]
        jmp     .defwndproc
endp
    


Compiles for me. My code is not an example of proper handling of WM_NOTIFY of course, I'm just doing a hit testing to confirm that the structure is defined in the standard package.
Post 10 Oct 2008, 15:41
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 21 Oct 2008, 18:18
revolution,
revolution wrote:
What is wrong with address of label?

"It defines the label whose value is equal to offset of the point where it’s defined." -- excerpt from FASM.PDF. I mean that label does not have an address (say COFF Wink), it's value is just an offset from some base.
Post 21 Oct 2008, 18:18
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 21 Oct 2008, 18:46
itsnobody,

Do you use struc directive for NMHDR? It differs from struct macroinstruction from MACRO\STRUCT.INC in many ways. This is (easily compiled) example of latter's use:
Code:
proc WndProc hWnd, wMsg, wParam, lParam
                mov     eax, [lParam]
virtual at eax
notification NMHDR
end virtual
                mov     eax, [notification.code]    
Looks like assume from MASM, eh?
Post 21 Oct 2008, 18:46
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.