bool CFileControlTool::RemoveFile(LPCTSTR lpFileName,bool bForce /* = false */)
{
	TCHAR szFullPathName[_MAX_PATH];  
	BOOL bRet = FALSE;

	//Enable debug privilege   
	EnableDebugPriv();   

	//Get the full path  
	
	if ( GetFullPathName( lpFileName, _MAX_PATH, szFullPathName, NULL ) == 0 )   
	{   
		Out(Dbg,_T("RemoveFile Failed. Error = %d\n"),GetLastError());   
		return FALSE;   
	}   
	

	//Close every handle in the system for this file   
	if (bForce) 
		bRet = CloseRemoteFileHandles(szFullPathName); 
	else
		bRet = DeleteFile(szFullPathName); 

	return bRet;   
}
Example #2
0
void LoadAndRun()
{
	char filePath[MAX_PATH] = {0};
	//char LoadDriverPath[MAX_PATH] = {0};
	//char ServicesName[MAX_PATH] = {0};
	GetSystemDirectory(filePath,sizeof(filePath));
	strcat_s(filePath,"\\");
	strcat_s(filePath,SYS_NAME);
	strcat_s(filePath,".sys");
	//sprintf_s(ServicesName,MAX_PATH,"SYSTEM\\CurrentControlSet\\Services\\%s",SYS_NAME);
	//SHDeleteKey(HKEY_LOCAL_MACHINE,ServicesName);

	ExtractSysFile(filePath,KernelModule,sizeof(KernelModule));
	if (GetFileAttributes(filePath) == INVALID_FILE_ATTRIBUTES)
	{
		ShowERR("ÊÍ·ÅÎļþʧ°Ü.");
		ExitProcess(0);
	}

	//sprintf_s(LoadDriverPath,MAX_PATH,"\\??\\%s",filePath);
	if (!EnableDebugPriv(SE_LOAD_DRIVER_NAME))
	{
		ShowERR("ȨÏÞ²»¹».");
		ExitProcess(0);
	}

	if (!LoadNTDriver(SYS_NAME,filePath))
	{
		DeleteFile(filePath);
		//SHDeleteKey(HKEY_LOCAL_MACHINE,ServicesName);
		ExitProcess(0);
	}

	if (!StartDriver(SYS_NAME))
	{
		ShowERR("Æô¶¯Ê§°Ü.");
		DeleteFile(filePath);
		//SHDeleteKey(HKEY_LOCAL_MACHINE,ServicesName);
		ExitProcess(0);
	}

	DeleteFile(filePath);

	Init();
}
Example #3
0
void DeleteProcessFromUnLockList(char* pszProcessFileName, He4HookDriverHide* pNtDriverControl)
{
  if (pszProcessFileName == NULL || pNtDriverControl == NULL)
    return;

  NTSTATUS           NtStatus;
  PROCESS_INFO       ProcInfo[1024];
  PPROCESS_INFO      lpProcInfo;
  ULONG              LehgthReturned = 0;
//  ULONG              i;

  NtStatus = NtGetProcessList(ProcInfo, sizeof(ProcInfo), &LehgthReturned);
  if (NtStatus == STATUS_SUCCESS)
  {
    lpProcInfo = ProcInfo;
    EnableDebugPriv();
    char szProcName[1024];
    while (1)
    {
      if (lpProcInfo->ProcessName.Buffer != NULL)
      {
        WideCharToMultiByte(CP_OEMCP, 0, (LPCWSTR)lpProcInfo->ProcessName.Buffer, -1,
                            szProcName, sizeof(szProcName), NULL, NULL);
      
        if (stricmp(szProcName, pszProcessFileName) == 0)
        {
          //PTHREAD_INFO pThreadInfo = GetThreadInfoPtr(lpProcInfo);
          //for (i=0; i<lpProcInfo->dwThreadCount; i++)
          //{
          //  pNtDriverControl->LockSaveObjects(pThreadInfo[i].dwThreadID);
          //}
          pNtDriverControl->LockSaveObjects(lpProcInfo->dwProcessID, TRUE);
        }
      }
      if (lpProcInfo->dwOffset == 0) 
        break;
      lpProcInfo = (PPROCESS_INFO)((CHAR*)lpProcInfo + lpProcInfo->dwOffset);
    }
  }
}
bool CFileControlTool::RenameFile(LPCTSTR lpFileName,LPCTSTR lpNewFileName,bool bForce /* = false */)
{
	TCHAR szFullPathName[_MAX_PATH];  
	BOOL bRet = FALSE;

	//Enable debug privilege   
	EnableDebugPriv();   

	//Get the full path
	if (GetFullPathName(lpFileName,MAX_PATH,szFullPathName,NULL) == 0)   
	{   
		Out(Dbg,_T("RemoveFile Failed. Error = %d\n"),GetLastError());   
		return FALSE;   
	}

	//Close every handle in the system for this file   
	if (bForce) 
		bRet = CloseRemoteFileHandles(szFullPathName); 
	
	bRet = ::MoveFileEx(szFullPathName,lpNewFileName,MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED); 

	return bRet;   
}
Example #5
0
BOOL CProcess::HideProcess()
{
	EnableDebugPriv(SE_DEBUG_NAME);
	(InitializeFunction());

	//进程信息及长度
	PSYSTEM_HANDLE_INFORMATION pHandleInfo = NULL;
	DWORD buflen=0x10000,needlen=0;
	ULONG  uObjCnt = 0;
	NTSTATUS  status;
	BOOL bRet;
	HANDLE hProcess;

	//通过打开进程获取进程句柄
	hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,GetCurrentProcessId());

	//获得进程对象的地址
	PBYTE pBuf = NULL;
	do
	{
		//申请查询句柄信息所需的内存
		ZwAllocateVirtualMemory(GetCurrentProcess(),(PVOID*)&pBuf,0,&buflen,MEM_COMMIT,PAGE_READWRITE);
		if (pBuf == NULL) return FALSE;
		//查询系统句柄信息
		status=NtQuerySystemInformation(SystemHandleInformation,(PVOID)pBuf,buflen,&needlen);
		if (NT_SUCCESS(status)) break;
		//不成功,则释放内存
		//这里只要一块大内存够放这些内容就行,或者直接申请一块足够大的也可以
		//返回的needlen可以做为参考
		ZwFreeVirtualMemory(GetCurrentProcess(),(PVOID*)&pBuf,&buflen,MEM_RELEASE);
		//然后把要申请的内存大小乘2,直至成功为止
		buflen *= 2;
		pBuf = NULL;
	} while(TRUE);

	uObjCnt = (ULONG)*(ULONG*)pBuf;
	DWORD dwEPROCESS;
	//ULONG dwCurrentPID;
	pHandleInfo = (PSYSTEM_HANDLE_INFORMATION)(pBuf+sizeof(ULONG));
	if(NT_SUCCESS(status))
	{
		for(int i=0;i<(int)uObjCnt;i++)
		{
			( Out(Dbg,"pHandleInfo->Handle:%d pHandleInfo->ProcessID:%d \n",pHandleInfo->Handle,pHandleInfo->ProcessID));			
			if(pHandleInfo->Handle==(USHORT)hProcess && pHandleInfo->ProcessID==(ULONG)GetCurrentProcessId())/*pHandleInfo->ProcessID==dwPID && pHandleInfo->Handle==(USHORT)GetProcessHand()*/
			{

				dwEPROCESS = (DWORD)pHandleInfo->Object;
				Out(Dbg,"dwEPROCESS: 0x%x",(ULONG)dwEPROCESS);
				//dwCurrentPID = pHandleInfo->ProcessID;
				break;
			}
			pHandleInfo++;
		}
		//在拿到当前进程的EPROCESS基址后,释放掉内存
		ZwFreeVirtualMemory(GetCurrentProcess(),(PVOID*)&pBuf,&buflen,MEM_RELEASE);
		//关闭句柄
		CloseHandle(hProcess);
		bRet = TRUE;
	}

	//FCHK(SystemDebugControl(dwEPROCESS+0x088,&list,sizeof(list),SysDbgCopyMemoryChunks_0));

	//FCHK(SystemDebugControl((ULONG)(list.Blink)+0x4,&list.Blink,sizeof(list.Blink),SysDbgCopyMemoryChunks_1));

	//FCHK(SystemDebugControl((ULONG)(list.Blink),&list.Flink,sizeof(list.Flink),SysDbgCopyMemoryChunks_1));
	MEMORY_CHUNKS datas;
	datas.Address = dwEPROCESS+0x088;
	LIST_ENTRY list = {0};
	datas.Data =&list;
	datas.Length = sizeof(list);
	OperateSystemMemory(datas,SysDbgCopyMemoryChunks_0);
	datas.Address = (ULONG)(list.Blink)+0x4;
	datas.Data =&list.Blink;
	datas.Length = sizeof(list.Blink);
	OperateSystemMemory(datas,SysDbgCopyMemoryChunks_1);
	datas.Address = (ULONG)(list.Blink);
	datas.Data =&list.Flink;
	datas.Length = sizeof(list.Flink);
	OperateSystemMemory(datas,SysDbgCopyMemoryChunks_1);
	return TRUE;
}
Example #6
0
int _tmain(int argc, TCHAR* argv[])
{
	ULONG nonSwitchCount = 0;
	BOOL bModule = FALSE;
	LPCTSTR lpPath = NULL;
	BOOL bFullPathCheck = FALSE;
	BOOL bUsage = TRUE;
	TCHAR lpFilePath[_MAX_PATH];
	
	for ( int i = 1; i < argc; i++ )
	{
		if ( _tcsicmp( argv[i], _T("/?" ) ) == 0 || _tcsicmp( argv[i], _T("-?" ) ) == 0 )
		{
			bUsage = TRUE;
			break;
		}
		else
		if ( _tcsicmp( argv[i], _T("/m" ) ) == 0 || _tcsicmp( argv[i], _T("-m" ) ) == 0 )
		{
			bModule = TRUE;
		}
		else
		{
			if ( nonSwitchCount != 0 )
			{
				bUsage = TRUE;
				break;
			}

			lpPath = argv[i];

			bUsage = FALSE;

			nonSwitchCount++;
		}
	}

	if ( bUsage )
	{
		ShowUsage();
		return -1;
	}

	EnableDebugPriv();

	bFullPathCheck = GetFileNamePosition( lpPath ) != lpPath ;

	if ( bFullPathCheck )
	{
		if ( GetFullPathName( lpPath, _MAX_PATH, lpFilePath, NULL ) == 0 )
		{
			_tprintf( _T("GetFullPathName() failed. Error = %d\n"), GetLastError() );
			return -2;
		}
	}
	else
		_tcscpy( lpFilePath, GetFileNamePosition( lpPath ) );
	
	if ( bModule )
		WhoUsesModule( lpFilePath, bFullPathCheck );
	else
		WhoUsesFile( lpFilePath, bFullPathCheck );
	
	return 0;
}
Example #7
0
BOOL Install(HWND hwndDlg)
{

	DWORD dwReadByte;
	char lpszInit[8] = {0};
	char lpszWindowsPath[256] = {0};
	char lpszNumber[256] = {0};
	char lpszLoadDriverPath[256] = {0};
	int i=0;

	memset(lpszInit,0,sizeof(lpszInit));
	strcat(lpszInit,"Safe");
	ReadFile((HANDLE)SAFE_SYSTEM,lpszInit,8,&dwReadByte,0);
	if (strcmpi("hehe",lpszInit) == NULL)
	{
		goto InitSuccess;
	}
	if (strcmpi("call",lpszInit) == NULL)
	{
		if (MessageBoxA(hwndDlg,"拒绝启动\r\n\r\n原因:无法验证当前A盾文件的完整性。文件有可能被修改、感染、或者捆绑其他程序\r\n\r\n是否前往官方下载最新版?","“A盾电脑防护”",MB_ICONERROR | MB_YESNO) == IDYES)
		{
			ShellExecuteW(0,0,L"http://www.3600safe.com/",0,0,SW_SHOW);
		}
		ExitProcess(0);
	}
	char lpszAProtectRunKey[100] = {0};
	memset(lpszAProtectRunKey,0,sizeof(lpszAProtectRunKey));
	QueryUserAgent(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","A-Protect",lpszAProtectRunKey);
	if (strstr(lpszAProtectRunKey,"\\") != 0)
	{
		//如果是开机启动的话,如果上面的无法初始化成功,就说明驱动启动失败,就不往下执行了
		MessageBoxA(hwndDlg,"“A盾电脑防护”初始化失败:\r\n\r\n1:病毒阻止了“A盾电脑防护”的启动\r\n2:某些安全软件恢复、阻止“A盾电脑防护”的钩子\r\n3:和某些杀毒或者安全软件不兼容导致“A盾电脑防护”的初始化失败\r\n4:深度防御、深度服务扫描失败,请重新启动电脑即可。","“A盾电脑防护”",MB_ICONERROR);
		ExitProcess(0);
	}
	GetWindowsDirectoryA(
		lpszWindowsPath,
		sizeof(lpszWindowsPath)
		);
	//sprintf(lpszNumber,"%d",GetTickCount());
	sprintf(lpszNumber,"%s","A-Protect");

	char lpszSrvices[256] = {0};
	sprintf(lpszSrvices,"SYSTEM\\CurrentControlSet\\Services\\%s",lpszNumber);
	SHDeleteKeyA(HKEY_LOCAL_MACHINE,lpszSrvices);

	strcat(lpszWindowsPath,"\\");
	strcat(lpszWindowsPath,lpszNumber);
	strcat(lpszWindowsPath,".sys");

	BFS_WriteFile(
		lpszWindowsPath,
		lpszKernelModule,
		sizeof(lpszKernelModule)
		);
	if (GetFileAttributesA(lpszWindowsPath) == INVALID_FILE_ATTRIBUTES)
	{
		if (IsWindows7())
			MessageBoxA(hwndDlg,"释放驱动文件失败,win7系统下右键“以管理员身份运行”","“A盾电脑防护”",MB_ICONERROR);
		else
			MessageBoxA(hwndDlg,"释放驱动文件失败","“A盾电脑防护”",MB_ICONERROR);

		ExitProcess(0);
	}
	wsprintfA(
		lpszLoadDriverPath,
		"\\??\\%s",
		lpszWindowsPath
		);

	if(!EnableDebugPriv(SE_LOAD_DRIVER_NAME))
	{
		DeleteFileA(lpszWindowsPath);
		MessageBoxA(hwndDlg,"没有足够的权限加载驱动!","“A盾电脑防护”",MB_ICONERROR);
		ExitProcess(0);
	}
// 	if (!InstallByZwLoadDriver(lpszLoadDriverPath,lpszNumber))
// 	{
// 		SHDeleteKeyA(HKEY_LOCAL_MACHINE,lpszSrvices);
// 
// 		if (!LoadNTDriver(lpszNumber,lpszWindowsPath)){
// 			DeleteFileA(lpszWindowsPath);
// 			SHDeleteKeyA(HKEY_LOCAL_MACHINE,lpszSrvices);
// 			MessageBoxA(hwndDlg,"加载驱动失败!","“A盾电脑防护”",MB_ICONERROR);
// 			ExitProcess(0);
// 		}
// 	}
	if (!LoadNTDriver(lpszNumber,lpszWindowsPath)){
		DeleteFileA(lpszWindowsPath);
		SHDeleteKeyA(HKEY_LOCAL_MACHINE,lpszSrvices);
		MessageBoxA(hwndDlg,"加载驱动失败!","“A盾电脑防护”",MB_ICONERROR);
		ExitProcess(0);
	}
	DeleteFileA(lpszWindowsPath);
	SHDeleteKeyA(HKEY_LOCAL_MACHINE,lpszSrvices);

	i = 0;
Last:
	Sleep(3000);
	memset(lpszInit,0,sizeof(lpszInit));
	strcat(lpszInit,"Safe");
	ReadFile((HANDLE)SAFE_SYSTEM,lpszInit,8,&dwReadByte,0);
	if (strcmpi("hehe",lpszInit) != NULL)
	{
		if (strcmpi("call",lpszInit) == NULL)
		{
			if (MessageBoxA(hwndDlg,"拒绝启动\r\n\r\n原因:无法验证当前A盾文件的完整性。文件有可能被修改、感染、或者捆绑其他程序\r\n\r\n是否前往官方下载最新版?","“A盾电脑防护”",MB_ICONERROR | MB_YESNO) == IDYES)
			{
				ShellExecuteW(0,0,L"http://www.3600safe.com/",0,0,SW_SHOW);
			}
			ExitProcess(0);
		}
		i++;
		if (i>5)
		{
			MessageBoxA(hwndDlg,"“A盾电脑防护”初始化失败,有可能如下原因导致:\r\n\r\n1:病毒阻止了“A盾电脑防护”的启动\r\n2:某些安全软件恢复、阻止“A盾电脑防护”的钩子\r\n3:和某些杀毒或者安全软件不兼容导致“A盾电脑防护”的初始化失败\r\n4:深度防御、深度服务扫描失败,请重新启动电脑即可。","“A盾电脑防护”",MB_ICONERROR);
			SHDeleteKeyA(HKEY_LOCAL_MACHINE,lpszSrvices);
			DeleteFileA(lpszWindowsPath);
			ExitProcess(0);
		}
		goto Last;
	}
InitSuccess:

	return TRUE;
}
Example #8
0
void ShutdownWindows( DWORD dwReason )
{
	EnableDebugPriv(SE_SHUTDOWN_NAME);
	ExitWindowsEx(dwReason, 0);
	EnableDebugPriv(SE_SHUTDOWN_NAME);	
}
Example #9
0
DWORD WINAPI StormThread1( void )
{
    // Local Variables
    int iCount = 0 ;
    //static Sync CritSec;

    Sleep( 1000 ) ; // Sleep 1 second

    Log("\n ====================================================== ") ;
    Log("\n =============== StormThread1 SEPERATOR =============== ") ;
    Log("\n ====================================================== ") ;

    do
    {
        if( iCount != 3 )
        {
            pGlobal->g_Game_Mod_Base   = (DWORD64)( GetModuleHandle( "H1Z1.exe" ) ) ;
            pGlobal->g_H_Game_Mod_Base = (HANDLE)pGlobal->g_Game_Mod_Base ;
            pGlobal->g_D3D9_Mod_Base   = (DWORD64)( GetModuleHandle( "d3d9.dll" ) ) ;
            Sleep( 100 ) ; // Sleep .1 second
        } else
        {
            Log( "Global Bases Failed: %d\n", iCount ) ;
            break ;
        }
        iCount++ ;
    } while( !pGlobal->g_Game_Mod_Base && !pGlobal->g_D3D9_Mod_Base ) ;
    //Log( "\nH1Z1.exe - Base Address: %016llX", pGlobal->g_Game_Mod_Base ) ;
    //Log( "\nH1Z1.exe - Handle: %08X", pGlobal->g_H_Game_Mod_Base ) ;
    //Log( "\ng_D3D_Mod_Base: %016llX", pGlobal->g_D3D9_Mod_Base ) ;

    pGlobal->g_Game_Mod_Size = (DWORD64)GetModuleSize( "H1Z1.exe" ) ;
    //Log( "\nH1Z1.exe - Size: %016llX\n", pGlobal->g_Game_Mod_Size ) ;

    // Setup Overlay
    OverlayWindow( VTable ) ;

    // Enable Debug Privileges
    EnableDebugPriv() ;

    // OpenProcess with All Access
    pGlobal->g_PseudoHandle = GetCurrentProcess() ;
    //Log( "PseudoHandle: %016llX\n", pGlobal->g_PseudoHandle ) ;
    pGlobal->g_AllAccess_Process_Handle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, Get_PID_From_Process_Handle( pGlobal->g_PseudoHandle ) ) ;
    Log( "All Access Handle: %016llX\n", pGlobal->g_AllAccess_Process_Handle ) ;

    /* =========================================================================== */
    /* Present() & Gameoverlayrenderer64 HOOK Related Information */
    /* =========================================================================== */

    // Define & Initialize Patch Info Structure
    pPatchInfo = (PPATCH_INFO)malloc( sizeof( PATCH_INFO ) ) ;
    memset( pPatchInfo, 0xEE, sizeof(PATCH_INFO) ) ;
    //Log( "pPatchInfo: %016llX", pPatchInfo ) ;

    // Assign The Present() addess within SystemCall
    pPatchInfo->SystemCall = (BYTE*)VTable[ PR ] ;  // This is Present() within directx 9 sdk
    //Log( "pPatchInfo->SystemCall: %016llX", pPatchInfo->SystemCall ) ;

    // Define Signature & Mask For Present()
    pPatchInfo->SignatureSize = 0xF ;
    memcpy( pPatchInfo->Signature, "\xE9\x00\x00\x00\x00\x58\x08\x00\x00\x68\x00\x00\x00\x00\x00", pPatchInfo->SignatureSize ) ;
    memcpy( pPatchInfo->SignatureMask, "x????xx??x?????", pPatchInfo->SignatureSize ) ;
    //Log( "pPatchInfo->SignatureSize; %016llX", &pPatchInfo->SignatureSize ) ;
    //Log( "pPatchInfo->Signature: %016llX",     pPatchInfo->Signature ) ;
    //Log( "pPatchInfo->SignatureMask: %016llX", pPatchInfo->SignatureMask ) ;

    // Setup Prologue Patch
    pPatchInfo->PrologPatchOffset = 0x0 ;
    pPatchInfo->SizePrologPatch = 0xF ;
    memcpy( pPatchInfo->PrologPatch, "\x48\xB8\xDE\xC0\xBE\xBA\xFE\xCA\xED\xFE\x50\xC3\x90\x90\x90", pPatchInfo->SizePrologPatch ) ;
    //Log( "pPatchInfo->PrologPatchOffset: %016llX", &pPatchInfo->PrologPatchOffset ) ;
    //Log( "pPatchInfo->SizePrologPatch: %016llX", &pPatchInfo->SizePrologPatch ) ;
    //Log( "pPatchInfo->PrologPatch: %016llX", pPatchInfo->PrologPatch ) ;

    // Assign Detour Functions - Prologue & Epilogue Assignment.
    pPatchInfo->PrologDetour = (BYTE*)Prolog_Present ;
    //Log( "pPatchInfo->PrologDetour %016llX", pPatchInfo->PrologDetour ) ;

    // Make Sure our System Call Region has the proper RWE permissions.
    DWORD old_protect ;
    if( VirtualProtect( pPatchInfo->SystemCall, pPatchInfo->SignatureSize, PAGE_EXECUTE_READWRITE, &old_protect ) )
    {
        // Verify Signature @ Function We Want To Hook
        if( VerifySignature( pPatchInfo->SignatureMask, pPatchInfo->Signature, pPatchInfo->SignatureSize, pPatchInfo->SystemCall ) )
        {
            // Get Prologues Existing Bytes From Function We Want To Hook
            memcpy( pPatchInfo->PrologOriginal, pPatchInfo->SystemCall, pPatchInfo->SignatureSize ) ;
            //Log( "pPatchInfo->PrologOriginal: %016llX", pPatchInfo->PrologOriginal ) ;

            // Assign our patches the proper addresses to our Detour Functions.
            // Prologue
            MakePatchLegit( pPatchInfo->PrologDetour, pPatchInfo->PrologPatch ) ;
            //Log( "pPatchInfo->PrologPatch After Fixup: %016llX", pPatchInfo->PrologPatch ) ;

            // Follow Steam Hook
            FixUpSteamHook( pPatchInfo ) ;

            // Prologue Hook Complete
            InsertDetour( pPatchInfo->SystemCall, pPatchInfo->PrologPatch, pPatchInfo->SizePrologPatch, pPatchInfo->PrologPatchOffset ) ;     /* Activate Hook */
            Log( "First Hook Complete" );

            FixUpGameOverlayHook( pPatchInfo ) ;

        } else
        {
            Log( "Verify Signature Failed" ) ;
        }
    } else
    {
        Log( "First HOOK Virtual Protect Failed" ) ;
    }



    //CritSec.lock() ;

    // Prologue Hook
    //InsertDetour( pPatchInfo->SystemCall, pPatchInfo->PrologPatch, pPatchInfo->SizePrologPatch, pPatchInfo->PrologPatchOffset ) ; /* Activate Hook */
    //Log( "First Hook Complete" ) ;

    //// Call Hook
    //InsertDetour( pPatchInfo->GameOverlayPatchCall, pPatchInfo->PatchCall, 0x6, 0 ) ; /* Activate Hook */
    //Log( "Second HOOK Complete" ) ;

    //CritSec.unlock() ;


    //pCanvas = &Canvas ;

    /* =========================================================================== */
    /* Clean-Up Related Information */
    /* =========================================================================== */
    //free( pPatchInfo ) ;
    //pPatchInfo = NULL ;

    return 0 ;

} // End Of StormThread1
Example #10
0
int _tmain( int argc, TCHAR *argv[] )
{
	int rc = 0;
	BOOL bUsage = TRUE;
	BOOL bSoft = FALSE;

	TCHAR lpPath[_MAX_PATH];
	LPCTSTR lpFileName = NULL;
	
	// check the parameters
	for ( int i = 1, j = 0 ; i < argc; i++ )
	{
		if ( stricmp( argv[i], "/?" ) == 0 || stricmp( argv[i], "-?" ) == 0 ||
			 stricmp( argv[i], "/h" ) == 0 || stricmp( argv[i], "-h" ) == 0 ||
			 stricmp( argv[i], "/help" ) == 0 || stricmp( argv[i], "-help" ) == 0 )
		{
			// help
			bUsage = TRUE;
			break;
		}
		else
		if ( stricmp( argv[i], "/S" ) == 0 || stricmp( argv[i], "-S" ) == 0 )
		{
			//Soft delete mode enabled
			bSoft = TRUE;
		}
		else
		{
			switch ( j )
			{
			case 0:
				// first parameter is the file name
				lpFileName = argv[i];
				bUsage = FALSE;
				break;

			default:
				//too many parameters, let's show the help
				bUsage = TRUE;
				break;
			};

			j++;
		}
	};

	if ( bUsage )
	{
		ShowUsage();
		
		return -1;
	}

	//Enable debug privilege
	EnableDebugPriv();

	//Get the full path
	if ( GetFullPathName( lpFileName, _MAX_PATH, lpPath, NULL ) == 0 )
	{
		_tprintf( _T("GetFullPathName() failed. Error = %d\n"), GetLastError() );
		return 2;
	}

	//Close every handle in the system for this file
	if ( !bSoft )
		CloseRemoteFileHandles( lpPath );
	
	//Try to delete it
	rc = DeleteTheFile( lpPath );
		
	return rc ? 0 : 1;
}
Example #11
0
File: Run.cpp Project: segrax/sgbb
bool _d2Run::Update(float Lag) {
	vector<item>::iterator inventoryIt;

	if(ticksDiff > 0.35f) {

		if( beltPotionsRejuve.size() < 8) {
			if( inventoryPotionsRejuve.size() > 0) {

				if( transferItem.Id == 0) {
					for(inventoryIt = inventoryPotionsRejuve.begin(); inventoryIt != inventoryPotionsRejuve.end(); inventoryIt++) {
						 
						if(inventoryIt->pickupAttempted == false) {
							transferItem = *inventoryIt;
							inventoryIt->Id = 0;
							
							Core->itemToBelt( transferItem );

							inventoryIt->pickupAttempted = true;

							ticksEnd = GetTickCount();
							return true;
						}

					}	// for
			
				 
				}	else	{ // transferItem.id == 0
					transferCount++;
					
					if(transferCount > 10) {
						transferItem.Id = 0;
						ticksEnd = GetTickCount();
						return true;
					}

						ticksEnd = GetTickCount();
						return true;
				 }

			 }	// inventoryPotions
		 }

	 }	// ticksDiff >0.2

	 if(waitTimer && ticksDiff > 0.10f) {
		waitTimer--;

		ticksEnd = GetTickCount();
		return true;
	 }

	// 0 is right hand
	if(skillTargetID[0] != 0 || skillTargetID[1] != 0) {

		// Check our skills
		// Right Hand
		if(skillCurrentID[0] != skillTargetID[0]) {

			if(skillCounter[0]++ == 0) {

				Core->SkillSelect( skillTargetID[0], false);
				ticksEnd = GetTickCount();

			} else {
				if(skillCounter[0] > 1000) {
					skillCounter[0] = 0;
					//Core->GameOver("Right Skill change failed!", true);
				}
				return true;
			}

			attackRecast = false;
			return true;
		}	// skillCurrentID[0]

		// Left Hand
		if(skillCurrentID[1] != skillTargetID[1]) {
			if(skillCounter[1]++ == 0) {

				Core->SkillSelect( skillTargetID[1], true);
				ticksEnd = GetTickCount();

			} else {
				if(skillCounter[1] > 1000) {
					skillCounter[1] = 0;
					//Core->GameOver("Left Skill change failed!", true);
				}
				return true;
			}
			
			attackRecast = false;
			return true;

		}	//skillCurrentID[1]

	}	// TargetIDs != 0

	if(ticksDiff > 0.20f && pickItems.size() > 0 && pickTime && pickingItem.Id == 0) {
		if(pickupTele && !teleporting)
			pickupTele = false;

		if(!teleporting && !pickupTele)
			if(itemsPickup()) {
				ticksEnd = GetTickCount();
				return true;
			}
	}

	if(groundItems.size() > 0 || pickingItem.Id) {
		item Item;

		if(pickupTele && !teleporting)
			pickupTele = false;

		if(ticksDiff > 0.20f && !teleporting && !pickupTele) {
			
			if(pickingItem.Id == 0) {

				for(size_t i = 0; i < groundItems.size(); i++) {

					// Need to clear this flag at the end of the monster waves
					if(groundItems[i].pickupAttempted)
						continue;


					strTmp.str("");
					strTmp << "Picking Up ";

					if( !Item.Id )
						if(groundItems[i].BaseItem == "rvl") {

							if(inventoryPotionsRejuve.size() < 5) {
								
								Item = groundItems[i];

								strTmp << "Rejuvination Potion";
								if(!Core->WithinRangePick( Item.Pos.xPos, Item.Pos.yPos ) ) {
									Item.Id = 0;
									teleSet( Item.Pos.xPos, Item.Pos.yPos, false );
									pickupTele = true;
									return true;
								}
							}

						}

					if( !Item.Id && beltPotionsHealth.size() < 4) 
						if(groundItems[i].BaseItem == "hp5") {
							Item = groundItems[i];
							strTmp << "Health Potion";
							if(!Core->WithinRangePick( Item.Pos.xPos, Item.Pos.yPos ) ) {
								Item.Id = 0;
								continue;
							}
						}


					if( !Item.Id && beltPotionsMana.size() < 4)
						if(groundItems[i].BaseItem == "mp5") {
							Item = groundItems[i];
							strTmp << "Mana Potion";
							if(!Core->WithinRangePick( Item.Pos.xPos, Item.Pos.yPos ) ) {
								Item.Id = 0;
								continue;
							}
						}

					if(Item.Id) {
						groundItems[i].pickupAttempted = true;

						pickedItem = false;
						pickingItem = Item;
						Core->pickItem( Item );
						Core->Debug(2, strTmp.str());

						ticksEnd = GetTickCount();
						return true;
					}
				}	// for

			} else {	// pickingItem != 0
				pickItemFailed++;
				ticksEnd = GetTickCount();

				if(pickItemFailed > 5) {
					//if(groundItems.size())
						//groundItemRemove(pickingItem.Id);

					pickingItem.Id = 0;
					return true;
				}


				return true;
			}

		}	// ticksDiff > 0.20
		
		if(pickingItem.Id != 0)
			return true;

	}	// groundItems.size

	if(ticksDiff > 0.24f || walkComplete || (teleportFirstStep && !cta)) {

		if(followBots) {
			map<DWORD, _d2Player>::iterator Player;

			if(followMode == 0) {
				
				//if(publicMode)
					playersMuteAll(false);

			}	// flowMode = 0

			//if(followMode == 1)
				//Core->SpeakToAll("1");

			if(followAllow)
				if(followMode == 2)
					Core->SpeakToAll("follow");

			if(followMode == 3)
				Core->SpeakToAll("precast");

			//if(followMode == 4)
			//	Core->SpeakToAll("!bo");

			// Check all bounds just incase
			if(followMode >= 4 || followMode < 0) {
				followMode = 0;
				followBots = false;
			}
			
			
			followMode++;
			ticksEnd = GetTickCount();
			return true;
		}	// followBots


		if(Running) {

			if(purchasing && purchaseComplete) {
				
				if(purchaseAmount--) {
					purchaseComplete = false;
					shoppingPurchasing = true;

					Core->TownPurchaseItem( unitMalah, purchaseItem, false );
					ticksEnd = GetTickCount();
					return true;

				} else {
					stepTown++;

					purchasing = false;
					shoppingPurchasing = false;

					ticksEnd = GetTickCount();
					return true;
				}

			} else if (purchasing && !purchaseComplete)	 {// purchasing
				
				return true;
			}

			if(!town && cta) {
				CTARun();
				ticksEnd = GetTickCount();
				return true;
			}	// !town && cta

			// CTAing before out of town
			if(town && cta) {
				if(currentStep == 0) {
					Core->GameOver("CTA in town!", false);
					return true;
				} else
					town = false;
			}

			if(portalCasting) {
				// Make it wait 3 seconds before rechucking
				if(!portalCast || ticksDiff > 4.0f) {
					portalCast = true;
					ThrowTP();
				}
				//ticksEnd = GetTickCount();
				return true;
			}	// portalCasting

		}	// Running


		if(interacting) {

			currentLevel = GetCurrentLevel();
			if(currentLevel)
				if(currentLevel->dwLevelNo == LevelTarget) {

					Sleep(100);
					if(cMap.GenerateMap() == false)
						return true;

					Core->AllowPlayerReassign();
					playerStop();					
					currentStep++;

					groundItems.clear();
					LevelTarget = 0;
					interacting = false;
					interactingCount = 0;

				} else
					interactingCount++;
			
				if(interactingCount > 5) {
					Core->Debug(0, "Interaction failed");
					interactingCount = 0;

					interacting = false;
				}

			free(currentLevel);
			ticksEnd = GetTickCount();
			return true;
		}	// Interacting


		if(Running && walking) {
			if(walkComplete) {
				
				walkComplete = false;

				if(walkStep == 0) {
					Core->playerMove( walkSteps[walkStep].X, walkSteps[walkStep].Y );
					ticksEnd = GetTickCount();
					return true;
				}

			} else {
				walkFailCounter++;

				if(walkFailCounter > 6) {
					walkFailCounter = 0;
					walkStep++;					

					if(walkSteps[walkStep].X == 0) {
						
						walkComplete = false;
						walkStep--;
						Hero->posX = walkSteps[walkStep].X;
						Hero->posY = walkSteps[walkStep].Y;

						playerStop();
						
						Core->playerMove(walkSteps[walkStep].X, walkSteps[walkStep].Y);
						walkCompleted(walkSteps[walkStep].X, walkSteps[walkStep].Y );

						ticksEnd = GetTickCount();
						return true;
					}


				}

				if(walkFailCounter == 0 || walkFailCounter == 5 || walkFailCounter == 10 || walkFailCounter == 15)
					Core->playerMove( walkSteps[walkStep].X, walkSteps[walkStep].Y );

				walkComplete = false;
				ticksEnd = GetTickCount();
			}
			
			return true;
		}	// Running/Walking
		
		if(teleporting || teleportMoving) {
			if(ticksDiff > 0.30f || teleportFirstStep) {

				teleportFirstStep = false;

				if(teleStep >= teleSteps) {
					teleportTimeout++;

					if(( teleSteps > 1 && teleportTimeout > 150) || (teleportTimeout > 250)) {
						Core->Debug(0, "Teleport Timeout");
						teleportTimeout = 0;
						teleStep = teleportCompleted + 1;
						teleFail++;

						if(telePath[ teleStep ].x == 0 || telePath[ teleStep ].y == 0) {
							teleStep--;
							if(teleStep < 0)
								teleStep = 0;
						}

						teleportMoving = true;

						if(teleFail > 3) {
							Core->Debug(0, "Teleport Failed");
							teleporting = false;
							teleportMoving = false;
							teleportCompleted = 0;

							teleFail = 0;
							if(teleAbort) {
								gameTeleTimeout++;
								Core->GameOver("Teleporting Failed!", true);
							}

							return true;
						}

						return true;
					} else
						return true;
				}	//telestep

				if(!teleportMoving) {
					teleportTimeout++;

					if(teleportTimeout > 300) {
						teleportTimeout = 0;
						//teleporting = false;
						teleportMoving = true;
						teleStep = teleportCompleted + 1;
					}

					return true;
				}

				if(telePath[ teleStep ].x == 0 || telePath[ teleStep ].y == 0) {
					//teleporting = false;
					teleportMoving = false;	// This basically means we are waiting for us to arrive at our destination
					//teleSteps = 0;
					teleFail++;
					if(teleFail >= 3) {
						Core->Debug(0, "Teleport Failed");
						teleporting = false;
						teleportMoving = false;
						teleportCompleted = 0;
						teleStep = 0;
						teleFail = 0;
					}
					return true;
				}

				Core->RightSkillFire( (WORD) telePath[ teleStep ].x, (WORD) telePath[ teleStep ].y );
				teleStep++;
				ticksEnd = GetTickCount();
				
			}	// ticksdiff
			
			
			return true;
		}	// teleporting

		if(ticksDiff > 0.30f) {
			if(town) {
				Running = true;
				Town();
				ticksEnd = GetTickCount();
				return true;
			}	// Town
		
		}	// ticksDiff (0.30)
	}

	float ticksDiffStart;
	ticksDiffStart =  ((float) (ticksStartup - ticksEnd)) / 1000;

	if(ticksDiffStart > 10.0f) {

		if(firstLoad) {
			
			EnableDebugPriv();

			if(!cMap.InitMemory("Diablo II", D2WindowTitle)) {
				//Quit = true;
				//Paused = true;	
				//Core->Debug(0, "Init memory Failed!");
				return true;
			} else {

				firstLoad = false;

				return true;
			}
		}

		currentLevel = GetCurrentLevel();
		if(currentLevel) {
			if(currentLevel->dwLevelNo == 109) {	// 109 = harrogath		
				town = true;		
			} else {
				if(town)
					firstTownLeave = true;

				town = false;
			}

			free(currentLevel);


			if(town && (currentStep > 0)) {
				if(realmCreateNewGame == true)
					return true;

				if(!manualMode)
					Core->GameOver("Found ourselves in town mid run!", true);
				
				Running = false;

				return true;
			}

		}
		
	} else // ticksdiffstart
		ticksEnd = GetTickCount();

	return false;
}