Transferred from: http://blog.csdn.net/yiyaaixuexi/article/details/29201699
Class-dump can be very convenient to export the program header file, not only to let the attackers understand the program structure to facilitate the reverse, but also to hurry to catch up with the progress of the imperfect program written to the peer left a laughingstock.
So, we are desperate to confuse our code.
The conventional thinking of confusion
Confusion points to many ideas, such as:
1) Flower Code flower instruction, that is, random to the program to add the code instruction of the confusing person
2) Easy-to-read character substitution
Wait a minute
An effective way to prevent class-dump from reading information is to replace the easy-to-read character.
Objective-c the time to confuse the method name confusion
We want to keep clear and readable program code at the time of development to make it easy for you.
At the same time, the binary that you want to compile contains messy, confusing program code that is disgusting to others.
Therefore, we can set the string substitution for the method name before compiling in build Phrase.
The method of confusion
Method name confusion is actually a string substitution, there are 2 methods can be, one is # define, one is the use of tops.
The advantage of using the # define method is that it is possible to merge the results of the confusion in a. h, #import the prefix.pch at the front of the project. It is confusing to not import or compile, import.
A single-segment selector, such as Func:, can be substituted by a # define Func.
Multiple segments of selector, such as A:B:C:, can be replaced by a string of # A, B, and C respectively.
My obfuscation tool
I wrote a simple confusion script, the main idea is to focus on the sensitive method name in a file called Func.list, one-to-a-box into random characters, append write. h.
The script is as follows:
- #!/usr/bin/env Bash
- Tablename=symbols
- symbol_db_file= "Symbols"
- String_symbol_file= "Func.list"
- head_file= "$PROJECT _dir/$PROJECT _name/codeobfuscation.h"
- Export Lc_ctype=c
- #维护数据库方便日后作排重
- CreateTable ()
- {
- echo "CREATE table $TABLENAME (src text, des text);" | Sqlite3 $SYMBOL _db_file
- }
- Insertvalue ()
- {
- echo "INSERT into $TABLENAME values (' $ ', ' $ ');" | Sqlite3 $SYMBOL _db_file
- }
- Query ()
- {
- echo "SELECT * from $TABLENAME where src= ' $ ';" | Sqlite3 $SYMBOL _db_file
- }
- Ramdomstring ()
- {
- OpenSSL rand-base64 64 | Tr-cd ' a-za-z ' |head-c 16
- }
- Rm-f $SYMBOL _db_file
- Rm-f $HEAD _file
- CreateTable
- Touch $HEAD _file
- Echo ' #ifndef Demo_codeobfuscation_h
- #define Demo_codeobfuscation_h ' >> $HEAD _file
- echo "//confuse string at ' Date '" >> $HEAD _file
- Cat "$STRING _symbol_file" | While Read-ra line; Do
- if [[!-Z ' $line]]; Then
- Ramdom= ' ramdomstring '
- echo $line $ramdom
- Insertvalue $line $ramdom
- echo "#define $line $ramdom" >> $HEAD _file
- Fi
- Done
- echo "#endif" >> $HEAD _file
- Sqlite3 $SYMBOL _db_file. Dump
Operation Steps
1. Place the confusion script confuse.sh in the project directory
MV Confuse.sh your_proj_path/
2. Modify PREFIX.PCH
Open Xcode, modify xxx-prefix.ch, add obfuscation header file:
- #ifdef __objc__
- #import <UIKit/UIKit.h>
- #import <Foundation/Foundation.h>
- //Add obfuscation header file (this file name is defined in script confuse.sh)
- #import "CodeObfuscation.h"
- #endif
3. Configure Build Phase
Add the Execute script action in the project build phase, execute the confuse.sh script,
4. Create the Function name list func.list, write the function names to be confused, such as:
-(void) sample;
-(void) SEG1: (NSString *) string SEG2: (Nsuinteger) num;
Write it like this:
Sample
Seg1
Seg2
and place the file in the same sibling as the confuse.sh script
MV Func.list your_proj_path/
5. Compiling view results
Direct build, the obfuscation script will run before compiling, random substitution of characters, and the random characters of each build are different
Objective-c code obfuscation (GO)