This commit is contained in:
anlicheng 2025-05-12 16:24:10 +08:00
parent f5701689c2
commit 61b6794a0c
5 changed files with 245 additions and 0 deletions

13
Tun/Info.plist Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.networkextension.packet-tunnel</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).PacketTunnelProvider</string>
</dict>
</dict>
</plist>

View File

@ -0,0 +1,36 @@
//
// PacketTunnelProvider.swift
// Tun
//
// Created by on 2025/5/12.
//
import NetworkExtension
class PacketTunnelProvider: NEPacketTunnelProvider {
override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) {
// Add code here to start the process of connecting the tunnel.
}
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
// Add code here to start the process of stopping the tunnel.
completionHandler()
}
override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) {
// Add code here to handle the message.
if let handler = completionHandler {
handler(messageData)
}
}
override func sleep(completionHandler: @escaping () -> Void) {
// Add code here to get ready to sleep.
completionHandler()
}
override func wake() {
// Add code here to wake up.
}
}

18
Tun/Tun.entitlements Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.networking.networkextension</key>
<array>
<string>packet-tunnel-provider</string>
<string>app-proxy-provider</string>
<string>content-filter-provider</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>

View File

@ -6,6 +6,11 @@
objectVersion = 77;
objects = {
/* Begin PBXBuildFile section */
C8A77F2A2DD1E77B00195617 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8A77F292DD1E77B00195617 /* NetworkExtension.framework */; };
C8A77F322DD1E77B00195617 /* Tun.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = C8A77F272DD1E77B00195617 /* Tun.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
C8A77F072DD1E6D100195617 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
@ -21,14 +26,47 @@
remoteGlobalIDString = C8A77EF22DD1E6D000195617;
remoteInfo = punchnet;
};
C8A77F302DD1E77B00195617 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C8A77EEB2DD1E6D000195617 /* Project object */;
proxyType = 1;
remoteGlobalIDString = C8A77F262DD1E77B00195617;
remoteInfo = Tun;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
C8A77F372DD1E77B00195617 /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
C8A77F322DD1E77B00195617 /* Tun.appex in Embed Foundation Extensions */,
);
name = "Embed Foundation Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
C8A77EF32DD1E6D000195617 /* punchnet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = punchnet.app; sourceTree = BUILT_PRODUCTS_DIR; };
C8A77F062DD1E6D100195617 /* punchnetTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = punchnetTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C8A77F102DD1E6D100195617 /* punchnetUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = punchnetUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C8A77F272DD1E77B00195617 /* Tun.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = Tun.appex; sourceTree = BUILT_PRODUCTS_DIR; };
C8A77F292DD1E77B00195617 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
C8A77F332DD1E77B00195617 /* Exceptions for "Tun" folder in "Tun" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
);
target = C8A77F262DD1E77B00195617 /* Tun */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
C8A77EF52DD1E6D000195617 /* punchnet */ = {
isa = PBXFileSystemSynchronizedRootGroup;
@ -45,6 +83,14 @@
path = punchnetUITests;
sourceTree = "<group>";
};
C8A77F2B2DD1E77B00195617 /* Tun */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
C8A77F332DD1E77B00195617 /* Exceptions for "Tun" folder in "Tun" target */,
);
path = Tun;
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
@ -69,6 +115,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
C8A77F242DD1E77B00195617 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
C8A77F2A2DD1E77B00195617 /* NetworkExtension.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
@ -78,6 +132,8 @@
C8A77EF52DD1E6D000195617 /* punchnet */,
C8A77F092DD1E6D100195617 /* punchnetTests */,
C8A77F132DD1E6D100195617 /* punchnetUITests */,
C8A77F2B2DD1E77B00195617 /* Tun */,
C8A77F282DD1E77B00195617 /* Frameworks */,
C8A77EF42DD1E6D000195617 /* Products */,
);
sourceTree = "<group>";
@ -88,10 +144,19 @@
C8A77EF32DD1E6D000195617 /* punchnet.app */,
C8A77F062DD1E6D100195617 /* punchnetTests.xctest */,
C8A77F102DD1E6D100195617 /* punchnetUITests.xctest */,
C8A77F272DD1E77B00195617 /* Tun.appex */,
);
name = Products;
sourceTree = "<group>";
};
C8A77F282DD1E77B00195617 /* Frameworks */ = {
isa = PBXGroup;
children = (
C8A77F292DD1E77B00195617 /* NetworkExtension.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -102,10 +167,12 @@
C8A77EEF2DD1E6D000195617 /* Sources */,
C8A77EF02DD1E6D000195617 /* Frameworks */,
C8A77EF12DD1E6D000195617 /* Resources */,
C8A77F372DD1E77B00195617 /* Embed Foundation Extensions */,
);
buildRules = (
);
dependencies = (
C8A77F312DD1E77B00195617 /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
C8A77EF52DD1E6D000195617 /* punchnet */,
@ -163,6 +230,28 @@
productReference = C8A77F102DD1E6D100195617 /* punchnetUITests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
};
C8A77F262DD1E77B00195617 /* Tun */ = {
isa = PBXNativeTarget;
buildConfigurationList = C8A77F342DD1E77B00195617 /* Build configuration list for PBXNativeTarget "Tun" */;
buildPhases = (
C8A77F232DD1E77B00195617 /* Sources */,
C8A77F242DD1E77B00195617 /* Frameworks */,
C8A77F252DD1E77B00195617 /* Resources */,
);
buildRules = (
);
dependencies = (
);
fileSystemSynchronizedGroups = (
C8A77F2B2DD1E77B00195617 /* Tun */,
);
name = Tun;
packageProductDependencies = (
);
productName = Tun;
productReference = C8A77F272DD1E77B00195617 /* Tun.appex */;
productType = "com.apple.product-type.app-extension";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@ -184,6 +273,9 @@
CreatedOnToolsVersion = 16.2;
TestTargetID = C8A77EF22DD1E6D000195617;
};
C8A77F262DD1E77B00195617 = {
CreatedOnToolsVersion = 16.2;
};
};
};
buildConfigurationList = C8A77EEE2DD1E6D000195617 /* Build configuration list for PBXProject "punchnet" */;
@ -203,6 +295,7 @@
C8A77EF22DD1E6D000195617 /* punchnet */,
C8A77F052DD1E6D100195617 /* punchnetTests */,
C8A77F0F2DD1E6D100195617 /* punchnetUITests */,
C8A77F262DD1E77B00195617 /* Tun */,
);
};
/* End PBXProject section */
@ -229,6 +322,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
C8A77F252DD1E77B00195617 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@ -253,6 +353,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
C8A77F232DD1E77B00195617 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
@ -266,6 +373,11 @@
target = C8A77EF22DD1E6D000195617 /* punchnet */;
targetProxy = C8A77F112DD1E6D100195617 /* PBXContainerItemProxy */;
};
C8A77F312DD1E77B00195617 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C8A77F262DD1E77B00195617 /* Tun */;
targetProxy = C8A77F302DD1E77B00195617 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
@ -511,6 +623,58 @@
};
name = Release;
};
C8A77F352DD1E77B00195617 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = Tun/Tun.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = PF3QG837XS;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Tun/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Tun;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnet.Tun;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
C8A77F362DD1E77B00195617 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = Tun/Tun.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = PF3QG837XS;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Tun/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Tun;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.jihe.punchnet.Tun;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@ -550,6 +714,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C8A77F342DD1E77B00195617 /* Build configuration list for PBXNativeTarget "Tun" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C8A77F352DD1E77B00195617 /* Debug */,
C8A77F362DD1E77B00195617 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = C8A77EEB2DD1E6D000195617 /* Project object */;

View File

@ -4,6 +4,11 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>Tun.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>punchnet.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>