I actually need my driver to read (line by line) some programs that are going to be blacklisted.
_T("bannedfile.exe") is where I actually need to put the blacklisted program.
How can I make _tcscmp read a text file, line by line?
(It makes a comparison between the host program that loads the driver, and the blacklisted one)
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;
}
}
Can't be done that way.
You should be able to use use getline to read the file line by line and then pass the lines to _tcscmp. Should work something like this:
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
Lacking a copy of VS to test it at the moment.
If you run into unicode parsing problems because the file's encoding isn't quite what the defaults expect, give this a read: What is std::wifstream::getline doing to my wchar_t array? It's treated like a byte array after getline returns