Example #1
0
BYTE CPatcher::InstallDetourPatchWithData(char * szLibrary, unsigned int uOrdinal, DWORD dwFunctionAddress)
{
	DWORD dwAddress = GetFunctionAddress(szLibrary, uOrdinal);
	DWORD dwDetourAddress = dwFunctionAddress;
	BYTE byteType = X86_JMP;
	int iSize = 5;

	// Allocate the trampoline memory
	BYTE * pbyteTrampoline = (BYTE *)malloc(iSize + 5);

	// Unprotect the trampoline memory
	Unprotect((DWORD)pbyteTrampoline, (iSize + 5));

	// Unprotect the address memory
	ProtectionInfo protectionInfo = Unprotect(dwAddress, (iSize + 5));

	// Copy the overwritten address memory to the trampoline memory
	memcpy(pbyteTrampoline, (void *)dwAddress, iSize);

	// Write the type to the trampoline memory
	DWORD dwTrampoline = (DWORD)(pbyteTrampoline + iSize);
	*(BYTE *)dwTrampoline = byteType;
	*(DWORD *)(dwTrampoline + 1) = ((dwAddress + iSize) - dwTrampoline - 5);

	// Write the type to the address memory
	*(BYTE *)dwAddress = byteType;
	*(DWORD *)(dwAddress + 1) = (dwDetourAddress - dwAddress - 5);

	// Re-protect the address memory
	Reprotect(protectionInfo);

	return (pbyteTrampoline != NULL);
}
Example #2
0
int LoadUserBusinessRll()
{
	int rnet ;
	char filename[ 512 + 1 ] ;
		
	memset( filename , 0x00, sizeof(filename) ) ;
	sprintf( filename, "%s/modules/%s", getenv("HOME"), procfg.so_name ) ;

	phandle = OpenLinkLibrary( filename ) ;
	if( phandle == NULL )
	{
		hzb_log_error(__FILE__, __LINE__, "    dlerror()[%s]\n" , dlerror() ) ; 
		hzb_log_error(__FILE__, __LINE__, "打开业务处理组件文件[%s]失败\n" , filename ) ; 
                return RETCODE_ERROR_OPENRllFILE_FAILED ;	
	}

        pfuncBusinessProcess = GetFunctionAddress( phandle , procfg.service_func )  ;
        if( pfuncBusinessProcess == NULL )
        {
		hzb_log_error(__FILE__, __LINE__, "    dlerror()[%s]\n" , dlerror() ) ; 
		hzb_log_error(__FILE__, __LINE__, "定位业务处理组件函数[%s]失败\n", procfg.service_func ) ; 
                CloseLinkLibrary( phandle ) ;
                return RETCODE_ERROR_GETFUNCPTR_FAILED ;
        }

	hzb_log_info(__FILE__, __LINE__, "挂接业务处理组件[%s]函数[%s]成功" , filename, procfg.service_func ) ; 

	return 0 ;
}
Example #3
0
IGraphicsApi* CreateGraphicsApi(IWindow* targetWindow, unsigned backBufferWidth, unsigned backBufferHeight, eGraphicsApiType type) {
	// try to load the dynamic libraries and return an api
	switch (type) {
		case eGraphicsApiType::GRAPHICS_API_D3D11:
			if (hDllD3D11) {
				if (CreateGraphicsApiD3D11)
					return CreateGraphicsApiD3D11(targetWindow, backBufferWidth, backBufferHeight);
				else
					return 0;
			}
			else {
				hDllD3D11 = LoadDynamicLibrary("GraphicsApiD3D11");
				if (!hDllD3D11) {
					return nullptr;
				}
				CreateGraphicsApiD3D11 = (IGraphicsApi*(*)(IWindow*, unsigned, unsigned))GetFunctionAddress(hDllD3D11, "CreateGraphicsApiD3D11");
				if (!CreateGraphicsApiD3D11) {
					assert(false);
					return nullptr;
				}
				return CreateGraphicsApiD3D11(targetWindow, backBufferWidth, backBufferHeight);
			}
			break;
		case eGraphicsApiType::GRAPHICS_API_OPENGL43:
			if (hDllOpenGL43) {
				if (CreateGraphicsApiGL43)
					return CreateGraphicsApiGL43(targetWindow, backBufferWidth, backBufferHeight);
				else
					return nullptr;
			}
			else {
				hDllOpenGL43 = LoadDynamicLibrary("GraphicsApiGL");
				if (!hDllOpenGL43) {
					return nullptr;
				}
				CreateGraphicsApiGL43 = (IGraphicsApi*(*)(IWindow*, unsigned, unsigned))GetFunctionAddress(hDllOpenGL43, "CreateGraphicsApiDL");
				if (!CreateGraphicsApiGL43) {
					assert(false);
					return nullptr;
				}
				return CreateGraphicsApiGL43(targetWindow, backBufferWidth, backBufferHeight);
			}
			break;
		default:
			return nullptr;
	}
}
Example #4
0
FARPROC WINAPI MyGetProcAddress(HMODULE hModule, LPCSTR lpProcName)
{
    static HMODULE hModuleKernel32;

    if (hModuleKernel32 == NULL)
    {
        Init();
        hModuleKernel32 = GetKernel32Handle();
    }

    if ((ULONG_PTR)lpProcName & 0xFFFF0000)
    {
        switch (HashAPI(lpProcName))
        {
            case 0xB231F005: return (FARPROC)MyCreateFileA;
#if defined(USE_CACHE)
//            case 0xFFADBAB0: return (FARPROC)MyPeekMessageA;
            case 0xFF85A538: return (FARPROC)MyGetMessageA;
#endif
            case 0xA1A757F2: return (FARPROC)MyGetGlyphOutlineA;
            case 0xC8E4BFAB: return (FARPROC)MyCreateFontIndirectA;
#if defined(NULL_IAT)
            case 0xD424F9FF: return (FARPROC)GetFunctionAddress;
#endif
//            case 0xD332F12B:
//            case 0x5E207A27: return (FARPROC)MylstrcmpiA;
            case 0x91E7D989: return (FARPROC)my_ov_read;
            case 0x1F24078F: return (FARPROC)my_ov_pcm_seek;
            case 0x41EE3F2A: return (FARPROC)my_ov_time_total;
            case 0xEA2196CE: return (FARPROC)my_ov_clear;
            case 0xCE40594F: return (FARPROC)my_ov_test_callbacks;
            case 0x9E4B6F26: return (FARPROC)my_ov_open_callbacks;
        }
    }

    if (hModule == (HMODULE)&__ImageBase)
        hModule = hModuleKernel32;

#if defined(NULL_IAT)
    return GetFunctionAddress(hModule, lpProcName);
#else
    return GetProcAddress(hModule, lpProcName);
#endif
}
CAndroidSystemLogger::CAndroidSystemLogger( void )
    : CILogger()        ,
      m_tag()           ,
      m_logFunc( NULL )
{GUCEF_TRACE;

    m_tag = "GUCEF:AndroidSystemLogger:" + PointerToString( this );

    // We load the log module dynamically to avoid adding dependencies
    void* logModule = LoadModuleDynamicly( "log.so" );
    if ( NULL != logModule )
    {
        // Find the address of the Android log function
        void* funcAddr = GetFunctionAddress( logModule                                     ,
                                             "__android_log_write"                         ,
                                             sizeof(android_LogPriority)+(2*sizeof(char*)) ).objPtr;
        if ( NULL != funcAddr )
        {
            m_logFunc = funcAddr;
        }
    }
}
Example #6
0
void * CPatcher::InstallDetourPatch(char * szLibrary, unsigned int uOrdinal, DWORD dwFunctionAddress)
{
	return InstallDetourPatchInternal(GetFunctionAddress(szLibrary, uOrdinal), dwFunctionAddress, X86_JMP, 5);
}
Example #7
0
void * CPatcher::InstallDetourPatch(char * szLibrary, char * szFunction, DWORD dwFunctionAddress)
{
	return InstallDetourPatchInternal(GetFunctionAddress(szLibrary, szFunction), dwFunctionAddress, X86_JMP, 5);
}
Example #8
0
DWORD CPatcher::GetFunctionAddress(char * szLibrary, unsigned int uOrdinal)
{
	return GetFunctionAddress(szLibrary, (char *)MAKELONG(uOrdinal, 0));
}
bool
CDStoreCodecPlugin::Link( void* modulePtr                   ,
                         TPluginMetaDataPtr pluginMetaData )
{GUCEF_TRACE;

    if ( IsLoaded() ) return false;
    
    _sohandle = modulePtr;
    if ( NULL != _sohandle )
    {
        GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "DStoreCodecPlugin: Linking API using module pointer: " + PointerToString( modulePtr ) );

        _fptable[ DSTOREPLUG_INIT ] = GetFunctionAddress( _sohandle         ,
                                                          "DSTOREPLUG_Init" ,
                                                          1*sizeof(void*)   ).funcPtr;
        _fptable[ DSTOREPLUG_SHUTDOWN ] = GetFunctionAddress( _sohandle             ,
                                                              "DSTOREPLUG_Shutdown" ,
                                                              1*sizeof(void*)       ).funcPtr;
        _fptable[ DSTOREPLUG_NAME ] = GetFunctionAddress( _sohandle         ,
                                                          "DSTOREPLUG_Name" ,
                                                          1*sizeof(void*)   ).funcPtr;
        _fptable[ DSTOREPLUG_COPYRIGHT ] = GetFunctionAddress( _sohandle              ,
                                                               "DSTOREPLUG_Copyright" ,
                                                               1*sizeof(void*)        ).funcPtr;
        _fptable[ DSTOREPLUG_VERSION ] = GetFunctionAddress( _sohandle            ,
                                                             "DSTOREPLUG_Version" ,
                                                             1*sizeof(void*)      ).funcPtr;
        _fptable[ DSTOREPLUG_TYPE ] = GetFunctionAddress( _sohandle         ,
                                                          "DSTOREPLUG_Type" ,
                                                          1*sizeof(void*)   ).funcPtr;
        _fptable[ DSTOREPLUG_DEST_FILE_OPEN ] = GetFunctionAddress( _sohandle                   ,
                                                                    "DSTOREPLUG_Dest_File_Open" ,
                                                                    3*sizeof(void*)             ).funcPtr;
        _fptable[ DSTOREPLUG_DEST_FILE_CLOSE ] = GetFunctionAddress( _sohandle                    ,
                                                                     "DSTOREPLUG_Dest_File_Close" ,
                                                                     2*sizeof(void*)              ).funcPtr;
        _fptable[ DSTOREPLUG_BEGIN_NODE_STORE ] = GetFunctionAddress( _sohandle                    ,
                                                                     "DSTOREPLUG_Begin_Node_Store" ,
                                                                     3*sizeof(void*)+8             ).funcPtr;
        _fptable[ DSTOREPLUG_END_NODE_STORE ] = GetFunctionAddress( _sohandle                   ,
                                                                    "DSTOREPLUG_End_Node_Store" ,
                                                                    3*sizeof(void*)+8           ).funcPtr;
        _fptable[ DSTOREPLUG_STORE_NODE_ATT ] = GetFunctionAddress( _sohandle                   ,
                                                                    "DSTOREPLUG_Store_Node_Att" ,
                                                                    5*sizeof(void*)+12          ).funcPtr;
        _fptable[ DSTOREPLUG_BEGIN_NODE_CHILDREN ] = GetFunctionAddress( _sohandle                        ,
                                                                         "DSTOREPLUG_Begin_Node_Children" ,
                                                                         3*sizeof(void*)                  ).funcPtr;
        _fptable[ DSTOREPLUG_END_NODE_CHILDREN ] = GetFunctionAddress( _sohandle                      ,
                                                                       "DSTOREPLUG_End_Node_Children" ,
                                                                       3*sizeof(void*)                ).funcPtr;
        _fptable[ DSTOREPLUG_SRC_FILE_OPEN ] = GetFunctionAddress( _sohandle                  ,
                                                                   "DSTOREPLUG_Src_File_Open" ,
                                                                   2*sizeof(void*)            ).funcPtr;
        _fptable[ DSTOREPLUG_SRC_FILE_CLOSE ] = GetFunctionAddress( _sohandle                   ,
                                                                    "DSTOREPLUG_Src_File_Close" ,
                                                                    2*sizeof(void*)             ).funcPtr;
        _fptable[ DSTOREPLUG_SET_READ_HANDLERS ] = GetFunctionAddress( _sohandle                      ,
                                                                       "DSTOREPLUG_Set_Read_Handlers" ,
                                                                       4*sizeof(void*)                ).funcPtr;
        _fptable[ DSTOREPLUG_START_READING ] = GetFunctionAddress( _sohandle                  ,
                                                                   "DSTOREPLUG_Start_Reading" ,
                                                                   2*sizeof(void*)            ).funcPtr;


        if ( ( _fptable[ DSTOREPLUG_INIT ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_SHUTDOWN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_NAME ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_COPYRIGHT ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_VERSION ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_TYPE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_DEST_FILE_OPEN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_DEST_FILE_CLOSE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_BEGIN_NODE_STORE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_END_NODE_STORE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_STORE_NODE_ATT ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_BEGIN_NODE_CHILDREN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_END_NODE_CHILDREN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_SRC_FILE_OPEN ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_SRC_FILE_CLOSE ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_SET_READ_HANDLERS ] == NULL ) ||
             ( _fptable[ DSTOREPLUG_START_READING ] == NULL ) )
        {
                memset( _fptable, NULL, sizeof(anyPointer) * DSTOREPLUG_LASTFPTR );
                _sohandle = NULL;

                GUCEF_ERROR_LOG( LOGLEVEL_NORMAL, "Invalid codec module: One or more functions could not be located in the module " + PointerToString( modulePtr ) );
                return false;
        }

        /*
         *      Intialize the plugin module
         */
        UInt32 statusCode = ( (TDSTOREPLUGFPTR_Init) _fptable[ DSTOREPLUG_INIT ] )( &_plugdata );
        if ( statusCode > 0 )
        {
            // We have loaded & linked our plugin module
            GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "DStoreCodecPlugin: Successfully loaded module and invoked Init() which returned status " + 
                    Int32ToString( statusCode  ) + " using module: " + PointerToString( modulePtr ) );
            GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "  - Name: " + GetName() );
            GUCEF_SYSTEM_LOG( LOGLEVEL_NORMAL, "  - Copyright/EULA: " + GetCopyright() );

            // Copy the given metadata and update it with info from the actual module
            m_metaData = new CPluginMetaData( *pluginMetaData );                 
            m_metaData->SetDescription( GetDescription() );
            m_metaData->SetCopyright( GetCopyright() );
            m_metaData->SetVersion( GetVersion() );
            
            return true;
        }
        else
        {
            memset( _fptable, NULL, sizeof(anyPointer) * DSTOREPLUG_LASTFPTR );
            _sohandle = NULL;
            _plugdata = NULL;

            GUCEF_ERROR_LOG( LOGLEVEL_NORMAL, "Initialization routine reported an error for module " + PointerToString( modulePtr ) );
            return false;
        }        
    }

    return false;
}
Example #10
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(private)
 *	Get the default profile data base path for windows.  The path
 *	is returned in the buffer pointed to by pDataBasePath.  The 
 *	size of the buffer in bytes is specified by size.
 *
 * AUTHOR
 * 	M. Biamonte
 *
 * DATE CREATED
 *	November 16, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI GetWinDefaultDB (KpTChar_p pDataBasePath, KpInt32_t size)
{

	KpInt32_t			retVal;
	KpChar_t			*p;
	HANDLE				hFindFile;
	WIN32_FIND_DATA		findData;
	char 				defProfileDB [DEFPROFILEDBSIZE];
	DWORD				dwSize = DEFPROFILEDBSIZE;
	KpChar_t			FAR ColorDir[256];
	HMODULE				hLib;
	BOOL				result = FALSE;

	*pDataBasePath = '\0';

	hLib = LoadLibrary("mscms.dll");
	if (hLib != NULL)
	{
		result = GetFunctionAddress(hLib, GETCOLORDIRNAME, (FARPROC FAR *)&GetColorDirFunc);
		if (result == TRUE) 
		{
			result = GetColorDirFunc(NULL, defProfileDB, &dwSize);
		}
		FreeLibrary(hLib);
	}
	if(result == FALSE)
	{
		/* Create the {Windows System Directory}\Color
		   directory to use as the default */
		retVal = GetSystemDirectory (defProfileDB, sizeof (defProfileDB));
		if (0 == retVal) {
			return SpStatFileNotFound;
		}

		/* Check for room to add  \\Color */
		LoadString(SpHInst, SpColorStr, (LPSTR)ColorDir, 255);
		if (retVal >= (KpInt32_t) (size - strlen (ColorDir) + 1)) {
			return SpStatBufferTooSmall;
		} 
		strcat (defProfileDB, KcpFileDirSep);
		strcat (defProfileDB, ColorDir);
	}

	/* Read default DB from registry.  If one is not present, set registry to
	   default of windows\system\color.  Note - this doesn't use the
	   KpReadStringPreferenceEx call so that the ini file stuff is skipped.  */

	retVal = KpReadRegistryString ( KPLOCAL_MACHINE, 
			(KpChar_p) sectICCProfiles,
			(KpChar_p) keyDefPath, 
			pDataBasePath, 
			(KpUInt32_p)&size);

	if (KCMS_SUCCESS != retVal) {
		if (KCMS_MORE_DATA == retVal) {
			return SpStatBufferTooSmall;
		}
		else {
			/* write registry entry */
			retVal = KpWriteRegistryString (KPLOCAL_MACHINE, (KpChar_p) sectICCProfiles,
							(KpChar_p) keyDefPath, defProfileDB);
			if (KCMS_SUCCESS != retVal)
				return SpStatFileNotFound;
			strncpy (pDataBasePath, defProfileDB, size);
		}
	}

	/* if trailing file separator - remove it */
	p = strrchr (pDataBasePath, '\\');
	if (p != NULL) {
		if (*(p+1) == '\0') {
			*p = '\0';
		}
	}

	/*	Check if path exists	*/
	hFindFile = FindFirstFile (pDataBasePath, &findData);

	if (INVALID_HANDLE_VALUE == hFindFile) {
		FindClose(hFindFile);
		return (SpStatFileNotFound);
	}
	FindClose(hFindFile);
	if (0 == (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {		
		return (SpStatFileNotFound);
	}

	return SpStatSuccess;

}
Example #11
0
ExecutableInMemory *LoadSharedLibrary(FileNode *file)
{
  //Read data from file and verify
  if (file == NULL)
  {
    return NULL;
  }
  ExecutableInMemory *sl = calloc(sizeof(ExecutableInMemory));

  ExecutableFileHeader *header = (ExecutableFileHeader *)file->contents;
  if (header->size != file->size)
  {
    debug_print("Invalid file header: size $d != $d\n", header->size, file->size);
    return NULL;
  }
  if (header->magic != EXECUTABLE_FILE_MAGIC)
  {
    debug_print("Invalid file header: magic\n");
    return NULL;
  }
  if ((header->type != EXECUTABLE_TYPE_LIBRARY)&&(header->type != EXECUTABLE_TYPE_EXECUTABLE))
  {
    debug_print("Invalid file header: type\n");
    return NULL;
  }
  if (header->functionCount == 0)
  {
    debug_print("Invalid file header: functions\n");
    return NULL;
  }
  if (header->functionTableOffset != sizeof(ExecutableFileHeader))
  {
    debug_print("Invalid file header: function table offset\n");
    return NULL;
  }
  if (header->resourceCount * sizeof(ResourceEntry) > file->size - sizeof(ExecutableFileHeader) - header->functionCount * sizeof(FunctionTableEntry))
  {
    debug_print("Invalid file header: resource size\n");
    return NULL;
  }
  if (header->resourceOffset > file->size - header->resourceCount * sizeof(ResourceEntry))
  {
    debug_print("Invalid file header: resource offset\n");
    return NULL;
  }
  if (header->functionsSize > file->size - sizeof(ExecutableFileHeader) - header->functionCount * sizeof(FunctionTableEntry) - header->resourceCount * sizeof(ResourceEntry))
  {
    debug_print("Invalid file header: functions size\n");
    return NULL;
  }
  if (header->functionsOffset > file->size - header->functionsSize)
  {
    debug_print("Invalid file header: functions size\n");
    return NULL;
  }
  sl->type = header->type;
  sl->functionCount = header->functionCount;
  sl->functionTable = calloc(header->functionCount * sizeof(FunctionTableEntry));
  cgc_memcpy(sl->functionTable, file->contents + header->functionTableOffset, header->functionCount * sizeof(FunctionTableEntry));
  for (int i = 0; i < sl->functionCount; i++)
  {
    sl->functionTable[i].offset -= header->functionsOffset;
  }
  sl->resourceCount = header->resourceCount;
  sl->resourceTable = calloc(header->resourceCount * sizeof(ResourceEntry));
  cgc_memcpy(sl->resourceTable, file->contents + header->resourceOffset, header->resourceCount * sizeof(ResourceEntry));
  sl->functions = calloc(header->functionsSize);
  cgc_memcpy(sl->functions, file->contents + header->functionsOffset, header->functionsSize);

  uint8_t *mainAddress = GetFunctionAddress("SharedLibraryMain", sl);
  ExecuteFunction(mainAddress);
  return sl;
}