Skip to content

Commit

Permalink
Bump Swift tools version to 5.9
Browse files Browse the repository at this point in the history
Includes:
 - Upgraded `swift-syntax` dependency to version 509.1.1;
 - Updated README and CI workflow configuration to align with the new
   minimum Swift version.
  • Loading branch information
mgutski committed Oct 2, 2024
1 parent a81e081 commit 1b3268b
Show file tree
Hide file tree
Showing 33 changed files with 455 additions and 633 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ jobs:
strategy:
matrix:
include:
- macos: 13
xcode: '14.2' # Swift 5.7
upload_coverage: false
- macos: 14
xcode: '14.3.1' # Swift 5.8
upload_coverage: false
- macos: 14
xcode: '15.2' # Swift 5.9
upload_coverage: false
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "72d3da66b085c2299dd287c2be3b92b5ebd226de",
"version" : "0.50700.1"
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 5.9

import PackageDescription

Expand Down Expand Up @@ -33,7 +33,7 @@ var package = Package(
#if os(macOS)
package.dependencies.append(contentsOf: [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.3"),
.package(url: "https://github.com/apple/swift-syntax.git", exact: "0.50700.1"),
.package(url: "https://github.com/apple/swift-syntax.git", exact: "509.1.1"),
.package(url: "https://github.com/pointfreeco/swift-parsing.git", from: "0.13.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.6")
])
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/securevale/swift-confidential/actions/workflows/ci.yml/badge.svg)](https://github.com/securevale/swift-confidential/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/securevale/swift-confidential/branch/master/graph/badge.svg)](https://codecov.io/gh/securevale/swift-confidential)
[![Swift](https://img.shields.io/badge/Swift-5.10%20%7C%205.9%20%7C%205.8%20%7C%205.7-red)](https://www.swift.org/download)
[![Swift](https://img.shields.io/badge/Swift-5.10%20%7C%205.9-red)](https://www.swift.org/download)
[![Platforms](https://img.shields.io/badge/Platforms-iOS%20%7C%20macOS%20%7C%20visionOS%20%7C%20watchOS%20%7C%20tvOS-red)]()

A highly configurable and performant tool for obfuscating Swift literals embedded in the application code that you should protect from static code analysis, making the app more resistant to reverse engineering.
Expand Down Expand Up @@ -107,7 +107,7 @@ Swift Confidential can be used with both SwiftPM and Xcode targets, depending on
To use Swift Confidential with your SwiftPM target, add the `ConfidentialKit` library along with `Confidential` plugin to the package's dependencies and then to your target's dependencies and plugins respectively:

```swift
// swift-tools-version: 5.7
// swift-tools-version: 5.9

import PackageDescription

Expand Down
4 changes: 2 additions & 2 deletions Scripts/generate_release_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ readonly OPTION_HELP="--help"
readonly PRODUCT_SWIFT_CONFIDENTIAL="swift-confidential"

readonly SWIFT_BUILD_ARCH_X86="x86_64"
readonly SWIFT_BUILD_ARCH_ARM="arm64"
readonly SWIFT_BUILD_ARCH_ARM="arm64"
readonly SWIFT_BUILD_DIR_NAME=".build"

readonly UNIVERSAL_BIN_DIR_ABS_PATH="$SCRIPT_ABS_PATH/../$SWIFT_BUILD_DIR_NAME/universal"
Expand Down Expand Up @@ -79,7 +79,7 @@ ${BOLD}DEPENDENCIES${NORMAL}
${BOLD}macOS 12 or newer${NORMAL} - the script uses optimization options that are not
available on older systems.
${BOLD}Bash 4.2 or newer${NORMAL} - you can upgrade Bash with ${UNDERLINE}upgrade_bash.sh${NORMAL} script.
${BOLD}Swift 5.6${NORMAL} - Swift toolchain comes bundled with Xcode.
${BOLD}Swift 5.9${NORMAL} - Swift toolchain comes bundled with Xcode.
Make sure that all dependencies are installed before you start using the script.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,34 @@ import SwiftSyntax

extension TokenSyntax {

static func atSign(
static func atSignToken(
leadingNewlines: Int,
followedByLeadingSpaces leadingSpaces: Int = C.Code.Format.indentWidth
) -> Self {
makeToken(
.atSign.withoutTrivia(),
.atSignToken(),
withLeadingNewlines: leadingNewlines,
followedByLeadingSpaces: leadingSpaces
)
}

static func period(
static func periodToken(
leadingNewlines: Int,
followedByLeadingSpaces leadingSpaces: Int = C.Code.Format.indentWidth
) -> Self {
makeToken(
.period.withoutTrivia(),
.periodToken(),
withLeadingNewlines: leadingNewlines,
followedByLeadingSpaces: leadingSpaces
)
}

static func rightParen(
static func rightParenToken(
leadingNewlines: Int,
followedByLeadingSpaces leadingSpaces: Int = C.Code.Format.indentWidth
) -> Self {
makeToken(
.rightParen.withoutTrivia(),
withLeadingNewlines: leadingNewlines,
followedByLeadingSpaces: leadingSpaces
)
}

static func `private`(
leadingNewlines: Int,
followedByLeadingSpaces leadingSpaces: Int = C.Code.Format.indentWidth,
trailingSpaces: Int = 1
) -> Self {
makeToken(
.private.withoutTrivia().withTrailingTrivia(.spaces(trailingSpaces)),
.rightParenToken(),
withLeadingNewlines: leadingNewlines,
followedByLeadingSpaces: leadingSpaces
)
Expand All @@ -59,9 +47,10 @@ private extension TokenSyntax {
return token
}

return token.withLeadingTrivia(
return token.with(
\.leadingTrivia,
.newlines(leadingNewlines)
.appending(.spaces(leadingSpaces))
.appending(Trivia.spaces(leadingSpaces))
)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Parsing
import SwiftSyntaxBuilder
import SwiftSyntax

struct DeobfuscateDataFunctionDeclParser: Parser {

typealias Algorithm = SourceSpecification.Algorithm

private let functionNestingLevel: UInt8
private let functionNestingLevel: Int

init(functionNestingLevel: UInt8) {
init(functionNestingLevel: Int) {
self.functionNestingLevel = functionNestingLevel
}

func parse(_ input: inout Algorithm) throws -> ExpressibleAsMemberDeclListItem {
func parse(_ input: inout Algorithm) throws -> any DeclSyntaxProtocol {
var obfuscationStepsCount = input.count
guard obfuscationStepsCount > .zero else {
throw ParsingError.assertionFailed(
Expand All @@ -37,8 +37,8 @@ struct DeobfuscateDataFunctionDeclParser: Parser {

input.removeAll()

return DeobfuscateDataFunctionDecl(
declNestingLevel: functionNestingLevel,
return FunctionDeclSyntax.makeDeobfuscateDataDecl(
nestingLevel: functionNestingLevel,
body: bodyExpr
)
}
Expand All @@ -53,87 +53,96 @@ private extension DeobfuscateDataFunctionDeclParser {
func obfuscationStepExpr(
for obfuscationStep: ObfuscationStep,
indentWidthMultiplier: Int
) throws -> ExpressibleAsExprBuildable {
) throws -> any ExprSyntaxProtocol {
let tryIndentWidth = try exprIndentWidth(with: indentWidthMultiplier)
let functionCallExprIndentWidth = tryIndentWidth + C.Code.Format.indentWidth
return TryExpr(
tryKeyword: .try.withLeadingTrivia(.spaces(tryIndentWidth)),
expression: FunctionCallExpr(
return TryExprSyntax(
tryKeyword: .keyword(.try, leadingTrivia: .spaces(tryIndentWidth)),
expression: FunctionCallExprSyntax(
calledExpression: deobfuscateFunctionAccessExpr(
for: obfuscationStep.technique,
indentWidth: functionCallExprIndentWidth
),
leftParen: .leftParen,
rightParen: .rightParen,
argumentListBuilder: {
TupleExprElement(
expression: IdentifierExpr(C.Code.Generation.deobfuscateDataFuncDataParamName),
trailingComma: .comma
leftParen: .leftParenToken(),
arguments: .init {
LabeledExprSyntax(
expression: DeclReferenceExprSyntax(
baseName: .identifier(C.Code.Generation.deobfuscateDataFuncDataParamName)
),
trailingComma: .commaToken()
)
TupleExprElement(
LabeledExprSyntax(
label: .identifier(Self.nonceArgumentName),
colon: .colon,
expression: IdentifierExpr(C.Code.Generation.deobfuscateDataFuncNonceParamName)
colon: .colonToken(),
expression: DeclReferenceExprSyntax(
baseName: .identifier(C.Code.Generation.deobfuscateDataFuncNonceParamName)
)
)
}
},
rightParen: .rightParenToken()
)
)
}

func obfuscationStepExpr(
for obfuscationStep: ObfuscationStep,
withInnerExpr innerExpr: ExpressibleAsExprBuildable,
withInnerExpr innerExpr: any ExprSyntaxProtocol,
indentWidthMultiplier: Int
) throws -> ExpressibleAsExprBuildable {
) throws -> any ExprSyntaxProtocol {
let tryIndentWidth = try exprIndentWidth(with: indentWidthMultiplier)
let functionCallExprIndentWidth = tryIndentWidth + C.Code.Format.indentWidth
let functionCallExprArgumentIndentWidth = functionCallExprIndentWidth + C.Code.Format.indentWidth
return TryExpr(
tryKeyword: .try.withLeadingTrivia(.spaces(tryIndentWidth)),
expression: FunctionCallExpr(
return TryExprSyntax(
tryKeyword: .keyword(.try, leadingTrivia: .spaces(tryIndentWidth)),
expression: FunctionCallExprSyntax(
calledExpression: deobfuscateFunctionAccessExpr(
for: obfuscationStep.technique,
indentWidth: functionCallExprIndentWidth
),
leftParen: .leftParen.withTrailingTrivia(.newlines(1)),
rightParen: .rightParen(
leadingNewlines: 1,
followedByLeadingSpaces: functionCallExprIndentWidth
),
argumentListBuilder: {
TupleExprElement(
leftParen: .leftParenToken(trailingTrivia: .newlines(1)),
arguments: .init {
LabeledExprSyntax(
expression: innerExpr,
trailingComma: .comma.withoutTrivia()
trailingComma: .commaToken()
)
TupleExprElement(
LabeledExprSyntax(
label: .identifier(Self.nonceArgumentName)
.withLeadingTrivia(
.newlines(1)
.appending(.spaces(functionCallExprArgumentIndentWidth))
.with(
\.leadingTrivia,
.newlines(1).appending(Trivia.spaces(functionCallExprArgumentIndentWidth))
),
colon: .colon,
expression: IdentifierExpr(C.Code.Generation.deobfuscateDataFuncNonceParamName)
colon: .colonToken(),
expression: DeclReferenceExprSyntax(
baseName: .identifier(C.Code.Generation.deobfuscateDataFuncNonceParamName)
)
)
}
},
rightParen: .rightParenToken(
leadingNewlines: 1,
followedByLeadingSpaces: functionCallExprIndentWidth
)
)
)
}

func deobfuscateFunctionAccessExpr(
for technique: ObfuscationStep.Technique,
indentWidth: Int
) -> ExpressibleAsExprBuildable {
let initCallExpr: ExpressibleAsExprBuildable
) -> any ExprSyntaxProtocol {
let initCallExpr: any ExprSyntaxProtocol
switch technique {
case let .compression(algorithm):
initCallExpr = DataCompressorInitializerCallExpr(compressionAlgorithm: algorithm)
initCallExpr = FunctionCallExprSyntax.makeDataCompressorInitializerCallExpr(algorithm: algorithm)
case let .encryption(algorithm):
initCallExpr = DataCrypterInitializerCallExpr(encryptionAlgorithm: algorithm)
initCallExpr = FunctionCallExprSyntax.makeDataCrypterInitializerCallExpr(algorithm: algorithm)
case .randomization:
initCallExpr = DataShufflerInitializerCallExpr()
initCallExpr = FunctionCallExprSyntax.makeDataShufflerInitializerCallExpr()
}

return DeobfuscateFunctionAccessExpr(initCallExpr, dotIndentWidth: indentWidth)
return MemberAccessExprSyntax.makeDeobfuscateFunctionAccessExpr(
initCallExpr,
dotIndentWidth: indentWidth
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Parsing
import SwiftSyntax
import SwiftSyntaxBuilder

struct ImportDeclParser: Parser {

func parse(_ input: inout SourceSpecification) throws -> [ExpressibleAsCodeBlockItem] {
func parse(_ input: inout SourceSpecification) throws -> [CodeBlockItemSyntax] {
guard
!input.implementationOnlyImport || canUseImplementationOnlyImport(given: input.secrets)
else {
Expand All @@ -22,6 +21,9 @@ struct ImportDeclParser: Parser {
from: input.secrets.namespaces,
implementationOnly: input.implementationOnlyImport
)
.map {
.init(item: .init($0))
}
}
}

Expand All @@ -37,7 +39,7 @@ private extension ImportDeclParser {
func makeImportDeclStatements<Namespaces: Collection>(
from namespaces: Namespaces,
implementationOnly: Bool
) -> [ExpressibleAsImportDecl]
) -> [ImportDeclSyntax]
where
Namespaces.Element == SourceSpecification.Secret.Namespace
{
Expand Down Expand Up @@ -73,25 +75,19 @@ private extension ImportDeclParser {
func makeImportDeclStatements(
implementationOnlyModuleNames: [String],
moduleNames: [String]
) -> [ExpressibleAsImportDecl] {
) -> [ImportDeclSyntax] {
let implementationOnlyImports = implementationOnlyModuleNames
.map { moduleName in
ImportDecl(
importTok: .import.withLeadingTrivia(.spaces(1)),
attributesBuilder: {
ImplementationOnlyAttribute()
},
pathBuilder: {
AccessPathComponent(name: .identifier(moduleName))
}
ImportDeclSyntax(
attributes: [.attribute(._implementationOnly)],
importKeyword: .keyword(.import, leadingTrivia: .spaces(1)),
path: [ImportPathComponentSyntax(name: .identifier(moduleName))]
)
}
let imports = moduleNames
.map { moduleName in
ImportDecl(
pathBuilder: {
AccessPathComponent(name: .identifier(moduleName))
}
ImportDeclSyntax(
path: [ImportPathComponentSyntax(name: .identifier(moduleName))]
)
}

Expand Down
Loading

0 comments on commit 1b3268b

Please sign in to comment.