Boost logo

Boost :

Subject: Re: [boost] [encrypted strings]
From: Eric Niebler (eric_at_[hidden])
Date: 2009-04-27 13:45:06


David Abrahams wrote:
> on Mon Apr 27 2009, Sohail Somani <sohail-AT-taggedtype.net> wrote:
>
>> There is an implementation of a mpl::string by Eric Neibler somewhere.
>
> well, that's an interesting point. The string itself wouldn't even
> appear in the data segment. Cool.

Below is the definition of a std_str() function that takes an
mpl::string and turns it into a std::string. (boost/mpl/string.hpp is
available on trunk, but hasn't been released yet.) It's not *very*
obfuscated, but should be enough to fool a naive string-dump.

#include <string>
#include <iostream>
#include <boost/mpl/string.hpp>
#include <boost/mpl/for_each.hpp>
using namespace boost;

struct push_back_str
{
     push_back_str(std::string & s)
       : str(s)
     {}

     void operator()(char c) const
     {
         this->str.push_back(c);
     }
private:
     std::string & str;
};

template<typename String>
std::string std_str()
{
     std::string result;
     result.reserve(mpl::size<String>());
     mpl::for_each<String>(push_back_str(result));
     return result;
}

int main()
{
     std::cout << std_str< mpl::string<'hell','o wo','rld!'> >() <<
std::endl;
     return 0;
}

HTH,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk