⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registry.cpp

📁 VC实现的系统HOOK,可以对系统的中断情况查询。
💻 CPP
字号:
/*
InterruptHook
Copyright (C) 2003  Alexander M.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "stdafx.h"
#include "registry.h"

void EvaluateResourceList( PCM_RESOURCE_LIST pData, PDEVICE pDev );

BOOL	IsNt()
{
	OSVERSIONINFO	ovi;

	ovi.dwOSVersionInfoSize = sizeof(ovi);
	GetVersionEx( &ovi );
	if( ovi.dwMajorVersion == 4 && ovi.dwMinorVersion == 0 )
		return TRUE;
	else
		return FALSE;
}

BOOL QueryDeviceListForIrq( UINT iIrq, list< PDEVICE > &DeviceList )
{
	LONG		iRet;
	HKEY		hEnum, hTopic, hPnp, hId, hConfig;
	char		szTopicKeys[128], szPnpKeys[128], szIdKeys[128];
	char		acData[512];
	char		szDesc[128];
	DWORD		iDescLen = sizeof(szDesc);
	DWORD		iDescType = REG_SZ;
	DWORD		iTopicKeysLen = sizeof(szTopicKeys), 
				iPnpKeysLen = sizeof(szPnpKeys), 
				iIdKeysLen = sizeof(szIdKeys);
	DWORD		iDataLen = sizeof(acData);
	DWORD		iType = REG_RESOURCE_LIST;
	DWORD		iTopicIndex = 0, iPnpIndex = 0, iIdKeyIndex = 0;
	FILETIME	ft;

	PDEVICE		pDev;

	PCM_RESOURCE_LIST	rl;

	iRet = RegOpenKeyEx( 
		HKEY_LOCAL_MACHINE, 
		"SYSTEM\\CurrentControlSet\\Enum", 
		0, 
		KEY_ENUMERATE_SUB_KEYS, 
		&hEnum );

	for( iTopicIndex = 0; ; iTopicIndex++, iTopicKeysLen = sizeof(szTopicKeys) )
	{
		iRet = RegEnumKeyEx( 
			hEnum, 
			iTopicIndex, 
			szTopicKeys, 
			&iTopicKeysLen, 
			NULL, 
			NULL, 
			NULL, 
			&ft );

		if( iRet != ERROR_SUCCESS && iRet != ERROR_MORE_DATA )
			break;

		if( !strcmp( szTopicKeys, "Root" ) )
			continue;

		iRet = RegOpenKeyEx( 
			hEnum, 
			szTopicKeys, 
			0, 
			KEY_ENUMERATE_SUB_KEYS, 
			&hTopic );

		if( iRet != ERROR_SUCCESS )
			continue;

		for( iPnpIndex = 0; ; iPnpIndex++, iPnpKeysLen = sizeof(szPnpKeys) )
		{
			iRet = RegEnumKeyEx( 
				hTopic, 
				iPnpIndex, 
				szPnpKeys, 
				&iPnpKeysLen, 
				NULL, 
				NULL, 
				NULL, 
				&ft );

			if( iRet != ERROR_SUCCESS && iRet != ERROR_MORE_DATA )
				break;

			iRet = RegOpenKeyEx( 
				hTopic, 
				szPnpKeys, 
				0, 
				KEY_ENUMERATE_SUB_KEYS, 
				&hPnp );

			if( iRet != ERROR_SUCCESS )
				continue;

			for( iIdKeyIndex = 0; ; iIdKeyIndex++, 
				iIdKeysLen = sizeof(szIdKeys), 
				iDataLen = sizeof(acData), 
				iDescLen = sizeof(szDesc) )
			{
				iRet = RegEnumKeyEx( 
					hPnp, 
					iIdKeyIndex, 
					szIdKeys, 
					&iIdKeysLen, 
					NULL, 
					NULL, 
					NULL, 
					&ft );

				if( iRet != ERROR_SUCCESS && iRet != ERROR_MORE_DATA )
					break;

				iRet = RegOpenKeyEx( 
					hPnp, 
					szIdKeys, 
					0, 
					KEY_ENUMERATE_SUB_KEYS | KEY_READ, 
					&hId );

				if( iRet != ERROR_SUCCESS )
					continue;

				iRet = RegQueryValueEx( 
					hId, 
					"DeviceDesc", 
					NULL, 
					&iDescType, 
					(BYTE *)szDesc, 
					&iDescLen );

				if( IsNt() )
				{
					iRet = RegOpenKeyEx( 
						hId, 
						"LogConf", 
						0, 
						KEY_READ, 
						&hConfig );

					if( iRet != ERROR_SUCCESS )
					{
						RegCloseKey( hId );
						continue;
					}

					iRet = RegQueryValueEx( 
						hConfig, 
						"BootConfig", 
						NULL, 
						&iType, 
						(BYTE *)&acData, 
						&iDataLen );

					if( iRet != ERROR_SUCCESS )
					{
						RegCloseKey( hConfig );
						RegCloseKey( hId );
						continue;
					}
				}
				else
				{
					iRet = RegOpenKeyEx( 
						hId, 
						"Control", 
						0, 
						KEY_READ, 
						&hConfig );

					iRet = RegQueryValueEx( 
						hConfig, 
						"AllocConfig", 
						NULL, 
						&iType, 
						(BYTE *)&acData, 
						&iDataLen );

					if( iRet != ERROR_SUCCESS && iRet != ERROR_FILE_NOT_FOUND )
					{
						RegCloseKey( hConfig );
						RegCloseKey( hId );
						continue;
					}
					else if( iRet == ERROR_FILE_NOT_FOUND )
					{
						/* try nt4.0 way */
						RegCloseKey( hConfig );

						iRet = RegOpenKeyEx( 
							hId, 
							"LogConf", 
							0, 
							KEY_READ, 
							&hConfig );

						if( iRet != ERROR_SUCCESS )
						{
							RegCloseKey( hId );
							continue;
						}

						iRet = RegQueryValueEx( 
							hConfig, 
							"BootConfig", 
							NULL, 
							&iType, 
							(BYTE *)&acData, 
							&iDataLen );
						if( iRet != ERROR_SUCCESS )
						{
							RegCloseKey( hConfig );
							RegCloseKey( hId );
							continue;
						}
					}
				}

				if( iRet == ERROR_SUCCESS )
				{
					DWORD i, e;

					rl = (PCM_RESOURCE_LIST)&acData;
					
					for( i = 0; i < rl->Count; i++ )
					{
						for( e = 0; e < rl->List[i].PartialResourceList.Count; e++ )
						{
							if( rl->List[i].PartialResourceList.PartialDescriptors[e].Type == CmResourceTypeInterrupt &&
								rl->List[i].PartialResourceList.PartialDescriptors[e].u.Interrupt.Level == iIrq )
							{
								pDev = new DEVICE;
								EvaluateResourceList( (PCM_RESOURCE_LIST)&acData, pDev );
								
								pDev->pszDesc = strdup( szDesc );
								DeviceList.push_back( pDev );
							}
						}
					}
				}

				RegCloseKey( hConfig );
				RegCloseKey( hId );
			}
		
			RegCloseKey( hPnp );
		}

		RegCloseKey( hTopic );
	}

	RegCloseKey( hEnum );

	return TRUE;
}

void EvaluateResourceList( PCM_RESOURCE_LIST pData, PDEVICE pDev )
{
	UINT		e, i;
	PMEMORY		pMem;
	PPORT		pPort;

	for( e = 0; e < pData->Count; e++ )
	{
		for( i = 0; i < pData->List[e].PartialResourceList.Count; i++ )
		{
			switch( pData->List[e].PartialResourceList.PartialDescriptors[i].Type )
			{
				case CmResourceTypePort:
					pPort = (PPORT)malloc( sizeof(PORT) );
					pPort->iPort = pData->List[e].PartialResourceList.PartialDescriptors[i].u.Port.Start;
					pPort->iLen = pData->List[e].PartialResourceList.PartialDescriptors[i].u.Port.Length;
					pDev->IoList.push_back( pPort );
					break;

				case CmResourceTypeInterrupt:
					pDev->IrqList.push_back( pData->List[e].PartialResourceList.PartialDescriptors[i].u.Interrupt.Level );
					break;

				case CmResourceTypeMemory:
					pMem = (PMEMORY)malloc( sizeof(MEMORY) );
					pMem->iAddr = pData->List[e].PartialResourceList.PartialDescriptors[i].u.Memory.Start;
					pMem->iLen = pData->List[e].PartialResourceList.PartialDescriptors[i].u.Memory.Length;
					pDev->MemoryList.push_back( pMem );
					break;

				default:
					break;
			}
		}
	}
}

void CleanupDeviceList( list< PDEVICE > &DeviceList )
{
	list< PDEVICE >::iterator itdev;
	list< PMEMORY >::iterator itmem;
	list< PPORT >::iterator itport;
	PDEVICE	pDev;

	int i = DeviceList.size();

	for( itdev = DeviceList.begin(); itdev != DeviceList.end(); itdev++ )
	{
		pDev = *itdev;
		free( pDev->pszDesc );
		
		for( itmem = pDev->MemoryList.begin(); itmem != pDev->MemoryList.end(); itmem++ )
			free( *itmem );

		for( itport = pDev->IoList.begin(); itport != pDev->IoList.end(); itport++ )
			free( *itport );

		pDev->IrqList.clear();
		pDev->IoList.clear();
		pDev->MemoryList.clear();

		delete pDev;
	}

	DeviceList.clear();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -