从c++文本文件中读取黑名单

Reading blacklist from a text file in C++

本文关键字:读取 黑名单 文件 c++ 文本      更新时间:2023-10-16

我实际上需要我的驱动程序(逐行)读取一些将要被列入黑名单的程序。

_T("bannedfile.exe")是我实际需要放置黑名单程序的地方。

如何使_tcscmp逐行读取文本文件?

(它将加载驱动程序的主机程序与列入黑名单的程序进行比较)

BOOL ProcessBlackList() {
    TCHAR modulename[MAX_PATH];
    GetModuleFileName(NULL, modulename, MAX_PATH);
    PathStripPath(modulename);
    if (_tcscmp(modulename, _T("bannedfile.exe")) != 1) {
        return 0;
    }
    else {
        return 0x2; 
    }   
}

不能那样做。

您应该能够使用use getline来逐行读取文件,然后将这些行传递给_tcscmp。应该是这样的:

wchar_t const name[] = L"bannedfile.exe";
std::wifstream file(name);
std::wstring line;
while (std::getline(file, line)
{
    if (_tcscmp(modulename, line.c_str()) == 0) {
        return TRUE; //module is in list
    }
}
return FALSE; // module is not in list

目前缺少VS的副本来测试。

如果你遇到unicode解析问题,因为文件的编码不完全是默认的期望,给这个读:std::wifstream::getline对我的wchar_t数组做了什么?在getline返回

之后,它'