Я не использую опцию -g компилятора, но все еще получаю строки в моем исполняемом файле, которые легко просматривать.например, с помощью программы для работы со строками.
Вот мой код:
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
вывод (сокращен) при использовании строк:
строк prog
_hideme_
_fixed_
;*3$"
zPLR
secret1
secret2
secret3
evenесли я запускаю команду strip:
strip -s -g prog
строки, которые я хочу скрыть, все еще находятся в проге.
Как я могу скрыть эти строки?