library/src/dynamic_modules/BP-DynamicModules.cc
// Checks to see if a dynamic module is already loaded in the GHT.
Checks to see if a dynamic module is already loaded in the GHT.
Checks to see if a dynamic module is already loaded in the GHT .
BP_BOOL BP_DynamicModuleIsAlreadyLoadedInGHT(P_BP_DYNAMIC_MODULE module)
{
	if(!module)
		return BP_FALSE;
	if(!BP_HashRegPathArrayIndexFilterTest(module->so_module_name, bpstrlen(module->so_module_name)))
	{
		module->load_check_failed = BP_TRUE;
		return BP_FALSE;
	}
	P_BP_HTKE mod_lookup = BP_HashRegLookupTableEntryByDataKeyIndexAndTablePathQuery
	(
		(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
		"/system/dynamic_modules",
		module->so_module_name
	);
	if(mod_lookup)
	{
		module->already_loaded                     = BP_TRUE;
		module->already_loaded_matched_module_name = BP_TRUE;
		return BP_TRUE;
	}
	P_BP_HTKE modules_table_lookup = BP_HashRegLookupTableByPathQuery((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, "/system/dynamic_modules");
	BP_HASH_ITER_OPEN(modules_table_lookup, table_entry_iter)
	{
		if(!table_entry_iter)
			break;
		if(!table_entry_iter->key)
			break;
		%%%%%%%%
		%%%%%%%%
		char * table_entry_lookup[] =
		{
			"system",
			"dynamic_modules",
			table_entry_iter->key,
			"so_module_filesystem_sha1_hash",
			NULL
		};
		P_BP_HTKE so_module_filesystem_sha1_hash_lookup = BP_HashRegLookupTableEntryByPath((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, (char **) &table_entry_lookup);
		if(!so_module_filesystem_sha1_hash_lookup)
		{
			continue;
		}
		if(so_module_filesystem_sha1_hash_lookup->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING)
			continue;
		if(so_module_filesystem_sha1_hash_lookup->data_size < 40)
			continue;
		if(ht_memmatch_entry(so_module_filesystem_sha1_hash_lookup, module->so_module_filesystem_sha1_hash, bpstrlen(module->so_module_filesystem_sha1_hash)))
		{
			module->already_loaded = BP_TRUE;
			module->already_loaded_matched_bin_sha1 = BP_TRUE;
		}
		%%%%%%%%
		%%%%%%%%
		char * fs_table_entry_lookup[] =
		{
			"system",
			"dynamic_modules",
			table_entry_iter->key,
			"so_module_load_path",
			NULL
		};
		P_BP_HTKE so_module_filesystem_load_path_hash_lookup = BP_HashRegLookupTableEntryByPath((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, (char **) &table_entry_lookup);
		if(!so_module_filesystem_sha1_hash_lookup)
		{
			continue;
		}
		if(so_module_filesystem_load_path_hash_lookup->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING)
			continue;
		if(so_module_filesystem_load_path_hash_lookup->data_size < 40)
			continue;
		if(ht_memmatch_entry(so_module_filesystem_load_path_hash_lookup, module->so_module_load_path, bpstrlen(module->so_module_load_path)))
		{
			module->already_loaded = BP_TRUE;
			module->already_loaded_matched_module_filesystem_path = BP_TRUE;
		}
		if(module->already_loaded == BP_TRUE)
			break;
	}
	BP_HASH_ITER_CLOSE;
	if(module->already_loaded == BP_TRUE)
		return BP_TRUE;
	return BP_FALSE;
}
BP_BOOL BP_DynamicModuleIsAlreadyLoadedInGHT ( P_BP_DYNAMIC_MODULE module ) { if ( ! module ) return BP_FALSE ; if ( ! BP_HashRegPathArrayIndexFilterTest ( module -> so_module_name , bpstrlen ( module -> so_module_name ) ) ) { module -> load_check_failed = BP_TRUE ; return BP_FALSE ; } P_BP_HTKE mod_lookup = BP_HashRegLookupTableEntryByDataKeyIndexAndTablePathQuery ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , " " , module -> so_module_name ) ; if ( mod_lookup ) { module -> already_loaded = BP_TRUE ; module -> already_loaded_matched_module_name = BP_TRUE ; return BP_TRUE ; } P_BP_HTKE modules_table_lookup = BP_HashRegLookupTableByPathQuery ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , " " ) ; BP_HASH_ITER_OPEN ( modules_table_lookup , table_entry_iter ) { if ( ! table_entry_iter ) break ; if ( ! table_entry_iter -> key ) break ; char * table_entry_lookup [ ] = { " " , " " , table_entry_iter -> key , " " , NULL } ; P_BP_HTKE so_module_filesystem_sha1_hash_lookup = BP_HashRegLookupTableEntryByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & table_entry_lookup ) ; if ( ! so_module_filesystem_sha1_hash_lookup ) { continue ; } if ( so_module_filesystem_sha1_hash_lookup -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING ) continue ; if ( so_module_filesystem_sha1_hash_lookup -> data_size < 40 ) continue ; if ( ht_memmatch_entry ( so_module_filesystem_sha1_hash_lookup , module -> so_module_filesystem_sha1_hash , bpstrlen ( module -> so_module_filesystem_sha1_hash ) ) ) { module -> already_loaded = BP_TRUE ; module -> already_loaded_matched_bin_sha1 = BP_TRUE ; } char * fs_table_entry_lookup [ ] = { " " , " " , table_entry_iter -> key , " " , NULL } ; P_BP_HTKE so_module_filesystem_load_path_hash_lookup = BP_HashRegLookupTableEntryByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & table_entry_lookup ) ; if ( ! so_module_filesystem_sha1_hash_lookup ) { continue ; } if ( so_module_filesystem_load_path_hash_lookup -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING ) continue ; if ( so_module_filesystem_load_path_hash_lookup -> data_size < 40 ) continue ; if ( ht_memmatch_entry ( so_module_filesystem_load_path_hash_lookup , module -> so_module_load_path , bpstrlen ( module -> so_module_load_path ) ) ) { module -> already_loaded = BP_TRUE ; module -> already_loaded_matched_module_filesystem_path = BP_TRUE ; } if ( module -> already_loaded == BP_TRUE ) break ; } BP_HASH_ITER_CLOSE ; if ( module -> already_loaded == BP_TRUE ) return BP_TRUE ; return BP_FALSE ; }
Checks to see if a dynamic module is already loaded in the GHT.
Checks to see if a dynamic module is already loaded in the GHT .
// ensure module name passes registry index filter test // attempt to lookup the module by name within the ght // if the lookup succeeded, return true immediately // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Check By SHA1() %%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt modules table lookup // walk through each entry // ensure we have a keyed entry // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt SHA1 Lookup %%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // allocate table lookup path // attempt to lookup the sha1 hash for this module // continue the loop if the type is mismatched // ensure the data size is at least 40 bytes (sha1 length) // attempt memory compare // set the already loaded flag to true // set the matched sha1 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt Filesystem Path Lookup %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // allocate table lookup path // attempt to lookup the sha1 hash for this module // continue the loop if the type is mismatched // ensure the data size is at least 40 bytes (sha1 length) // attempt memory compare // set the already loaded flag to true // set the matched sha1 // if we detected that or module is already loaded, exit here // if the module is already loaded, return indicating so // return unfound by default