@@ -2397,20 +2397,25 @@ CMDRESULT cbInstrMnemonicbrief(int argc, char* argv[])
2397
2397
2398
2398
CMDRESULT cbGetPrivilegeState (int argc, char * argv[])
2399
2399
{
2400
+ if (argc < 2 )
2401
+ {
2402
+ dputs (" Not enough arguments" );
2403
+ return STATUS_ERROR;
2404
+ }
2400
2405
DWORD returnLength;
2401
2406
LUID luid;
2402
2407
if (LookupPrivilegeValueW (nullptr , StringUtils::Utf8ToUtf16 (argv[1 ]).c_str (), &luid) == 0 )
2403
2408
{
2404
2409
varset (" $result" , (duint)0 , false );
2405
- return CMDRESULT:: STATUS_CONTINUE;
2410
+ return STATUS_CONTINUE;
2406
2411
}
2407
2412
Memory <TOKEN_PRIVILEGES*> Privileges (64 * 16 + 8 , " _dbg_getprivilegestate" );
2408
2413
if (GetTokenInformation (hProcessToken, TokenPrivileges, Privileges (), 64 * 16 + 8 , &returnLength) == 0 )
2409
2414
{
2410
2415
if (returnLength > 4 * 1024 * 1024 )
2411
2416
{
2412
2417
varset (" $result" , (duint)0 , false );
2413
- return CMDRESULT:: STATUS_CONTINUE;
2418
+ return STATUS_CONTINUE;
2414
2419
}
2415
2420
Privileges.realloc (returnLength, " _dbg_getprivilegestate" );
2416
2421
if (GetTokenInformation (hProcessToken, TokenPrivileges, Privileges (), returnLength, &returnLength) == 0 )
@@ -2432,32 +2437,42 @@ CMDRESULT cbGetPrivilegeState(int argc, char* argv[])
2432
2437
2433
2438
CMDRESULT cbEnablePrivilege (int argc, char * argv[])
2434
2439
{
2440
+ if (argc < 2 )
2441
+ {
2442
+ dputs (" Not enough arguments" );
2443
+ return STATUS_ERROR;
2444
+ }
2435
2445
LUID luid;
2436
2446
if (LookupPrivilegeValueW (nullptr , StringUtils::Utf8ToUtf16 (argv[1 ]).c_str (), &luid) == 0 )
2437
2447
{
2438
2448
dprintf (" Could not find the specified privilege: %s\n " , argv[1 ]);
2439
- return CMDRESULT:: STATUS_ERROR;
2449
+ return STATUS_ERROR;
2440
2450
}
2441
- Memory< TOKEN_PRIVILEGES*> Privilege ( sizeof (LUID_AND_ATTRIBUTES), " _dbg_enableprivilege " ) ;
2442
- Privilege ()-> PrivilegeCount = 1 ;
2443
- Privilege ()-> Privileges [0 ].Attributes = SE_PRIVILEGE_ENABLED;
2444
- Privilege ()-> Privileges [0 ].Luid = luid;
2445
- bool ret = AdjustTokenPrivileges (hProcessToken, FALSE , Privilege () , sizeof (LUID_AND_ATTRIBUTES) + 4 , nullptr , nullptr ) != NO_ERROR;
2446
- return ret ? CMDRESULT:: STATUS_CONTINUE : CMDRESULT:: STATUS_CONTINUE;
2451
+ TOKEN_PRIVILEGES Privilege;
2452
+ Privilege. PrivilegeCount = 1 ;
2453
+ Privilege. Privileges [0 ].Attributes = SE_PRIVILEGE_ENABLED;
2454
+ Privilege. Privileges [0 ].Luid = luid;
2455
+ bool ret = AdjustTokenPrivileges (hProcessToken, FALSE , & Privilege, sizeof (TOKEN_PRIVILEGES) , nullptr , nullptr ) != NO_ERROR;
2456
+ return ret ? STATUS_CONTINUE : STATUS_CONTINUE;
2447
2457
}
2448
2458
2449
2459
CMDRESULT cbDisablePrivilege (int argc, char * argv[])
2450
2460
{
2461
+ if (argc < 2 )
2462
+ {
2463
+ dputs (" Not enough arguments" );
2464
+ return STATUS_ERROR;
2465
+ }
2451
2466
LUID luid;
2452
2467
if (LookupPrivilegeValueW (nullptr , StringUtils::Utf8ToUtf16 (argv[1 ]).c_str (), &luid) == 0 )
2453
2468
{
2454
2469
dprintf (" Could not find the specified privilege: %s\n " , argv[1 ]);
2455
- return CMDRESULT:: STATUS_ERROR;
2456
- }
2457
- Memory< TOKEN_PRIVILEGES*> Privilege ( sizeof (LUID_AND_ATTRIBUTES), " _dbg_disableprivilege " ) ;
2458
- Privilege ()-> PrivilegeCount = 1 ;
2459
- Privilege ()-> Privileges [0 ].Attributes = 0 ;
2460
- Privilege ()-> Privileges [0 ].Luid = luid;
2461
- bool ret = AdjustTokenPrivileges (hProcessToken, FALSE , Privilege () , sizeof (LUID_AND_ATTRIBUTES) + 4 , nullptr , nullptr ) != NO_ERROR;
2462
- return ret ? CMDRESULT:: STATUS_CONTINUE : CMDRESULT:: STATUS_CONTINUE;
2470
+ return STATUS_ERROR;
2471
+ }
2472
+ TOKEN_PRIVILEGES Privilege;
2473
+ Privilege. PrivilegeCount = 1 ;
2474
+ Privilege. Privileges [0 ].Attributes = 0 ;
2475
+ Privilege. Privileges [0 ].Luid = luid;
2476
+ bool ret = AdjustTokenPrivileges (hProcessToken, FALSE , & Privilege, sizeof (TOKEN_PRIVILEGES) , nullptr , nullptr ) != NO_ERROR;
2477
+ return ret ? STATUS_CONTINUE : STATUS_CONTINUE;
2463
2478
}
0 commit comments