1
0
Fork 0

DBG: renamed filereader to filehelper

This commit is contained in:
Mr. eXoDia 2015-08-16 00:38:14 +02:00
parent d0ed3a7c96
commit e5c18df86f
4 changed files with 34 additions and 24 deletions

View File

@ -0,0 +1,29 @@
#include "filehelper.h"
bool FileHelper::ReadAllText(const String & fileName, String & content)
{
Handle hFile = CreateFileW(StringUtils::Utf8ToUtf16(fileName).c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
if(hFile == INVALID_HANDLE_VALUE)
return false;
unsigned int filesize = GetFileSize(hFile, 0);
if(!filesize)
{
content.clear();
return true;
}
Memory<char*> filedata(filesize + 1, "FileReader::ReadAllText:filedata");
DWORD read = 0;
if(!ReadFile(hFile, filedata(), filesize, &read, 0))
return false;
content = String(filedata());
return true;
}
bool FileHelper::WriteAllText(const String & fileName, const String & content)
{
Handle hFile = CreateFileW(StringUtils::Utf8ToUtf16(fileName).c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, nullptr);
if(hFile == INVALID_HANDLE_VALUE)
return false;
DWORD written = 0;
return !!WriteFile(hFile, content.c_str(), content.length(), &written, nullptr);
}

View File

@ -3,10 +3,11 @@
#include "_global.h"
class FileReader
class FileHelper
{
public:
static bool ReadAllText(const String & fileName, String & content);
static bool WriteAllText(const String & fileName, const String & content);
};
#endif //_FILEREADER_H

View File

@ -1,20 +0,0 @@
#include "filereader.h"
bool FileReader::ReadAllText(const String & fileName, String & content)
{
Handle hFile = CreateFileW(StringUtils::Utf8ToUtf16(fileName).c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
if(hFile == INVALID_HANDLE_VALUE)
return false;
unsigned int filesize = GetFileSize(hFile, 0);
if(!filesize)
{
content.clear();
return true;
}
Memory<char*> filedata(filesize + 1, "FileReader::ReadAllText:filedata");
DWORD read = 0;
if(!ReadFile(hFile, filedata(), filesize, &read, 0))
return false;
content = String(filedata());
return true;
}

View File

@ -25,7 +25,7 @@
#include "patternfind.h"
#include "module.h"
#include "stringformat.h"
#include "filereader.h"
#include "filehelper.h"
#include "linearanalysis.h"
#include "controlflowanalysis.h"
#include "analysis_nukem.h"
@ -1756,7 +1756,7 @@ CMDRESULT cbInstrYara(int argc, char* argv[])
}
String rulesContent;
if(!FileReader::ReadAllText(argv[1], rulesContent))
if(!FileHelper::ReadAllText(argv[1], rulesContent))
{
dprintf("Failed to read the rules file \"%s\"\n", argv[1]);
return STATUS_ERROR;
@ -1971,7 +1971,7 @@ CMDRESULT cbInstrCfanalyse(int argc, char* argv[])
uint base = MemFindBaseAddr(sel.start, &size);
ControlFlowAnalysis anal(base, size, exceptionDirectory);
anal.Analyse();
//anal.SetMarkers();
anal.SetMarkers();
GuiUpdateAllViews();
return STATUS_CONTINUE;
}