The MASM Forum

General => The Campus => Topic started by: FastLife on June 12, 2014, 06:57:24 AM

Title: acces union var in structure
Post by: FastLife on June 12, 2014, 06:57:24 AM
hello masm32 forum

i want to retrieve a value in a union structure.
its about the IMAGE_RESOURCE_DIRECTORY_ENTRY STRUCT structure. i want to acces NameIsString value.
But this doesn't work because it says "undefined symbol".


lea edx, ResDirectoryEntry
assume edx : ptr IMAGE_RESOURCE_DIRECTORY_ENTRY
mov al, byte ptr ds:[edx].NameIsString ; ERROR HERE > undefined symbol
Title: Re: acces union var in structure
Post by: jj2007 on June 12, 2014, 07:17:23 AM
1. Have a closer look at the definition of IMAGE_RESOURCE_DIRECTORY_ENTRY
2. Read the forum rules
Title: Re: acces union var in structure
Post by: qWord on June 12, 2014, 08:30:44 AM
NameIsString and NameOffset are bit fields and a corresponding RECORD type (DWORD sized) has been declared in windows.inc. To access the bits, use the union-member Name1 (also a DWORD) and the MASK operator:
; get boolean value NameIsString
xor eax,eax
test [edx].Name1, MASK NameIsString
setnz al

; get NameOffset
mov ecx, [edx].Name1 ; copy DWORD
and ecx, MASK NameOffset ; mask bits
Title: Re: acces union var in structure
Post by: FastLife on June 15, 2014, 04:54:10 AM
thank you very much qWord, works perfect! :t