📄 removent.c
字号:
HKEY hkey,
LPSTR szValue,
LPSTR szString)
{
BOOL bReturn = FALSE;
BYTE* pBuffer;
BYTE* pSrc;
BYTE* pDst;
DWORD dwSize;
DWORD dwType;
// get type and length of existing string
if (ERROR_SUCCESS == RegQueryValueEx (
hkey,
szValue,
NULL,
&dwType,
NULL,
&dwSize))
{
// verify type
if (dwType == REG_MULTI_SZ)
{
// allocate buffer
pBuffer = malloc (dwSize);
if (pBuffer)
{
// get existing data
RegQueryValueEx (
hkey,
szValue,
NULL,
&dwType,
pBuffer,
&dwSize);
// kill all instances of specified string
pSrc = pDst = pBuffer;
while (*pSrc)
{
if (!strstr (pSrc, szString))
{
dwSize = lstrlen (pSrc);
lstrcpy (pDst, pSrc);
pDst += lstrlen (pDst) +1;
pSrc += dwSize +1;
}
else
{
pSrc += lstrlen (pSrc) +1;
}
}
// add the final NULL
*pDst = '\0';
dwSize = pDst - pBuffer +1;
// write the new string back to the registry
if (ERROR_SUCCESS == RegSetValueEx (
hkey,
szValue,
0,
REG_MULTI_SZ,
pBuffer,
dwSize))
{
bReturn = TRUE;
}
free (pBuffer);
}
}
}
return bReturn;
}
BOOL AddInf ()
{
HKEY hMainKey = HKEY_LOCAL_MACHINE;
HKEY hOpenKey = NULL;
LPSTR KeyValue;
LPSTR szString;
UINT nBufferLengthMax = 1024;
if (RegOpenKeyEx(hMainKey, NCPA, 0, KEY_ALL_ACCESS, &hOpenKey)
== ERROR_SUCCESS)
{
KeyValue = malloc(15);
ZeroMemory (KeyValue, 15);
strcpy (KeyValue, "ReviewPrograms");
szString = malloc(nBufferLengthMax);
ZeroMemory (szString, nBufferLengthMax);
GetCurrentDirectory(nBufferLengthMax, szString);
strcat(szString, "\\PGPRebind.inf");
//Get the short path (no spaces)
GetShortPathName(szString, szString, nBufferLengthMax);
AddStringToMultiString (
hOpenKey,
KeyValue,
szString);
RegCloseKey (hOpenKey);
free(szString);
free(KeyValue);
}/*if*/
return TRUE;
}
BOOL RemoveInf ()
{
HKEY hMainKey = HKEY_LOCAL_MACHINE;
HKEY hOpenKey = NULL;
LPSTR KeyValue;
LPSTR szString;
UINT nBufferLengthMax = 1024;
if (RegOpenKeyEx(hMainKey, NCPA, 0, KEY_ALL_ACCESS, &hOpenKey)
== ERROR_SUCCESS)
{
KeyValue = malloc(15);
ZeroMemory (KeyValue, 15);
strcpy (KeyValue, "ReviewPrograms");
szString = malloc(10);
ZeroMemory (szString, 10);
strcpy (szString, "PGP");
DeleteStringFromMultiString(
hOpenKey,
KeyValue,
szString);
RegCloseKey (hOpenKey);
free(szString);
free(KeyValue);
}/*if*/
return TRUE;
}
//____________________________
//
// Disable all protocols that bind to us except
// the ones we use.
BOOL DisableExtraProtocols ()
{
//#define SERVICESSUBKEY "SYSTEM\\CurrentControlSet\\Services"
HKEY hMainKey = HKEY_LOCAL_MACHINE;
HKEY hOpenKey = NULL;
/*these are service keys we use PLUS all PGPmac.... keys*/
LPTSTR LinkedKeys[] = {"RasArp",
"NetBT",
"LanmanServer",
"LanmanWorkstation",
"RemoteAccess",
"NetBIOS",
"Tcpip"};
HKEY hNewKey = NULL;
HKEY hNewKeyb = NULL;
HKEY hLinkKey = NULL;
HKEY hDisableKey = NULL;
LPBYTE pData = NULL;
LPBYTE pOurBindStr = NULL;
LPTSTR pSubkeyBuffer = NULL;
LPTSTR KeyTitle = NULL;
LPTSTR CurrentKey = NULL;
LPTSTR DisableKey = NULL;
unsigned long nSubkeyNameLen;
unsigned long dwBufSize;
DWORD nSubkeys;
DWORD dwIndex;
DWORD dwIndexb;
DWORD dwSize;
DWORD dwType;
LONG lResult = ERROR_SUCCESS;
BOOL Pass;
BOOL bRC;
BOOL bregerr = FALSE;
BOOL ItemDisabled = FALSE;
/*get value like \Device\PGPMacMP4*/
if (RegOpenKeyEx(hMainKey, PATHTOPGPNETREGKEY, 0, KEY_ALL_ACCESS, &hOpenKey) == ERROR_SUCCESS)
{
if (RegQueryValueEx (hOpenKey, "BindString", NULL, &dwType, NULL, &dwSize)
== ERROR_SUCCESS)
{
pOurBindStr = (LPBYTE) calloc(sizeof(BYTE), dwSize);
ZeroMemory (pOurBindStr, dwSize);
if (RegQueryValueEx (hOpenKey, "BindString", NULL, &dwType, pOurBindStr, &dwSize)
== ERROR_SUCCESS)
goto success;
else
bregerr = TRUE;
}/*if*/
else
bregerr = TRUE;
success:
RegCloseKey(hOpenKey);
}/*if*/
else
bregerr = TRUE;
if (bregerr)
{
MessageBox (GetFocus(), ERR_READREG, "Set Adapter", 0 | MB_ICONERROR);
exit (1);
}
/*Open key*/
if (RegOpenKeyEx(hMainKey, SERVICESSUBKEY, 0, KEY_ALL_ACCESS, &hOpenKey) == ERROR_SUCCESS)
{
/*Determine number of keys to enumerate*/
RegQueryInfoKey(hOpenKey, NULL, NULL, NULL, &nSubkeys,
&nSubkeyNameLen, NULL, NULL, NULL,
NULL, NULL, NULL);
/*Retrieve Registry values*/
pSubkeyBuffer = malloc(nSubkeyNameLen + 1);
CurrentKey = malloc(1024);
DisableKey = malloc(1024);
for (dwIndex = 0; dwIndex < nSubkeys; dwIndex++)
{
dwBufSize = nSubkeyNameLen + 1;
lResult = RegEnumKeyEx(hOpenKey, dwIndex, pSubkeyBuffer, &dwBufSize,
NULL, NULL, NULL, NULL);
Pass = TRUE;
for (dwIndexb = 0; dwIndexb<=6; dwIndexb++)
{
/*check if key is one of the ones NOT to touch*/
if ((strcmp (pSubkeyBuffer, LinkedKeys[dwIndexb])==0) ||
(strstr(pSubkeyBuffer, "PGPMac") != NULL))
Pass = FALSE;
/*we now check if changes need to be made*/
}/*for*/
if (Pass)
{
ZeroMemory(CurrentKey, 1024);
ZeroMemory(DisableKey, 1024);
/*SERVICESSUBKEY contains the path to the top of the
services reg. key.
pSubkeyBuffer contains the name of the current key
to examine within the services tree.*/
strcpy(CurrentKey, SERVICESSUBKEY);
strcat(CurrentKey, "\\");
strcat(CurrentKey, pSubkeyBuffer);
strcat(CurrentKey, "\\Linkage");
strcpy(DisableKey, CurrentKey);
strcat(DisableKey, "\\Disabled");
if (lResult = RegOpenKeyEx(hMainKey, CurrentKey, 0, KEY_ALL_ACCESS,
&hLinkKey) == ERROR_SUCCESS)
{
if (RegQueryValueEx (hLinkKey, BIND, NULL, &dwType, NULL, &dwSize)
== ERROR_SUCCESS)
{
pData = (LPBYTE) calloc(sizeof(BYTE), dwSize);
ZeroMemory (pData, dwSize);
if (RegQueryValueEx (hLinkKey, BIND, NULL, &dwType, pData, &dwSize)
== ERROR_SUCCESS)
bRC = MultiStrStrCmp((char*)pData, (char*)pOurBindStr);
if(bRC)
{
/*Add pOurBindStr to Linkage\\Disable Bind value
of CurrentKey*/
if (lResult = RegOpenKeyEx(hMainKey, DisableKey, 0, KEY_ALL_ACCESS, &hDisableKey)
== ERROR_SUCCESS)
{
AddStringToMultiString (hDisableKey,
BIND,
pOurBindStr);
RegCloseKey (hDisableKey);
ItemDisabled = TRUE;
}/*if*/
}/*if*/
free(pData);
}/*if*/
RegCloseKey(hLinkKey);
}/*if*/
}/*if*/
}/*for*/
free(CurrentKey);
free(DisableKey);
free(pSubkeyBuffer);
free(pOurBindStr);
RegCloseKey(hOpenKey);
}/*if*/
return ItemDisabled;
}
//____________________________
//
// Find if stringb is in multistringa
//
BOOL MultiStrStrCmp (LPSTR multistringa, LPSTR stringb)
{
int strlength;
int count;
compare:
if (strstr(multistringa, stringb) == NULL)
{
strlength = strlen (multistringa);
for (count = 0; count <= strlength; count++)
*multistringa++;
if (*multistringa == '\0')
/*we are at the end of the multisting*/
return FALSE;
else
goto compare;
}
else
return TRUE;
}
/*if (iReturn == 0)
{
char szText[256];
wsprintf(szText, "Error code: %d", GetLastError());
MessageBox(NULL, szText, "Delete Service", MB_OK);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -