///////////////////////////////////////////////////////////////////////////////
//
// main()
//
int main (int argc, char *argv[])
{
    STARTUPINFO sui;
    PROCESS_INFORMATION pi;

    sui.cb = sizeof (sui);
    sui.lpReserved = NULL;
    sui.lpDesktop = NULL;
    sui.lpTitle = NULL;
    sui.cbReserved2 = 0;
    sui.lpReserved2 = NULL;

    pi.hProcess = NULL;
    pi.hThread = NULL;
    pi.dwProcessId = 0;
    pi.dwThreadId = 0;

    BOOL bProcessStarted =
        DetourCreateProcessWithDll (MATRIX_EXE_NAME, "-nopatch -clone", NULL, NULL, FALSE,
                                    0, NULL, NULL, &sui, &pi,
                                    DETOURS_DLL_NAME, DLL_NAME, NULL);

    if (FALSE == bProcessStarted)
    {
        TCHAR msgBuffer[0x100];
        wsprintf (msgBuffer, "Failed to start %s", MATRIX_EXE_NAME);
        MessageBox (NULL, msgBuffer, EXE_NAME, MB_OK);
        return (-1);
    }

    return (0);
}
Exemple #2
0
int _tmain(int argc, _TCHAR* argv[])
{
	// EnableDebugPrivilege();
	// LoadRemoteDll(5804, "xdbgcore.dll");
	STARTUPINFO si;
	memset(&si, 0, sizeof(si));
	si.cb = sizeof(si);
	
	PROCESS_INFORMATION pi;

	if (!DetourCreateProcessWithDll(NULL, argv[1], NULL, NULL, FALSE, 0, NULL, NULL, 
		&si, &pi, "xdbgcore.dll", NULL)) {

		printf("failed!\n");
	}

	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
    if (argc < 3) {
        printf("usage: DetourHook <cmd> <dll>\n");
        return 0;
    }

    LPTSTR cmdLine = argv[1];
    LPSTR dllPath = NULL;

#ifdef UNICODE
    DWORD num = WideCharToMultiByte(CP_OEMCP, NULL, argv[2], -1, NULL, 0, NULL, FALSE);
    dllPath = new CHAR[num];
    WideCharToMultiByte(CP_OEMCP, NULL, argv[2], -1, dllPath, num, NULL, FALSE);
#else
    dllPath = argv[2];
#endif

    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    ZeroMemory(&si, sizeof(STARTUPINFO));
    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    si.cb = sizeof(STARTUPINFO);

    DWORD flags = CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED;
    if (!DetourCreateProcessWithDll(NULL, cmdLine,
                                    NULL, NULL, FALSE, flags, NULL, NULL, &si, &pi,
                                    dllPath, NULL)) {
        LPSTR errMsg = GetLastErrorAsString();
        printf("failed to create process, error: %s", errMsg);
        LocalFree(errMsg);
    }

    ResumeThread(pi.hThread);
    WaitForSingleObject(pi.hProcess, INFINITE);
    
#ifdef UNICODE
    delete [] dllPath;
#endif

    return 0;
}
Exemple #4
0
int main(int argc, char** argv) {
	CommandServer cs(1);
	cs.init();

	CommonNet dis(1);
	dis.init_server(100);

	PROCESS_INFORMATION pi = {0};
	STARTUPINFO si = {0};
	si.cb = sizeof(si);

	HANDLE hnd = GetCurrentProcess();

	printf("Listening\nhandle %d\n", hnd);

	LPSECURITY_ATTRIBUTES lp_attributes;
	LPSECURITY_ATTRIBUTES lpThreadAttributes;
	STARTUPINFO startupInfo = {sizeof(startupInfo)};
	memset(&startupInfo,0,sizeof(STARTUPINFO));
	startupInfo.cb = sizeof(STARTUPINFO);
	startupInfo.dwFlags=0;
	startupInfo.wShowWindow = SW_HIDE;

	PROCESS_INFORMATION processInformation;
	char cmdLine[100];
	string AppName;
	int recv_len = 0;
	char RecvB[100];

	if(argc == 2 || argc == 3) {
		//启动游戏进程
		DWORD id = GetCurrentProcessId();

		int dump_mesh = 0;
		if(argc == 3) dump_mesh = 1;

		sprintf(cmdLine,"%s %d %d %d %d",argv[1], dump_mesh, -1,-1, id);
		printf("cmd line is %s\n", cmdLine);

		bool ret = DetourCreateProcessWithDll(NULL,cmdLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
			NULL, NULL, &si, &pi, "game_server.dll", NULL);

		if(!ret) {
			char err_str[200];
			sprintf(err_str, "Game Start %s Failed", AppName.c_str());
			MessageBox(NULL, err_str, "Error", MB_OK);
		}

		return 0;
	}

	while(true) {
		cs.accept_client();
		printf("client has come with connect socket:%d\n", cs.get_connect_socket());

		dis.AcceptClient(1);
		printf("input client connect to socket:%d\n", dis.get_connect_socket());
		
		cs.recv_raw_buffer(AppName, recv_len);
		if(recv_len <= 0) {
			printf("recv error\n");
			break;
		}
		printf("Appname: %s\n", AppName.c_str());


		//启动游戏进程
		DWORD id = GetCurrentProcessId();
		sprintf(cmdLine,"%s %d %d %d %d",AppName.c_str(), 0, cs.get_connect_socket(), dis.get_connect_socket(), id);
		printf("cmd line is %s\n", cmdLine);
		bool ret = DetourCreateProcessWithDll(NULL,cmdLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
			NULL, NULL, &si, &pi, "game_server.dll", NULL);

		if(!ret) {
			char err_str[200];
			sprintf(err_str, "Game Start %s Failed", AppName.c_str());
			MessageBox(NULL, err_str, "Error", MB_OK);
		}
	}

	return 0;
}
Exemple #5
0
int _tmain(int argc, _TCHAR* argv[])
{

	// This sample will take path to the executable which will invoke GetVersionEx
	// so that our detoured function will return them our custom version details
	if (argc != 5)
	{
		// Usage is:
		//
		// ForceVersion <path> <major ver> <minor ver> <build #>
		//
		// For e.g.
		//
		// ForceVersion c:\app.exe 4 1 2000
		// 
		// will return OS version as 4.1.2000 when the application calls GetVersionEx API

		printf("ForceVersion - returns a user defined OS version details to application\n");
		printf("by Gaurav Khanna - http://www.wintoolzone.com/\n\n");
		printf("Usage:\n\nForceVersion <app path> <major ver> <minor ver> <build #>\nwhere:\n");
		printf("\t<app path> - path to the executable which will request OS version\n");
		printf("\t<major ver> - OS major version to be returned to calling applications\n");
		printf("\t<minor ver> - OS minor version to be returned to calling applications\n");
		printf("\t<build #> - OS build version to be returned to calling applications\n");
		return 0;
	}

	// Get the version details
	VersionPayLoad payload;
	payload.iMajor = atoi(argv[2]);
	payload.iMinor = atoi(argv[3]);
	payload.iBuild = atoi(argv[4]);
	
	// Now, we will ask Detours to launch this executable and load our DetourDLL into the process
	STARTUPINFO startup;
	memset(&startup, 0, sizeof(startup));
	PROCESS_INFORMATION pi;
	memset(&pi, 0, sizeof(pi));
	startup.cb = sizeof(startup);
	
	// init the buffer that will hold the current working folder of the application
	TCHAR tCurDir[MAX_PATH];
	memset(tCurDir,0, sizeof(tCurDir));
	DWORD dwCount = GetCurrentDirectory(MAX_PATH,tCurDir);
	if (!dwCount)
	{
		printf("Unable to get the working folder!");
		return -1;
	}

	// Form the paths to the DETOURED.DLL and our Detouring DLL
	TCHAR szDetouredPath[MAX_PATH]; 
	memset(szDetouredPath, 0, sizeof(szDetouredPath));

	TCHAR szInjectDLLPath[MAX_PATH]; 
	memset(szInjectDLLPath, 0, sizeof(szInjectDLLPath));
	
	if (FormPath(szDetouredPath, tCurDir, _TEXT("detoured.dll")) == FALSE)
	{
		printf("Unable to form path to DETOURED.DLL!\n");
		return -1;
	}

	if (FormPath(szInjectDLLPath, tCurDir, _TEXT("ForceVersionDLL.dll")) == FALSE)
	{
		printf("Unable to form path to Injection DLL!\n");
		return -1;
	}

	// We create the process as suspended since we will copy payload
	// to the target process containing the versions we want it to get
	BOOL fLaunchApp = DetourCreateProcessWithDll(argv[1],
		0,0,0,TRUE,CREATE_SUSPENDED|CREATE_DEFAULT_ERROR_MODE,0,0,&startup,&pi,
		szDetouredPath,
		szInjectDLLPath,
		NULL);
	
	if (!fLaunchApp)
	{
		printf("Error: %d\n",GetLastError());
		return -1;
	}

	// Send the payload data...
	BOOL fRetVal = DetourCopyPayloadToProcess(pi.hProcess, my_guid, (PVOID)&payload, sizeof(payload));
	if (!fRetVal)
	{
		printf("Unable to write version information in the target process!");
		return -1;
	}

	// Resume thread and wait on the process..
	ResumeThread(pi.hThread);

	WaitForSingleObject(pi.hProcess, INFINITE);
	return 0;
}
// start the game with a named dll
// the game name is full path with a game name or just the current path and the name
void CharactorMaker::loadGame(char * _gameName, char * _dllName){
	// define the variables
	PROCESS_INFORMATION pi = { 0 };
	STARTUPINFO si = { 0 };
	LPSECURITY_ATTRIBUTES lpAttributes;
	LPSECURITY_ATTRIBUTES lpThreadAttributes;
	STARTUPINFO startupInfo = { sizeof(startupInfo) };
	PROCESS_INFORMATION processInformation;
	char cmdLine[100], tem[100] = {0};
	HANDLE curProcessHandle = NULL;

	si.cb = sizeof(si);

#if 0
	// first set the work directory
	if (!GetCurrentDirectory(MAX_PATH, path)){
		// get the directory failed
	}
	strcat(path, gameFolder);

	char * endPoint = path;
	while (*endPoint){
		endPoint++;
	}


	

	// get the folder in game name
	char * p = gameName;
	char * newGameName = gameName;
	while (*p){
		if (*p == '\\' || *p == '/'){
			strncpy(endPoint, gameName, p - gameName + 1);
			newGameName = p + 1;
			break;
		}
		p++;
	}

#endif
	bool relativePath = true;
	printf("Game Name: %s\n", _gameName);
	char * p = _gameName, * lastSlash = NULL;
	while(*p != 0){
		if(*p == ':' || *p == '\\' || *p == '/'){
			// the game name contains the path
			relativePath = false;
		}
		p++;
	}

	p = _gameName;
	// use the relative path or the full path
	if(relativePath == true){
		strcpy(path, ".\\");   // set the path to the current path
	}else{
		// get the path
		while(*p != 0){
			if(*p == '\\' || *p=='/'){
				lastSlash = p;
			}
			p++;
		}

		strncpy(path, _gameName, lastSlash - _gameName);
		printf("Path: %s.\n", path);
	}
	

#if 0
	if (!SetCurrentDirectory(path)){
		// set the directory failed.
		printf("[error]: set current path to '%s' failed.\n", path);
	}
#endif
	// load the game with cmdline
	memset(&startupInfo, 0, sizeof(STARTUPINFO));
	curProcessHandle = GetCurrentProcess();
	startupInfo.cb = sizeof(STARTUPINFO);
	startupInfo.dwFlags = 0;
	startupInfo.wShowWindow = SW_HIDE;

	// prepare the cmd line, the optional parameter is just -F or -f, to limit the fps
	// the game name is the full path?
	if (this->limitFps){
		printf("[INFO]: enable limit fps?\n");
		sprintf(tem, "%s -F %d", _gameName, this->maxFps);
	}
	else{
#if 1
		sprintf(tem, "%s", _gameName);
#else

		sprintf(tem, "%s", newGameName);

#endif
	}

	///write the save directory and the output file name
	if(this->saveDirectory != NULL){
		strcat(tem, " -S ");
		strcat(tem, saveDirectory);
	}
	// the output set file name
	if(this->outputFileName != NULL){
		strcat(tem, " -O ");
		strcat(tem, outputFileName);
	}

	if(this->toLogFrame){
		printf("[INFO]: enable frame Log.\n");
		sprintf(cmdLine, "%s -L %s", tem, "frame");

	}else{
		sprintf(cmdLine, "%s", tem);
	}

	printf("[INFO in Tool]: game cmdline:%s, dll name:%s.\n", cmdLine, _dllName);
#if 0
	bool ret = DetourCreateProcessWithDll(NULL, cmdLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, path, &startupInfo, &processInformation, _dllName, NULL);
#else
	bool ret = DetourCreateProcessWithDll(NULL, cmdLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, path, &si, &pi, _dllName, NULL);

#endif
	if (!ret){
		printf("[error]: create game '%s' with dll '%s' failed.\n", cmdLine, _dllName);
	}
}
Exemple #7
0
int main() {
	STARTUPINFO s = { sizeof(STARTUPINFO) };
	PROCESS_INFORMATION p = { 0 };
	return !DetourCreateProcessWithDll("Falcon BMS.exe", NULL, NULL, NULL, TRUE, 0, NULL, NULL, &s, &p, "FalconDisplaysExposer.dll", 0);
}