Skip to content

Commit 672f7f5

Browse files
authored
Merge pull request #90 from hwdavr/enum-support
Revert "Code optimisation by removing suffix of USR"
2 parents c161764 + 1a27574 commit 672f7f5

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

swiftshield-Sources/AutomaticSwiftShield.swift

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,6 @@ class AutomaticSwiftShield: Protector {
8181
}
8282
let name = data.name
8383
let usr = data.usr
84-
let kind = data.kind
85-
86-
if let type = self.sourceKit.referenceType(kind: kind), type == .enum && name.hasSuffix("CodingKeys") {
87-
obfuscationData.excludedEnums.insert(self.usrWithoutSuffix(usr))
88-
return
89-
}
90-
9184
obfuscationData.usrDict.insert(usr)
9285
if dict.getString(.receiverId) == nil {
9386
obfuscationData.usrRelationDict[usr] = variant
@@ -137,8 +130,7 @@ extension AutomaticSwiftShield {
137130
private func getNameData(from dict: SourceKitdResponse.Dictionary,
138131
obfuscationData: ObfuscationData) -> (name: String,
139132
usr: String,
140-
obfuscatedName: String,
141-
kind: String)? {
133+
obfuscatedName: String)? {
142134
let kind = dict.getUID(.kindId).asString
143135
guard sourceKit.declarationType(for: kind) != nil else {
144136
return nil
@@ -150,18 +142,9 @@ extension AutomaticSwiftShield {
150142
guard let protected = obfuscationData.obfuscationDict[name] else {
151143
let newName = String.random(length: self.protectedClassNameSize, excluding: obfuscationData.allObfuscatedNames)
152144
obfuscationData.obfuscationDict[name] = newName
153-
return (name, usr, newName, kind)
145+
return (name, usr, newName)
154146
}
155-
return (name, usr, protected, kind)
156-
}
157-
158-
private func usrWithoutSuffix(_ usr: String) -> String {
159-
let lastIndex = usr.lastIndex(of: "_")
160-
if let index = lastIndex {
161-
let usrPrefix = usr[..<index]
162-
return String(usrPrefix)
163-
}
164-
return usr
147+
return (name, usr, protected)
165148
}
166149

167150
func findReferencesInIndexed(obfuscationData: AutomaticObfuscationData) {
@@ -182,11 +165,17 @@ extension AutomaticSwiftShield {
182165
return
183166
}
184167

168+
if type == .enum && name.hasSuffix("CodingKeys") {
169+
obfuscationData.excludedEnums.insert(usr)
170+
return
171+
}
185172

186173
if type == .enumelement {
187-
let usrPrefix = self.usrWithoutSuffix(usr)
188-
if obfuscationData.excludedEnums.contains(usrPrefix) {
189-
return
174+
for exclusion in obfuscationData.excludedEnums {
175+
// Enum element belongs to excluded enum
176+
if usr.hasPrefix(exclusion) {
177+
return
178+
}
190179
}
191180
}
192181

0 commit comments

Comments
 (0)