Skip to content

Commit

Permalink
Exclude public
Browse files Browse the repository at this point in the history
  • Loading branch information
vrujbr committed Nov 12, 2018
1 parent 04e067e commit be459da
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
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 attribtuesArray = dict.getDictionaryValue(key: sourceKit.attributesId)
if attribtuesArray.isArray {
let count = attribtuesArray.getArrayCount()
for i in 0..<count {
let attributeDict = attribtuesArray.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

0 comments on commit be459da

Please sign in to comment.