I am trying to hide original code from library file which is written in C++. My question is "How can I hide my code securely when I built library file, like .o or .so ?"
Environment description
- Ubuntu 20.04 LTS (with WSL2)
- gcc 9.3.0
Problem description.
Source code
let's think there is test.cpp
file
#include <iostream>
void foo() {
std::cout << "This is FOO\n";
}
int bar() {
int a = 5;
int b = 12;
std::cout << "This is BAR\n";
return a + b;
}
char test() {
std::cout << "This is TEST\n";
return 'T';
}
How did I build (on terminal)
$ g++ -o test.o -c test.cpp -O2
$ g++ -c -fPIC test.cpp -o test.so -O2
I built 2 files if there is difference between object file and static object file to solve my problem.
test.o
You can see like below picture. There is "FOO" "BAR" or something else.
and also when I use nm test.o
it shows function name like T _Z3barv
T _Z3foov
etc.
$ nm test.o
0000000000000000 r .LC0
000000000000000d r .LC1
000000000000001a r .LC2
U _GLOBAL_OFFSET_TABLE_
0000000000000000 t _GLOBAL__sub_I__Z3foov
0000000000000020 T _Z3barv
0000000000000000 T _Z3foov
0000000000000050 T _Z4testv
U _ZNSt8ios_base4InitC1Ev
U _ZNSt8ios_base4InitD1Ev
U _ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
U _ZSt4cout
0000000000000000 b _ZStL8__ioinit
U __cxa_atexit
U __dso_handle
test.so
This file also shows "FOO" "BAR" things which prints string.
like above, when I use nm test.so
, it shows function name like T _Z3barv
T _Z3foov
etc.
$ nm test.so
0000000000000000 r .LC0
000000000000000d r .LC1
000000000000001a r .LC2
U _GLOBAL_OFFSET_TABLE_
0000000000000000 t _GLOBAL__sub_I_test.cpp
0000000000000020 T _Z3barv
0000000000000000 T _Z3foov
0000000000000050 T _Z4testv
U _ZNSt8ios_base4InitC1Ev
U _ZNSt8ios_base4InitD1Ev
U _ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
U _ZSt4cout
0000000000000000 b _ZStL8__ioinit
U __cxa_atexit
U __dso_handle
Question
I want to hide everything securely, so that the malicious cannot disassemble my library easily. Can I hide that strings like "FOO" "BAR" "TEST"?