Example #1
0
BOOL WINAPI iSAuthorized(LPCWSTR lpFileName)
{
	BOOL	ret = FALSE;
	BOOL    wow64 = FALSE;
	LPWSTR	filename = NULL;
	wchar_t *szAuthorizedList[] = {L"comctl32.dll", L"uxtheme.dll", L"indicdll.dll",
								   L"msctf.dll",L"shell32.dll", L"imageres.dll",
								   L"winmm.dll",L"ole32.dll", L"oleacc.dll", 
								   L"oleaut32.dll",L"secur32.dll",L"shlwapi.dll",
								   L"ImSCTip.DLL",L"gdi32.dll",L"dwmapi.dll"
								  };
	WORD line = sizeof(szAuthorizedList)/sizeof(szAuthorizedList[0]);
	IsWow64Process(NtCurrentProcess(),&wow64);
	if (lpFileName[1] == L':')
	{
		wchar_t sysdir[VALUE_LEN+1] = {0};
		GetEnvironmentVariableW(L"SystemRoot",sysdir,VALUE_LEN);
		if (wow64)
		{
			PathAppendW(sysdir,L"SysWOW64");
		}
		else
		{
			PathAppendW(sysdir,L"system32");
		}
		if ( _wcsnicmp(lpFileName,sysdir,wcslen(sysdir)) == 0 )
		{
			filename = PathFindFileNameW(lpFileName);
		}
		else if ( wow64 && wcslen(sysdir)>0 )   /* compare system32 directory again */
		{
			PathRemoveFileSpecW(sysdir);
			PathAppendW(sysdir,L"system32");
			filename = _wcsnicmp(lpFileName,sysdir,wcslen(sysdir))?NULL:PathFindFileNameW(lpFileName);
		}
	}
	else
	{
		filename = (LPWSTR)lpFileName;
	}
	if (filename)
	{
		WORD  i;
		for(i=0;i<line;i++)
		{
			if ( _wcsicmp(filename,szAuthorizedList[i]) == 0 )
			{
				ret = TRUE;
				break;
			}
		}
	}
	return ret;
}
Example #2
0
CMWDiscovery::CMWDiscovery(IDispatch* pDispatch) :
    m_hwnd(0), m_pReportManager(NULL), m_pDocDispatch(pDispatch), m_bHasPassword(false)
{
    Excel::_WorkbookPtr spWorkBook;
    spWorkBook = m_pDocDispatch;
    if(spWorkBook)
    {
        m_officeType = OfficeApplicationType::Excel;
        m_name = PathFindFileNameW(spWorkBook->FullName);
        m_bHasPassword = spWorkBook->GetHasPassword() == VARIANT_TRUE;
        return;
    }

    PowerPoint::_PresentationPtr spPresentation = pDispatch;
    if(spPresentation)
    {
        m_officeType = OfficeApplicationType::PowerPoint;
        PowerPoint::_ApplicationPtr pPptApp = spPresentation->Application;
        // hopefully PowerPoint 14 will give a new way to get the App HWND?
#pragma warning (push)
#pragma warning (disable : 4312)
        m_hwnd = reinterpret_cast<HWND>(pPptApp->GetHWND());
#pragma warning (pop)
        return;
    }

    Word::_DocumentPtr spDocument;
    spDocument = m_pDocDispatch;
    if(spDocument)
    {
        m_officeType = OfficeApplicationType::Word;
    }
}
Example #3
0
NTSTATUS GenerateXlAccCommandLine(PWSTR* XlAccCmdLine, PWSTR Entry, PCWSTR ApplicationName, PCWSTR CommandLine)
{
    PWSTR           Buffer;
    ULONG_PTR       Length;
    PLDR_MODULE     Module;
    UNICODE_STRING  AccPath;

    ApplicationName = ApplicationName == NULL ? L"" : ApplicationName;
    CommandLine = CommandLine == NULL ? L"" : CommandLine;

    Module = FindLdrModuleByHandle(&__ImageBase);
    Length = (lstrlenW(ApplicationName) + lstrlenW(CommandLine) + MAX_NTPATH) * sizeof(WCHAR) + Module->FullDllName.Length;
    Buffer = (PWSTR)malloc(Length);
    if (Buffer == NULL)
        return STATUS_NO_MEMORY;

    *XlAccCmdLine = Buffer;

    AccPath = Module->FullDllName;
    AccPath.Length = (USHORT)PtrOffset(PathFindFileNameW(Module->FullDllName.Buffer), Module->FullDllName.Buffer);

    swprintf(
        Buffer,
        L"\"%wZXLacc.exe\" -hookstart game:\"%s\" path:\"%s\" param:%s",
        &AccPath,
        Entry, ApplicationName, CommandLine
    );

    return STATUS_SUCCESS;
}
Example #4
0
BOOL KProcessInfo::IsSpecialProc()
{
    LPCWSTR pwcszPath = NULL;
    LPWSTR  pwszFileName = NULL;

    if (!m_bFirstCheck)
    {
        return m_bSpecialProc;
    }

    m_bFirstCheck = FALSE;

    pwcszPath = GetProcPath();
    if (NULL == pwcszPath)
    {
        return FALSE;
    }
    
    pwszFileName = PathFindFileNameW(pwcszPath);
    if (NULL == pwszFileName)
    {
        return FALSE;
    }

    if (wcsicmp(pwszFileName, L"wscript.exe") == 0 ||
        wcsicmp(pwszFileName, L"rundll32.exe") == 0)
    {
        m_bSpecialProc = TRUE;
        return TRUE;
    }

    return FALSE;
}
void CReadChangesRequest::ProcessNotification()
{
	BYTE* pBase = m_BackupBuffer.data();

	for (;;)
	{
		FILE_NOTIFY_INFORMATION& fni = (FILE_NOTIFY_INFORMATION&)*pBase;

		CStringW wstrFilename(fni.FileName, fni.FileNameLength/sizeof(wchar_t));
		// Handle a trailing backslash, such as for a root directory.
		if (wstrFilename.Right(1) != L"\\")
			wstrFilename = m_wstrDirectory + L"\\" + wstrFilename;
		else
			wstrFilename = m_wstrDirectory + wstrFilename;

		// If it could be a short filename, expand it.
		LPCWSTR wszFilename = PathFindFileNameW(wstrFilename);
		int len = lstrlenW(wszFilename);
		// The maximum length of an 8.3 filename is twelve, including the dot.
		if (len <= 12 && wcschr(wszFilename, L'~'))
		{
			// Convert to the long filename form. Unfortunately, this
			// does not work for deletions, so it's an imperfect fix.
			wchar_t wbuf[MAX_PATH];
			if (::GetLongPathNameW(wstrFilename, wbuf, _countof(wbuf)) > 0)
				wstrFilename = wbuf;
		}

		m_pServer->m_pBase->Push(fni.Action, wstrFilename);

		if (!fni.NextEntryOffset)
			break;
		pBase += fni.NextEntryOffset;
	};
}
Example #6
0
/***********************************************************************
 *                              FD31_UpdateResult            [internal]
 *      update the displayed file name (with path)
 */
static void FD31_UpdateResult(PFD31_DATA lfs, WCHAR *tmpstr)
{
    int lenstr2;
    LPOPENFILENAMEW ofnW = lfs->ofnW;
    WCHAR tmpstr2[BUFFILE];
    WCHAR *p;

    TRACE("%s\n", debugstr_w(tmpstr));
    if(ofnW->Flags & OFN_NOVALIDATE)
        tmpstr2[0] = '\0';
    else
        GetCurrentDirectoryW(BUFFILE, tmpstr2);
    lenstr2 = strlenW(tmpstr2);
    if (lenstr2 > 3)
        tmpstr2[lenstr2++]='\\';
    lstrcpynW(tmpstr2+lenstr2, tmpstr, BUFFILE-lenstr2);
    if (ofnW->lpstrFile)
        lstrcpynW(ofnW->lpstrFile, tmpstr2, ofnW->nMaxFile);

    /* set filename offset */
    p = PathFindFileNameW(ofnW->lpstrFile);
    ofnW->nFileOffset = (p - ofnW->lpstrFile);

    /* set extension offset */
    p = PathFindExtensionW(ofnW->lpstrFile);
    ofnW->nFileExtension = (*p) ? (p - ofnW->lpstrFile) + 1 : 0;

    TRACE("file %s, file offset %d, ext offset %d\n",
          debugstr_w(ofnW->lpstrFile), ofnW->nFileOffset, ofnW->nFileExtension);

    /* update the real client structures if any */
    lfs->callbacks->UpdateResult(lfs);
}
// main function - sets up a 'meta command' to contain each of the library commands, and executes it on the given arguments
int wmain(int argc, wchar_t *argv[])
{
    // initialize COM before doing anything else, since the IShellLibrary API depends on COM
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    if (SUCCEEDED(hr))
    {
        CMetaCommand::PFNCREATECOMMAND rgMainCmds[] =
        {
            CMetaCommand::Create<CCreateCommand>,
            CMetaCommand::Create<CInfoCommand>,
            CMetaCommand::Create<CEnumCommand>,
            CMetaCommand::Create<CSetAttributeCommand>,
            CMetaCommand::Create<CAddCommand>,
            CMetaCommand::Create<CRemoveCommand>,
            CMetaCommand::Create<CSetDefaultSaveFolderCommand>,
            CMetaCommand::Create<CResolveCommand>,
            CMetaCommand::Create<CResolveAllCommand>,
            CMetaCommand::Create<CManageCommand>,
        };

        {
            PCWSTR pszExeName = PathFindFileNameW(CONSUME_NEXT_ARG(argv, argc));
            CMetaCommand main(pszExeName, L"Displays and modifies the attributes of Shell Libraries.", rgMainCmds, ARRAYSIZE(rgMainCmds));
            main.Execute(const_cast<PCWSTR*>(argv), argc);
        }
        CoUninitialize();
    }

    return 0;
}
Example #8
0
bool ModuleFileName(std::wstring* out, HMODULE hModule)
{
	std::unique_ptr<wchar_t[]> buffer(new wchar_t[MAX_PATH]);
	GetModuleFileNameW(hModule, buffer.get(), MAX_PATH);
	*out = PathFindFileNameW(buffer.get());
	return !out->empty();
}
Example #9
0
//===================================
void DirMonitor::ScanDirectoryForChanges_CS () {
    // Search for all files in this directory
    wchar filespec[MAX_PATH];
    PathCombineW(filespec, m_directory, L"*");

    // Start search
    WIN32_FIND_DATAW data;
    HANDLE find = FindFirstFileW(filespec, &data);
    if (find == INVALID_HANDLE_VALUE) {
        LOG_OS_LAST_ERROR(L"FindFirstFileW");
        return;
    }

    // Search for watched files
    do {
        // Ignore directories
        if (data.dwFileAttributes & (FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_DIRECTORY))
            continue;
        
        // Convert to lowercase for hash matching
        wchar * filename = PathFindFileNameW(data.cFileName);
        CharLowerW(filename);

        // Reparse if file changed
        CheckReparseFile_CS(filename);

    } while (FindNextFileW(find, &data));

    // Cleanup
    FindClose(find);
}
Example #10
0
extern "C" bool ArchExtractFilesW(HZIP hZip,WCHAR *pstrPath)
{
    bool r=false;
    ZIPDECOMPRESSION *p=(ZIPDECOMPRESSION*)hZip;
    if ((hZip) && (pstrPath) && (p->bHandleType == HT_DECOMPRESSOR))
    {
        lstrcpyW(p->strOutputDir,pstrPath);

        unzGoToFirstFile(p->hZip);

        if (!p->bInMem)
        {
            WCHAR filePath[MAX_PATH],fileName[MAX_PATH],*pstrFile;

            lstrcpyW(filePath,p->strZipFile);
            pstrFile=PathFindFileNameW(filePath);
            PathRemoveFileSpecW(filePath);

            lstrcpyW(fileName,pstrFile);
            PathAddBackslashW(filePath);
        }
        r=(InternalEnumFiles(hZip) < 0) ? false : true;
    }
    else
        ArchSetLastError(ARCH_INVALID_PARAMETER);
    return r;
}
Example #11
0
BOOL IsHookStartEnabled()
{
    BOOL        Enabled;
    ULONG_PTR   Length;
    PWSTR       Buffer;
    PLDR_MODULE Module;

    static WCHAR Config[] = L"config.ini";

    Module = FindLdrModuleByHandle(&__ImageBase);
    if (Module == NULL)
        return FALSE;

    Length = Module->FullDllName.Length + sizeof(Config);
    Buffer = (PWSTR)malloc(Length);
    if (Buffer == NULL)
        return FALSE;

    CopyMemory(Buffer, Module->FullDllName.Buffer, Module->FullDllName.Length);
    Buffer[Module->FullDllName.Length / sizeof(WCHAR)] = 0;
    CopyMemory(PathFindFileNameW(Buffer), Config, sizeof(Config));

    Enabled = GetPrivateProfileIntW(L"HOOKSTART", L"BOpen", FALSE, Buffer);

    free(Buffer);

    return Enabled;
}
Example #12
0
int Cx_PluginLoader::GetPluginIndex(const wchar_t* filename)
{
    const wchar_t* title = PathFindFileNameW(filename);
    int i = x3::GetSize(m_modules);

    while (--i >= 0)
    {
        // ignore folders
        if (_wcsicmp(title, PathFindFileNameW(m_modules[i]->filename)) == 0)
        {
            break;
        }
    }

    return i;
}
void TestDominoDocArtifact::TestName()
{
	DomDocHelper domDocHelper(TEST_ARTIFACT_FILE);   
	DominoDocArtifact validArtifact(m_spLibrary, domDocHelper.DocumentId, domDocHelper.GetVersionLabel());
	wchar_t fileName[_MAX_PATH] = {0};
	lstrcpynW(fileName, PathFindFileNameW(TEST_ARTIFACT_FILE), _MAX_PATH);
	PathRemoveExtensionW(fileName);   

	assertEquals(domDocHelper.GetFileNameWithoutExtension(), validArtifact.Name);
}
Example #14
0
static int parse_arguments_and_execute()
{
    enum
    {
        Argument_logical_sector = 0,
        Argument_file_name,
        Argument_help,
    };

    const std::vector<Parsing::Argument_descriptor> argument_map =
    {
        { Argument_logical_sector, u8"logical-sector", u8's', true,  u8"The logical block address (LBA) of the sector to read." },
        { Argument_file_name,      u8"file-name",      u8'f', true,  u8"The name of the file to hold the output. This file will be overwritten." },
        { Argument_help,           u8"help",           u8'?', false, nullptr },
    };
#ifndef NDEBUG
    Parsing::validate_argument_map(argument_map);
#endif

    const auto arguments = WindowsCommon::args_from_command_line();
    const auto options = Parsing::options_from_allowed_args(arguments, argument_map);

    int error_level = 0;
    if(options.count(Argument_help) == 0)
    {
        CHECK_EXCEPTION(options.count(Argument_logical_sector) > 0, u8"Missing a required argument: --" + std::string(argument_map[Argument_logical_sector].long_name));
        CHECK_EXCEPTION(options.count(Argument_file_name) > 0,      u8"Missing a required argument: --" + std::string(argument_map[Argument_file_name].long_name));

        // There is no _atoui64 function (and perhaps a private implementation is a good idea), but
        // reading an int64_t into a uint64_t will have no negative (ha!) consequences, as any sector
        // number is considered a valid sector to read.
        const uint64_t sector_number = _atoi64(options.at(Argument_logical_sector).c_str());
        GetSector::read_physical_drive_sector_to_file(0, sector_number, PortableRuntime::utf16_from_utf8(options.at(Argument_file_name)).c_str());
    }
    else
    {
        constexpr auto arg_program_name = 0;

        // Hold a reference to program_name_long for the duration of the output functions.
        const auto program_name_long = PortableRuntime::utf16_from_utf8(arguments[arg_program_name]);
        const auto program_name = PathFindFileNameW(program_name_long.c_str());

        std::fwprintf(stderr, L"Usage: %s [options]\nOptions:\n", program_name);
        std::fwprintf(stderr, PortableRuntime::utf16_from_utf8(Parsing::Options_help_text(argument_map)).c_str());
        std::fwprintf(stderr,
                      L"\nTo read the Master Boot Record:\n  %s -%c 1 -%c mbr.bin\n",
                      program_name,
                      argument_map[Argument_logical_sector].short_name,
                      argument_map[Argument_file_name].short_name);
        error_level = 1;
    }

    return error_level;
}
Example #15
0
static HRESULT WINAPI RecycleBin_GetDisplayNameOf(IShellFolder2 *This, LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET *pName)
{
    WIN32_FIND_DATAW data;

    TRACE("(%p, %p, %x, %p)\n", This, pidl, uFlags, pName);
    TRASH_UnpackItemID(&pidl->mkid, &data);
    pName->uType = STRRET_WSTR;
    pName->u.pOleStr = StrDupW(PathFindFileNameW(data.cFileName));
    if (pName->u.pOleStr == NULL)
        return E_OUTOFMEMORY;

    return S_OK;
}
Example #16
0
HMODULE WINAPI HookLoadLibrary(LPCWSTR lpFileName)
{
	HMODULE hModule = TrueLoadLibrary(lpFileName);

	// Only enable the GetProcAddress hook when the Oculus Runtime was loaded.
	WCHAR modulePath[MAX_PATH];
	GetModuleFileName(hModule, modulePath, sizeof(modulePath));
	LPCWSTR moduleName = PathFindFileNameW(modulePath);
	if (wcscmp(moduleName, ovrModuleName) == 0)
		MH_EnableHook(GetProcAddress);

	return hModule;
}
Example #17
0
HRESULT WINAPI CRecycleBin::CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
{
    PIDLRecycleStruct* pData1 = _ILGetRecycleStruct(pidl1);
    PIDLRecycleStruct* pData2 = _ILGetRecycleStruct(pidl2);
    LPWSTR pName1, pName2;

    if(!pData1 || !pData2 || LOWORD(lParam) >= COLUMNS_COUNT)
        return E_INVALIDARG;

    SHORT result;
    LONGLONG diff;
    switch (LOWORD(lParam))
    {
        case 0: /* Name */
            pName1 = PathFindFileNameW(pData1->szName);
            pName2 = PathFindFileNameW(pData2->szName);
            result = wcsicmp(pName1, pName2);
            break;
        case 1: /* Orig. Location */
            result = wcsicmp(pData1->szName, pData2->szName);
            break;
        case 2: /* Date Deleted */
            result = CompareFileTime(&pData1->DeletionTime, &pData2->DeletionTime);
            break;
        case 3: /* Size */
            diff = pData1->FileSize.QuadPart - pData2->FileSize.QuadPart;
            return MAKE_COMPARE_HRESULT(diff);
        case 4: /* Type */
            pName1 = PathFindExtensionW(pData1->szName);
            pName2 = PathFindExtensionW(pData2->szName);
            result = wcsicmp(pName1, pName2);
            break;
        case 5: /* Modified */
            result = CompareFileTime(&pData1->LastModification, &pData2->LastModification);
            break;
    }
    return MAKE_COMPARE_HRESULT(result);
}
Example #18
0
FARPROC HookGetProcAddress(HMODULE hModule, LPCSTR lpProcName) 
{
	WCHAR modulePath[MAX_PATH];
	GetModuleFileName(hModule, modulePath, sizeof(modulePath));
	LPCWSTR moduleName = PathFindFileNameW(modulePath);
	if (wcscmp(moduleName, ovrModuleName) == 0) {
		FARPROC reviveFuncAddress = TrueGetProcAddress(ReviveModule, lpProcName);
		if (reviveFuncAddress) {
			return reviveFuncAddress;
		}
	}

	return TrueGetProcAddress(hModule, lpProcName);
}
Example #19
0
static void create_target_directory(LPWSTR Target)
{
    WCHAR dir[MAX_PATH];
    int res;

    strcpyW(dir, Target);
    *PathFindFileNameW(dir) = 0; /* Truncate file name */
    if(!PathIsDirectoryW(dir))
    {
        res = SHCreateDirectoryExW(NULL, dir, NULL);
        if(res != ERROR_SUCCESS && res != ERROR_ALREADY_EXISTS)
            WINE_ERR("Can't create directory: %s\n", wine_dbgstr_w(dir));
    }
}
Example #20
0
HMODULE WINAPI HookLoadLibrary(LPCWSTR lpFileName)
{
	LPCWSTR name = PathFindFileNameW(lpFileName);
	LPCWSTR ext = PathFindExtensionW(name);
	size_t length = ext - name;

	// Load our own library again so the ref count is incremented.
	if (wcsncmp(name, ovrModuleName, length) == 0)
		return TrueLoadLibrary(revModuleName);

	// We've already injected OpenVR, block attempts to override it.
	if (wcsncmp(name, L"openvr_api.dll", length) == 0)
		return NULL;

	return TrueLoadLibrary(lpFileName);
}
Example #21
0
static HRESULT WINAPI FolderImpl_get_Title(Folder3 *iface, BSTR *pbs)
{
    FolderImpl *This = impl_from_Folder(iface);
    WCHAR *p;
    int len;

    TRACE("(%p,%p)\n", iface, pbs);

    *pbs = NULL;

    if (V_VT(&This->dir) == VT_I4)
    {
        FIXME("special folder constants are not supported\n");
        return E_NOTIMPL;
    }
    p = PathFindFileNameW(V_BSTR(&This->dir));
    len = lstrlenW(p);
    *pbs = SysAllocStringLen(p, p[len - 1] == '\\' ? len - 1 : len);
    return *pbs ? S_OK : E_OUTOFMEMORY;
}
Example #22
0
BOOL
CFileDefExt::InitFilePath(HWND hwndDlg)
{
    /* Find the filename */
    WCHAR *pwszFilename = PathFindFileNameW(m_wszPath);

    if (pwszFilename > m_wszPath)
    {
        /* Location field */
        WCHAR wszLocation[MAX_PATH];
        StringCchCopyNW(wszLocation, _countof(wszLocation), m_wszPath, pwszFilename - m_wszPath);
        PathRemoveBackslashW(wszLocation);

        SetDlgItemTextW(hwndDlg, 14009, wszLocation);
    }

    /* Filename field */
    SetDlgItemTextW(hwndDlg, 14001, pwszFilename);

    return TRUE;
}
Example #23
0
static UINT
LoadPropSheetHandlers(LPCWSTR pwszPath, PROPSHEETHEADERW *pHeader, UINT cMaxPages, HPSXA *phpsxa, IDataObject *pDataObj)
{
    WCHAR wszBuf[MAX_PATH];
    UINT cPages = 0, i = 0;

    LPWSTR pwszFilename = PathFindFileNameW(pwszPath);
    BOOL bDir = PathIsDirectoryW(pwszPath);

    if (bDir)
    {
        phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, L"Folder", cMaxPages - cPages, pDataObj);
        cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);

        phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, L"Directory", cMaxPages - cPages, pDataObj);
        cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);
    }
    else
    {
        /* Load property sheet handlers from ext key */
        LPWSTR pwszExt = PathFindExtensionW(pwszFilename);
        phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, pwszExt, cMaxPages - cPages, pDataObj);
        cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);

        /* Load property sheet handlers from prog id key */
        DWORD cbBuf = sizeof(wszBuf);
        if (RegGetValueW(HKEY_CLASSES_ROOT, pwszExt, L"", RRF_RT_REG_SZ, NULL, wszBuf, &cbBuf) == ERROR_SUCCESS)
        {
            TRACE("EnumPropSheetExt wszBuf %s, pwszExt %s\n", debugstr_w(wszBuf), debugstr_w(pwszExt));
            phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszBuf, cMaxPages - cPages, pDataObj);
            cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);
        }

        /* Add property sheet handlers from "*" key */
        phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, L"*", cMaxPages - cPages, pDataObj);
        cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);
    }

    return cPages;
}
Example #24
0
HMODULE WINAPI HookLoadLibrary(LPCWSTR lpFileName)
{
	LPCWSTR name = PathFindFileNameW(lpFileName);
	LPCWSTR ext = PathFindExtensionW(name);
	size_t length = ext - name;

	// Load our own library again so the ref count is incremented.
	if (wcsncmp(name, ovrModuleName, length) == 0)
		return TrueLoadLibrary(revModuleName);

	// The following functions will patch the module, so we have to load it here.
	HMODULE module = TrueLoadLibrary(lpFileName);

	// Patch the export table of Oculus Platform to point to our entitlement functions.
	if (wcsncmp(name, ovrPlatformName, length) == 0)
	{
		TrueIsError = (_IsError)DetourEATptr("ovr_Message_IsError", ovr_Message_IsError, module);
		DetourEATptr("ovr_IsEntitled", ovr_IsEntitled, module);
	}

	return module;
}
int wmain(int argc,  wchar_t *argv[])
{
    // initialize COM before doing anything else, since the IShellLibrary API depends on COM
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    if (SUCCEEDED(hr))
    {
        CMetaCommand::PFNCREATECOMMAND rgMainCmds[] =
        {
            CMetaCommand::Create<CReindexMatchingFileTypeCommand>,
            CMetaCommand::Create<CReindexMatchingMimeTypeCommand>,
            CMetaCommand::Create<CReindexMatchingWhereClauseCommand>,
        };
        {
            PCWSTR pszExeName = PathFindFileNameW(CONSUME_NEXT_ARG(argv, argc));
            CMetaCommand main(pszExeName, L"Reindexes the files that match the requirements specified. \nreindex <command> -? will give you the usage for each command", rgMainCmds, ARRAYSIZE(rgMainCmds));
            main.Execute(const_cast<PCWSTR *>(argv), argc);
        }
        CoUninitialize();
    }

    return 0;
}
Example #26
0
//===================================
void ConfigMonitorFile (const wchar filename[]) {
    // Convert to canonical lowercase form
    wchar fullpath[MAX_PATH];
    if (!GetFullPathNameW(filename, _countof(fullpath), fullpath, NULL)) {
        LOG_OS_LAST_ERROR(L"GetFullPathNameW");
        FatalError();
    }
    CharLowerW(fullpath);

    // Create the directory that contains the file to be watched
    wchar directory[MAX_PATH];
    PathRemoveFileName(directory, _countof(directory), fullpath);
    if (!PathCreateDirectory(directory))
        FatalError();

    // Get the filename part
    filename = PathFindFileNameW(fullpath);

    s_critsect.Enter();
    {
        // Create a monitor for this directory
        DirMonitor * dir = FindOrCreateDirectoryMonitor_CS(directory);

        // Does this file already exist in the monitor's file list?
        ConfigFile * file;
        ConfigFileMap::iterator pair = dir->m_files.find(filename);
        if (pair == dir->m_files.end()) {
            file = new ConfigFile(fullpath);
            dir->m_files.insert(ConfigFilePair(file->m_filename, file));
        }
        else {
            file = pair->second;
        }

        // TODO: signal file for reparsing so the callback gets called.
    }
    s_critsect.Leave();
}
Example #27
0
static void loadGeneralParams(LPCWSTR path) {
	GeneralParams.HookTarget = (HookTargetEnum)GetPrivateProfileIntW(
		L"General",
		L"HookTarget",
		(int)GeneralParams.HookTarget,
		path);
	GeneralParams.ForceNoHinting = 0 != GetPrivateProfileIntW(
		L"General",
		L"ForceNoHinting",
		(int)GeneralParams.ForceNoHinting,
		path);
	
	wchar_t exePath[_MAX_PATH];
	GetModuleFileNameW(NULL, exePath, _MAX_PATH);
	wchar_t* exeName = PathFindFileNameW(exePath);
	CharLower(exeName);
	
	switch (GeneralParams.HookTarget) {
		case HookTargetEnum::All:
			GeneralParams.isHookTarget = true;
			break;
		case HookTargetEnum::ExcludeMode: {
			std::set<std::wstring, std::less<>> set;
			loadExeName(set, L"Exclude", path);
			GeneralParams.isHookTarget = set.count(exeName) == 0;
			break;
		}
		case HookTargetEnum::IncludeMode: {
			std::set<std::wstring, std::less<>> set;
			loadExeName(set, L"Include", path);
			GeneralParams.isHookTarget = set.count(exeName) > 0;
			break;
		}
		case HookTargetEnum::None:
			GeneralParams.isHookTarget = false;
			break;
	}
}
Example #28
0
long Cx_StringTable::RegisterFile(const std::wstring& filename)
{
    Cx_Interface<Ix_ConfigXml> pIFFile(x3::CLSID_ConfigXmlFile);
    if (pIFFile.IsNull())
    {
        return 0;
    }

    pIFFile->SetFileName(filename.c_str());
    X3LOG_DEBUG2(L"@StringTable:IDS_LOAD_STRFILE", PathFindFileNameW(filename.c_str()));

    long count = 0;
    for (int i = 0; i < 99; i++)
    {
        Cx_ConfigSection sec (pIFFile->GetData()->GetSectionByIndex(NULL, L"module", i));
        ITEM item;

        item.file = pIFFile->GetData();
        item.group = sec;
        item.module = sec->GetString(L"name");
        ASSERT(item.group && item.file);

        if (item.module.empty())
            break;

        if (Find(item.module) == m_groups.end())
        {
            m_groups.push_back(item);
            count++;
        }
        else
        {
            X3LOG_WARNING2(L"@StringTable:IDS_IGNORE_STRGROUP", item.module);
        }
    }

    return count;
}
Example #29
0
wstring CFileMonitorRequest::GetNotifyPath( CONST FILE_NOTIFY_INFORMATION * aNotifyInfo )
{
    _ASSERT( aNotifyInfo );
    wstring wstrFullPath( aNotifyInfo->FileName , aNotifyInfo->FileNameLength/sizeof(WCHAR) );

    //Handle a trailing backslash, such as for a root directory
    if ( m_wstrMonitorPath.length() > 0 && m_wstrMonitorPath[m_wstrMonitorPath.length()-1] != L'\\' )
        wstrFullPath = ( m_wstrMonitorPath + L"\\" ) + wstrFullPath;
    else
        wstrFullPath = m_wstrMonitorPath + wstrFullPath;

    //Handle the case it's a 8.3 short filename. Convert it to long name
    WCHAR * wzFilename = PathFindFileNameW( wstrFullPath.c_str() );
    if ( wcslen( wzFilename ) <= 12 && wcschr(wzFilename , L'~') )
    {
        // Convert to the long filename form. Unfortunately, this does not work for deletions, so it's an imperfect fix
        WCHAR wzBuf[MAX_PATH];
        if ( GetLongPathNameW( wstrFullPath.c_str() , wzBuf, _countof(wzBuf) ) > 0 )
            wstrFullPath = wzBuf;
    }

    return wstrFullPath;
}
Example #30
0
void createCrashReport(EXCEPTION_POINTERS* exceptionPointers)
{
    wchar_t appDataDirectory[MAX_PATH];
    if (FAILED(SHGetFolderPathW(0, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, appDataDirectory)))
        return;

    wchar_t executablePath[MAX_PATH];
    ::GetModuleFileNameW(0, executablePath, MAX_PATH);
    ::PathRemoveExtensionW(executablePath);

    std::wstring directory = std::wstring(appDataDirectory) + L"\\" + PathFindFileNameW(executablePath);
    if (::SHCreateDirectoryEx(0, directory.c_str(), 0) != ERROR_SUCCESS
        && ::GetLastError() != ERROR_FILE_EXISTS
        && ::GetLastError() != ERROR_ALREADY_EXISTS)
        return;

    std::wstring fileName = directory + L"\\CrashReport.dmp";
    HANDLE miniDumpFile = ::CreateFile(fileName.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

    if (miniDumpFile && miniDumpFile != INVALID_HANDLE_VALUE) {

        MINIDUMP_EXCEPTION_INFORMATION mdei;
        mdei.ThreadId = ::GetCurrentThreadId();
        mdei.ExceptionPointers  = exceptionPointers;
        mdei.ClientPointers = 0;

#ifdef _DEBUG
        MINIDUMP_TYPE dumpType = MiniDumpWithFullMemory;
#else
        MINIDUMP_TYPE dumpType = MiniDumpNormal;
#endif

        ::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), miniDumpFile, dumpType, &mdei, 0, 0);
        ::CloseHandle(miniDumpFile);
        processCrashReport(fileName.c_str());
    }
}