Polidea / ios-class-guard

Simple Objective-C obfuscator for Mach-O executables.
http://www.polidea.com
1.64k stars 240 forks source link

How to exclude some classes and pods libraries #55

Open Mohamed3amer opened 8 years ago

Mohamed3amer commented 8 years ago

I need to exclude some some classes and all pods libraries like UISS, StompKit, else...

I am trying like this CLASS_GUARD_OPTS="-F 'IG ' -F 'UISS '", but still iOS class guard obfuscating it

also i tried like this CLASS_GUARD_OPTS="-F '!IG ' -F '!UISS '"

2016-01-10 11:47:54.693 ios-class-guard[71726:1372666] Obfuscating@ class IGAxis 
2016-01-10 11:47:54.694 ios-class-guard[71726:1372666] Obfuscating @class IGCategoryAxisBase 
2016-01-10 11:47:54.694 ios-class-guard[71726:1372666] Obfuscating @class IGNumericAxisBase

Am using xcode 7.1.1

kajot commented 8 years ago

Did you copy-paste the opts you use?

CLASS_GUARD_OPTS="-F '!IG *' -F '!UISS *'"

you have unnecessary spaces between the class prefix and the asterisk. Try removing the spaces and use

CLASS_GUARD_OPTS="-F '!IG*' -F '!UISS*'"

if that still fails to resolve the problem, I'll dig deeper into it

Mohamed3amer commented 8 years ago

No i didn't copy/paste. I added this spaces because when i posted the post like this -F '!IG' the \ character disappears.

kajot commented 8 years ago

OK, took a closer look at it.

Instead of CLASS_GUARD_OPTS="-F '!IG*' -F '!UISS*'"

use CLASS_GUARD_OPTS="-F !IG* -F !UISS*"

In other words, get rid of the single apostrophes around excluded prefixes. Hope this helps! :)

PS. When pasting any code/command samples, it's best to use inline code formatting like this and not tamper with said samples (pasting them verbatim).

Mohamed3amer commented 8 years ago

@kajot After i removed the single apostrophes, now ios-class-guard now ignoring the excluded classes in the terminal shows:

Ignoring @class UISS Ignoring @class DDLog

but when building the project there is many errors appeared for example: 1- in DDLog.h Lumberjact Library @class DDLogMessage; Unexpected '@' in program

2- No visible @interface for 'NSRunLoop' declares the selector 'performSelector:target:argument

Mohamed3amer commented 8 years ago

@kajot
Another question: in the .pch file #import "symbols.h" should be in the beginning or in the last of the file ?

Mohamed3amer commented 8 years ago

@kajot please any solution ?

lin493369 commented 8 years ago

@Mohamed3amer @kajot

In fact,I thought that the problem is the filter of iOS static library is not working well in the Xcode 7.2. But I don't know where is the obfuscation happen?

I encounter many Warning Failed to load file,but the path I opened in the finder is correct,and the file is right there!Dose this Warning is the key of the problem?

Warning: Failed to load: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/usr/lib/libc++.1.dylib ........................ 2016-03-16 12:00:14.899 ios-class-guard[67193:4825627] Warning: Couldn't load MachOFile with ID: /System/Library/Frameworks/QuartzCore.framework/QuartzCore, adjustedID: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/QuartzCore.framework/QuartzCore

Can anybody tell me why the static library is also obfuscating in the Xcode 7.2.

softwind0214 commented 8 years ago

It's because the libraries is named '.tbd' in the Xcode 7.2 instead of '.dylib'. Can anybody fix this issue?

lin493369 commented 8 years ago

@softwind0214 Simulator use .dylib,and iPhone use .tbd.

neuralmer commented 8 years ago

@Mohamed3amer and @lin493369, I will repeat some of the response that I gave on other issues you've posted to, but I have some additional comments for new issues you mention here.

The approach ios-class-guard takes to renaming is clever, but can produce less than intuitive compiler errors when there is a problem. In order for it to work well, the system libraries that your app uses must be analyzed. ios-class-guard will warn you if this fails. Pay attention to warnings like the following:

2016-04-25 12:41:44.173 ios-class-guard[2598:64769341] Warning: Failed to load: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/QuartzCore.framework/QuartzCore
2016-04-25 12:41:44.174 ios-class-guard[2598:64769341] Warning: Couldn't load MachOFile with ID: /System/Library/Frameworks/QuartzCore.framework/QuartzCore, adjustedID: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/QuartzCore.framework/QuartzCore
2016-04-25 12:41:44.174 ios-class-guard[2598:64769341] Warning: Failed to load: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics
2016-04-25 12:41:44.174 ios-class-guard[2598:64769341] Warning: Couldn't load MachOFile with ID: /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics, adjustedID: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics

This means that ios-class-guard is not able to analyze the dependencies correctly. Apple has dramatically changed the SDKs ship with Xcode (6 and again in 7) to reduce download footprints. iPhoneSimulator SDK still works, but the iPhoneOS SDK format is unsupported. This means that analysis of an ARM binary will not work.

Make sure to look for the Forbidden keywords line:

2016-04-25 12:41:45.225 ios-class-guard[2598:64769341] Forbidden keywords = 98

This number should be > 50k for even a simple iOS project. If the number is very small, analysis of the SDK failed, and poor build results can be expected, including error messages like unexpected '@' in program.

We (PreEmptive Solutions) forked iOS Class Guard, creating a new product, called PreEmptive Protection for iOS - Rename (or PPiOS-Rename), that fixes this issue and a number of others.

PPiOS-Rename uses the same approach to renaming, but will use iPhoneSimulator SDK in lieu of iPhoneOS SDK, even for ARM binaries.

@Mohamed3amer

  1. Cocoapods should work fine, so long as they are open-source (e.g. they are compiled as part of your build), and not pulled down as compiled static libraries. Closed-source Cocoapods will need to be excluded with something like:

    ppios-rename --analyze -F '!CSC*' path/to/your.app

    This will exclude all classes, etc. starting with "CSC" ("Closed-Source Cocoapod").

  2. The NSRunLoop error is almost certainly caused by failed analysis, but will work in PPiOS-Rename.
  3. When specifying a class filter pattern, the apostrophes ' are only necessary to escape shell expansion of ! and * (and ? if you use that wildcard).
  4. The error with @class DDLogMessage; may have been caused by an attempt to rename class. In this case, PPiOS-Rename considers class to be a keyword, and it is automatically excluded.
  5. The program injects the include of the symbols-header at the start of the *-Prefix.pch file, but the location in the file should not matter.

@lin493369

You likely tried to obfuscate an ARM binary (compiled for "Generic iOS Device"), but used the iPhoneSimulator SDK to do the analysis. PPiOS-Rename will work with the .dylibs in the simulator SDK in this case.

@softwind0214

It sounds like you too encountered the issue described above with the iPhoneOS SDK. PPiOS-Rename should work for you, but it will need to use the iPhoneSimulator SDK for analysis.

Note that PPiOS-Rename changes the way the obfuscation process is integrated into the build (to make it easier to use), so you'll probably need to make changes to your build, and to pay attention to the new/changed argument names.

Please give it a try and let us know how it works for you.

softwind0214 commented 8 years ago

@lin493369 @neuralmer Thanks for help. Finally I found that I made mistakes in building my project. In fact I used the package built with iPhoneOS SDK for analysis since I can't build with iPhoneSimulator SDK.

I write my obfuscate script according to the example ios-class-guard-example. To build the iPhoneSimulator SDK, it uses the bash command

xcodebuild \ -project "$PROJECT" \ -scheme "$SCHEME" \ -configuration "$CONFIGURATION" \ -sdk "$OBFUSCATION_SDK" \ clean build \ OBJROOT=build/ \ SYMROOT=build/ |\ xcpretty -c

but it doesn't work for me. It always shows me "ld: xxxx not found"(xxxx is a pod project). After searching in google and stackoverflow I solved this problem. And then my ios-class-guard works well now.

The solution is change the params of OBJROOT and SYMROOT to absolute path, just like

OBJROOT=$PWD/build/ \ SYMROOT=$PWD/build/ |\