Skip to content

Commit f4e255d

Browse files
committed
Updated dependencies
1 parent 700c17e commit f4e255d

File tree

521 files changed

+17369
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

521 files changed

+17369
-101
lines changed

FileExtractor/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The output data format is called `Files.json` and presented below:
5353
],
5454
"frameworkSearchPaths": [ <string> ],
5555
"headerSearchPaths": [ <string> ],
56+
"configurationFile": <string>,
5657
"bridgingHeader": <string>
5758
}
5859
```
@@ -74,6 +75,8 @@ The output data format is called `Files.json` and presented below:
7475

7576
`headerSearchPaths` contain the list of paths to search for Objective-C headers. It's used by compiler to find the headers imported via the bridging header into Swift.
7677

78+
`configurationFile` is a path to the configuration file for the obfuscation process. It should be named `.obfuscation.yml` and placed under the project's root path.
79+
7780
`bridgingHeader` is a path to the bridging header, which contains the parts imported from Objective-C that should be visible and accesible from Swift.
7881

7982
Sample `Files.json` file might look like that:
@@ -115,8 +118,10 @@ Sample `Files.json` file might look like that:
115118
"headerSearchPaths": [
116119
"/Users/siejkowski/Polidea/SwiftObfuscator/TestProjects/iOS/Original/XcodeSampleProject/Pods/Headers/Public"
117120
],
118-
"bridgingHeader": "/Users/siejkowski/Polidea/SwiftObfuscator/TestProjects/iOS/Original/XcodeSampleProject/Bridging-header.h"
121+
"configurationFile": "/Users/siejkowski/Polidea/SwiftObfuscator/TestProjects/iOS/Original/XcodeSampleProject/.obfuscation.yml"
119122
],
123+
"bridgingHeader": "/Users/siejkowski/Polidea/SwiftObfuscator/TestProjects/iOS/Original/XcodeSampleProject/Bridging-header.h"
124+
]
120125
}
121126
```
122127

FileExtractor/lib/file-extractor/command.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module FileExtractor
33
require 'claide'
44

55
require 'file-extractor/arguments_decorator'
6+
require 'file-extractor/configuration_determiner'
67
require 'file-extractor/data_extractor'
78
require 'file-extractor/dependency_builder'
89
require 'file-extractor/xcodefiles_determiner'
@@ -68,6 +69,7 @@ def run
6869
puts @project_root_path
6970
xcodeprojs, xcworkspaces = FileExtractor::XcodefilesDeterminer.find_xcode_files(@project_root_path)
7071
projects, schemes = FileExtractor::XcworkspaceExtractor.extract_projects_and_dependency_schemes(xcworkspaces, xcodeprojs)
72+
configuration_path = FileExtractor::ConfigurationDeterminer.find_configuration_file(@project_root_path)
7173
if projects.empty?
7274
puts "\n\nNo Xcode project document found in the project root directory"
7375
elsif projects.count == 1
@@ -76,7 +78,7 @@ def run
7678
puts "Path to files:"
7779
puts @files_path
7880

79-
json, output_string, build_dir = FileExtractor::DataExtractor.extract_data(@project_root_path, xcodeprojs.first, @files_path)
81+
json, output_string, build_dir = FileExtractor::DataExtractor.extract_data(@project_root_path, xcodeprojs.first, @files_path, configuration_path)
8082
puts "\nFound data:\n#{json}"
8183
puts "\n#{output_string}"
8284

@@ -87,7 +89,7 @@ def run
8789
puts "Path to files:"
8890
puts @files_path
8991

90-
json, output_string, build_dir = FileExtractor::DataExtractor.extract_data(@project_root_path, xcodeprojs.first, @files_path)
92+
json, output_string, build_dir = FileExtractor::DataExtractor.extract_data(@project_root_path, xcodeprojs.first, @files_path, configuration_path)
9193
puts "\nFound data:\n#{json}"
9294
puts "\n#{output_string}"
9395

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module FileExtractor
2+
3+
require 'find'
4+
5+
class ConfigurationDeterminer
6+
7+
CONFIGURATION_FILES = [".obfuscation.yaml", ".obfuscation.yml", "obfuscation.yaml", "obfuscation.yml"]
8+
9+
def self.find_configuration_file(path)
10+
configuration_path = find_configuration_files(path, CONFIGURATION_FILES).first
11+
if configuration_path.nil?
12+
return ""
13+
end
14+
return configuration_path
15+
end
16+
17+
private
18+
19+
def self.find_configuration_files(path, types)
20+
Find.find(path).select do |path|
21+
types.include?(File.basename(path))
22+
end.each do |path|
23+
File.expand_path(path)
24+
end
25+
end
26+
27+
end
28+
29+
end

FileExtractor/lib/file-extractor/data_extractor.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module FileExtractor
77

88
class DataExtractor
99

10-
def self.extract_data(root_path, project_path, files_path)
11-
data, build_dir = extract_data_from_all_sources(root_path, project_path)
10+
def self.extract_data(root_path, project_path, files_path, configuration_path)
11+
data, build_dir = extract_data_from_all_sources(root_path, project_path, configuration_path)
1212
data_is_ok, error_message = FileExtractor::DataIntegrityChecker.verify_data_integrity(data)
1313
json = JSON.pretty_generate(data)
1414
if data_is_ok
@@ -20,10 +20,11 @@ def self.extract_data(root_path, project_path, files_path)
2020

2121
private
2222

23-
def self.extract_data_from_all_sources(root_path, project_path)
23+
def self.extract_data_from_all_sources(root_path, project_path, configuration_path)
2424
data_extractor = FileExtractor::XcodeprojExtractor.new(root_path, project_path)
2525
data, build_dir = data_extractor.extract_data_and_build_directory
2626
data.implicitlyLinkedFrameworks = FileExtractor::ModulesExtractor.system_linked_frameworks(data)
27+
data.configurationFile = configuration_path
2728
return data, build_dir
2829
end
2930

FileExtractor/lib/file-extractor/files_json_struct.rb

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def to_json(options = {})
3333
:implicitlyLinkedFrameworks,
3434
:frameworkSearchPaths,
3535
:headerSearchPaths,
36+
:configurationFile,
3637
:bridgingHeader) do
3738
include StructSerialization
3839

FileExtractor/lib/file-extractor/xcodeproj_extractor.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ def extract_data_and_build_directory
2424
source_files(@main_target),
2525
layout_files(@main_target),
2626
update_frameworks_paths(explicitly_linked_frameworks(@main_target), @main_build_settings),
27-
nil,
27+
nil, # for implicitely linked frameworks
2828
framework_search_paths(@main_build_settings),
2929
header_search_paths(@main_build_settings),
30+
nil, # for configuration file
3031
bridging_header(@main_build_settings)
3132
), dir
3233
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef ConfigurationExcluder_h
2+
#define ConfigurationExcluder_h
3+
4+
#include "swift/Obfuscation/DataStructures.h"
5+
#include "swift/Obfuscation/Excluder.h"
6+
7+
namespace swift {
8+
namespace obfuscation {
9+
10+
class ConfigurationExcluder: public Excluder {
11+
12+
private:
13+
14+
ObfuscationConfiguration Configuration;
15+
16+
public:
17+
18+
ConfigurationExcluder(ObfuscationConfiguration&&);
19+
20+
void identifyExclusions(Decl *Declaration);
21+
};
22+
23+
24+
} // namespace obfuscation
25+
} // namespace swift
26+
27+
#endif /* ConfigurationExcluder_h */

SymbolExtractorAndRenamer/swift/include/swift/Obfuscation/DataStructures.h

+90
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct FilesJson {
4343
std::vector<std::string> FrameworkSearchPaths;
4444
std::vector<std::string> HeaderSearchPaths;
4545
std::string BridgingHeader;
46+
std::string ConfigurationFile;
4647
};
4748

4849
enum class SymbolType: int {
@@ -107,6 +108,65 @@ struct SymbolRenaming {
107108
struct RenamesJson {
108109
std::vector<SymbolRenaming> Symbols;
109110
};
111+
112+
enum class ExclusionKind: int {
113+
UnknownKind,
114+
115+
Type,
116+
117+
Inheritance,
118+
119+
Conformance
120+
};
121+
122+
struct TypeExclusion;
123+
struct InheritanceExclusion;
124+
struct ConformanceExclusion;
125+
126+
struct Exclusion {
127+
128+
std::string Module;
129+
130+
ExclusionKind Kind;
131+
132+
const TypeExclusion* getAsTypeExclusion() const;
133+
const InheritanceExclusion* getAsInheritanceExclusion() const;
134+
const ConformanceExclusion* getAsConformanceExclusion() const;
135+
};
136+
137+
struct TypeExclusion: public Exclusion {
138+
std::string Name;
139+
140+
TypeExclusion() = default;
141+
TypeExclusion(const TypeExclusion&) = default;
142+
TypeExclusion(TypeExclusion&&) = default;
143+
};
144+
145+
struct InheritanceExclusion: public Exclusion {
146+
std::string Base;
147+
148+
InheritanceExclusion() = default;
149+
InheritanceExclusion(const InheritanceExclusion&) = default;
150+
InheritanceExclusion(InheritanceExclusion&&) = default;
151+
};
152+
153+
struct ConformanceExclusion: public Exclusion {
154+
std::string Protocol;
155+
156+
ConformanceExclusion() = default;
157+
ConformanceExclusion(const ConformanceExclusion&) = default;
158+
ConformanceExclusion(ConformanceExclusion&&) = default;
159+
};
160+
161+
struct ObfuscationConfiguration {
162+
std::vector<std::unique_ptr<Exclusion>> Exclude;
163+
164+
ObfuscationConfiguration() = default;
165+
ObfuscationConfiguration(const ObfuscationConfiguration&) = delete;
166+
ObfuscationConfiguration(ObfuscationConfiguration&&) = default;
167+
ObfuscationConfiguration& operator=(const ObfuscationConfiguration &) = delete;
168+
ObfuscationConfiguration& operator=(ObfuscationConfiguration &&) = default;
169+
};
110170

111171
/// SymbolWithRange - struct for linking the symbol identified in the Swift
112172
/// source code with the range in which it was encountered.
@@ -214,6 +274,36 @@ struct MappingTraits<SymbolRenaming> {
214274
static void mapping(IO &Io, SymbolRenaming &Object);
215275
};
216276

277+
template <>
278+
struct MappingTraits<ObfuscationConfiguration> {
279+
static void mapping(IO &Io, ObfuscationConfiguration &Object);
280+
};
281+
282+
template <>
283+
struct ScalarEnumerationTraits<ExclusionKind> {
284+
static void enumeration(IO &Io, ExclusionKind &Enum);
285+
};
286+
287+
template <>
288+
struct MappingTraits<std::unique_ptr<Exclusion>> {
289+
static void mapping(IO &Io, std::unique_ptr<Exclusion> &Object);
290+
};
291+
292+
template <>
293+
struct MappingTraits<TypeExclusion> {
294+
static void mapping(IO &Io, TypeExclusion &Object);
295+
};
296+
297+
template <>
298+
struct MappingTraits<InheritanceExclusion> {
299+
static void mapping(IO &Io, InheritanceExclusion &Object);
300+
};
301+
302+
template <>
303+
struct MappingTraits<ConformanceExclusion> {
304+
static void mapping(IO &Io, ConformanceExclusion &Object);
305+
};
306+
217307
template <typename U>
218308
struct SequenceTraits<std::vector<U>> {
219309
static size_t size(IO &Io, std::vector<U> &Vec);

SymbolExtractorAndRenamer/swift/include/swift/Obfuscation/NameMapping.h

+19-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ namespace swift {
1414
namespace obfuscation {
1515

1616
/// Name mapping strategies:
17-
/// - random generates unique random identifiers
18-
/// - deterministic generates predictible identifiers, we use it in tests
17+
/// - Random generates unique random identifiers
18+
/// - Deterministic generates predictible identifiers, we use it in tests
19+
/// - Minifying generates shortes possible names
1920
enum NameMappingStrategy {
20-
random, deterministic
21+
Random, Deterministic, Minifying
2122
};
2223

2324
/// Base class for names generators.
@@ -47,6 +48,21 @@ class BaseIdentifierGenerator {
4748
{ SymbolType::Variable, {} },
4849
{ SymbolType::Operator, {} }
4950
};
51+
52+
// taken from https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html
53+
std::set<std::string> SwiftKeywords = {
54+
"associatedtype", "class", "deinit", "enum", "extension", "fileprivate",
55+
"func", "import", "init", "inout", "internal", "let", "open", "operator",
56+
"private", "protocol", "public", "static", "struct", "subscript",
57+
"typealias", "var", "break", "case", "continue", "default", "defer", "do",
58+
"else", "fallthrough", "for", "guard", "if", "in", "repeat", "return",
59+
"switch", "where", "while", "as", "Any", "catch", "false", "is", "nil",
60+
"rethrows", "super", "self", "Self", "throw", "throws", "true", "try",
61+
"associativity", "convenience", "dynamic", "didSet", "final", "get", "infix",
62+
"indirect", "lazy", "left", "mutating", "none", "nonmutating", "optional",
63+
"override", "postfix", "precedence", "prefix", "Protocol", "required",
64+
"right", "set", "Type", "unowned", "weak", "willSet"
65+
};
5066

5167
static std::vector<std::string>
5268
concatenateSymbols(const std::vector<std::string> &Head,

SymbolExtractorAndRenamer/swift/include/swift/Obfuscation/Renaming.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ using FilesList = std::vector<std::pair<std::string, std::string>>;
5252
/// \param DiagnosticStream Stream for writing the diagnostic information into.
5353
///
5454
/// \returns List of project files that were affected by the renaming.
55-
llvm::Expected<FilesList> performRenaming(std::string MainExecutablePath,
56-
const FilesJson &FilesJson,
57-
const RenamesJson &RenamesJson,
58-
std::string ObfuscatedProjectPath,
59-
llvm::raw_ostream &DiagnosticStream);
55+
llvm::Expected<FilesList>
56+
performRenaming(std::string MainExecutablePath,
57+
const FilesJson &FilesJson,
58+
ObfuscationConfiguration &&ObfuscationConfiguration,
59+
const RenamesJson &RenamesJson,
60+
std::string ObfuscatedProjectPath,
61+
llvm::raw_ostream &DiagnosticStream);
6062

6163
} //namespace obfuscation
6264
} //namespace swift

SymbolExtractorAndRenamer/swift/lib/Obfuscation/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
44

55
add_swift_library(swiftObfuscation STATIC
66
CompilerInfrastructure.cpp
7+
ConfigurationExcluder.cpp
78
DataStructures.cpp
89
DeclarationParser.cpp
910
OperatorParser.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "swift/Obfuscation/ConfigurationExcluder.h"
2+
3+
namespace swift {
4+
namespace obfuscation {
5+
6+
ConfigurationExcluder::
7+
ConfigurationExcluder(ObfuscationConfiguration&& Configuration)
8+
: Configuration(std::move(Configuration)) {
9+
10+
// TODO: remove when there's logic added to identifyExclusions method
11+
for (auto &Exclusion : this->Configuration.Exclude) {
12+
switch (Exclusion->Kind) {
13+
case ExclusionKind::Type: {
14+
auto Type = Exclusion->getAsTypeExclusion();
15+
llvm::outs() << Type->Name << '\n';
16+
break;
17+
}
18+
case ExclusionKind::Inheritance: {
19+
auto Type = Exclusion->getAsInheritanceExclusion();
20+
llvm::outs() << Type->Base << '\n';
21+
break;
22+
}
23+
case ExclusionKind::Conformance: {
24+
auto Type = Exclusion->getAsConformanceExclusion();
25+
llvm::outs() << Type->Protocol << '\n';
26+
break;
27+
}
28+
}
29+
}
30+
31+
}
32+
33+
void ConfigurationExcluder::identifyExclusions(Decl *Declaration) {
34+
35+
}
36+
37+
} // namespace obfuscation
38+
} // namespace swift

0 commit comments

Comments
 (0)