I am not using the -g compiler option, yet I am still getting strings in my executable easily viewable. for example by using strings program.
Here is my code:
test.hpp:
#ifndef TEST_HPP_
#define TEST_HPP_
#include <string>
namespace ns1 {
class Test
{
public:
std::string Get(const std::string& root);
private:
void append_other_stuff(std::string& s);
};
} // namespace ns1
#endif // TEST_HPP_
test.cpp:
#include "test.hpp"
static const char* privatePart = "_hideme_";
namespace ns1 {
std::string Test::Get(const std::string& root) {
std::string result = root + "_fixed_" + privatePart;
append_other_stuff(result);
return result;
}
void Test::append_other_stuff(std::string& s) {
// all these string must be hidden
static char middle1[] = {'s','e','c','r', 'e','t','1','\0'};
static char middle2[] = {'s','e','c','r', 'e','t','2','\0'};
static char endbit[] = {'s','e','c','r', 'e','t','3','\0'};
s += middle1;
s += middle2;
s += endbit;
}
}
main.cpp:
#include "test.hpp"
#include <iostream>
using namespace std;
int main() {
ns1::Test t1;
cout << t1.Get("123") << endl;
}
Makefile:
CXX = g++
CXXFLAGS = -Wall -std=c++11
main.o: main.cpp
$(CXX) $(CXXFLAGS) -c main.cpp
test.o: test.cpp test.hpp
$(CXX) $(CXXFLAGS) -c test.cpp
prog: main.o test.o
$(CXX) $(CXXFLAGS) main.o test.o -o prog
output (shortened) from using strings:
strings prog
_hideme_
_fixed_
;*3$"
zPLR
secret1
secret2
secret3
even if I run the strip command:
strip -s -g prog
the strings I want to hide are still in prog.
How can I hide these strings?