src/Neo6/NDIS6.c
// Read the information from the registry

Read the information from the registry
Read the information from the registry
BOOL NeoLoadRegistry()
{
	void *buf;
	NDIS_STATUS ret;
	UINT size;
	NDIS_HANDLE config;
	NDIS_CONFIGURATION_PARAMETER *param;
	UNICODE *name;
	ANSI_STRING ansi;
	UNICODE_STRING *unicode;
	UINT64 speed;
	BOOL keep;
	NDIS_CONFIGURATION_OBJECT config_obj;
	NeoZero(&config_obj, sizeof(config_obj));
	config_obj.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT;
	config_obj.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1;
	config_obj.Header.Size = NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1;
	config_obj.NdisHandle = ctx->NdisMiniport;
	ret = NdisOpenConfigurationEx(&config_obj, &config);
	if (NG(ret))
	{
		return FALSE;
	}
	NdisReadNetworkAddress(&ret, &buf, &size, config);
	if (NG(ret))
	{
		NdisCloseConfiguration(config);
		return FALSE;
	}
	if (size != NEO_MAC_ADDRESS_SIZE)
	{
		NdisCloseConfiguration(config);
		return FALSE;
	}
	NeoCopy(ctx->MacAddress, buf, NEO_MAC_ADDRESS_SIZE);
	if (ctx->MacAddress[0] == 0x00 &&
		ctx->MacAddress[1] == 0x00 &&
		ctx->MacAddress[2] == 0x01 &&
		ctx->MacAddress[3] == 0x00 &&
		ctx->MacAddress[4] == 0x00 &&
		ctx->MacAddress[5] == 0x01)
	{
		UINT ptr32 = (UINT)((UINT64)ctx);
		LARGE_INTEGER current_time;
		UCHAR *current_time_bytes;
		KeQuerySystemTime(&current_time);
		current_time_bytes = (UCHAR *)&current_time;
		ctx->MacAddress[0] = 0x00;
		ctx->MacAddress[1] = 0xAD;
		ctx->MacAddress[2] = ((UCHAR *)(&ptr32))[0];
		ctx->MacAddress[3] = ((UCHAR *)(&ptr32))[1];
		ctx->MacAddress[4] = ((UCHAR *)(&ptr32))[2];
		ctx->MacAddress[5] = ((UCHAR *)(&ptr32))[3];
		ctx->MacAddress[2] ^= current_time_bytes[0];
		ctx->MacAddress[3] ^= current_time_bytes[1];
		ctx->MacAddress[4] ^= current_time_bytes[2];
		ctx->MacAddress[5] ^= current_time_bytes[3];
		ctx->MacAddress[2] ^= current_time_bytes[4];
		ctx->MacAddress[3] ^= current_time_bytes[5];
		ctx->MacAddress[4] ^= current_time_bytes[6];
		ctx->MacAddress[5] ^= current_time_bytes[7];
	}
	name = NewUnicode("MatchingDeviceId");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterString);
	FreeUnicode(name);
	if (NG(ret))
	{
		NdisCloseConfiguration(config);
		return FALSE;
	}
	if (param->ParameterType != NdisParameterString)
	{
		NdisCloseConfiguration(config);
		return FALSE;
	}
	unicode = &param->ParameterData.StringData;
	NeoZero(&ansi, sizeof(ANSI_STRING));
	ansi.MaximumLength = MAX_SIZE - 1;
	ansi.Buffer = NeoZeroMalloc(MAX_SIZE);
	NdisUnicodeStringToAnsiString(&ansi, unicode);
	strcpy(ctx->HardwareID, ansi.Buffer);
	strcpy(ctx->HardwareID_Raw, ctx->HardwareID);
	_strupr(ctx->HardwareID);
	NeoFree(ansi.Buffer);
	name = NewUnicode("MaxSpeed");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);
	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		speed = NEO_MAX_SPEED_DEFAULT;
	}
	else
	{
		speed = (UINT64)param->ParameterData.IntegerData * 1000000ULL;
	}
	max_speed = speed;
	name = NewUnicode("KeepLink");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);
	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		keep = false;
	}
	else
	{
		keep = (param->ParameterData.IntegerData == 0 ? false : true);
	}
	keep_link = keep;
	name = NewUnicode("*IfType");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);
	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		reg_if_type = IF_TYPE_ETHERNET_CSMACD;
	}
	else
	{
		reg_if_type = param->ParameterData.IntegerData;
	}
	NdisCloseConfiguration(config);
	return TRUE;
}
BOOL NeoLoadRegistry ( ) { void * buf ; NDIS_STATUS ret ; UINT size ; NDIS_HANDLE config ; NDIS_CONFIGURATION_PARAMETER * param ; UNICODE * name ; ANSI_STRING ansi ; UNICODE_STRING * unicode ; UINT64 speed ; BOOL keep ; NDIS_CONFIGURATION_OBJECT config_obj ; NeoZero ( & config_obj , sizeof ( config_obj ) ) ; config_obj . Header . Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT ; config_obj . Header . Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1 ; config_obj . Header . Size = NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1 ; config_obj . NdisHandle = ctx -> NdisMiniport ; ret = NdisOpenConfigurationEx ( & config_obj , & config ) ; if ( NG ( ret ) ) { return FALSE ; } NdisReadNetworkAddress ( & ret , & buf , & size , config ) ; if ( NG ( ret ) ) { NdisCloseConfiguration ( config ) ; return FALSE ; } if ( size != NEO_MAC_ADDRESS_SIZE ) { NdisCloseConfiguration ( config ) ; return FALSE ; } NeoCopy ( ctx -> MacAddress , buf , NEO_MAC_ADDRESS_SIZE ) ; if ( ctx -> MacAddress [ 0 ] == 0x00 && ctx -> MacAddress [ 1 ] == 0x00 && ctx -> MacAddress [ 2 ] == 0x01 && ctx -> MacAddress [ 3 ] == 0x00 && ctx -> MacAddress [ 4 ] == 0x00 && ctx -> MacAddress [ 5 ] == 0x01 ) { UINT ptr32 = ( UINT ) ( ( UINT64 ) ctx ) ; LARGE_INTEGER current_time ; UCHAR * current_time_bytes ; KeQuerySystemTime ( & current_time ) ; current_time_bytes = ( UCHAR * ) & current_time ; ctx -> MacAddress [ 0 ] = 0x00 ; ctx -> MacAddress [ 1 ] = 0xAD ; ctx -> MacAddress [ 2 ] = ( ( UCHAR * ) ( & ptr32 ) ) [ 0 ] ; ctx -> MacAddress [ 3 ] = ( ( UCHAR * ) ( & ptr32 ) ) [ 1 ] ; ctx -> MacAddress [ 4 ] = ( ( UCHAR * ) ( & ptr32 ) ) [ 2 ] ; ctx -> MacAddress [ 5 ] = ( ( UCHAR * ) ( & ptr32 ) ) [ 3 ] ; ctx -> MacAddress [ 2 ] ^= current_time_bytes [ 0 ] ; ctx -> MacAddress [ 3 ] ^= current_time_bytes [ 1 ] ; ctx -> MacAddress [ 4 ] ^= current_time_bytes [ 2 ] ; ctx -> MacAddress [ 5 ] ^= current_time_bytes [ 3 ] ; ctx -> MacAddress [ 2 ] ^= current_time_bytes [ 4 ] ; ctx -> MacAddress [ 3 ] ^= current_time_bytes [ 5 ] ; ctx -> MacAddress [ 4 ] ^= current_time_bytes [ 6 ] ; ctx -> MacAddress [ 5 ] ^= current_time_bytes [ 7 ] ; } name = NewUnicode ( " " ) ; NdisReadConfiguration ( & ret , & param , config , GetUnicode ( name ) , NdisParameterString ) ; FreeUnicode ( name ) ; if ( NG ( ret ) ) { NdisCloseConfiguration ( config ) ; return FALSE ; } if ( param -> ParameterType != NdisParameterString ) { NdisCloseConfiguration ( config ) ; return FALSE ; } unicode = & param -> ParameterData . StringData ; NeoZero ( & ansi , sizeof ( ANSI_STRING ) ) ; ansi . MaximumLength = MAX_SIZE - 1 ; ansi . Buffer = NeoZeroMalloc ( MAX_SIZE ) ; NdisUnicodeStringToAnsiString ( & ansi , unicode ) ; strcpy ( ctx -> HardwareID , ansi . Buffer ) ; strcpy ( ctx -> HardwareID_Raw , ctx -> HardwareID ) ; _strupr ( ctx -> HardwareID ) ; NeoFree ( ansi . Buffer ) ; name = NewUnicode ( " " ) ; NdisReadConfiguration ( & ret , & param , config , GetUnicode ( name ) , NdisParameterInteger ) ; FreeUnicode ( name ) ; if ( NG ( ret ) || param -> ParameterType != NdisParameterInteger ) { speed = NEO_MAX_SPEED_DEFAULT ; } else { speed = ( UINT64 ) param -> ParameterData . IntegerData * 1000000ULL ; } max_speed = speed ; name = NewUnicode ( " " ) ; NdisReadConfiguration ( & ret , & param , config , GetUnicode ( name ) , NdisParameterInteger ) ; FreeUnicode ( name ) ; if ( NG ( ret ) || param -> ParameterType != NdisParameterInteger ) { keep = false ; } else { keep = ( param -> ParameterData . IntegerData == 0 ? false : true ) ; } keep_link = keep ; name = NewUnicode ( " " ) ; NdisReadConfiguration ( & ret , & param , config , GetUnicode ( name ) , NdisParameterInteger ) ; FreeUnicode ( name ) ; if ( NG ( ret ) || param -> ParameterType != NdisParameterInteger ) { reg_if_type = IF_TYPE_ETHERNET_CSMACD ; } else { reg_if_type = param -> ParameterData . IntegerData ; } NdisCloseConfiguration ( config ) ; return TRUE ; }
Read the information from the registry
Read the information from the registry
// Get the Config handle
 // Failure
 // Read the MAC address
 // Failure
 // Copy the MAC address
 // Invalid size
 // Special MAC address
 // Initialize the key name of the device name
 // Read the hardware ID
 // Failure
 // Type checking
 // Failure
 // Prepare a buffer for ANSI string
 // Convert to ANSI string
 // Copy
 // Convert to upper case
 // Release the memory
 // Read the bit rate
 // Read the link keeping flag
 // Read the *IfType value
 // Close the config handle
