@@ -2392,47 +2392,37 @@ CMDRESULT cbInstrMnemonicbrief(int argc, char* argv[])
2392
2392
return STATUS_CONTINUE;
2393
2393
}
2394
2394
2395
-
2396
2395
CMDRESULT cbGetPrivilegeState (int argc, char * argv[])
2397
2396
{
2398
- TOKEN_PRIVILEGES* Privileges;
2399
2397
DWORD returnLength;
2400
2398
LUID luid;
2401
2399
if (LookupPrivilegeValueW (nullptr , StringUtils::Utf8ToUtf16 (argv[1 ]).c_str (), &luid) == 0 )
2402
2400
{
2403
2401
varset (" $result" , (duint)0 , false );
2404
2402
return CMDRESULT::STATUS_CONTINUE;
2405
2403
}
2406
- Privileges = ( TOKEN_PRIVILEGES*) emalloc (64 * 16 + 8 , " _dbg_getprivilegestate" );
2407
- if (GetTokenInformation (hProcessToken, TokenPrivileges, Privileges, 64 * 16 + 8 , &returnLength) == 0 )
2404
+ Memory < TOKEN_PRIVILEGES*> Privileges (64 * 16 + 8 , " _dbg_getprivilegestate" );
2405
+ if (GetTokenInformation (hProcessToken, TokenPrivileges, Privileges () , 64 * 16 + 8 , &returnLength) == 0 )
2408
2406
{
2409
2407
if (returnLength > 4 * 1024 * 1024 )
2410
2408
{
2411
2409
varset (" $result" , (duint)0 , false );
2412
2410
return CMDRESULT::STATUS_CONTINUE;
2413
2411
}
2414
- Privileges = (TOKEN_PRIVILEGES*)erealloc (Privileges, returnLength, " _dbg_getprivilegestate" );
2415
- if (GetTokenInformation (hProcessToken, TokenPrivileges, Privileges, returnLength, &returnLength) == 0 )
2416
- {
2417
- efree (Privileges, " _dbg_getprivilegestate" );
2412
+ Privileges.realloc (returnLength, " _dbg_getprivilegestate" );
2413
+ if (GetTokenInformation (hProcessToken, TokenPrivileges, Privileges (), returnLength, &returnLength) == 0 )
2418
2414
return STATUS_ERROR;
2419
- }
2420
2415
}
2421
- for (unsigned int i = 0 ; i < Privileges->PrivilegeCount ; i++)
2416
+ for (unsigned int i = 0 ; i < Privileges () ->PrivilegeCount ; i++)
2422
2417
{
2423
2418
if (4 + sizeof (LUID_AND_ATTRIBUTES) * i > returnLength)
2424
- {
2425
- efree (Privileges, " _dbg_getprivilegestate" );
2426
2419
return STATUS_ERROR;
2427
- }
2428
- if (memcmp (&Privileges->Privileges [i].Luid , &luid, sizeof (LUID)) == 0 )
2420
+ if (memcmp (&Privileges ()->Privileges [i].Luid , &luid, sizeof (LUID)) == 0 )
2429
2421
{
2430
- efree (Privileges, " _dbg_getprivilegestate" );
2431
- varset (" $result" , (duint)(Privileges->Privileges [i].Attributes + 1 ), false ); // 2=enabled, 3=default, 1=disabled
2422
+ varset (" $result" , (duint)(Privileges ()->Privileges [i].Attributes + 1 ), false ); // 2=enabled, 3=default, 1=disabled
2432
2423
return STATUS_CONTINUE;
2433
2424
}
2434
2425
}
2435
- efree (Privileges, " _dbg_getprivilegestate" );
2436
2426
varset (" $result" , (duint)0 , false );
2437
2427
return STATUS_CONTINUE;
2438
2428
}
@@ -2445,13 +2435,11 @@ CMDRESULT cbEnablePrivilege(int argc, char* argv[])
2445
2435
dprintf (" Could not find the specified privilege: %s\n " , argv[1 ]);
2446
2436
return CMDRESULT::STATUS_ERROR;
2447
2437
}
2448
- TOKEN_PRIVILEGES* Privilege;
2449
- Privilege = (TOKEN_PRIVILEGES*)emalloc (sizeof (LUID_AND_ATTRIBUTES) + 4 , " _dbg_enableprivilege" );
2450
- Privilege->PrivilegeCount = 1 ;
2451
- Privilege->Privileges [0 ].Attributes = SE_PRIVILEGE_ENABLED;
2452
- Privilege->Privileges [0 ].Luid = luid;
2453
- bool ret = AdjustTokenPrivileges (hProcessToken, FALSE , Privilege, sizeof (LUID_AND_ATTRIBUTES) + 4 , nullptr , nullptr ) != NO_ERROR;
2454
- efree (Privilege, " _dbg_enableprivilege" );
2438
+ Memory<TOKEN_PRIVILEGES*> Privilege (sizeof (LUID_AND_ATTRIBUTES), " _dbg_enableprivilege" );
2439
+ Privilege ()->PrivilegeCount = 1 ;
2440
+ Privilege ()->Privileges [0 ].Attributes = SE_PRIVILEGE_ENABLED;
2441
+ Privilege ()->Privileges [0 ].Luid = luid;
2442
+ bool ret = AdjustTokenPrivileges (hProcessToken, FALSE , Privilege (), sizeof (LUID_AND_ATTRIBUTES) + 4 , nullptr , nullptr ) != NO_ERROR;
2455
2443
return ret ? CMDRESULT::STATUS_CONTINUE : CMDRESULT::STATUS_CONTINUE;
2456
2444
}
2457
2445
@@ -2463,12 +2451,10 @@ CMDRESULT cbDisablePrivilege(int argc, char* argv[])
2463
2451
dprintf (" Could not find the specified privilege: %s\n " , argv[1 ]);
2464
2452
return CMDRESULT::STATUS_ERROR;
2465
2453
}
2466
- TOKEN_PRIVILEGES* Privilege;
2467
- Privilege = (TOKEN_PRIVILEGES*)emalloc (sizeof (LUID_AND_ATTRIBUTES) + 4 , " _dbg_disableprivilege" );
2468
- Privilege->PrivilegeCount = 1 ;
2469
- Privilege->Privileges [0 ].Attributes = 0 ;
2470
- Privilege->Privileges [0 ].Luid = luid;
2471
- bool ret = AdjustTokenPrivileges (hProcessToken, FALSE , Privilege, sizeof (LUID_AND_ATTRIBUTES) + 4 , nullptr , nullptr ) != NO_ERROR;
2472
- efree (Privilege, " _dbg_disableprivilege" );
2454
+ Memory<TOKEN_PRIVILEGES*> Privilege (sizeof (LUID_AND_ATTRIBUTES), " _dbg_disableprivilege" );
2455
+ Privilege ()->PrivilegeCount = 1 ;
2456
+ Privilege ()->Privileges [0 ].Attributes = 0 ;
2457
+ Privilege ()->Privileges [0 ].Luid = luid;
2458
+ bool ret = AdjustTokenPrivileges (hProcessToken, FALSE , Privilege (), sizeof (LUID_AND_ATTRIBUTES) + 4 , nullptr , nullptr ) != NO_ERROR;
2473
2459
return ret ? CMDRESULT::STATUS_CONTINUE : CMDRESULT::STATUS_CONTINUE;
2474
2460
}
0 commit comments