├── README.md ├── LICENSE ├── deobfusscript.sh └── obfusscript.sh /README.md: -------------------------------------------------------------------------------- 1 |

CodeObfus

2 | 3 |

Introduction

4 | Simple Shell script which can Obfuscate Code before pack, use for App, especially for iOS project. 5 |
6 |

Usage

7 |

Change the property or method name AAA as ob_AAA_fus and run script obfusscript.sh to obfuscate in the project.

8 |

Run script deobfusscript.sh to retore.

9 | 10 |

You need to set these path Before running script.

11 | 12 | #项目路径 13 | ProjectPath 14 | #替换文本存放路径(不能在项目目录或其子目录) 15 | SecretFile 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 RyoHo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /deobfusscript.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ 3 | # 4 | # 5 | # 代码还原脚本 RyoHo 2016.2.25 6 | # 7 | # 8 | ############################################################ 9 | #识别含有多字节编码字符时遇到的解析冲突问题 10 | export LC_CTYPE=C 11 | export LANG=C 12 | #配置项: 13 | #项目路径 14 | ProjectPath="/Users/RyoHo/Desktop/confuseTestProject" 15 | #替换文本存放路径(不能在项目目录或其子目录) 16 | SecretFile="/Users/RyoHo/Desktop/secret/rlf20160225_1406" 17 | #第一个参数为项目路径 18 | if [[ $1 ]] 19 | then 20 | if [[ $1 != "_" ]]; then 21 | ProjectPath=$1 22 | fi 23 | fi 24 | #第二个参数指定密钥文件路径及文件名 25 | if [[ $2 ]] 26 | then 27 | if [[ $2 != "_" ]]; then 28 | SecretFile=$2 29 | fi 30 | fi 31 | ############################################################################## 32 | #内容还原 33 | x=`cat $SecretFile` 34 | recordnum=1 35 | while [[ 1 == 1 ]]; do 36 | record=`echo $x|cut -d "|" -f$recordnum` 37 | if [[ -z $record ]] 38 | then 39 | break 40 | fi 41 | record1=`echo $record|cut -d ":" -f1` 42 | echo "原项:"$record1 43 | record2=`echo $record|cut -d ":" -f2` 44 | echo "加密项:"$record2 45 | #若项目中加密项与密钥文件的加密项不符合则退出程序 46 | searchresult=`grep $record2 -rl $ProjectPath` 47 | if [[ -z $searchresult ]]; then 48 | echo "指定的密钥文件不能还原" 49 | exit 50 | fi 51 | #替换文件夹中所有文件的内容(支持正则) 52 | #单引号不能扩展 53 | sed -i '' "s/${record2}/${record1}/g" $searchresult 54 | echo "第"$recordnum"项混淆代码还原完毕" 55 | let "recordnum = $recordnum + 1" 56 | done 57 | #文件还原 58 | filerecordnum=1 59 | while [[ 1 == 1 ]]; do 60 | filerecord=`echo $x|cut -d "|" -f$filerecordnum` 61 | if [[ -z $filerecord ]] 62 | then 63 | break 64 | fi 65 | filerecord1=`echo $filerecord|cut -d ":" -f1` 66 | #echo "原项:"$filerecord1 67 | filerecord2=`echo $filerecord|cut -d ":" -f2` 68 | #echo "加密项:"$filerecord2 69 | #改文件名 70 | 71 | find $ProjectPath -name $filerecord2"*"| awk ' 72 | BEGIN{ 73 | frecord1="'"$filerecord1"'"; 74 | frecord2="'"$filerecord2"'"; 75 | finish=1; 76 | } 77 | { 78 | filestr=$0; 79 | gsub(frecord2,frecord1,filestr); 80 | print "mv " $0 " "filestr ";echo 第"finish"个混淆文件还原完毕" 81 | finish++; 82 | }'|bash 83 | let "filerecordnum = $filerecordnum + 1" 84 | done 85 | 86 | 87 | -------------------------------------------------------------------------------- /obfusscript.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ 3 | # 4 | # 5 | # 代码混淆脚本 RyoHo 2016.2.25 6 | # 7 | # 8 | ############################################################ 9 | #识别含有多字节编码字符时遇到的解析冲突问题 10 | export LC_CTYPE=C 11 | export LANG=C 12 | #配置项: 13 | #项目路径 14 | ProjectPath="/Users/RyoHo/Desktop/confuseTestProject" 15 | #替换文本存放路径(不能在项目目录或其子目录) 16 | SecretFile="/Users/RyoHo/Desktop/secret/rlf"$(date +%Y%m%d)"_"$(date +%H%M) 17 | #第一个参数为项目路径 18 | if [[ $1 ]] 19 | then 20 | if [[ $1 != "_" ]]; then 21 | ProjectPath=$1 22 | fi 23 | fi 24 | #第二个参数指定密钥文件路径及文件名 25 | if [[ $2 ]] 26 | then 27 | if [[ $2 != "_" ]]; then 28 | SecretFile=$2 29 | fi 30 | fi 31 | ############################################################################## 32 | 33 | #查找文本中所有要求混淆的属性\方法\类 34 | resultfiles=`grep 'ob_[A-Za-z0-9_]*_fus' -rl $ProjectPath` 35 | #查找结果为空则退出 36 | if [[ -z $resultfiles ]] 37 | then 38 | echo "项目没有需要混淆的代码" 39 | exit 40 | else 41 | echo "开始混淆代码..." 42 | echo > $SecretFile 43 | fi 44 | 45 | x=$(awk ' 46 | BEGIN{srand();k=0;} 47 | #随机数生成函数 48 | function random_int(min, max) { 49 | return int( rand()*(max-min+1) ) + min; 50 | } 51 | #随机字符串生成函数 52 | function random_string(len) { 53 | result="UCS"k; 54 | alpbetnum=split("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", alpbet, ","); 55 | for (i=0; i 0) { 64 | tempstr=substr(x, RSTART, RLENGTH); 65 | #判断是否有之前已经找过的重复字符串 66 | for ( i = 0; i < k; i++ ){ 67 | if (strarr[i] == tempstr){break;} 68 | } 69 | if(i $SecretFile 87 | 88 | recordnum=1 89 | while [[ 1 == 1 ]]; do 90 | record=`echo $x|cut -d "|" -f$recordnum` 91 | if [[ -z $record ]] 92 | then 93 | break 94 | fi 95 | record1=`echo $record|cut -d ":" -f1` 96 | echo "原项:"$record1 97 | record2=`echo $record|cut -d ":" -f2` 98 | echo "加密项:"$record2 99 | #替换文件夹中所有文件的内容(支持正则) 100 | #单引号不能扩展 101 | sed -i '' "s/${record1}/${record2}/g" `grep $record1 -rl $ProjectPath` 102 | echo "第"$recordnum"项混淆代码处理完毕" 103 | let "recordnum = $recordnum + 1" 104 | done 105 | 106 | #查找需要混淆的文件名并替换 107 | filerecordnum=1 108 | while [[ 1 == 1 ]]; do 109 | filerecord=`echo $x|cut -d "|" -f$filerecordnum` 110 | if [[ -z $filerecord ]] 111 | then 112 | break 113 | fi 114 | filerecord1=`echo $filerecord|cut -d ":" -f1` 115 | #echo "原项:"$filerecord1 116 | filerecord2=`echo $filerecord|cut -d ":" -f2` 117 | #echo "加密项:"$filerecord2 118 | #改文件名 119 | 120 | find $ProjectPath -name $filerecord1"*"| awk ' 121 | BEGIN{frecord1="'"$filerecord1"'";frecord2="'"$filerecord2"'";finish=1} 122 | { 123 | filestr=$0; 124 | gsub(frecord1,frecord2,filestr); 125 | print "mv " $0 " " filestr";echo 第"finish"个混淆文件处理完毕"; 126 | finish++; 127 | }'|bash 128 | let "filerecordnum = $filerecordnum + 1" 129 | done 130 | --------------------------------------------------------------------------------