示例#1
0
CPLErr GNMFileNetwork::CreateFeaturesLayerFromFile( const char* pszFilename, char** papszOptions )
{
    CPLErr eResult = CheckLayerDriver(GNM_MD_DEFAULT_FILE_FORMAT, papszOptions);
    if(CE_None != eResult)
        return eResult;

    eResult = FormPath(pszFilename, papszOptions);
    if(CE_None != eResult)
        return eResult;

    const char* pszExt = m_poLayerDriver->GetMetadataItem(GDAL_DMD_EXTENSION);
    CPLString osDSFileName = CPLFormFilename(m_soNetworkFullName,
                                                GNM_SYSLAYER_FEATURES, pszExt);

    m_pFeaturesDS = m_poLayerDriver->Create(osDSFileName, 0, 0, 0, GDT_Unknown,
                                            NULL );

    if( m_pFeaturesDS == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined, "Creation of '%s' file failed",
                  osDSFileName.c_str() );
        return CE_Failure;
    }

    return GNMGenericNetwork::CreateFeaturesLayer(m_pFeaturesDS);
}
示例#2
0
int _tmain(int argc, _TCHAR* argv[])
{

	// This sample will take path to the executable which will invoke GetVersionEx
	// so that our detoured function will return them our custom version details
	if (argc != 5)
	{
		// Usage is:
		//
		// ForceVersion <path> <major ver> <minor ver> <build #>
		//
		// For e.g.
		//
		// ForceVersion c:\app.exe 4 1 2000
		// 
		// will return OS version as 4.1.2000 when the application calls GetVersionEx API

		printf("ForceVersion - returns a user defined OS version details to application\n");
		printf("by Gaurav Khanna - http://www.wintoolzone.com/\n\n");
		printf("Usage:\n\nForceVersion <app path> <major ver> <minor ver> <build #>\nwhere:\n");
		printf("\t<app path> - path to the executable which will request OS version\n");
		printf("\t<major ver> - OS major version to be returned to calling applications\n");
		printf("\t<minor ver> - OS minor version to be returned to calling applications\n");
		printf("\t<build #> - OS build version to be returned to calling applications\n");
		return 0;
	}

	// Get the version details
	VersionPayLoad payload;
	payload.iMajor = atoi(argv[2]);
	payload.iMinor = atoi(argv[3]);
	payload.iBuild = atoi(argv[4]);
	
	// Now, we will ask Detours to launch this executable and load our DetourDLL into the process
	STARTUPINFO startup;
	memset(&startup, 0, sizeof(startup));
	PROCESS_INFORMATION pi;
	memset(&pi, 0, sizeof(pi));
	startup.cb = sizeof(startup);
	
	// init the buffer that will hold the current working folder of the application
	TCHAR tCurDir[MAX_PATH];
	memset(tCurDir,0, sizeof(tCurDir));
	DWORD dwCount = GetCurrentDirectory(MAX_PATH,tCurDir);
	if (!dwCount)
	{
		printf("Unable to get the working folder!");
		return -1;
	}

	// Form the paths to the DETOURED.DLL and our Detouring DLL
	TCHAR szDetouredPath[MAX_PATH]; 
	memset(szDetouredPath, 0, sizeof(szDetouredPath));

	TCHAR szInjectDLLPath[MAX_PATH]; 
	memset(szInjectDLLPath, 0, sizeof(szInjectDLLPath));
	
	if (FormPath(szDetouredPath, tCurDir, _TEXT("detoured.dll")) == FALSE)
	{
		printf("Unable to form path to DETOURED.DLL!\n");
		return -1;
	}

	if (FormPath(szInjectDLLPath, tCurDir, _TEXT("ForceVersionDLL.dll")) == FALSE)
	{
		printf("Unable to form path to Injection DLL!\n");
		return -1;
	}

	// We create the process as suspended since we will copy payload
	// to the target process containing the versions we want it to get
	BOOL fLaunchApp = DetourCreateProcessWithDll(argv[1],
		0,0,0,TRUE,CREATE_SUSPENDED|CREATE_DEFAULT_ERROR_MODE,0,0,&startup,&pi,
		szDetouredPath,
		szInjectDLLPath,
		NULL);
	
	if (!fLaunchApp)
	{
		printf("Error: %d\n",GetLastError());
		return -1;
	}

	// Send the payload data...
	BOOL fRetVal = DetourCopyPayloadToProcess(pi.hProcess, my_guid, (PVOID)&payload, sizeof(payload));
	if (!fRetVal)
	{
		printf("Unable to write version information in the target process!");
		return -1;
	}

	// Resume thread and wait on the process..
	ResumeThread(pi.hThread);

	WaitForSingleObject(pi.hProcess, INFINITE);
	return 0;
}
示例#3
0
int GNMFileNetwork::CheckNetworkExist(const char *pszFilename, char **papszOptions)
{
    // check if path exist
    // if path exist check if network already present and OVERWRITE option
    // else create the path

    bool bOverwrite = CSLFetchBoolean(papszOptions, "OVERWRITE", FALSE);

    if(m_soName.empty())
    {
        const char* pszNetworkName = CSLFetchNameValue(papszOptions, GNM_MD_NAME);

        if( NULL != pszNetworkName )
        {
            m_soName = pszNetworkName;
        }
    }

    if(FormPath(pszFilename, papszOptions) != CE_None)
    {
        return TRUE;
    }

    if (CPLCheckForFile((char*)m_soNetworkFullName.c_str(), NULL))
    {
        char **papszFiles = CPLReadDir( m_soNetworkFullName );
        if( CSLCount(papszFiles) == 0 )
        {
            return FALSE;
        }

        // search for base GNM files
        for(int i = 0; papszFiles[i] != NULL; i++ )
        {
            if( EQUAL(papszFiles[i],".") || EQUAL(papszFiles[i],"..") )
                continue;

            if( EQUAL(CPLGetBasename(papszFiles[i]), GNM_SYSLAYER_META) ||
                EQUAL(CPLGetBasename(papszFiles[i]), GNM_SYSLAYER_GRAPH) ||
                EQUAL(CPLGetBasename(papszFiles[i]), GNM_SYSLAYER_FEATURES) ||
                EQUAL(papszFiles[i], GNM_SRSFILENAME) )
            {
                if(bOverwrite)
                {
                    const char* pszDeleteFile = CPLFormFilename(
                                m_soNetworkFullName, papszFiles[i], NULL);
                    CPLDebug("GNM", "Delete file: %s", pszDeleteFile);
                    if( VSIUnlink(pszDeleteFile) != 0 )
                    {
                        return TRUE;
                    }
                }
                else
                {
                    return TRUE;
                }
            }
        }
        CSLDestroy( papszFiles );
    }
    else
    {
        if (VSIMkdir(m_soNetworkFullName, 0755) != 0)
        {
            return TRUE;
        }
    }

    return FALSE;
}