Click here to Skip to main content
15,879,326 members
Articles / Desktop Programming / MFC

Task Manager Extension 2.0

Rate me:
Please Sign up or sign in to vote.
4.92/5 (149 votes)
22 Jan 2007CDDL11 min read 596.5K   18.7K   263  
Task Manager Extension. This is a Windows Task Manager (NT/2000/XP/2003) plug-in. It adds lots of useful features to the standard Task Manager. It can show process modules, memory map, used handles, open files, file properties and a lot of other info!
#ifndef LOADDLL_H_INCLUDED
#define LOADDLL_H_INCLUDED

//#include "TaskManagerExDll.h"

typedef HMODULE (WINAPI *PLoadLibraryW)(LPCWSTR);
typedef HMODULE (WINAPI *PGetModuleHandleW)(LPCWSTR);
typedef BOOL    (WINAPI *PFreeLibrary)(HMODULE);
typedef FARPROC (WINAPI *PGetProcAddress)(HMODULE, char*);
typedef DWORD   (WINAPI *PGetCurrentDirectoryW)(LPWSTR,DWORD);
typedef DWORD   (WINAPI *PGetLastError) ( VOID );
typedef VOID    (WINAPI *PSetLastError) ( DWORD dwErrCode );

#define MARKER_BEGIN	0x19822891
#define MARKER_END		0x31415926
#define REMOTE_MAX_ARGUMENTS	8

struct RemoteDllThreadBlock
{
	DWORD				MarkerBegin;
	DWORD				ErrorLoad;					// error value for LoadLibrary
	DWORD				ErrorFunction;				// error value for executed function
	DWORD				ReturnCodeForFunction;		// error value for executed function
	DWORD				ErrorFree;					// error value for FreeLibrary
	DWORD				LastError;

	HMODULE				hModule;
	BOOL				bLoadLibrary;
	BOOL				bFreeLibrary;
	DWORD				dwArgumentCount; // 0..8
	DWORD				Arguments[REMOTE_MAX_ARGUMENTS];

	PLoadLibraryW		fnLoadLibraryW;
	PGetModuleHandleW	fnGetModuleHandleW;
	PFreeLibrary		fnFreeLibrary;
	PGetProcAddress		fnGetProcAddress;
	PGetLastError		fnGetLastError;
	PSetLastError		fnSetLastError;

	WCHAR				lpModulePath[MAX_PATH];	// the DLL path
	CHAR				lpFunctionName[256];		// the called function
	DWORD				MarkerEnd;
};

struct RemoteGetCurrentDirectoryThreadBlock
{
	PGetCurrentDirectoryW	fnGetCurrentDirectoryW;
	WCHAR					lpDirectory[MAX_PATH];
	DWORD					dwReturnCode;
};

// try to enable SeDebugPrivilege
//TASKMANAGEREXDLL_API void EnableDebugPriv( void );

// inject function RemoteThread() into target process
DWORD ExecuteRemoteThread(
		HANDLE	hProcess,
		BOOL	bLoad,
		BOOL	bFree,
		LPCTSTR	lpDllPath,
		char*	lpFunctionName,
		DWORD*	pReturnCodeForFunction,
		LONG*	pLastError,
		DWORD*	pErrorLoad,
		DWORD*	pErrorFunction,
		DWORD*	pErrorFree,
		DWORD	dwArgumentCount,
		DWORD*	pdwArguments
		);

// and this is the code we are injecting
DWORD __stdcall RemoteDllThread( RemoteDllThreadBlock* );

// and this is the code we are injecting
DWORD __stdcall RemoteGetCurrentDirectoryThread( RemoteGetCurrentDirectoryThreadBlock* );


// That's the THING
// The whole shebang makes a number of assumptions:
// -- target process is a Win32 process
// -- kernel32.dll loaded at same address in each process (safe)
// -- bem() shorter than MAXINJECTSIZE
// -- bem() does not rely on the C/C++ runtime
// -- /GZ is _not_ used. (If it is, the compiler generates calls
//    to functions which are not injected into the target. Oops!
// -- Target function uses WINAPI (pascal) call convention.
DWORD LoadDllForRemoteThread(
		DWORD	processID,
		BOOL	bLoad,
		BOOL	bFree,
		LPCTSTR	lpModuleName,
		char*	lpFunctionName,
		DWORD*	pReturnCodeForFunction,
		LONG*	pLastError,
		DWORD*	pErrorLoad,
		DWORD*	pErrorFunction,
		DWORD*	pErrorFree,
		DWORD	dwArgumentCount,
		DWORD*	pdwArguments
		);

//DWORD RemoteGetCurrentDirectory( DWORD, LPWSTR, DWORD, DWORD* );

// Check OS
DWORD IsWindowsNT();

BOOL RemoteSimpleFunction( DWORD processId, DWORD dwArgument, char* lpszFunction, DWORD* lpdwFuncRetVal );

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
Belarus Belarus
He is a young and forward-looking software developer. He also has lots of interesting hobbies like snowboarding, bicycle riding, carting racing and of course talking about himself in a third person. Smile | :)

github.com/kolomenkin

Curriculum Vitae

Comments and Discussions