void* GetPEBLocation(HANDLE hProcess)
{
	NTSTATUS ntstat = 0;
    ULONG RequiredLen = 0;
    void * PebAddress = 0;
    PROCESS_BASIC_INFORMATION myProcessBasicInformation = { 0 };

	ntstat = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &myProcessBasicInformation, sizeof(PROCESS_BASIC_INFORMATION), &RequiredLen);

    if (ntstat == STATUS_SUCCESS)
    {
        PebAddress = (void*)myProcessBasicInformation.PebBaseAddress;
    }
	else
	{
		LogError("NtQueryInformationProcess failed with status %X", ntstat);
	}

	if (!PebAddress)
	{
		LogErrorBox("GetPEBLocation PEB Address is 0");
	}

    return PebAddress;
}
/** Starts the next job in the list */
void D2DContentDownloadDialog::RunNextJob()
{
	// Clean up potential done job
	delete Zip; Zip = NULL;
	delete Downloader; Downloader = NULL;

	if(NextJobs.empty())
	{
		SetHidden(true); // FIXME: Add method to actually close these dialogs...

		// We're done with everything, apply changes
		Engine::GAPI->ReloadTextures();

		return;
	}

	Zip = new ZipArchive;

	// Get next job
	Job = NextJobs.front();
	NextJobs.pop_front();

	LogInfo() << "Downloading file: " << Job.DownloadPackage;

	// Start new download
	switch(DownloadType)
	{
	case EDL_Normalmaps_Find:
	default:
		{
			// Find which normalmap package we have to download
			std::string pck = ModSpecific::GetModNormalmapPackName();

			Header->SetCaption("Downloading...");
			CreateDirectory(Job.TargetPath.c_str(), NULL);
			TargetFolder = Job.TargetPath.c_str();
		}
		break;
	}

	try{
		Downloader = new FileDownloader("http://www.gothic-dx11.de/download/" + Job.DownloadPackage, Job.DownloadPackage, ProgressCallback, this);
	}catch(std::exception e)
	{
		LogErrorBox() << "Failed to start content download. Reason: " << e.what();
		delete Downloader;

		// FIXME: Ugly. Should close this on error.
		SetHidden(true); 
		return;
	}

	
}
Example #3
0
//--------------------------------------------------------------------------------------
// Find and compile the specified shader
//--------------------------------------------------------------------------------------
HRESULT D3D11VShader::CompileShaderFromFile(const CHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut, std::vector<D3D10_SHADER_MACRO>& makros)
{
	HRESULT hr = S_OK;

	char dir[260];
	GetCurrentDirectoryA(260, dir);
	SetCurrentDirectoryA(Engine::GAPI->GetStartDirectory().c_str());

	DWORD dwShaderFlags = 0;
#if defined( DEBUG ) || defined( _DEBUG )
	// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
	// Setting this flag improves the shader debugging experience, but still allows 
	// the shaders to be optimized and to run exactly the way they will run in 
	// the release configuration of this program.
	//dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif

	// Construct makros
	std::vector<D3D10_SHADER_MACRO> m;
	D3D11GraphicsEngine::ConstructShaderMakroList(m);
	
	// Push these to the front
	m.insert(m.begin(), makros.begin(), makros.end());

	ID3DBlob* pErrorBlob;
	hr = D3DX11CompileFromFileA(szFileName, &m[0], NULL, szEntryPoint, szShaderModel,
		dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL);
	if (FAILED(hr))
	{
		LogInfo() << "Shader compilation failed!";
		if (pErrorBlob != NULL)
		{

			LogErrorBox() << (char*)pErrorBlob->GetBufferPointer() << "\n\n (You can ignore the next error from Gothic about too small video memory!)";
			pErrorBlob->Release();
		}

		SetCurrentDirectoryA(dir);
		return hr;
	}
	if (pErrorBlob)
	{
		/*if(Engine->SwapchainCreated())
		Engine->GetConsole()->PostConsoleMessage((char*)pErrorBlob->GetBufferPointer());
		else
		LogWarnBox() << (char*)pErrorBlob->GetBufferPointer() << "\n\n (You can ignore the next error from Gothic about too small video memory!)";
		*/
		pErrorBlob->Release();
	}

	SetCurrentDirectoryA(dir);
	return S_OK;
}
void ReadPebToBuffer(HANDLE hProcess, unsigned char * buffer, int bufferSize)
{
	void * AddressOfPEB = GetPEBLocation(hProcess);
	if (AddressOfPEB)
	{
		if (!ReadProcessMemory(hProcess, AddressOfPEB, (void*)buffer, bufferSize, 0))
		{
			LogError("ReadPebToBuffer->ReadProcessMemory failed");
		}
	}
	else
	{
		LogErrorBox("ReadPebToBuffer->GetPEBLocation returns NULL");
	}	
}