Beispiel #1
0
bool CText::Init()
{
#define LoadFTFunc(ptr, type, name) (FreeType_loaded&=(ptr=(type)GetProcAddress(FreeType,name))!=NULL)

	if (FreeType_loaded)
		return true;

	SetDllDirectory(CSettings::DataDir);
	FreeType=LoadLibrary(FREETYPE_DLL);
	SetDllDirectory(NULL);

	if (FreeType)
	{
		FreeType_loaded=true;
		LoadFTFunc(pFT_Init_FreeType,ptr_FT_Init_FreeType,"FT_Init_FreeType");
		LoadFTFunc(pFT_Done_FreeType,ptr_FT_Done_FreeType,"FT_Done_FreeType");
		LoadFTFunc(pFT_New_Face,ptr_FT_New_Face,"FT_New_Face");
		LoadFTFunc(pFT_Done_Face,ptr_FT_Done_Face,"FT_Done_Face");
		LoadFTFunc(pFT_Set_Char_Size,ptr_FT_Set_Char_Size,"FT_Set_Char_Size");
		LoadFTFunc(pFT_Get_Char_Index,ptr_FT_Get_Char_Index,"FT_Get_Char_Index");
		LoadFTFunc(pFT_Load_Glyph,ptr_FT_Load_Glyph,"FT_Load_Glyph");
		LoadFTFunc(pFT_Done_Glyph,ptr_FT_Done_Glyph,"FT_Done_Glyph");
		LoadFTFunc(pFT_Get_Glyph,ptr_FT_Get_Glyph,"FT_Get_Glyph");
		LoadFTFunc(pFT_Glyph_To_Bitmap,ptr_FT_Glyph_To_Bitmap,"FT_Glyph_To_Bitmap");
	}

	return FreeType_loaded;
}
/*
** Attempts to load Rainmeter.dll. If it fails, retries after loading our own copies of the CRT
** DLLs in the Runtime directory.
*/
HINSTANCE LoadRainmeterLibrary()
{
	HINSTANCE rmDll = LoadLibrary(L"Rainmeter.dll");
	if (!rmDll)
	{
		WCHAR path[MAX_PATH];
		if (GetModuleFileName(nullptr, path, MAX_PATH) > 0)
		{
			PathRemoveFileSpec(path);
			PathAppend(path, L"Runtime");
			SetDllDirectory(path);
			PathAppend(path, L"msvcp120.dll");

			// Loading msvcpNNN.dll will load msvcrNNN.dll as well.
			HINSTANCE msvcrDll = LoadLibrary(path);
			SetDllDirectory(L"");

			if (msvcrDll)
			{
				rmDll = LoadLibrary(L"Rainmeter.dll");
				FreeLibrary(msvcrDll);
			}
		}
	}

	return rmDll;
}
Beispiel #3
0
ZENI_REST_DLL int zenilib_main(int argc, char **argv) {
#ifdef _WINDOWS
  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

#ifdef X64
  if(_chdir("..\\..")) {
#else
  if(_chdir("..")) {
#endif
    std::cerr << "Setting working directory failed with error code ':" << GetLastError() << "'\n";
    return -1;
  }
#ifdef X64
  if(!SetDllDirectory("bin\\x64")) {
#else
  if(!SetDllDirectory("bin")) {
#endif
    std::cerr << "Setting DLL directory failed with error code ':" << GetLastError() << "'\n";
    return -2;
  }
#else
  {
    char application_path[FILENAME_MAX];
#ifndef _MACOSX
    int length = readlink("/proc/self/exe", application_path, FILENAME_MAX);
    up_one_dir(application_path, length);
#else
    uint32_t size = sizeof(application_path);
    if(_NSGetExecutablePath(application_path, &size)) {
      std::cerr << "Loading working directory failed.\n";
      return -1;
    }
    int length = int(strlen(application_path));
    
    for(int i = 0; i != 2; ++i)
      up_one_dir(application_path, length);
    memcpy(application_path + length, "/zenilib", 9);
#endif
    if(chdir(application_path)) {
      std::cerr << "chdir: " << application_path << '\n';
      std::cerr << "Setting working directory failed with error code: '" << errno << "'\n";
      std::cerr << strerror(errno) << '\n';
      return -1;
    }
  }
#endif

  return main2(argc, argv);
}
bool CI8DeskSvr::StartRemoteControl()
{
	stdex::tString strFilePath = utility::GetAppPath() + _T("WinVNC\\");
	SetDllDirectory(strFilePath.c_str());

	strFilePath += TEXT("WinVNC.dll");
	m_hRemoteCtrl = LoadLibrary(strFilePath.c_str());
	if (m_hRemoteCtrl == NULL)
		return false;

	typedef BOOL (WINAPI* PFNSTARTVNC)();
	PFNSTARTVNC pfnStartVNC = GetProcAddress(m_hRemoteCtrl, "_StartVNC@0");
	if (pfnStartVNC == NULL)
		return false;

	try
	{
		pfnStartVNC(); 
	}
	catch(...)
	{
		m_pLogger->WriteLog(LM_INFO, TEXT("加载远程控制客户端失败。\r\n"));
		BOOL (WINAPI* pfnStopVNC)();
		pfnStopVNC = GetProcAddress(m_hRemoteCtrl, "_StopVNC@0");
		if (pfnStopVNC == NULL)
			return false;

		pfnStopVNC(); 
	}

	m_pLogger->WriteLog(LM_INFO, TEXT("加载远程控制客户端成功。\r\n"));
	return true;
}
int
main(int argc, char* argv[])
{
#ifdef MOZ_WIDGET_GONK
  // The first call of ProcessState::self() (per process) will register into
  // binder driver by current thread info, so the main thread is a best one to
  // do registration because it never leaves.
  android::sp<android::ProcessState> proc(android::ProcessState::self());
#endif

#if defined(XP_WIN) && defined(DEBUG_bent)
    MessageBox(NULL, L"Hi", L"Hi", MB_OK);
#endif

    // Check for the absolute minimum number of args we need to move
    // forward here. We expect the last arg to be the child process type.
    if (argc < 1)
      return 1;
    GeckoProcessType proctype = XRE_StringToChildProcessType(argv[--argc]);

#ifdef XP_WIN
    // For plugins, this is done in PluginProcessChild::Init, as we need to
    // avoid it for unsupported plugins.  See PluginProcessChild::Init for
    // the details.
    if (proctype != GeckoProcessType_Plugin) {
        mozilla::SanitizeEnvironmentVariables();
        SetDllDirectory(L"");
    }
#endif

    nsresult rv = XRE_InitChildProcess(argc, argv, proctype);
    NS_ENSURE_SUCCESS(rv, 1);

    return 0;
}
int
main(int argc, char* argv[])
{
#if defined(XP_WIN) && defined(DEBUG_bent)
    MessageBox(NULL, L"Hi", L"Hi", MB_OK);
#endif

    // Check for the absolute minimum number of args we need to move
    // forward here. We expect the last arg to be the child process type.
    if (argc < 1)
      return 1;
    GeckoProcessType proctype = XRE_StringToChildProcessType(argv[--argc]);

#ifdef XP_WIN
    // For plugins, this is done in PluginProcessChild::Init, as we need to
    // avoid it for unsupported plugins.  See PluginProcessChild::Init for
    // the details.
    if (proctype != GeckoProcessType_Plugin) {
        mozilla::SanitizeEnvironmentVariables();
        SetDllDirectory(L"");
    }
#endif

    nsresult rv = XRE_InitChildProcess(argc, argv, proctype);
    NS_ENSURE_SUCCESS(rv, 1);

    return 0;
}
Beispiel #7
0
BOOL APIENTRY DllMain(HMODULE hModule,
	DWORD  ul_reason_for_call,
	LPVOID lpReserved
	)
{
	WCHAR path[MAX_PATH];
	GetModuleFileName(NULL, path, MAX_PATH);
	PathRemoveFileSpec(path);
	wcscat_s(path, L"\\ffmpeg");

#if defined(_WIN64)
	BOOL Is64BitProcess = TRUE;   // 64-bit program
#else
	BOOL Is64BitProcess = FALSE;
#endif

	wcscat_s(path, Is64BitProcess ? L"\\x64" : L"\\x86");
	SetDllDirectory(path);
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
Beispiel #8
0
//////////////////////////////////////////////////////////
//
// CheckOnRestartCommand
//
// Changes current directory if required
//
//////////////////////////////////////////////////////////
SString CheckOnRestartCommand ( void )
{
    const SString strMTASAPath = GetMTASAPath ();

    SetCurrentDirectory ( strMTASAPath );
    SetDllDirectory( strMTASAPath );

    SString strOperation, strFile, strParameters, strDirectory, strShowCmd;
    if ( GetOnRestartCommand ( strOperation, strFile, strParameters, strDirectory, strShowCmd ) )
    {
        if ( strOperation == "files" || strOperation == "silent" )
        {
            //
            // Update
            //

            // Make temp path name and go there
            SString strArchivePath, strArchiveName;
            strFile.Split ( "\\", &strArchivePath, &strArchiveName, -1 );

            SString strTempPath = MakeUniquePath ( strArchivePath + "\\_" + strArchiveName + "_tmp_" );

            if ( !MkDir ( strTempPath ) )
                return "FileError1";

            if ( !SetCurrentDirectory ( strTempPath ) )
                return "FileError2";

            // Start progress bar
            if ( !strParameters.Contains( "hideprogress" ) )
               StartPseudoProgress( g_hInstance, "MTA: San Andreas", _("Extracting files...") );

            // Try to extract the files
            if ( !ExtractFiles ( strFile ) )
            {
                // If extract failed and update file is an exe, try to run it
                if ( ExtractExtension ( strFile ).CompareI ( "exe" ) )
                    ShellExecuteBlocking ( "open", strFile, "-s" );
            }

            // Stop progress bar
            StopPseudoProgress();

            // If a new "Multi Theft Auto.exe" exists, let that complete the install
            if ( FileExists ( MTA_EXE_NAME_RELEASE ) )
                return "install from far " + strOperation + " " + strParameters;

            // Otherwise use the current exe to install
            return "install from near " + strOperation + " " + strParameters;
        }
        else
        {
            AddReportLog ( 5052, SString ( "CheckOnRestartCommand: Unknown restart command %s", strOperation.c_str () ) );
        }
    }
    return "no update";
}
Beispiel #9
0
int APIENTRY _tWinMain(HINSTANCE	/*hInstance*/,
					 HINSTANCE		/*hPrevInstance*/,
					 LPTSTR			lpCmdLine,
					 int			/*nCmdShow*/)
{
	SetDllDirectory(L"");

	InitCommonControls();

	size_t cmdlineLen =_tcslen(lpCmdLine);
	if (lpCmdLine[0] == '"' && cmdlineLen > 1 && lpCmdLine[cmdlineLen - 1] == '"')
	{
		lpCmdLine[cmdlineLen - 1] = 0;
		++lpCmdLine;
	}
	if (lpCmdLine[0] != 0)
		g_Prompt = lpCmdLine;

	const TCHAR *yesno=_T("(yes/no)");
	const size_t lens = _tcslen(yesno);
	const TCHAR *p = lpCmdLine;
	BOOL bYesNo=FALSE;

	while(*p)
	{
		if (_tcsncicmp(p, yesno, lens) == 0)
		{
			bYesNo = TRUE;
			break;
		}
		++p;
	}

	if(bYesNo)
	{
		if (::MessageBox(nullptr, g_Prompt, _T("TortoiseGit - git CLI stdin wrapper"), MB_YESNO | MB_ICONQUESTION) == IDYES)
		{
			_tprintf(_T("yes"));
		}
		else
		{
			_tprintf(_T("no"));
		}
		return 0;
	}
	else
	{
		if (DialogBox(hInst, MAKEINTRESOURCE(IDD_ASK_PASSWORD), nullptr, PasswdDlg) == IDOK)
		{
			_tprintf(_T("%s\n"), (LPCTSTR)g_PassWord);
			return 0;
		}
		_tprintf(_T("\n"));
		return -1;
	}
}
Beispiel #10
0
CTortoiseGitBlameApp::CTortoiseGitBlameApp()
{
	SetDllDirectory(L"");
	CCrashReportTGit crasher(L"TortoiseGitBlame " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
	CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
	EnableHtmlHelp();

	m_gdiplusToken = NULL;
	m_bHiColorIcons = TRUE;
}
Beispiel #11
0
CMATLAB::CMATLAB()
{
    std::wstring wpath=string2WideString(path);
    SetDllDirectory(LPCWSTR(wpath.data()));

    libmat.setFileName("libmat");
    if (!libmat.load()) throw "CMATLAB::CMATLAB error: unable to load libmat";

    libmx.setFileName("libmx");
    if(!libmx.load()) throw "CMATLAB::CMATLAB error: unable to load libmx";

    libeng.setFileName("libeng");
    if(!libeng.load()) throw "CMATLAB::CMATLAB error: unable to load libeng";

    pMatOpen = (matftype1) libmat.resolve("matOpen");
    if (!pMatOpen)  throw "CMATLAB::CMATLAB error: unable to resolve libmat for matOpen";
    pMatClose = (matftype2) libmat.resolve("matClose");
    if (!pMatClose) throw "CMATLAB::CMATLAB error: unable to resolve libmat for matClose";
    pMatPutVariable = (matftype3) libmat.resolve("matPutVariable");
    if (!pMatPutVariable) throw "CMATLAB::CMATLAB error: unable to resolve libmat for matPutVariable";
    pMatGetVariable = (matftype4) libmat.resolve("matGetVariable");
    if (!pMatGetVariable) throw "CMATLAB::CMATLAB error: unable to resolve libmat for matGetVariable";


    pMxCreateDoubleMatrix = (mxftype1) libmx.resolve("mxCreateDoubleMatrix");
    if (!pMxCreateDoubleMatrix) throw "CMATLAB::CMATLAB error: unable to resolve libmx for mxCreateDoubleMatrix";
    pMxDestroyArray = (mxftype2) libmx.resolve("mxDestroyArray");
    if (!pMxDestroyArray) throw "CMATLAB::CMATLAB error: unable to resolve libmx for mxDestroyArray";
    pMxGetPr = (mxftype3) libmx.resolve("mxGetPr");
    if (!pMxGetPr) throw "CMATLAB::CMATLAB error: unable to resolve libmx for mxGetPr";
    pMxSetPr = (mxftype4) libmx.resolve("mxSetPr");
    if (!pMxSetPr) throw "CMATLAB::CMATLAB error: unable to resolve libmx for mxSetPr";
    pMxGetNumberOfElements = (mxftype5) libmx.resolve("mxGetNumberOfElements");
    if (!pMxGetNumberOfElements) throw "CMATLAB::CMATLAB error: unable to resolve libmx for mxGetNumberOfElements";


    pEngOpenSingleUse = (engftype1) libeng.resolve("engOpenSingleUse");
    if (!pEngOpenSingleUse) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engOpenSingleUse";
    pEngOpen = (engftype2) libeng.resolve("engOpen");
    if (!pEngOpen) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engOpen";
    pEngClose = (engftype3) libeng.resolve("engClose");
    if (!pEngClose) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engClose";
    pEngGetVisible = (engftype4) libeng.resolve("engGetVisible");
    if (!pEngGetVisible) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engGetVisible";
    pEngSetVisible = (engftype5) libeng.resolve("engSetVisible");
    if (!pEngSetVisible) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engSetVisible";
    pEngEvalString = (engftype6) libeng.resolve("engEvalString");
    if (!pEngEvalString) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engEvalString";
    pEngGetVariable = (engftype7) libeng.resolve("engGetVariable");
    if (!pEngGetVariable) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engGetVariable";
    pEngPutVariable = (engftype8) libeng.resolve("engPutVariable");
    if (!pEngPutVariable) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engPutVariable";
    pEngOutputBuffer = (engftype9) libeng.resolve("engOutputBuffer");
    if (!pEngOutputBuffer) throw "CMATLAB::CMATLAB error: unable to resolve libeng for engOutputBuffer";
}
Beispiel #12
0
    void EvalService::loadPlugin( const CString& arxFilePath )
    {
        TCHAR szDrive[_MAX_DRIVE];
        TCHAR szDir[_MAX_DIR];
        TCHAR szFile[_MAX_FNAME];
        TCHAR szExt[_MAX_EXT];
        _tsplitpath( ( LPCTSTR )arxFilePath, szDrive, szDir, szFile, szExt ); // 拆分路径

        CString serviceName;
        serviceName.Format( _T( "%s_SERVICE_NAME" ), CString( szFile ).MakeUpper() );

        /* 问题:插件(cmsr2010.arx)加载过程中无法找到所有使用的其它dll
         * 奇怪:正常加载dll应该从当前目录下搜索,按理说应该是能够找到的???
         * 临时解决方案:
         *		1) 将插件所在文件夹路径添加到dll搜索路径
         *		2) 或将dll的路径添加到path环境变量
         *		3) 或提前加载插件(手动或在VVLoader中自动加载)
         */
        // 构造arx所在文件夹路径
        TCHAR szPath[_MAX_PATH];
        _tmakepath( szPath, szDrive, szDir, NULL, NULL ); // 合并盘符

        // 将该路径添加到dll搜索路径中
        // API使用前提:xp sp1(>=0x0502),在stdafx.h中修改
        SetDllDirectory( szPath );

        m_pEvalPluginManager->load( arxFilePath, serviceName );

        //TCHAR szDllPath[_MAX_PATH];
        //GetDllDirectory(_MAX_PATH, szDllPath);
        //AfxMessageBox(szDllPath);

        // 还原dll搜索路径
        SetDllDirectory( NULL );

        // 打印显示路径为空
        //     注:191版本能够正常运行,测试显示路径也是为空(默认)
        //TCHAR szDllPath2[_MAX_PATH];
        //GetDllDirectory(_MAX_PATH, szDllPath2);
        //AfxMessageBox(szDllPath2);
    }
Beispiel #13
0
int WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, PVOID pvNothing)
{
    CFilePathTranslator     FileTranslator;
    std::string             WorkingDirectory;

    if ( dwReason == DLL_PROCESS_ATTACH )
    {
        WriteDebugEvent( SString( "DLL_PROCESS_ATTACH %08x", pvNothing ) );
        if ( IsGTAProcess() )
        {
            WriteDebugEvent( SString( "ModuleFileName: %s", *GetLaunchPathFilename() ) );

            AddUtf8FileHooks();

            // Set low frag heap for XP
            ULONG heapInfo = 2 ;
            HeapSetInformation( GetProcessHeap(), HeapCompatibilityInformation, &heapInfo, sizeof( heapInfo ) );

            FileTranslator.GetGTARootDirectory ( WorkingDirectory );
            SetCurrentDirectory ( WorkingDirectory.c_str ( ) );

            // For dll searches, this call replaces the current directory entry and turns off 'SafeDllSearchMode'
            // Meaning it will search the supplied path before the system and windows directory.
            // http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx
            SetDllDirectory( CalcMTASAPath ( "MTA" ) );

            g_pCore = new CCore;

            FileTranslator.GetGTARootDirectory ( WorkingDirectory );
            SetCurrentDirectory ( WorkingDirectory.c_str ( ) );
        }
    } 
    else if (dwReason == DLL_PROCESS_DETACH)
    {
        WriteDebugEvent( SString( "DLL_PROCESS_DETACH %08x", pvNothing ) );
        if ( IsGTAProcess () )
        {
            RemoveUtf8FileHooks();

            AddReportLog( 7102, "Core - PROCESS_DETACH" );
            // For now, TerminateProcess if any destruction is attempted (or we'll crash)
            TerminateProcess ( GetCurrentProcess (), 0 );

            if ( g_pCore )
            {
                delete g_pCore;
                g_pCore = NULL;
            }
        }
    }

    return TRUE;
}
Beispiel #14
0
gboolean
ws_init_dll_search_path()
{
    gboolean dll_dir_set = FALSE, npf_found = FALSE;
    wchar_t *program_path_w;
    wchar_t npcap_path_w[MAX_PATH];
    unsigned int retval;
    SC_HANDLE h_scm, h_serv;

    dll_dir_set = SetDllDirectory(_T(""));
    if (dll_dir_set) {
        /* Do not systematically add Npcap path as long as we favor WinPcap over Npcap. */
        h_scm = OpenSCManager(NULL, NULL, 0);
        if (h_scm) {
            h_serv = OpenService(h_scm, _T("npf"), SC_MANAGER_CONNECT|SERVICE_QUERY_STATUS);
            if (h_serv) {
                CloseServiceHandle(h_serv);
                npf_found = TRUE;
            }
            CloseServiceHandle(h_scm);
        }
        if (!npf_found) {
            /* npf service was not found, so WinPcap is not (properly) installed.
               Add Npcap folder to libraries search path. */
            retval = GetSystemDirectoryW(npcap_path_w, MAX_PATH);
            if (0 < retval && retval <= MAX_PATH) {
                wcscat_s(npcap_path_w, MAX_PATH, L"\\Npcap");
                dll_dir_set = SetDllDirectory(npcap_path_w);
            }
        }
    }

    if (!dll_dir_set && init_dll_load_paths()) {
        program_path_w = g_utf8_to_utf16(program_path, -1, NULL, NULL, NULL);
        SetCurrentDirectory(program_path_w);
        g_free(program_path_w);
    }

    return dll_dir_set;
}
void CCrashDumpWriter::RunErrorTool ( CExceptionInformation* pExceptionInformation )
{
// MTA Error Reporter is now integrated into the launcher

    // Only do once
    static bool bDoneReport = false;
    if ( bDoneReport )
        return;
    bDoneReport = false;

    // Log the basic exception information
    SString strMessage ( "Crash 0x%08X 0x%08X %s"
                         " EAX=%08X EBX=%08X ECX=%08X EDX=%08X ESI=%08X"
                         " EDI=%08X EBP=%08X ESP=%08X EIP=%08X FLG=%08X"
                         " CS=%04X DS=%04X SS=%04X ES=%04X"
                         " FS=%04X GS=%04X",
                         pExceptionInformation->GetCode (),
                         pExceptionInformation->GetAddressModuleOffset (),
                         pExceptionInformation->GetModulePathName (),
                         pExceptionInformation->GetEAX (),
                         pExceptionInformation->GetEBX (),
                         pExceptionInformation->GetECX (),
                         pExceptionInformation->GetEDX (),
                         pExceptionInformation->GetESI (),
                         pExceptionInformation->GetEDI (),
                         pExceptionInformation->GetEBP (),
                         pExceptionInformation->GetESP (),
                         pExceptionInformation->GetEIP (),
                         pExceptionInformation->GetEFlags (),
                         pExceptionInformation->GetCS (),
                         pExceptionInformation->GetDS (),
                         pExceptionInformation->GetSS (),
                         pExceptionInformation->GetES (),
                         pExceptionInformation->GetFS (),
                         pExceptionInformation->GetGS ()
                        );

    AddReportLog ( 3120, strMessage );

    // Try relaunch with crashed flag
    SString strMTASAPath = GetMTASABaseDir ();
    SetCurrentDirectory ( strMTASAPath );
    SetDllDirectory( strMTASAPath );

#ifdef MTA_DEBUG
    #define MTA_EXE_NAME            "Multi Theft Auto_d.exe"
#else
    #define MTA_EXE_NAME            "Multi Theft Auto.exe"
#endif
    SString strFile = strMTASAPath + "\\" + MTA_EXE_NAME;
    ShellExecute( NULL, "open", strFile, "install_stage=crashed", NULL, SW_SHOWNORMAL );
}
CTortoiseGitBlameApp::CTortoiseGitBlameApp()
{
	SetDllDirectory(L"");
	SetTaskIDPerUUID();
#if ENABLE_CRASHHANLDER
	CCrashReportTGit crasher(L"TortoiseGitBlame " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
	CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
#endif
	EnableHtmlHelp();
	git_libgit2_init();
	m_gdiplusToken = NULL;
	m_bHiColorIcons = TRUE;
}
Beispiel #17
0
void* _LoadLibrary(const std::string& libpath)
{
	void* res = NULL;
#ifdef WIN32
	const std::wstring wparentpath = Util::s2ws(LSL::Util::ParentPath(libpath));
	const std::wstring wlibpath = Util::s2ws(libpath);
	SetDllDirectory(NULL);
	SetDllDirectory(wparentpath.c_str());
	res = LoadLibrary(wlibpath.c_str());
	if (res == NULL) {
		const std::string errmsg = Util::geterrormsg().c_str();
		LSL_THROWF(unitsync, "Couldn't load the unitsync library: %s", errmsg.c_str());
	}
#else
	res = dlopen(libpath.c_str(), RTLD_GLOBAL | RTLD_LAZY);
	if (res == NULL) {
		const char* errmsg = dlerror();
		LSL_THROWF(unitsync, "Couldn't load the unitsync library '%s': %s", libpath.c_str(), errmsg);
	}
#endif
	return res;
}
Beispiel #18
0
JSBool win32_setdlldirectory(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	JS_BeginRequest(cx);
	if(argc < 1)
	{
		JS_ReportError(cx, "Must pass a path to SetDllDirectory.");
		JS_EndRequest(cx);
		return JS_FALSE;
	}
	JSString * str = JS_ValueToString(cx, *argv);
	*rval = SetDllDirectory((LPWSTR)JS_GetStringChars(str)) ? JSVAL_TRUE : JSVAL_FALSE;
	JS_EndRequest(cx);
	return JS_TRUE;
}
Beispiel #19
0
CTortoiseProcApp::CTortoiseProcApp()
{
	SetDllDirectory(L"");
	// prevent from inheriting %GIT_DIR% from parent process by resetting it,
	// use MSVC function instead of Windows API because MSVC runtime caches environment variables
	_tputenv(_T("GIT_DIR="));
	CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
	EnableHtmlHelp();
	SYS_IMAGE_LIST();
	CHooks::Create();
	m_bLoadUserToolbars = FALSE;
	m_bSaveState = FALSE;
	retSuccess = false;
	m_gdiplusToken = NULL;
}
Beispiel #20
0
void rpath_hack() {
        printf("RUNNING RPATH HACK");
#define _DEBUG
    char libpathbuf[FILENAME_MAX]; // path buffer
    HMODULE thislibname = getThisLibHandle(); // get *this* module handle
    if(!thislibname) {
#ifdef _DEBUG
        printf("Failed to get handle for current module.\n");
#endif // _DEBUG
        exit(-1);
    }
    // get file name for the handle e.g. SOME_PATH\module.dll
    int libpath_len = GetModuleFileName(thislibname ,libpathbuf,FILENAME_MAX);
    if(libpath_len<=0) {
#ifdef _DEBUG
        printf("Failed to get module name from handle.\n");
#endif // _DEBUG
        exit(-1);
    }
    if(libpath_len+1>=FILENAME_MAX) { // catch potential buffer overflow
#ifdef _DEBUG
        printf("NUL termination of libpath name will result in buffer overflow.\n");
#endif // _DEBUG
        exit(-1);
    }
#ifdef _DEBUG
    libpathbuf[libpath_len] = '\0'; // nul terminate compound string
    libpath_len++; // for nul terminate
    printf("Got hmodule name as: %s.\n",libpathbuf);
#endif // _DEBUG

    // find last instance of the WINSLASH, this gives path to dir where currently executing lib is
    char * last = strrchr(libpathbuf, WINSLASH);
    *last='\0'; // set last WINSLASH to nul
    // set dll dir to now also search for other libs where this lib is
    int setdllret = SetDllDirectory(libpathbuf);
    // check for fail
    if(!setdllret) {
#ifdef _DEBUG
        printf("attempted to set lib dir as %s and failed.\n",libpathbuf);
#endif // _DEBUG
        exit(-1);
    } else {
#ifdef _DEBUG
        printf("setdlldir() as %s\n",libpathbuf);
#endif // _DEBUG
    }
}
Beispiel #21
0
CTortoiseProcApp::CTortoiseProcApp()
{
	SetDllDirectory(L"");
	EnableHtmlHelp();
//	int argc = 0;
//	const char* const * argv = NULL;
//	apr_app_initialize(&argc, &argv, NULL);
//	svn_dso_initialize2();
	SYS_IMAGE_LIST();
	CHooks::Create();
	g_GitAdminDir.Init();
	m_bLoadUserToolbars = FALSE;
	m_bSaveState = FALSE;
	retSuccess = false;

}
Beispiel #22
0
BOOL LoadNpcapDlls()
{
	_TCHAR npcap_dir[512];
	UINT len;
	len = GetSystemDirectory(npcap_dir, 480);
	if (!len) {
		fprintf(stderr, "Error in GetSystemDirectory: %x", GetLastError());
		return FALSE;
	}
	_tcscat_s(npcap_dir, 512, _T("\\Npcap"));
	if (SetDllDirectory(npcap_dir) == 0) {
		fprintf(stderr, "Error in SetDllDirectory: %x", GetLastError());
		return FALSE;
	}
	return TRUE;
}
Beispiel #23
0
//¼ÓÔزå¼þ
CTBoxComponent *TBoxPlugLoader::LoadTBoxPlug()
{
	SetDllDirectory(m_plugFolder);
	HMODULE hm = ::LoadLibrary(m_plugInfo.plugDLL);
	if (hm != NULL)
	{
		pCreateComponent pcreate = (pCreateComponent)GetProcAddress(hm,"CreateComponent");
		if (NULL == pcreate)
		{
			return NULL;
		}
		m_component = pcreate();
		return m_component;
	}
	return NULL;
}
Beispiel #24
0
// CBT Hook-style injection.
BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved )
{
    if (fdwReason == DLL_PROCESS_ATTACH)  // When initializing....
    {
        hDLL = hModule;

        // We don't need thread notifications for what we're doing.  Thus, get
        // rid of them, thereby eliminating some of the overhead of this DLL
        DisableThreadLibraryCalls(hModule);

        // Only hook the APIs if this is the right process.
        GetModuleFileName(GetModuleHandle(NULL), targetExe, sizeof(targetExe));
        PathStripPath(targetExe);

		GetModuleFileName(GetModuleHandle(NULL), targetPath, sizeof(targetPath));
		targetPathString = std::string(targetPath);
		targetPathString = targetPathString.substr(0, targetPathString.find_last_of("\\/"));

        OutputDebugString("HIJACKDLL checking process: ");
        OutputDebugString(targetExe);
        OutputDebugString("\n");

		ParsePaths();
		ProxyHelper helper = ProxyHelper();

        if (helper.HasProfile(targetExe))
		{
			if (HookAPICalls(&D3DHook))
			{
				OutputDebugString("HookAPICalls(D3D): TRUE\n");
			} 
			else if(HookAPICalls(&KernelHook))
			{	
				OutputDebugString("HookAPICalls(Kernel): TRUE\n");
			} 
			else 
			{
				OutputDebugString("HookAPICalls(Both): FALSE\n");
			}

			SetDllDirectory(dllDir);
			SaveExeName(targetExe);
		}
    }

    return TRUE;
}
Beispiel #25
0
//returns pixelNum
//modified by LZ to have dll directory passed as arguments
static PyObject* pyspectro_setupavs1(PyObject* self, PyObject* args) {
 	char *dllDirectory;
	long hDevice;
	char *serial;
	if(PyArg_ParseTuple(args, "sls", &dllDirectory, &hDevice, &serial) == 0) {
		return NULL;
	}
	SetDllDirectory(dllDirectory);
	
	//SetDllDirectory("C:\\photonbec\\Control\\spectrometer\\");
	//AS5216.dll is called by avs-spectro.dll.
	
	//avs_spectro = LoadLibrary("avs-spectro.dll");
	//if(avs_spectro){
	//	printf("Freeing straight after setup\n");
	//	FreeLibrary(avs_spectro);
	//	printf("Freed\n");
	//	avs_spectro=NULL;
	//}
	
	avs_spectro = LoadLibrary("avs-spectro.dll");
	if(!avs_spectro) {
		printf("couldnt load library: %d\n", (int)GetLastError());
		return NULL;
	}
	//fhelloworld = (HW)GetProcAddress(avs_spectro, "helloworld");
	fSetupAVS1 = (SA1)GetProcAddress(avs_spectro, "SetupAVS1");
	fGetLambda = (GL)GetProcAddress(avs_spectro, "GetLambda");
	fSetupAVS2 = (SA2)GetProcAddress(avs_spectro, "SetupAVS2");
	fReadAVSSpectrum = (RAS)GetProcAddress(avs_spectro, "ReadAVSSpectrum");
	fStopMeasure = (SM)GetProcAddress(avs_spectro, "StopMeasure");
	fCloseAVS = (CA)GetProcAddress(avs_spectro, "CloseAVS");
	if(!fSetupAVS1 || !fSetupAVS2 || !fGetLambda || !fReadAVSSpectrum || !fCloseAVS || !fStopMeasure)
		printf("fail to get procedure: %d\n", (int)GetLastError());
	
	int err;
	unsigned short pixelNum;
	
	if((err = fSetupAVS1(&hDevice, &pixelNum)) != 0) {
		char line[512];
		snprintf(line, sizeof(line), "SetupAVS1(): %d\n", err);
		PyErr_SetString(PyExc_IOError, line);
		return NULL;
	}
	
	return Py_BuildValue("i", hDevice);
}
Beispiel #26
0
CTortoiseGitBlameApp::CTortoiseGitBlameApp()
{
    SetDllDirectory(L"");
    SetTaskIDPerUUID();
    // prevent from inheriting %GIT_DIR% from parent process by resetting it,
    // use MSVC function instead of Windows API because MSVC runtime caches environment variables
    _tputenv(_T("GIT_DIR="));
#if ENABLE_CRASHHANLDER
    CCrashReportTGit crasher(L"TortoiseGitBlame " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
    CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
#endif
    EnableHtmlHelp();

    m_nAppLook = 0;
    m_gdiplusToken = NULL;
    m_bHiColorIcons = TRUE;
}
Beispiel #27
0
bool SetDllPath(const char* wdir)
{
	std::string path;

	if (wdir)
		path = wdir;
	else if (!FindWorkingDir(path))
		return false;

	if (path.size() == 0)
		return false;

	std::string binDir = path + DIRS_STR + "bin";

	SetCurrentDirectory(path.c_str());
	SetDllDirectory(binDir.c_str());

	return true;
}
Beispiel #28
0
int APIENTRY _tWinMain(HINSTANCE	/*hInstance*/,
					 HINSTANCE		/*hPrevInstance*/,
					 LPTSTR			lpCmdLine,
					 int			/*nCmdShow*/)
{
	SetDllDirectory(L"");

	InitCommonControls();

	size_t cmdlineLen = wcslen(lpCmdLine);
	if (lpCmdLine[0] == '"' && cmdlineLen > 1 && lpCmdLine[cmdlineLen - 1] == '"')
	{
		lpCmdLine[cmdlineLen - 1] = L'\0';
		++lpCmdLine;
	}
	if (lpCmdLine[0] != L'\0')
		g_Prompt = lpCmdLine;

	if (StrStrI(lpCmdLine, L"(yes/no)"))
	{
		if (::MessageBox(nullptr, g_Prompt, L"TortoiseGit - git CLI stdin wrapper", MB_YESNO | MB_ICONQUESTION) == IDYES)
			wprintf(L"yes");
		else
			wprintf(L"no");
		return 0;
	}

	if (StrStrI(lpCmdLine, L"Should I try again?"))
	{
		if (::MessageBox(nullptr, g_Prompt, L"TortoiseGit - git CLI yes/no wrapper", MB_YESNO | MB_ICONQUESTION) == IDYES)
			return 0;

		return 1;
	}

	if (DialogBox(hInst, MAKEINTRESOURCE(IDD_ASK_PASSWORD), nullptr, PasswdDlg) == IDOK)
	{
		printf("%s\n", CUnicodeUtils::StdGetUTF8(g_PassWord).c_str());
		return 0;
	}
	wprintf(L"\n");
	return -1;
}
Beispiel #29
0
int WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, PVOID pvNothing)
{
    CFilePathTranslator     FileTranslator;
    std::string             WorkingDirectory;

    if ( dwReason == DLL_PROCESS_ATTACH )
    {
        WriteDebugEvent( SString( "DLL_PROCESS_ATTACH %08x", pvNothing ) );
        if ( IsRealDeal () )
        {
            FileTranslator.GetGTARootDirectory ( WorkingDirectory );
            SetCurrentDirectory ( WorkingDirectory.c_str ( ) );

            // For dll searches, this call replaces the current directory entry and turns off 'SafeDllSearchMode'
            // Meaning it will search the supplied path before the system and windows directory.
            // http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx
            SetDllDirectory( CalcMTASAPath ( "MTA" ) );

            g_pCore = new CCore;

            FileTranslator.GetGTARootDirectory ( WorkingDirectory );
            SetCurrentDirectory ( WorkingDirectory.c_str ( ) );
        }
    } 
    else if (dwReason == DLL_PROCESS_DETACH)
    {
        WriteDebugEvent( SString( "DLL_PROCESS_DETACH %08x", pvNothing ) );
        if ( IsRealDeal () )
        {
            // For now, TerminateProcess if any destruction is attempted (or we'll crash)
            TerminateProcess ( GetCurrentProcess (), 0 );

            if ( g_pCore )
            {
                delete g_pCore;
                g_pCore = NULL;
            }
        }
    }

    return TRUE;
}
Beispiel #30
0
static PyObject* pyspectro_closedll(PyObject* self, PyObject* args) {
	printf("Closing\n");
	
	char *dllDirectory;
	long hDevice;
	if(PyArg_ParseTuple(args, "sl", &dllDirectory, &hDevice) == 0) {
		return NULL;
	}
	SetDllDirectory(dllDirectory);
	
	
	if(avs_spectro) {
		printf("Going to try to free avs-spectro lib\n");
		FreeLibrary(avs_spectro);
		printf("Have freed the library (inside if)\n");
		avs_spectro = NULL;
	}
	//printf("Not freeing the library. Possibly a bad idea.\n");
	Py_RETURN_NONE;
}