How to REALLY strip a binary in MacOs

后端 未结 4 1933
野性不改
野性不改 2021-01-02 08:26

MacOs 10.6, if I have a file \"unwanted.c\" which contains:

class secret_thing {
public:
secret_thing() {}
void revealing_method_name() {}
};

main()
{
    s         


        
相关标签:
4条回答
  • 2021-01-02 08:58

    Given the example code you’ve posted, adding the ‘-O’ optimisation flag results in those symbols not being shown by nm after compilation.

    0 讨论(0)
  • 2021-01-02 08:59

    It sounds like what you really want isn't to strip the executable, but to obfuscate its symbol table. I'm not sure, but perhaps something like this would be helpful. At least, "C++ symbol table obfuscator" is probably a better Google search string..

    0 讨论(0)
  • 2021-01-02 09:02

    Using the following compile line I successfully strip the symbols from the executable:

    $ g++ -Xlinker -unexported_symbol -Xlinker "*" -o executable file.cpp
    $ strip executable
    

    Given the latest sample file, this results in:

    $ nm executable
                     U __ZTVN10__cxxabiv117__class_type_infoE
                     U __ZTVN10__cxxabiv120__si_class_type_infoE
                     U __ZdlPv
                     U __Znwm
                     U ___cxa_pure_virtual
                     U ___gxx_personality_v0
    0000000100000000 A __mh_execute_header
                     U _exit
                     U dyld_stub_binder
    
    0 讨论(0)
  • 2021-01-02 09:10

    This seems to work as desired...:

    $ strip unwanted
    $ nm unwanted | grep secret | cut -f 3 -d ' ' > /tmp/remove
    $ strip -R /tmp/remove unwanted
    
    0 讨论(0)
提交回复
热议问题