I'm delving deep into the Windows security systems and I've hit a bit of a brick wall. It's made me realize that my knowledge is quite lacking in some areas. My first problem is using the sizeof() function to get the size of an array or structure pointed to by a pointer. Eg:
Code:
char *tc=new char[256];
cout << sizeof(tc) << endl;
Of course, this didn't work, and why should it? The size of tc is 4, which is appropriate for a pointer. But is there any way to find out the size of the array? Ie, I need a function that will return 256 when I input tc.
My second problem is with arbitrary sized arrays. For example, here is the structure of TOKEN_PRIVILEGES:
Code:
typedef struct _TOKEN_PRIVILEGES
{
DWORD PrivilegeCount;
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
} TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
I'm using this structure in conjunction with the function GetTokenInformation(). The problem is, in the context that I am using it, it needs a TOKEN_PRIVILEGES structure of size 220 bytes. How do I manipulate the structure to achieve this? This is my code:
Code:
TOKEN_PRIVILEGES ti;
DWORD soti; //sizeof(ti)
DWORD rl; //Returns the required length of the array
int rCode; //Return code
soti=sizeof(ti);
rCode=GetTokenInformation(hToken,TokenPrivileges,&ti,&soti,&rl);
if (!rCode)
{
soti=rl;
GetTokenInformation(...);
}
I'm sure you get the idea. Basically, I create the empiric structure, pass it to the function, then repeat if necessary with the appropriate sized array. Except, I need to know how to make the TOKEN_PRIVILEGES structure the size returned in rl. Any help, please?