谁能帮我详细解释下以下代码!在线等,谢谢

2025-03-21 10:32:23
推荐回答(3个)
回答1:

DWORD CmdAddKey(CCmdParam *pCmdParam) {

// Just ignore empty key requests.
//忽略空的键值请求 (键值为空,返回))
if (pCmdParam->szParam1 == NULL) {
return 0;
}

//
// Filter the key using the same criteria as the the Password entry
// dialog. Remember about Unicode and Ansi...
//
//和密码输入对话框使用相同的原理来适配键值,要注意(Unicode与Ansi编码)
//这句话的目的是为了让程序可以同时处理Unicode 与Ansi(先转成TCHAR *,再到char *)
const char *pNxtInChar = axpl::t2s((TCHAR *)(pCmdParam->szParam1)).c_str();

// Ensure that szFilterKey is deallocated on exit of this function.
//在函数结束确定szFilterKey的空间被分配
//分配空间没的说,然后把在传进来的参数中出现的字符放到szFilterKey中
CPtrTo szFilterKey;
szFilterKey = new char[strlen(pNxtInChar) + 1];
ASSPTR(szFilterKey);

char *pNxtOutChar = szFilterKey;

while (*pNxtInChar) {
if (strchr((const char *)szPassphraseChars, *pNxtInChar) != NULL) {
*pNxtOutChar++ = *pNxtInChar;
}
pNxtInChar++;
}
*pNxtOutChar = '\0';

// We are responsible for ensuring the deletion of the returned key hash pointer
//把szFilterKey转化成Key hash,创建一个hash表,返回对应的指针utKey
CPtrTo utKey = CSha1().GetKeyHash((BYTE *)(char *)szFilterKey, strlen(szFilterKey));

if (pCmdParam->fIsEncKey) {
// AddEncKey checks with find key first...
//使用AddEncKey先检查需要查找的key
(void)pgKeyList->AddEncKey(utKey, pCmdParam->dwBatch);
} else {
// Check if we already know the key...
//检查是否pgKeyList中存在utKey(没看到pgKeyList定义)
if (!pgKeyList->FindKey(utKey, pCmdParam->dwBatch, FALSE)) {
// ...if not - add it to the list of known keys.
//没有的话把utKey添加到pgKeyList中作为已知Key
pgKeyList->AddKey(utKey, FALSE, pCmdParam->dwBatch);
}
}
return 0;
}

回答2:

程序里面有英文注释啊,这应该能帮到你
我把它们翻译成中文,你再对照着看看吧

DWORD CmdAddKey(CCmdParam *pCmdParam) {

// Just ignore empty key requests.
//仅仅忽略空键值的请求
if (pCmdParam->szParam1 == NULL) {
return 0;
}

//
// Filter the key using the same criteria as the the Password entry
// dialog. Remember about Unicode and Ansi...
//使用跟密码输入框一样的标准,去过滤键值。注意是Unicode和Ansi编码
TCHAR *,再到char *)
const char *pNxtInChar = axpl::t2s((TCHAR *)(pCmdParam->szParam1)).c_str();

// Ensure that szFilterKey is deallocated on exit of this function.
//在本函数结束时,确保szFilterKey的空间被释放
szFilterKey中
CPtrTo szFilterKey;
szFilterKey = new char[strlen(pNxtInChar) + 1];
ASSPTR(szFilterKey);

char *pNxtOutChar = szFilterKey;

while (*pNxtInChar) {
if (strchr((const char *)szPassphraseChars, *pNxtInChar) != NULL) {
*pNxtOutChar++ = *pNxtInChar;
}
pNxtInChar++;
}
*pNxtOutChar = '\0';

// We are responsible for ensuring the deletion of the returned key hash pointer
//我们负责确保对返回的键值hash指针的删除

CPtrTo utKey = CSha1().GetKeyHash((BYTE *)(char *)szFilterKey, strlen(szFilterKey));

if (pCmdParam->fIsEncKey) {
//AddEncKey checks with find key first...
//AddEncKey 先用找到的键值,进行检查
(void)pgKeyList->AddEncKey(utKey, pCmdParam->dwBatch);
} else {
// Check if we already know the key...
//检查是否我们已经知道了这个键值
if (!pgKeyList->FindKey(utKey, pCmdParam->dwBatch, FALSE)) {
// ...if not - add it to the list of known keys.
//没有的话,把它添加到已知键值的列表中
pgKeyList->AddKey(utKey, FALSE, pCmdParam->dwBatch);
}
}
return 0;
}

回答3:

程序的完整性不够撒````