- 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_CMD_H_INCLUDED__
#define __TEST_RUNNER_CMD_H_INCLUDED__
#include "TestRunner.hpp"
#include "CountObserver.hpp"
#include "PrintObserver.hpp"
#include "StatusObserver.hpp"
#include "ObserversPool.hpp"
#include <iosfwd>
#include <fstream>
class TestRunnerCmd
{
public:
enum RunMode
{
tst_Print = 0x1,
tst_Count = 0x2,
tst_Status = 0x4,
tst_ToFile = 0x10,
tst_UsingApi = 0x20
};
static void
RunTest(const std::wstring& fileName, int mode)
{
std::vector<char> buffer;
TestRunner<wchar_t>::ReadFile(fileName,&buffer);
switch(GetRegVersion(buffer))
{
case reg_NT4:RunTest<char>(buffer,mode);break;
case reg_NT5:RunTest<wchar_t>(buffer,mode);break;
default:
throw std::exception("Wrong file format");
}
}
private:
enum FileType
{
reg_unknown,
reg_NT4,
reg_NT5
};
static int GetRegVersion(const std::vector<char>& buffer)
{
std::string regNt4("REGEDIT4\n");
std::wstring regNt5;
regNt5 += (wchar_t)0xFEFF; // signifies that the bytes are big endian
regNt5 += L"Windows Registry Editor Version 5.00\n";
if(StrFind(buffer,regNt4))
return reg_NT4;
if(StrFind(buffer,regNt5))
return reg_NT5;
else
return reg_unknown;
}
template<class stringT>
static bool StrFind(const std::vector<char>& buffer,
const stringT& str)
{
size_t strMemSize = str.size()*sizeof(stringT::value_type);
if(buffer.size() < strMemSize)
return false;
return ( memcmp(&buffer[0],str.c_str(),strMemSize) ==0 );
}
template<class> static void
RunTest(const std::vector<char>& buffer, int mode){throw std::exception("Wrong type");}
template<> static void
RunTest<char>(const std::vector<char>& buffer, int mode){RunTestImpl(buffer,mode,std::cout);}
template<> static void
RunTest<wchar_t>(const std::vector<char>& buffer, int mode){RunTestImpl(buffer,mode,std::wcout);}
template<class charT> static void
RunTestImpl(const std::vector<char>& buffer,
int mode,
std::basic_ostream<charT>& coutRef)
{
using namespace reg_parser;
typedef std::basic_string<charT> stringT;
typedef std::basic_ostream<charT> streamT;
typedef std::basic_stringstream<charT> stringstreamT;
typedef std::basic_fstream<charT> fstreamT;
typedef std::auto_ptr< IRegFileObserver<charT> > ObserverPtr;
typedef CRegObserversPool<charT> ObserversPool;
typedef CRegPrintObserver<charT, streamT> PrintObserver;
typedef CRegStatusObserver<charT, streamT> StatusObserver;
typedef CRegCountObserver<charT,streamT> CountObserver;
ObserversPool observersPool;
stringstreamT stream;
ObserverPtr printObsrv;
if( mode & tst_Print )
{
printObsrv.reset( new PrintObserver(coutRef) );
observersPool.PushBack(printObsrv.get());
}
ObserverPtr statusObsrv;
if( mode & tst_Status )
{
statusObsrv.reset( new StatusObserver((size_t)&buffer[0],buffer.size(),coutRef) );
observersPool.PushBack(statusObsrv.get());
}
ObserverPtr countObsrv;
if( mode & tst_Count )
{
countObsrv.reset( new CountObserver(coutRef) );
observersPool.PushBack(countObsrv.get());
}
CRegFileParser<charT> regParser(&observersPool);
// Run parsing
if( !regParser.Parse( (charT*)&buffer[0] ) )
throw std::exception("Parsing fail.");
}
};
#endif // __TEST_RUNNER_CMD_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.