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

📄 lister.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 3 页
字号:
					/*cleanup*/
					if(hPGPnetkey)
						RegCloseKey(hPGPnetkey);
					if(hNewKeyb)
						RegCloseKey(hNewKeyb);
					if(pData)
						free (pData);
				}/*if*/
				
			}/*while*/
			RegCloseKey(state.hKey);
		}/*if*/
		FreeRegSearchState(&state);
	}/*else*/
	
	//if only 1 adapter select it by default
	if (nCount == 1)
	{
		//there is only 1 adapter bound to TCP/IP
		ListView_SetItemState(hListControl, 0, LVIS_SELECTED, LVIS_SELECTED);
		hOkButton = GetDlgItem(hwndDlg, IDB_PGPNETOK);
		Button_Enable(hOkButton, TRUE);
		
		//if this is a silent install and we just press OK
		if (bSilentInstall)
			PostMessage(hwndDlg, WM_COMMAND, 1004, 0);
	}/*if*/
	return TRUE;
}/*end*/


/*
 * ListerOnCommand [WM_COMMAND]
 */
BOOL Lister_OnCommand(HWND hwndDlg, int id, HWND hwndCommand, UINT Event)
{
	HKEY			hkey			= NULL;
	HKEY			hMainKey		= HKEY_LOCAL_MACHINE;
	HKEY			hOpenKey		= NULL;
	DWORD			dwDisposition;
	int				cchTextMax		= 1024;
	HWND			hListControl	= NULL;
	BOOL			brc				= TRUE;
	LPTSTR			lpBuffer		= NULL;
	LPTSTR 			pszText			= NULL;
	char  			*RealMac		= NULL;
	int				Response;
	int				Count;
	char*			Path;
	
	
	switch (id)
    {
		case IDB_HELP:
			ShowWindow(hwndDlg, SW_HIDE);
			DialogBox(g_hInstance, MAKEINTRESOURCE (IDD_HELPDIALOG), hwndDlg, (DLGPROC) HelpDlgProc);
 			ShowWindow(hwndDlg, SW_SHOW);
			return TRUE;

		case IDB_PGPNETOK:

			hListControl = GetDlgItem(hwndDlg, IDC_ADAPTERLIST);

			if (bIsNT)
			{
				//delete PGPnetNTSafeToRebind entry
				if (RegOpenKeyEx(hMainKey, PATHTOPGPNETREGKEY, 0, KEY_ALL_ACCESS, &hOpenKey)
					== ERROR_SUCCESS)	
				{
					RegDeleteValue(hOpenKey, "PGPnetNTSafeToRebind");
					RegCloseKey (hOpenKey);
				}/*if*/

				//delete Run entry
				if (RegOpenKeyEx(hMainKey, RUNKEY, 0, KEY_ALL_ACCESS, &hOpenKey)
					== ERROR_SUCCESS)	
				{
					RegDeleteValue(hOpenKey, "ZZRunSetAdapter");
					RegCloseKey (hOpenKey);
				}/*if*/

				//Set Runonce entry
				if (RegOpenKeyEx(hMainKey, RUNONCE, 0, KEY_ALL_ACCESS, &hOpenKey)
					== ERROR_SUCCESS)	
				{
					Path = SetExePath();
					strcat(Path, "\\setadapter.exe void");
					GetShortPathName(Path, Path, strlen(Path) + 1);

					RegSetValueEx(hOpenKey, "PGPnetNeedsReboot" , 0, REG_SZ, Path, strlen(Path)+1);
					RegCloseKey (hOpenKey);
					free(Path);
				}/*if*/

				RemoveInf();
				/*We are running NT*/
				SetbWan (hListControl);
				if (SetSelectedItems (hListControl, FALSE))
				{	
					SetCursor(LoadCursor(NULL, IDC_WAIT));
					ShowWindow(hwndDlg, SW_HIDE);
					if (InstallInfFile(hwndDlg))
					{	
						brc = SetSelectedItems (hListControl, TRUE);
						brc = BindReview (hwndDlg);
					}/*if*/
					if(DisableExtraProtocols())
						brc = BindReview (hwndDlg);
					if (bSansCmdLine) 
					{
						RebootYesNo();
					}/*if*/
					SetCursor(LoadCursor(NULL, IDC_ARROW));

					/*If this is not WAN, Set DependOnServiceValue*/
					if(!bWan)
					{
						if (RegOpenKeyEx(hMainKey, PGPMACMPKEY, 0, KEY_ALL_ACCESS, &hOpenKey)
							== ERROR_SUCCESS)
						{
							/*this is REG_MULTI_SZ add the final null*/
							Count = strlen (lpbActualServiceName);
							lpbActualServiceName[Count] = '\0';
							lpbActualServiceName[Count+1] = '\0';

							Count = strlen(lpbActualServiceName) + 2;

							if(lpbActualServiceName)
								RegSetValueEx(hOpenKey, "DependOnService" , 0, REG_MULTI_SZ, lpbActualServiceName,
												Count);
							RegCloseKey (hOpenKey);
							if(lpbActualServiceName)
								free(lpbActualServiceName);
						}/*if*/
					}/*if*/
					brc = SendMessage(hwndDlg, WM_QUIT, (WPARAM)NULL,(LPARAM)NULL);
					AddInf();				
					return TRUE;
				}/*if*/
			}/*if*/
			else
			{
				SetCursor(LoadCursor(NULL, IDC_WAIT));
				/*We are running 95/98*/
				Remove95(CLASSNETTRANS, 0);
				Remove95(ROOTNET, 1);
				Remove95(CLASSNET, 0);
				SetSelectedItems95(hListControl, &RealMac);
				//configure the driver
				ConfigSystemNetTrans();
				ConfigSystemNet();
				ConfigEnumNet();
				ConfigEnumNetwork();
				SetRealMac(RealMac);
				free (RealMac);
				Sleep (1500);
				SetCursor(LoadCursor(NULL, IDC_ARROW));
				ShowWindow(hwndDlg, SW_HIDE);
				SetbWan(NULL);
				if (bSansCmdLine) 
				{
					RebootYesNo();
				}/*if*/				
				brc = SendMessage(hwndDlg, WM_QUIT, (WPARAM)NULL,(LPARAM)NULL);
			}/*else*/

			return TRUE;

		case IDB_PGPNETCANCEL:
			/*if this was ran without command line, it is ok to*/
			/*just quit.*/
			if (bSansCmdLine) 
			{
				SendMessage(hwndDlg, WM_QUIT, (WPARAM)NULL,(LPARAM)NULL);
				return TRUE;
			}/*if*/

			Response = MessageBox (GetFocus(), CONFIRM, "PGPnet",MB_YESNO | MB_ICONQUESTION);
			switch (Response)
			{
			case IDYES:
				MessageBox (GetFocus(), PGPNETCANCELED, "PGPnet", 0 | MB_ICONINFORMATION);

				/*Write the PGPnetCancelled entry*/
				RegCreateKeyEx(HKEY_LOCAL_MACHINE, PATHTOPGPNETREGKEY,
							0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey,
							&dwDisposition);
				RegSetValueEx(hkey, "PGPnetCancelled", 0, REG_SZ, "UserCancelled",
							14);
				RegCloseKey(hkey);
				SendMessage(hwndDlg, WM_QUIT, (WPARAM)NULL,(LPARAM)NULL);
			case IDNO:
				return FALSE;
			}/*switch*/

			return TRUE;

		default:
			return FALSE;
    }/*switch*/
	return TRUE;
}/*end*/


/*
 * 	CreateImageList 
 */
BOOL CreateImageList ()
{
	HBITMAP			hBmp	= NULL;
	HWND			hHelpButton = NULL;
	int				iNumBits= 0;
	HDC				hDC     = NULL;

	hDC = GetDC (NULL);		/*DC for desktop*/
	iNumBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
	ReleaseDC (NULL, hDC);

	/*Check the resolution we are running at*/
	if (iNumBits <= 8) 
	{
		/*Low Res*/
		g_hImages = ImageList_Create (16, 16, ILC_COLOR | ILC_MASK, 
					NUM_BITMAPS, 0); 
		hBmp      = LoadBitmap (g_hInstance, MAKEINTRESOURCE (IDB_IMAGES4BIT));
		ImageList_AddMasked (g_hImages, hBmp, RGB(255, 0, 255));
		DeleteObject (hBmp);
		return TRUE;

	}/*if*/
	else 
	{
		/*High res.*/
		g_hImages = ImageList_Create (16, 16, ILC_COLOR24 | ILC_MASK, 
					NUM_BITMAPS, 0); 
		hBmp      = LoadBitmap (g_hInstance, MAKEINTRESOURCE (IDB_IMAGES24BIT));
		ImageList_AddMasked (g_hImages, hBmp, RGB(255, 0, 255));
		DeleteObject (hBmp);
		return TRUE;
	}/*else*/

	return FALSE;	
}/*end*/


/*
 * 	GetRealNameFromServiceName
 */
LPTSTR ResolveRealName(LPTSTR ServiceName)
{
	HKEY			hMainKey		= HKEY_LOCAL_MACHINE;
	HKEY			hNewKey			= NULL;
	HKEY			hNewKeyb		= NULL;
	LPBYTE			pData			= NULL;
	LPTSTR 			pSubkeyBuffer	= NULL;	
	LPTSTR			KeyTitle        = NULL;
	unsigned long	nSubkeyNameLen;
	unsigned long   MaxValueNameLen;
	unsigned long   MaxDataNameLen;
	unsigned long	dwBufSize;
	DWORD			nSubkeys;
	DWORD			dwIndex;
	DWORD			dwSize;
	DWORD			dwType;
	LONG			lResult			= ERROR_SUCCESS;
	char			*RegKeyBuffer = NULL;

	/*Open key*/
   	if (RegOpenKey(hMainKey, NETWORKCARDS_KEY, &hNewKey) == ERROR_SUCCESS)
	{
		/*Determine number of keys to enumerate*/
		RegQueryInfoKey(hNewKey, NULL, NULL, NULL, &nSubkeys, 
						&nSubkeyNameLen, NULL, NULL, NULL,
						NULL, NULL, NULL);

		/*Retrieve Registry values*/
		pSubkeyBuffer = malloc(nSubkeyNameLen + 1);

		RegKeyBuffer = (char *)malloc(strlen(NETWORKCARDS_KEY) + 4);

		for (dwIndex = 0; dwIndex < nSubkeys; dwIndex++)
		{
			dwBufSize = nSubkeyNameLen + 1;
			lResult = RegEnumKeyEx(hNewKey, dwIndex, pSubkeyBuffer, &dwBufSize, 
							       NULL, NULL, NULL, NULL);
			strcpy(RegKeyBuffer, NETWORKCARDS_KEY);
			strcat(RegKeyBuffer, "\\");
			strcat(RegKeyBuffer, pSubkeyBuffer);

			/*Try to open the key*/
			if (RegOpenKey(hMainKey, RegKeyBuffer, &hNewKeyb) == ERROR_SUCCESS)
			{
				/*Query NETWORKCARDS_KEYVALUE*/
				RegQueryInfoKey(hNewKeyb, NULL, NULL, NULL, NULL, 
							    NULL, NULL, NULL, &MaxValueNameLen,
							    &MaxDataNameLen, NULL, NULL);
				pData = (LPBYTE) calloc(sizeof(BYTE), MaxDataNameLen + 1);
				dwSize = MaxDataNameLen;
				lResult = RegQueryValueEx(hNewKeyb, NETWORKCARDS_KEYVALUE, 0,
										  &dwType, pData, &dwSize);
				/*Check if this is the key we are looking for*/
				if (strcmp(ServiceName, pData) == 0)
				{ 
					free(pData);
					pData  = (LPBYTE) calloc(sizeof(BYTE), MaxDataNameLen);
					dwSize = MaxDataNameLen;
					lResult= RegQueryValueEx(hNewKeyb, NETWORKCARDTITLE, 0,
											  NULL, pData, &dwSize);
					if (lResult != ERROR_SUCCESS)
					{
						MessageBox (GetFocus(), ERR_READREG, "", 0 | MB_ICONERROR);
						RegCloseKey(hNewKeyb);
						free(pData);
						free (RegKeyBuffer);
						free(pSubkeyBuffer);
						RegCloseKey(hNewKey);
						return FALSE;
					}/*if*/
					RegCloseKey(hNewKeyb);
					free (RegKeyBuffer);
					free(pSubkeyBuffer);
					RegCloseKey(hNewKey);/*NETWORKCARDS_KEY*/
					return pData;
				}/*if*/
				free(pData);
				RegCloseKey(hNewKeyb);
			}/*if*/
		}/*for*/
		RegCloseKey(hNewKey);/*NETWORKCARDS_KEY*/
	}/*if*/
	free (RegKeyBuffer);
	free(pSubkeyBuffer);
	return FALSE;
}/*end*/


/*
 * 	GetServiceNameFromRealName
 */
LPTSTR ResolveServiceName(LPTSTR RealName)
{
	HKEY			hMainKey		= HKEY_LOCAL_MACHINE;
	HKEY			hNewKey			= NULL;
	HKEY			hNewKeyb		= NULL;
	LPBYTE			pData			= NULL;
	LPTSTR 			pSubkeyBuffer	= NULL;	
	LPTSTR			KeyTitle        = NULL;
	unsigned long	nSubkeyNameLen;
	unsigned long   MaxValueNameLen;
	unsigned long   MaxDataNameLen;
	unsigned long	dwBufSize;
	DWORD			nSubkeys;
	DWORD			dwIndex;
	DWORD			dwSize;
	DWORD			dwType;
	LONG			lResult			= ERROR_SUCCESS;
	char      		RegKeyBuffer[sizeof(NETWORKCARDS_KEY) + 3];


	/*Open key*/
   	if (RegOpenKey(hMainKey, NETWORKCARDS_KEY, &hNewKey) == ERROR_SUCCESS)
	{
		/*Determine number of keys to enumerate*/
		RegQueryInfoKey(hNewKey, NULL, NULL, NULL, &nSubkeys, 
						&nSubkeyNameLen, NULL, NULL, NULL,
						NULL, NULL, NULL);

		/*Retrieve Registry values*/
		pSubkeyBuffer = malloc(nSubkeyNameLen + 1);
		for (dwIndex = 0; dwIndex < nSubkeys; dwIndex++)
		{
			dwBufSize = nSubkeyNameLen;
			lResult = RegEnumKeyEx(hNewKey, dwIndex, pSubkeyBuffer, &dwBufSize, 
							       NULL, NULL, NULL, NULL);
			strcpy(RegKeyBuffer, NETWORKCARDS_KEY);
			strcat(RegKeyBuffer, "\\");
			strcat(RegKeyBuffer, pSubkeyBuffer);

			/*Try to open the key*/
			if (RegOpenKey(hMainKey, RegKeyBuffer, &hNewKeyb) == ERROR_SUCCESS)
			{
				/*Query NETWORKCARDS_KEYVALUE*/
				RegQueryInfoKey(hNewKeyb, NULL, NULL, NULL, NULL, 
							    NULL, NULL, NULL, &MaxValueNameLen,
							    &MaxDataNameLen, NULL, NULL);

				pData = (LPBYTE) calloc(sizeof(BYTE), MaxDataNameLen + 1);
			
				dwSize = MaxDataNameLen + 1;
				lResult = RegQueryValueEx(hNewKeyb, NETWORKCARDTITLE, 0,
										  &dwType, pData, &dwSize);
				/*Check if this is the key we are looking for*/
				if (strcmp(RealName, pData) == 0)
				{ 
					free(pData);
					pData  = (LPBYTE) calloc(sizeof(BYTE), MaxDataNameLen + 1);

					/*Get actual service name, this is used to set Depend
					  on service value to control load order*/
					if(!bWan)
					{
						lpbActualServiceName = (LPBYTE) calloc(sizeof(BYTE), MaxDataNameLen + 2);
						dwSize = MaxDataNameLen + 2;
						lResult= RegQueryValueEx(hNewKeyb, REALSERVICENAMEKEY, 0,
											  NULL, lpbActualServiceName, &dwSize);
					}/*if*/
					
					dwSize = MaxDataNameLen + 1;
					/*get the instance name ie: PGPMacMP#*/
					lResult= RegQueryValueEx(hNewKeyb, NETWORKCARDS_KEYVALUE, 0,
											  NULL, pData, &dwSize);
					if (lResult != ERROR_SUCCESS)
					{
						MessageBox (GetFocus(), ERR_READREG, "", 0 | MB_ICONERROR);
						RegCloseKey(hNewKeyb);
						free(pData);
						free(pSubkeyBuffer);
						RegCloseKey(hNewKey);
						return FALSE;
					}/*if*/
					RegCloseKey(hNewKeyb);
					free(pSubkeyBuffer);
					RegCloseKey(hNewKey);/*NETWORKCARDS_KEY*/
					return pData;
				}/*if*/
				free(pData);
				RegCloseKey(hNewKeyb);
			}/*if*/
		}/*for*/
		RegCloseKey(hNewKey);/*NETWORKCARDS_KEY*/
	}/*if*/
	return FALSE;
}/*end*/


/*
 * 	GetTxtAfterLastSlash
 */
LPTSTR GetTxtAfterLastSlash(LPTSTR Text)
{
	int		i				= 0;
	LPSTR	pszText			= NULL;
	
	while (*Text != '\0')
	{
		*Text ++;
	}/*while*/

	/* *ServiceName is now at the end of the string*/
	while (*Text != '\\')
	{
		*Text --;
	}/*while*/

	*Text ++;/*We do not want the '/'*/
	i = strlen(Text);
	pszText = malloc (i + 1);
	strcpy(pszText,Text);
	return pszText;
}/*end*/	


/*
 * 	GetTxtAfterFirstSlash
 */
LPTSTR GetTxtAfterFirstSlash(LPTSTR Text)
{
	int		i				= 0;
	LPSTR	pszText			= NULL;
	
	while (*Text != '\\')
	{
		*Text ++;
	}/*while*/

	*Text ++;/*We do not want the '/'*/
	i = strlen(Text);
	pszText = malloc (i + 1);
	strcpy(pszText,Text);
	return pszText;
}/*end*/


/*
 * 	SetSelectedItems
 */
BOOL SetSelectedItems(HWND hwnd, BOOL SetBindings)
{
	HKEY	hkey;
	DWORD	dwDisposition;
	UINT	NumberOfItems;
	int		Flag;
	DWORD	dwIndex			= 0;
	int     cchTextMax		= 1024;
	LPSTR	pszText			= NULL;
	LPSTR	pszServiceName	= NULL;

	NumberOfItems = ListView_GetSelectedCount(hwnd);

	if (NumberOfItems == 0)
		return FALSE;
	
	NumberOfItems = ListView_GetItemCount(hwnd);

	pszText		= malloc(cchTextMax);

	for (dwIndex = 0; dwIndex < NumberOfItems; dwIndex++)
	{
		ListView_GetItemText(hwnd, dwIndex, 0, pszText, cchTextMax);
		Flag = ListView_GetItemState(hwnd, dwIndex, LVNI_SELECTED);		

		if (Flag == 2)
		{
			if(SetBindings)
			{
				pszServiceName = ResolveServiceName(pszText);
				
				/*Write the FullSecuredCard reg entry*/
				RegCreateKeyEx(HKEY_LOCAL_MACHINE, PATHTOPGPNETREGKEY,
							0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey,
							&dwDisposition);
				RegSetValueEx(hkey, "FullSecuredCard", 0, REG_SZ, pszText,
							strlen(pszText) + 1);
				RegCloseKey(hkey);
				/*Write the SecuredCard reg entry*/
				RegCreateKeyEx(HKEY_LOCAL_MACHINE, PATHTOPGPNETREGKEY,
							0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey,
							&dwDisposition);
				RegSetValueEx(hkey, "SecuredCard", 0, REG_SZ, pszServiceName,
							strlen(pszServiceName) + 1);
				RegCloseKey(hkey);
				free(pszServiceName);
			}/*if*/
		}/*if*/
	}/*for*/
	free (pszText);
	return TRUE;
}/*end*/


/*
 * 	SetSelectedItems95
 */
BOOL SetSelectedItems95(HWND hwnd, LPSTR *RealMac)
{
	HKEY	hkey;
	DWORD	dwDisposition;
	UINT	NumberOfItems;
	int		Flag;
	DWORD	dwIndex			= 0;
	int     cchTextMax		= 1024;
	LPSTR	pszText			= NULL;
	LPSTR	pszServiceName	= NULL;

	NumberOfItems = ListView_GetSelectedCount(hwnd);

	if (NumberOfItems == 0)
		return FALSE;
	
	NumberOfItems = ListView_GetItemCount(hwnd);

	pszText		= malloc(cchTextMax);

	for (dwIndex = 0; dwIndex < NumberOfItems; dwIndex++)
	{
		ListView_GetItemText(hwnd, dwIndex, 0, pszText, cchTextMax);
		Flag = ListView_GetItemState(hwnd, dwIndex, LVNI_SELECTED);		

		if (Flag == 2)
		{
			/*Write the FullSecuredCard reg entry*/
			RegCreateKeyEx(HKEY_LOCAL_MACHINE, PATHTOADAPTERLIST,
						0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey,
						&dwDisposition);
			RegSetValueEx(hkey, "FullSecuredCard", 0, REG_SZ, pszText,
					strlen(pszText) + 1);
			RegCloseKey(hkey);
			*RealMac = (char *) malloc (strlen(pszText) + 1);
			ZeroMemory(*RealMac, (strlen(pszText) + 1));
			strcpy(*RealMac, pszText);
		}/*if*/
	}/*for*/
	free (pszText);

⌨️ 快捷键说明

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