Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude public option #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Exclude public
  • Loading branch information
vrujbr committed Nov 12, 2018
commit a649d312bdebcdd1d16e73da99e1a1356fe1a539
20 changes: 19 additions & 1 deletion swiftshield-Sources/AutomaticSwiftShield.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class AutomaticSwiftShield: Protector {
let projectToBuild: String
let schemeToBuild: String
let modulesToIgnore: Set<String>
let excludePublic: Bool

var isWorkspace: Bool {
return projectToBuild.hasSuffix(".xcworkspace")
Expand All @@ -14,10 +15,12 @@ class AutomaticSwiftShield: Protector {
projectToBuild: String,
schemeToBuild: String,
modulesToIgnore: Set<String>,
protectedClassNameSize: Int) {
protectedClassNameSize: Int,
excludePublic: Bool = false) {
self.projectToBuild = projectToBuild
self.schemeToBuild = schemeToBuild
self.modulesToIgnore = modulesToIgnore
self.excludePublic = excludePublic
super.init(basePath: basePath, protectedClassNameSize: protectedClassNameSize)
if self.schemeToBuild.isEmpty || self.projectToBuild.isEmpty {
Logger.log(.helpText)
Expand Down Expand Up @@ -108,6 +111,21 @@ extension AutomaticSwiftShield {
guard let name = dict.getString(key: sourceKit.nameID)?.trueName, let usr = dict.getString(key: sourceKit.usrID) else {
return nil
}

if excludePublic {
let attributesArray = dict.getDictionaryValue(key: sourceKit.attributesId)
if attributesArray.isArray {
let count = attributesArray.getArrayCount()
for i in 0..<count {
let attributeDict = attributesArray.getArrayValue(index: i)
let attribute = attributeDict.getUUIDString(key: sourceKit.attributeId)
if attribute.split(separator: ".").last == "public" {
return nil
}
}
}
}

guard let protected = obfuscationData.obfuscationDict[name] else {
let newName = String.random(length: self.protectedClassNameSize, excluding: obfuscationData.allObfuscatedNames)
obfuscationData.obfuscationDict[name] = newName
Expand Down
11 changes: 10 additions & 1 deletion swiftshield-Sources/SourceKit+Variant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ extension sourcekitd_variant_t {
return String( cString: SKApi.sourcekitd_uid_get_string_ptr( uuid! )! )// ?: "NOUUID"
}

func getDictionary(key: sourcekitd_uid_t) -> sourcekitd_variant_t {
func getDictionaryValue( key: sourcekitd_uid_t ) -> sourcekitd_variant_t {
return SKApi.sourcekitd_variant_dictionary_get_value(self, key)
}

func getArrayValue( index: Int ) -> sourcekitd_variant_t {
return SKApi.sourcekitd_variant_array_get_value(self, index)
}

func getArrayCount() -> Int {
let count = sourcekitd_variant_array_get_count(self)
return Int(count)
}
}
2 changes: 2 additions & 0 deletions swiftshield-Sources/SourceKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ final class SourceKit {
lazy var lineID = SKApi.sourcekitd_uid_get_from_cstr("key.line")!
lazy var colID = SKApi.sourcekitd_uid_get_from_cstr("key.column")!
lazy var usrID = SKApi.sourcekitd_uid_get_from_cstr("key.usr")!
lazy var attributesId = SKApi.sourcekitd_uid_get_from_cstr("key.attributes")!
lazy var attributeId = SKApi.sourcekitd_uid_get_from_cstr("key.attribute")!

func array(argv: [String]) -> sourcekitd_object_t {
let objects = argv.map { SKApi.sourcekitd_request_string_create($0) }
Expand Down
3 changes: 2 additions & 1 deletion swiftshield-Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ if automatic {
let schemeToBuild = UserDefaults.standard.string(forKey: "automatic-project-scheme") ?? ""
let projectToBuild = UserDefaults.standard.string(forKey: "automatic-project-file") ?? ""
let modulesToIgnore = UserDefaults.standard.string(forKey: "ignore-modules")?.components(separatedBy: ",") ?? []
protector = AutomaticSwiftShield(basePath: basePath, projectToBuild: projectToBuild, schemeToBuild: schemeToBuild, modulesToIgnore: Set(modulesToIgnore), protectedClassNameSize: protectedClassNameSize)
let excludePublic = CommandLine.arguments.contains("-exclude-public")
protector = AutomaticSwiftShield(basePath: basePath, projectToBuild: projectToBuild, schemeToBuild: schemeToBuild, modulesToIgnore: Set(modulesToIgnore), protectedClassNameSize: protectedClassNameSize, excludePublic: excludePublic)
} else {
let tag = UserDefaults.standard.string(forKey: "tag") ?? "__s"
protector = ManualSwiftShield(basePath: basePath, tag: tag, protectedClassNameSize: protectedClassNameSize)
Expand Down