Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Function Pointers


  • Please log in to reply
1 reply to this topic

#1 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:19 AM

Posted 24 March 2009 - 07:28 PM

Hello all :thumbsup:

Been working on tool lately, and I would like to call the internal function NtOpenProcess. However, to do so, I need to use Run-Time-Dynamic-Linking, described in this article:
http://msdn.microsoft.com/en-us/library/ms686944(VS.85).aspx

My problem lies in creating the function pointer. Here's my declaration:

typedef NTSTATUS (NTAPI *_NtOpenProcess) (
	OUT PHANDLE,
	IN ACCESS_MASK,
	IN POBJECT_ATTRIBUTES,
	IN PCLIENT_ID OPTIONAL);

class procManager
{
	HINSTANCE hNTDLL;
public:
	procManager()
	{
		hNTDLL = LoadLibrary(L"ntdll.dll");
		if (!hNTDLL)
			throw std::runtime_error("NTDLL.DLL failure.");
		_NtOpenProcess NtOpenProcess;
		NtOpenProcess = reinterpret_cast <_NtOpenProcess> (GetProcAddress(hNTDLL, L"NtOpenProcess")); 
		if (!NtOpenProcess)
			throw std::runtime_error("NtOpenProcess not found.");
		//Use NTOpenProcess for stuff here
	};
	~procManager()
	{
		FreeLibrary(hNTDLL);
	};
};

The compiler error is:

error C2059: syntax error : '__stdcall'


__stdcall is what the macro NTAPI resolves to. If I remove NTAPI from the declaration, here's the error I get:

error C2065: '_NtOpenProcess' : undeclared identifier


At which point, I'm saying, "Well duh! That's why it's a TYPEDEF!!" I'm DECLARING it!

Anyone have any ideas on my syntax error here?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer

  • Topic Starter

  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:19 AM

Posted 24 March 2009 - 08:44 PM

Hello :thumbsup:

Thanks to groovicus, I got this sorted:
http://stackoverflow.com/questions/679862/...nction-pointers

Thanks!

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users