- regfileparser_source_no_boost.zip
- RegFileParser_source_no_boost
- src
- RegFileParser.sln
- RegFileParserAutoTest
- main.cpp
- RegFileParserAutoTest.vcproj
- TestFiles
- 0_test_simple_a.reg
- 0_test_simple_w.reg
- 1_test_key_name_a.reg
- 1_test_key_name_w.reg
- 2_test_value_name_a.reg
- 2_test_value_name_w.reg
- 3_test_value_name_default_a.reg
- 3_test_value_name_default_w.reg
- 4_test_value_big_data_a.reg
- 4_test_value_big_data_w.reg
- 5_test_value_big_string_a.reg
- 5_test_value_big_string_w.reg
- TestRunner.hpp
- RegFileParserLib
- RegFileParserTestCmd
- regfileparser_bin.zip
- RegFileParser_bin
- bin
- RegFileParserAutoTest.exe
- RegFileParserTestCmd.exe
- regfileparser_source.zip
- RegFileParser_source
- src
- boost_libs
- libboost_program_options-vc90-mt-s-1_38.lib
- libboost_program_options-vc90-mt-sgd-1_38.lib
- RegFileParser.sln
- RegFileParserAutoTest
- main.cpp
- RegFileParserAutoTest.vcproj
- TestFiles
- 0_test_simple_a.reg
- 0_test_simple_w.reg
- 1_test_key_name_a.reg
- 1_test_key_name_w.reg
- 2_test_value_name_a.reg
- 2_test_value_name_w.reg
- 3_test_value_name_default_a.reg
- 3_test_value_name_default_w.reg
- 4_test_value_big_data_a.reg
- 4_test_value_big_data_w.reg
- 5_test_value_big_string_a.reg
- 5_test_value_big_string_w.reg
- TestRunner.hpp
- RegFileParserLib
- RegFileParserTestCmd
|
#ifndef __TEST_RUNNER_H_INCLUDED__
#define __TEST_RUNNER_H_INCLUDED__
#include <string>
#include <vector>
#include <iostream>
#include <iosfwd>
#include "RegFileParser.hpp"
#include "PrintObserver.hpp"
#include <boost/scope_exit.hpp>
#include <boost/algorithm/string.hpp>
inline void AddRegHeader(std::string* string)
{
*string += "REGEDIT4\n";
}
inline void AddRegHeader(std::wstring* string)
{
*string += (wchar_t)0xFEFF; // signifies that the bytes are big endian
*string += L"Windows Registry Editor Version 5.00\n";
}
template<class charT>
class TestRunner
{
protected:
typedef std::basic_string<charT> stringT;
typedef std::basic_stringstream<charT> stringstreamT;
typedef std::basic_fstream<charT> fstreamT;
public:
static void
ReadFile(const std::wstring& fileName,
std::vector<char>* pBuffer)
{
FILE * fin = 0;
_wfopen_s(&fin,fileName.c_str(),L"r,ccs=UNICODE");
if (!fin)
throw std::exception("Can't open file.\n");
BOOST_SCOPE_EXIT( (&fin) )
{
if (!fin)
fclose(fin);
}
BOOST_SCOPE_EXIT_END
fseek(fin,0, SEEK_END);
int filesize = ftell(fin);
fseek(fin,0, SEEK_SET);
if(filesize == 0)
throw std::exception("File is empty");
// Reserve one character for trailing null
pBuffer->resize(filesize+sizeof(charT));
size_t readed = fread(&pBuffer->at(0), sizeof(char),filesize, fin);
if(readed == 0)
throw std::exception("Can't read file or file is empty");
// Add trailing null
charT* pString = (charT*)&pBuffer->at(0);
size_t neededIndex = readed / sizeof(charT);
pString[neededIndex] = '\0';
}
static void
RunTest(const std::wstring& fileName)
{
std::vector<char> buffer;
ReadFile(fileName,&buffer);
stringstreamT stream;
reg_parser::CRegPrintObserver<charT,stringstreamT> coutObserver(stream);
reg_parser::CRegFileParser<charT> regParser(&coutObserver);
// Run parsing
if( !regParser.Parse( (charT*)&buffer[0] ) )
throw std::exception("Parsing fail.");
// Prepare data for comparison
stringT parsedStr;
AddRegHeader(&parsedStr);
parsedStr += stream.str();
stringT originalStr = stringT((charT*)&buffer[0]);
// Trim unneeded symbols
using namespace boost;
trim_if(originalStr,is_any_of("\n\t\0 "));
trim_if(parsedStr,is_any_of("\n\t\0 "));
if( parsedStr != originalStr)
{
// Save to file result of parsing
std::wstring parsedFileName = fileName + L"_parsed";
fstreamT file(parsedFileName.c_str(),fstreamT::out | fstreamT::trunc);
if( file.is_open() == false )
throw std::exception("Can't create file for result of parsing.");
BOOST_SCOPE_EXIT( (&file) )
{
file.close();
}
BOOST_SCOPE_EXIT_END
file << parsedStr;
throw std::exception("Parsed data not equal to original data.");
}
}
};
#endif // __TEST_RUNNER_H_INCLUDED__
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
ApriorIT is a software research and development company specializing in cybersecurity and data management technology engineering. We work for a broad range of clients from Fortune 500 technology leaders to small innovative startups building unique solutions.
As Apriorit offers integrated research&development services for the software projects in such areas as endpoint security, network security, data security, embedded Systems, and virtualization, we have strong kernel and driver development skills, huge system programming expertise, and are reals fans of research projects.
Our specialty is reverse engineering, we apply it for security testing and security-related projects.
A separate department of Apriorit works on large-scale business SaaS solutions, handling tasks from business analysis, data architecture design, and web development to performance optimization and DevOps.
Official site: https://www.apriorit.com
Clutch profile: https://clutch.co/profile/apriorit
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.