Jump to content

How to create a struct that one of its elements is an array of structs?


Recommended Posts

When the type of a registry value given by RegQueryValueEx() is REG_RESOURCE_LIST constant (i.e. 8), the data received in the lpData (out) parameter is a pointer to a variable of type CM_RESOURCE_LIST struct.

According to MSDN, CM_RESOURCE_LIST struct is defined as follows:

typedef struct _CM_RESOURCE_LIST {
  ULONG                       Count;
  CM_FULL_RESOURCE_DESCRIPTOR List[1];
} *PCM_RESOURCE_LIST, CM_RESOURCE_LIST;

Additionally, CM_FULL_RESOURCE_DESCRIPTOR struct is defined as follows:

typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  INTERFACE_TYPE           InterfaceType;
  ULONG                    BusNumber;
  CM_PARTIAL_RESOURCE_LIST PartialResourceList;
} *PCM_FULL_RESOURCE_DESCRIPTOR, CM_FULL_RESOURCE_DESCRIPTOR;

Furthermore, CM_PARTIAL_RESOURCE_LIST struct  is defined as follows:

typedef struct _CM_PARTIAL_RESOURCE_LIST {
  USHORT                         Version;
  USHORT                         Revision;
  ULONG                          Count;
  CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
} CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;

Finally, CM_PARTIAL_RESOURCE_DESCRIPTOR struct is defined like that (long enough to be posted here).

I have no idea how to create these kind of structs in AutoIt.

Please tell me how to write them in AutoIt just until the second struct (CM_FULL_RESOURCE_DESCRIPTOR).

Edited by tukangusil7
Link to comment
Share on other sites

OK, after struggling to find a way to create a struct that contains an array of structs, I come with the following solution:

Take TOKEN_PRIVILEGES struct as an example:

typedef struct _TOKEN_PRIVILEGES {
  DWORD               PrivilegeCount;
  LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
} TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;

The Privileges element of TOKEN_PRIVILEGES struct is an array of LUID_AND_ATTRIBUTES struct defined as follows:

typedef struct _LUID_AND_ATTRIBUTES {
  LUID  Luid;
  DWORD Attributes;
} LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;

See also the definition of the LUID struct.

The general rule is that: To define an element that is an array of n structs, we just need to write the definition of the struct n times. That's it.

; Tag of one LUID_AND_ATTRIBUTES struct
Local $tagLUID                = "DWORD LowPart; LONG HighPart"
Local $tagLUID_AND_ATTRIBUTES = $tagLUID & "; DWORD Attributes"

; Tag of three LUID_AND_ATTRIBUTES structs
Local $iNumberOfStructs = 3
Local $tagArrayOfLUID_AND_ATTRIBUTES = $tagLUID_AND_ATTRIBUTES
For $iIdx = 1 To ($iNumberOfStructs - 1)
  $tagArrayOfLUID_AND_ATTRIBUTES &= "; " & $tagLUID_AND_ATTRIBUTES
Next

; Finally, create the TOKEN_PRIVILEGES struct
Local $tagTOKEN_PRIVILEGES = "DWORD PrivilegeCount; " & $tagArrayOfLUID_AND_ATTRIBUTES
Local $tTOKEN_PRIVILEGES = DllStructCreate($tagTOKEN_PRIVILEGES)

Good luck!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...