Click here to Skip to main content
15,879,348 members
Articles / Desktop Programming / MFC

Driver to Hide Processes and Files

, ,
Rate me:
Please Sign up or sign in to vote.
4.57/5 (145 votes)
17 Aug 2009CPOL12 min read 653.7K   28.5K   369  
In this article, we describe the driver we created to hide processes and files in a system.
#include "PackageParserTest.h"
#include <boost/test/test_tools.hpp>

#include "PackageParser.h"

namespace UnitTest
{
void PackThreeToOne_SimpleTest()
/*++
Routine Description:
    PackThreeToOne test. Pack strings then unpack it and check for equal string.
--*/
{
    std::wstring packedString;

    std::wstring firstParamIn(L"FirstParam");
    std::wstring secondParamIn(L"SecondParam");
    std::wstring thirdParamIn(L"ThirdParam");
    utils::PackThreeToOne(firstParamIn,secondParamIn,thirdParamIn,&packedString);

    std::wstring firstParamOut;
    std::wstring secondParamOut;
    std::wstring thirdParamOut;
    utils::UnPackThreeToOne(packedString,&firstParamOut,&secondParamOut,&thirdParamOut);
    
    BOOST_REQUIRE(firstParamIn.size() == firstParamOut.size());
    BOOST_CHECK( std::equal(firstParamIn.begin(),firstParamIn.end(),firstParamOut.begin()) );
    
    BOOST_REQUIRE(secondParamIn.size() == secondParamOut.size());
    BOOST_CHECK( std::equal(secondParamIn.begin(),secondParamIn.end(),secondParamOut.begin()) );
    
    BOOST_REQUIRE(thirdParamIn.size() == thirdParamOut.size());
    BOOST_CHECK( std::equal(thirdParamIn.begin(),thirdParamIn.end(),thirdParamOut.begin()) );
}

#define PACK_CHECK_THROW(P1,P2,P3,P4) \
    BOOST_CHECK_THROW( utils::PackThreeToOne(P1,P2,P3,P4),std::exception )

void PackThreeToOne_WrongParameterTest()
/*++
Routine Description:
    Test wrong parameter passed to function PackThreeToOne().
--*/
{
    std::wstring packedString;

    std::wstring firstParamIn;
    std::wstring secondParamIn;
    std::wstring thirdParamIn;

/* Test empty strings*/

    // First param empty
    PACK_CHECK_THROW(firstParamIn,secondParamIn,thirdParamIn,&packedString);

    // Second param empty
    firstParamIn = L"1";
    PACK_CHECK_THROW(firstParamIn,secondParamIn,thirdParamIn,&packedString);

    // Third param empty
    secondParamIn = L"2";
    PACK_CHECK_THROW(firstParamIn,secondParamIn,thirdParamIn,&packedString);

/* Test illegal symbols*/
    thirdParamIn = L"3";

    // First param with illegal characters
    firstParamIn = L"ab;cd";
    PACK_CHECK_THROW(firstParamIn,secondParamIn,thirdParamIn,&packedString);

    // Second param with illegal characters
    firstParamIn = L"abcd";
    secondParamIn = L"ab;cd";
    PACK_CHECK_THROW(firstParamIn,secondParamIn,thirdParamIn,&packedString);

    // Third param with illegal characters
    secondParamIn = L"abcd";
    thirdParamIn = L"ab;cd";
    PACK_CHECK_THROW(firstParamIn,secondParamIn,thirdParamIn,&packedString);
}

#define UNPACK_CHECK_THROW(P1,P2,P3,P4) \
    BOOST_CHECK_THROW( utils::UnPackThreeToOne(P1,P2,P3,P4),std::exception )

void UnPackThreeToOne_WrongParameterTest()
/*++
Routine Description:
    Test wrong parameter passed to function UnPackThreeToOne.
--*/
{
    std::wstring packedString;

/* Test empty params */
    std::wstring firstParamOut;
    std::wstring secondParamOut;
    std::wstring thirdParamOut;

    // Without separators
    packedString = L"FirstParam";
    UNPACK_CHECK_THROW(packedString,&firstParamOut,&secondParamOut,&thirdParamOut);

    // One separator
    packedString = L"FirstParam;SecondParam";
    UNPACK_CHECK_THROW(packedString,&firstParamOut,&secondParamOut,&thirdParamOut);

    // First param empty
    packedString = L";SecondParam;ThirdParam";
    UNPACK_CHECK_THROW(packedString,&firstParamOut,&secondParamOut,&thirdParamOut);

    // Second param empty
    packedString = L"FirstParam;;ThirdParam";
    UNPACK_CHECK_THROW(packedString,&firstParamOut,&secondParamOut,&thirdParamOut);

    // Third param empty
    packedString = L"FirstParam;SecondParam;";
    UNPACK_CHECK_THROW(packedString,&firstParamOut,&secondParamOut,&thirdParamOut);
}

/////////////////////////////////////////////////////////////////////////////////////////

void PackByComma_SimpleTestImpl(const WStringList& stringListIn)
{
    std::wstring packedString;
    utils::PackByComma(stringListIn,&packedString);

    WStringList stringListOut;
    utils::UnPackByComma(packedString,&stringListOut);

    BOOST_REQUIRE(stringListOut.size() == stringListIn.size());
    BOOST_CHECK( std::equal(stringListIn.begin(),stringListIn.end(),stringListOut.begin()) );
}
void PackByComma_SimpleTest1()
{
    WStringList stringListIn;
    stringListIn.push_back(L"SingleValue");

    PackByComma_SimpleTestImpl(stringListIn);
}
void PackByComma_SimpleTest3()
{
    WStringList stringListIn;
    stringListIn.push_back(L"FirstValue");
    stringListIn.push_back(L"SecondValue");
    stringListIn.push_back(L"ThirdValue");

    PackByComma_SimpleTestImpl(stringListIn);
}
void PackByComma_SimpleTest()
/*++
Routine Description:
    PackThreeToOne test strings by comma then unpack it and check for equal string
--*/
{
    PackByComma_SimpleTest1();
    PackByComma_SimpleTest3();
}

#define PACK_BY_COMMA_CHECK_THROW(P1,P2) \
    BOOST_CHECK_THROW( utils::PackByComma(P1,P2),std::exception )

void PackByComma_WrongParameterTest()
/*++
Routine Description:
    Test wrong parameter passed to PackByComma function
--*/
{
    std::wstring packedString;
    WStringList stringListIn;

    // Empty string list
    PACK_BY_COMMA_CHECK_THROW(stringListIn,&packedString);

    // Empty value inside string list
    stringListIn.push_back(L"");
    PACK_BY_COMMA_CHECK_THROW(stringListIn,&packedString);
}

#define UNPACK_BY_COMMA_CHECK_THROW(X,Y) \
    BOOST_CHECK_THROW( utils::UnPackByComma(X,Y),std::exception )

void UnPackByComma_WrongParameterTest()
/*++
Routine Description:
    Test wrong parameter passed to UnPackByComma function
--*/
{
    std::wstring packedString;
    WStringList stringListOut;

    // Empty packed string
    UNPACK_BY_COMMA_CHECK_THROW(packedString,&stringListOut);

    // Second param empty
    packedString = L"abcd,";
    UNPACK_BY_COMMA_CHECK_THROW(packedString,&stringListOut);

    // First param empty
    packedString = L",abcd";
    UNPACK_BY_COMMA_CHECK_THROW(packedString,&stringListOut);

    // Middle param empty
    packedString = L"abcd,,abcd";
    UNPACK_BY_COMMA_CHECK_THROW(packedString,&stringListOut);
}
}//namespace UnitTest

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Apriorit Inc.
United States United States
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 is a Organisation

33 members

Written By
Software Developer Codedgers Inc
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Software Developer (Junior) ApriorIT
Ukraine Ukraine
Sergey Popenko.
22 years old.
The Driver Team`s software developer.
Master of the Applied Math faculty, the Dnipropetrovsk National University, Ukraine.

Comments and Discussions