Skip to content

Commit

Permalink
Project files
Browse files Browse the repository at this point in the history
  • Loading branch information
matrejek committed Mar 29, 2020
1 parent 5e846a8 commit b48bd00
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

# Created by https://www.gitignore.io/api/xcode,swift,swiftpm,swiftpackagemanager
# Edit at https://www.gitignore.io/?templates=xcode,swift,swiftpm,swiftpackagemanager

### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
.build/
# Add this line if you want to avoid checking in Xcode SPM integration.
# .swiftpm/xcode

# CocoaPods
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# Accio dependency management
Dependencies/
.accio/

# fastlane
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

### SwiftPackageManager ###
Packages
xcuserdata
*.xcodeproj


### SwiftPM ###


### Xcode ###
# Xcode
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)

## Xcode Patch
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno

### Xcode Patch ###
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.gitignore.io/api/xcode,swift,swiftpm,swiftpackagemanager
13 changes: 13 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SwiftEntitlements",
products: [ .library( name: "SwiftEntitlements", targets: ["SwiftEntitlements"])],
dependencies: [],
targets: [ .target( name: "SwiftEntitlements", dependencies: []),
.testTarget(name: "SwiftEntitlementsTests", dependencies: ["SwiftEntitlements"]),
]
)
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 👨🏻‍💻 SwiftEntitlements

📱 This is a simple Swift utility package that reads application entitlements for you.

## Features

✅ Reading entitlements from iOS Application binary

### Note
⚠️ The library currently does not support reading entitlements from fat Mach-O file. If that is your use-case - please let me know.

## Usage

Library exposes ``entitlements`` property on UIApplication instances.

```
public extension UIApplication {
public var entitlements: Entitlements { get }
}
```
Library provides a set of predefines keys for most common entitlements keys as described in [Apple docs](https://developer.apple.com/documentation/bundleresources/entitlements). Please see ```Entitlements.Keys``` to check available options.

Instance of Entitlements class exposes simple API for getting values
```
let value = UIApplication.shared.entitlements.value(forKey: .apsEnvironment) as? String
```
If the required key is not present - it could be easily defined.
```
let myAwesomeKey = Entitlements.Key("some.awesome.key")
let value = UIApplication.shared.entitlements.value(forKey: myAwesomeKey)
```

## Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method. I am open for changes, fixes and suggestions.

## License

SwiftEntitlements is released under the MIT license. See LICENSE for details.
35 changes: 35 additions & 0 deletions Sources/SwiftEntitlements/ApplicationBinary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by Mateusz Matrejek
//

import Foundation

class ApplicationBinary {

private let handle: FileHandle

init?(_ path: String) {
guard let binaryHandle = FileHandle(forReadingAtPath: path) else {
return nil
}
handle = binaryHandle
}

var currentOffset: UInt64 { handle.offsetInFile }

func seek(to offset: UInt64) {
handle.seek(toFileOffset: offset)
}

func read<T>() -> T {
handle.readData(ofLength: MemoryLayout<T>.size).withUnsafeBytes( { $0.load(as: T.self) })
}

func readData(ofLength length: Int) -> Data {
handle.readData(ofLength: length)
}

deinit {
handle.closeFile()
}
}
69 changes: 69 additions & 0 deletions Sources/SwiftEntitlements/Entitlements.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// Created by Mateusz Matrejek
//

import Foundation

public class Entitlements {

public struct Key {

let rawKey: String

public init(_ name: String) {
self.rawKey = name
}

public static let autofillCredentialProvider = Key("com.apple.developer.authentication-services.autofill-credential-provider")
public static let signWithApple = Key("com.apple.developer.applesignin")
public static let contacts = Key("com.apple.developer.contacts.notes")
public static let classKit = Key("com.apple.developer.ClassKit-environment")
public static let automaticAssesmentConfiguration = Key("com.apple.developer.automatic-assessment-configuration")
public static let gameCenter = Key("com.apple.developer.game-center")
public static let healthKit = Key("com.apple.developer.healthkit")
public static let healthKitCapabilities = Key("com.apple.developer.healthkit.access")
public static let homeKit = Key("com.apple.developer.homekit")
public static let iCloudDevelopmentContainersIdentifiers = Key("com.apple.developer.icloud-container-development-container-identifiers")
public static let iCloudContainersEnvironment = Key("com.apple.developer.icloud-container-environment")
public static let iCloudContainerIdentifiers = Key("com.apple.developer.icloud-container-identifiers")
public static let iCloudServices = Key("com.apple.developer.icloud-services")
public static let iCloudKeyValueStore = Key("com.apple.developer.ubiquity-kvstore-identifier")
public static let interAppAudio = Key("inter-app-audio")
public static let networkExtensions = Key("com.apple.developer.networking.networkextension")
public static let personalVPN = Key("com.apple.developer.networking.vpn.api")
public static let apsEnvironment = Key("aps-environment")
public static let appGroups = Key("com.apple.security.application-groups")
public static let keychainAccessGroups = Key("keychain-access-groups")
public static let dataProtection = Key("com.apple.developer.default-data-protection")
public static let siri = Key("com.apple.developer.siri")
public static let passTypeIDs = Key("com.apple.developer.pass-type-identifiers")
public static let merchantIDs = Key("com.apple.developer.in-app-payments")
public static let wifiInfo = Key("com.apple.developer.networking.wifi-info")
public static let externalAccessoryConfiguration = Key("com.apple.external-accessory.wireless-configuration")
public static let multipath = Key("com.apple.developer.networking.multipath")
public static let hotspotConfiguration = Key("com.apple.developer.networking.HotspotConfiguration")
public static let nfcTagReaderSessionFormats = Key("com.apple.developer.nfc.readersession.formats")
public static let associatedDomains = Key("com.apple.developer.associated-domains")
public static let maps = Key("com.apple.developer.maps")
public static let driverKit = Key("com.apple.developer.driverkit.transport.pci")
}

static let empty: Entitlements = Entitlements([:])

private let values: [String: Any]

init(_ values: [String: Any]) {
self.values = values
}

public func value(forKey key: Entitlements.Key) -> Any? {
values[key.rawKey]
}

class func entitlements(from data: Data) -> Entitlements {
guard let rawValues = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String: Any] else {
return .empty
}
return Entitlements(rawValues)
}
}
Loading

0 comments on commit b48bd00

Please sign in to comment.