The RegLoadKey function requires that I set both SE_BACKUP_NAME and SE_RESTORE_NAME to enabled. I'm currently trying, but I keep getting an error:
Run-Time Check Failure #2 - Stack around the variable 'tkp' was corrupted.
The code:
#include <windows.h>
int WINAPI WinMain(HINSTAN CE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HANDLE hToken = NULL;
LUID rLuid;
LUID bLuid;
OpenProcessToke n(GetCurrentPro cess(), TOKEN_ADJUST_PR IVILEGES|TOKEN_ QUERY, &hToken);
TOKEN_PRIVILEGE S tkp;
LookupPrivilege Value(NULL, SE_BACKUP_NAME, &tkp.Privile ges[0].Luid);
LookupPrivilege Value(NULL, SE_RESTORE_NAME , &tkp.Privile ges[1].Luid);
tkp.PrivilegeCo unt = 2;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_EN ABLED;
tkp.Privileges[1].Attributes = SE_PRIVILEGE_EN ABLED;
AdjustTokenPriv ileges(hToken, FALSE, &tkp, 0, NULL, 0);
CloseHandle(hTo ken);
RegLoadKey(HKEY _USERS, L"Test\\", L"C:\\Docume nts and Settings\\test\ \NTUSER.DAT");
return 0;
}
I'm just digging into WinAPI, and I only picked up c++ last semester, so I'm willing to bet that this is a fairly elementary mistake. But I can't seem to find it. I did track that the error occurs when I try to set anything to tkp.Privileges[1], so it's probably an array issue, but I just can't figure out exactly how to go about fixing this. Anyone?
Run-Time Check Failure #2 - Stack around the variable 'tkp' was corrupted.
The code:
#include <windows.h>
int WINAPI WinMain(HINSTAN CE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HANDLE hToken = NULL;
LUID rLuid;
LUID bLuid;
OpenProcessToke n(GetCurrentPro cess(), TOKEN_ADJUST_PR IVILEGES|TOKEN_ QUERY, &hToken);
TOKEN_PRIVILEGE S tkp;
LookupPrivilege Value(NULL, SE_BACKUP_NAME, &tkp.Privile ges[0].Luid);
LookupPrivilege Value(NULL, SE_RESTORE_NAME , &tkp.Privile ges[1].Luid);
tkp.PrivilegeCo unt = 2;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_EN ABLED;
tkp.Privileges[1].Attributes = SE_PRIVILEGE_EN ABLED;
AdjustTokenPriv ileges(hToken, FALSE, &tkp, 0, NULL, 0);
CloseHandle(hTo ken);
RegLoadKey(HKEY _USERS, L"Test\\", L"C:\\Docume nts and Settings\\test\ \NTUSER.DAT");
return 0;
}
I'm just digging into WinAPI, and I only picked up c++ last semester, so I'm willing to bet that this is a fairly elementary mistake. But I can't seem to find it. I did track that the error occurs when I try to set anything to tkp.Privileges[1], so it's probably an array issue, but I just can't figure out exactly how to go about fixing this. Anyone?
Comment