Go Back   FileForums > Games > Game Coders

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 19-03-2007, 13:24
TippeX's Avatar
TippeX TippeX is offline
zeroes and ones.....
 
Join Date: Jan 2003
Posts: 3,842
Thanks: 2
Thanked 33 Times in 23 Posts
TippeX is on a distinguished road
god, thats awful code..

NOT closing the process handles, crap buffer sizes, 12 bytes max in 1 write... not exiting with a return value (for processing to see if the stuff actually wrote)...crap crap crap

considerably better code can be found on the net, in c or asm or delphi or even visual basic...

please, if you're going to put source code for people to use, at least do some work on it, and document the code properly

Code:
//=========================
#include <iostream.h>
#include <windows.h>
//=========================

static volatile HANDLE 	ProcessHandle 	= (HANDLE) INVALID_HANDLE_VALUE;
static volatile BOOL	EngineInUse		= FALSE;

//=========================

BOOL engine_close_process() {

	if (EngineInUse) {

		// are we in use?

		if (CloseHandle(ProcessHandle)) {

			// yup, so close the process handle

			EngineInUse = FALSE;
			return TRUE;
		}
	}

	return FALSE;
}

//=========================

BOOL engine_open_process(char * processwindowtitle) {

	HWND 	TargetWindowHandle	= (HWND) -1;
	DWORD 	ProcessId 			= -1;
	HANDLE 	WindowProcessId		= (HANDLE) INVALID_HANDLE_VALUE;

	if (EngineInUse) {
		// we are already in use...
		return FALSE;
	}

	TargetWindowHandle = FindWindow(NULL, processwindowtitle); 	// see if it exist

	if (TargetWindowHandle) {

		// got the window handle...

		Process_Id = GetWindowThreadProcessId(TargetWindowHandle, &ProcessId); //get a PROCESS number

		if (Process_Id) {

			// we have a valid process id, now to open it...

			ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS,NULL, ProcessId);

			if (ProcessHandle) {

				// process succesfully opened

				EngineInUse = TRUE;
				return TRUE;
			 }

		}

	return FALSE;
}

//=========================

BOOL engine_write_process(LPVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize) {

	BOOL SuccessCode = FALSE;

	if (EngineInUse) {
		
		// are we in use

		if (ProcessHandle) {
			
			// do we have a process handle

			DWORD BytesWritten = 0;
			BOOL  ProcessSuspended = FALSE;

			if (SuspendThread(ProcessHandle) != (DWORD) -1) {
				// suspend the thread - its safer
				ProcessSuspended = TRUE;
			}

			if ((WriteProcessMemory(ProcessHandle, lpBaseAddress, lpBuffer, nSize, &BytesWritten) && BytesWritten == nSize) {
				// write was successful
				// flush the instruction cache (for safety)
				FlushInstructionCache(ProcessHandle, lpBaseAddress, nSize);
				SuccessCode = TRUE;
			}
			
			// resume the process if we suspended it

			if (ProcessSuspended) {
				ResumeThread(ProcessHandle);
			}

		}
	}

	return SuccessCode;
}

//=========================

BOOL engine_read_process(LPVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize) {
	
	BOOL SuccessCode = FALSE;

	if (EngineInUse) {

		if (ProcessHandle) {

			DWORD BytesRead = 0;
			BOOL  ProcessSuspended = FALSE;

			if (SuspendThread(ProcessHandle) != (DWORD) -1) {
				ProcessSuspended = TRUE;
			}

			if ((ReadProcessMemory(ProcessHandle, lpBaseAddress, lpBuffer, nSize, &BytesWritten) && BytesRead == nSize) {
				SuccessCode = TRUE;
			}

			if (ProcessSuspended) {
				ResumeThread(ProcessHandle);
			}

		}
	}

	return SuccessCode;
}

//=========================

BOOL engine_kill_process_and_close() {

	if (EngineInUse) {

		if (TerminateProcess(ProcessHandle, (UINT) 0x0D1ED1E)) {
			CloseHandle(ProcessHandle);
			EngineInUse = FALSE;
			return TRUE;
		}
	}
	
	return FALSE;
}
	
//=========================
__________________
bleh
DO NOT PM me with questions, leave that in the forums...ESPECIALLY if i dont know you...

Last edited by TippeX; 19-03-2007 at 13:51.
Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rainbow Six Vegas v1.04 Trainer Doesn't work mfw41 Game Trainers 7 30-03-2007 22:13
The best (and fun) NFS:Carbon trainer available intoksicated General Gaming 3 22-12-2006 04:55
Simple questions please answer jimmyps2dimwit PS2 Games 3 01-09-2002 11:05



All times are GMT -7. The time now is 20:52.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
FileForums @ https://fileforums.com