Author Topic: acces union var in structure  (Read 1875 times)

FastLife

  • Guest
acces union var in structure
« 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".

Code: [Select]
lea edx, ResDirectoryEntry
assume edx : ptr IMAGE_RESOURCE_DIRECTORY_ENTRY
mov al, byte ptr ds:[edx].NameIsString ; ERROR HERE > undefined symbol

jj2007

  • Member
  • *****
  • Posts: 10107
  • Assembler is fun ;-)
    • MasmBasic
Re: acces union var in structure
« Reply #1 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

qWord

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: acces union var in structure
« Reply #2 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:
Code: [Select]
; 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
MREAL macros - when you need floating point arithmetic while assembling!

FastLife

  • Guest
Re: acces union var in structure
« Reply #3 on: June 15, 2014, 04:54:10 AM »
thank you very much qWord, works perfect! :t