Skip to content

Commit

Permalink
Show errors at runtime if game capture files are blocked by AV
Browse files Browse the repository at this point in the history
  • Loading branch information
notr1ch committed Apr 25, 2014
1 parent 9977a22 commit ec4ef87
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 75 deletions.
187 changes: 112 additions & 75 deletions GraphicsCapture/GraphicsCaptureSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,35 @@ void GraphicsCaptureSource::BeginScene()
AttemptCapture();
}

BOOL GraphicsCaptureSource::CheckFileIntegrity(LPCTSTR strDLL)
{
HANDLE hFileTest = CreateFile(strDLL, GENERIC_READ | GENERIC_EXECUTE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFileTest == INVALID_HANDLE_VALUE)
{
String strWarning;

DWORD err = GetLastError();
if (err == ERROR_FILE_NOT_FOUND)
strWarning = TEXT("Important game capture files have been deleted. This is likely due to anti-virus software. Please make sure the OBS folder is excluded or ignored from any anti-virus / security software and re-install OBS.");
else if (err == ERROR_ACCESS_DENIED)
strWarning = TEXT("Important game capture files can not be loaded. This is likely due to anti-virus or security software. Please make sure the OBS folder is excluded / ignored from any anti-virus / security software.");
else
strWarning = FormattedString(TEXT("Important game capture files can not be loaded (error %d). This is likely due to anti-virus or security software. Please make sure the OBS folder is excluded / ignored from any anti-virus / security software."), err);

Log(TEXT("GraphicsCaptureSource::CheckFileIntegrity: Error %d while accessing %s"), err, strDLL);

//not sure if we should be using messagebox here, but probably better than "help why do i have black screen"
OBSMessageBox(API->GetMainWindow(), strWarning.Array(), NULL, MB_ICONERROR | MB_OK);

return FALSE;
}
else
{
CloseHandle(hFileTest);
return TRUE;
}
}

void GraphicsCaptureSource::AttemptCapture()
{
//Log(TEXT("attempting to capture.."));
Expand All @@ -338,7 +367,7 @@ void GraphicsCaptureSource::AttemptCapture()
targetThreadID = GetWindowThreadProcessId(hwndTarget, &targetProcessID);
if (!targetThreadID || !targetProcessID)
{
AppWarning(TEXT("GraphicsCaptureSource::BeginScene: GetWindowThreadProcessId failed, GetLastError = %u"), GetLastError());
AppWarning(TEXT("GraphicsCaptureSource::AttemptCapture: GetWindowThreadProcessId failed, GetLastError = %u"), GetLastError());
bErrorAcquiring = true;
return;
}
Expand Down Expand Up @@ -425,99 +454,107 @@ void GraphicsCaptureSource::AttemptCapture()
if(Is64BitWindows())
IsWow64Process(hProcess, &b32bit);

if (bSameBit && !useSafeHook)
{
String strDLL;
DWORD dwDirSize = GetCurrentDirectory(0, NULL);
strDLL.SetLength(dwDirSize);
GetCurrentDirectory(dwDirSize, strDLL);

strDLL << TEXT("\\plugins\\GraphicsCapture\\GraphicsCaptureHook");
//verify the hook DLL is accessible
String strDLL;
DWORD dwDirSize = GetCurrentDirectory(0, NULL);
strDLL.SetLength(dwDirSize);
GetCurrentDirectory(dwDirSize, strDLL);

BOOL b32bit = TRUE;
if (Is64BitWindows())
IsWow64Process(hProcess, &b32bit);
strDLL << TEXT("\\plugins\\GraphicsCapture\\GraphicsCaptureHook");

if (!b32bit)
strDLL << TEXT("64");
if (!b32bit)
strDLL << TEXT("64");

strDLL << TEXT(".dll");
strDLL << TEXT(".dll");

if (InjectLibrary(hProcess, strDLL))
{
captureWaitCount = 0;
bCapturing = true;
}
else
{
AppWarning(TEXT("GraphicsCaptureSource::BeginScene: Failed to inject library, GetLastError = %u"), GetLastError());

CloseHandle(hProcess);
hProcess = NULL;
bErrorAcquiring = true;
}
if (!CheckFileIntegrity(strDLL.Array()))
{
bErrorAcquiring = true;
}
else
{

String strDLLPath;
DWORD dwDirSize = GetCurrentDirectory(0, NULL);
strDLLPath.SetLength(dwDirSize);
GetCurrentDirectory(dwDirSize, strDLLPath);

strDLLPath << TEXT("\\plugins\\GraphicsCapture");

String strHelper = strDLLPath;
strHelper << ((b32bit) ? TEXT("\\injectHelper.exe") : TEXT("\\injectHelper64.exe"));

String strCommandLine;
strCommandLine << TEXT("\"") << strHelper << TEXT("\" ");
if (useSafeHook)
strCommandLine << UIntString(targetThreadID) << " 1";
else
strCommandLine << UIntString(targetProcessID) << " 0";

//---------------------------------------

PROCESS_INFORMATION pi;
STARTUPINFO si;

zero(&pi, sizeof(pi));
zero(&si, sizeof(si));
si.cb = sizeof(si);

if (CreateProcess(strHelper, strCommandLine, NULL, NULL, FALSE, 0, NULL, strDLLPath, &si, &pi))
if (bSameBit && !useSafeHook)
{
int exitCode = 0;

CloseHandle(pi.hThread);

if (!useSafeHook)
{
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, (DWORD*)&exitCode);
CloseHandle(pi.hProcess);
}
else
{
injectHelperProcess = pi.hProcess;
}

if (exitCode == 0)
if (InjectLibrary(hProcess, strDLL))
{
captureWaitCount = 0;
bCapturing = true;
}
else
{
AppWarning(TEXT("GraphicsCaptureSource::BeginScene: Failed to inject library, error code = %d"), exitCode);
AppWarning(TEXT("GraphicsCaptureSource::AttemptCapture: Failed to inject library, GetLastError = %u"), GetLastError());
bErrorAcquiring = true;
}
}
else
{
AppWarning(TEXT("GraphicsCaptureSource::BeginScene: Could not create inject helper, GetLastError = %u"), GetLastError());
bErrorAcquiring = true;
String strDLLPath;
DWORD dwDirSize = GetCurrentDirectory(0, NULL);
strDLLPath.SetLength(dwDirSize);
GetCurrentDirectory(dwDirSize, strDLLPath);

strDLLPath << TEXT("\\plugins\\GraphicsCapture");

String strHelper = strDLLPath;
strHelper << ((b32bit) ? TEXT("\\injectHelper.exe") : TEXT("\\injectHelper64.exe"));

if (!CheckFileIntegrity(strHelper.Array()))
{
bErrorAcquiring = true;
}
else
{
String strCommandLine;
strCommandLine << TEXT("\"") << strHelper << TEXT("\" ");
if (useSafeHook)
strCommandLine << UIntString(targetThreadID) << " 1";
else
strCommandLine << UIntString(targetProcessID) << " 0";

//---------------------------------------

PROCESS_INFORMATION pi;
STARTUPINFO si;

zero(&pi, sizeof(pi));
zero(&si, sizeof(si));
si.cb = sizeof(si);

if (CreateProcess(strHelper, strCommandLine, NULL, NULL, FALSE, 0, NULL, strDLLPath, &si, &pi))
{
int exitCode = 0;

CloseHandle(pi.hThread);

if (!useSafeHook)
{
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, (DWORD*)&exitCode);
CloseHandle(pi.hProcess);
}
else
{
injectHelperProcess = pi.hProcess;
}

if (exitCode == 0)
{
captureWaitCount = 0;
bCapturing = true;
}
else
{
AppWarning(TEXT("GraphicsCaptureSource::AttemptCapture: Failed to inject library, error code = %d"), exitCode);
bErrorAcquiring = true;
}
}
else
{
AppWarning(TEXT("GraphicsCaptureSource::AttemptCapture: Could not create inject helper, GetLastError = %u"), GetLastError());
bErrorAcquiring = true;
}
}
}
}
}
Expand All @@ -533,7 +570,7 @@ void GraphicsCaptureSource::AttemptCapture()
}
else
{
AppWarning(TEXT("GraphicsCaptureSource::BeginScene: OpenProcess failed, GetLastError = %u"), GetLastError());
AppWarning(TEXT("GraphicsCaptureSource::AttemptCapture: OpenProcess failed, GetLastError = %u"), GetLastError());
bErrorAcquiring = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions GraphicsCapture/GraphicsCaptureSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GraphicsCaptureSource : public ImageSource
void EndCapture();

void AttemptCapture();
BOOL CheckFileIntegrity(LPCTSTR path);

static void STDCALL CaptureHotkey(DWORD hotkey, GraphicsCaptureSource *capture, bool bDown);

Expand Down

0 comments on commit ec4ef87

Please sign in to comment.