Jump to content

What is wrong with this code convertion ?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Guest_Jophry_*

Guest_Jophry_*
  • Guests
Hi :)
I have this code in c++, and I want to gain full access over an application.
HANDLE hToken; 

TOKEN_PRIVILEGES tkp; 

 

// Get a token for this process. 

if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))

	return FALSE;

 

// Get the LUID for the shutdown privilege. 

LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid); 

tkp.PrivilegeCount = 1;  // one privilege to set    

tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 

 

// Get the shutdown privilege for this process. 

AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
and it works, but here comes my problem.
I want to convert this code to Pascal. All functions return true, but a call of GetLastError() just after AdjustTokenPrivileges() gives me an errorcode 1300 ( Not all privileges or groups referenced are assigned to the caller ). So what do I do wrong ?
Here's my code ( in Pascal )

 var

  hToken : handle;

  tp: TOKEN_PRIVILEGES;


   OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, @hToken);

   LookupPrivilegeValue( NULL, SE_DEBUG_NAME, @tp.Privileges[0].LUID );

   tp.PrivilegeCount := 1;

   tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

   AdjustTokenPrivileges( hToken, FALSE, @tp, sizeof(TOKEN_PRIVILEGES), 0, 0 );

   GetLastError(); // <- Returns 1300 :/

So please help me. What is wrong here :confused: I've compiled this code by using Dev-Pas v1.9.2.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Not seeing how AdjustTokenPrivileges or GetLastError are implemented, it's kind of tough to say.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog