0
点赞
收藏
分享

微信扫一扫

(二十三):Objective-C代码混淆扩展----安全之代码混淆的一个小工具iOS安全


觉得非常好,不过里面提到一个func.list的文件。

规则:

创建函数名列表func.list,写入待混淆的函数名,如:

-(void)sample;
-(void)seg1:(NSString *)string seg2:(NSUInteger)num;



就这样写:

sample
seg1
seg2

所以我用c语言写了以下的代码,专门用来生成func.list文件。

代码的功能是遍历你的工程,把里面的.h和.m文件找出来。并且把里面的类名,方法名,参数名等按上面的规则列出来。

注:因为一般.m和.h是配对的,比如test.m就有test.h,不过有时也只有config.h,而没有对应的.m文件。所以里面有一个小逻辑是如果有m文件,就不处理h文件,怕重复类名方法名等。

 



[cpp]  view plain  copy

1. #include <stdio.h>  
2. #include <sys/types.h>  
3. #include <dirent.h>  
4. #include <string.h>  
5. #include <sys/stat.h>  
6. #include <unistd.h>  
7.    
8.   
9. //编译方法,  
10. //gcc file.c -o file  
11. //运行方法  
12. //./file  
13. //然后就会输出你工程里的类名方法名,就可以把这里组装成一个需要混淆的配置文件了。  
14. //缺限  
15. //1.输出名字没有做重复处理。  
16. //2.判断方法时只是处理了两种情况,如果空格多于2个没有处理。  
17.   
18.   
19. #if 0//放开调试  
20. #define Printf_info(x,y) printf(x,y);  
21. #else  
22. #define Printf_info(x,y)  
23. #endif  
24.    
25.   
26. int Mydir(const char *filepath);  
27. int checkFile(const char *filepath);  
28.   
29. int findNum = 0;  
30.   
31. int main(int argc, char *argv[])  
32. {  
33. //此代码的功能是遍历ios的项目的所有。h和。m的文件,把里面的类名,方法名,参数名等都提取出来,  
34. //方便用CSDN博主“念茜”的方法来混淆自己的代码用。  
35. "/myProject");//填写自己的工程的根目录路径。  
36.   
37. return 0;  
38. }  
39. void Print_fileName(const char * filename)  
40. {  
41. int a = strlen(filename);  
42. for(int i=0;i<a - 2; i++){  
43. "%c",filename[i]);  
44.     }  
45. "\n");  
46. }  
47. int Mydir(const char *filepath)  
48. {  
49. char *fullpath,*filetype,*tmp;  
50. struct stat statbuf;  
51.     DIR *dr;  
52. struct dirent *drt;  
53.       
54. if((dr=opendir(filepath))==NULL)  
55. return 2;  
56.       
57. while((drt=readdir(dr))!=NULL)  
58.     {  
59.           
60. if(strcmp(drt->d_name,".")==0||strcmp(drt->d_name,"..")==0||strcmp(drt->d_name,".DS_Store")==0)  
61. continue;  
62.           
63.         fullpath=strdup(filepath);  
64. "/");  
65.         fullpath=strcat(fullpath,drt->d_name);  
66.           
67. "%s\n",fullpath);  
68.           
69. if(stat(fullpath,&statbuf)<0)  
70. continue;  
71.           
72. if (S_ISREG(statbuf.st_mode))  
73.         {  
74. "reguler";  
75. int a = strlen(drt->d_name);  
76. char *pp = drt->d_name;  
77. //printf("----  %c %c" , pp[a - 2], pp[a - 1]);  
78.               
79. if(pp[a - 2] == '.' && pp[a - 1] == 'm')  
80.             {  
81.                 Print_fileName(drt->d_name);  
82.                 checkFile(fullpath);  
83.             }  
84. #if 0  
85. else if(pp[a - 2] == '.' && pp[a - 1] == 'h')  
86.             {  
87. char *mPath = strdup(fullpath);  
88. //printf("\nmpath: %s\n",mPath);  
89. char *ppp = mPath;//drt->d_name;  
90. int a = strlen(ppp);  
91. 'm';//检查m文件是否存在。  
92. //printf("\nmpath: %s\n",mPath);  
93. if((access(mPath,F_OK))==0){  
94. continue;  
95.                 }  
96.                 Print_fileName(drt->d_name);  
97.                 checkFile(fullpath);  
98.             }  
99. #endif  
100.         }  
101. else if(S_ISDIR(statbuf.st_mode))  
102.         {  
103. "directory";  
104. //fullpath=strcat(fullpath,"/");  
105. //printf("%s,%s\n",fullpath,filetype);  
106.             tmp=strdup(fullpath);  
107.             Mydir(tmp);  
108.         }  
109. else  
110.         {  
111. "invalid";  
112. "%s,%s\n",fullpath,filetype);  
113.         }  
114. //printf("%s,%s\n",fullpath,filetype);  
115.         bzero(fullpath,strlen(fullpath));  
116.     }  
117. return 0;  
118. }  
119. int print_Method(char *text)  
120. {  
121. char *p = text;  
122. char c;  
123. int start = 0;  
124. while((c = *p++) !='\n'){//Method  
125. if(c == ':' || c == '{' || c == ';'){  
126.             start = 0;  
127. break;  
128.         }  
129. if(start == 1){  
130. "%c", c);  
131.         }  
132. if(c == ')')  
133.             start = 1;  
134.     }  
135. "\n");  
136. #if 0  
137.     start = 0;  
138. while((c = *p++) !='\n'){//arge  
139. if(c == ':'){  
140.             start = 0;  
141. "\n");  
142.         }  
143. if(start == 2 && c != '{'){  
144. "%c", c);  
145.         }  
146. if(c == ' ' && start == 1)  
147.             start = 2;  
148. if(c == ')')  
149.             start = 1;  
150.     }  
151. //printf("\n");  
152. #endif  
153. return 0;  
154. }  
155. int findMethod(char *text)  
156. {  
157. char *p = text;  
158. char c;  
159. while((c = *p++) !='\n'){  
160. if(c == '-' && ((*p == ' ' && *(p + 1) == '(') || *p == '(' )){  
161. if( text[0] == '-' )  
162.             {  
163. //printf("%d %s\n", findNum++, text);  
164.                 print_Method(text);  
165.             }  
166. //else  
167. //  printf("%d %s\n", findNum++, text);  
168.         }  
169. if(c == '+' && ((*p == ' ' && *(p + 1) == '(') || *p == '(' )){  
170. if( text[0] == '+' )  
171.             {  
172. //printf("%d %s\n", findNum++, text);  
173.                 print_Method(text);  
174.             }  
175. //else  
176. //  printf("%d %s\n", findNum++, text);  
177.         }  
178.     }  
179. return 0;  
180. }  
181. int checkFile(const char *filepath)  
182. {  
183. //printf("====%s\n", filepath);  
184.       
185. FILE *fp1;//定义文件流指针,用于打开读取的文件  
186. char text[40961];//定义一个字符串数组,用于存储读取的字符  
187. "r");//只读方式打开文件a.txt  
188. while(fgets(text,40960,fp1)!=NULL)//逐行读取fp1所指向文件中的内容到text中  
189.     {  
190. //puts(text);//输出到屏幕  
191.         findMethod(text);  
192.     }  
193. //关闭文件a.txt,有打开就要有关闭  
194.       
195. return 0;  
196. }

举报

相关推荐

0 条评论