From 61b6794a0c8d4b196c2bde3b44058d0976975aec Mon Sep 17 00:00:00 2001
From: anlicheng <244108715@qq.com>
Date: Mon, 12 May 2025 16:24:10 +0800
Subject: [PATCH] add Tun
---
Tun/Info.plist | 13 ++
Tun/PacketTunnelProvider.swift | 36 ++++
Tun/Tun.entitlements | 18 ++
punchnet.xcodeproj/project.pbxproj | 173 ++++++++++++++++++
.../xcschemes/xcschememanagement.plist | 5 +
5 files changed, 245 insertions(+)
create mode 100644 Tun/Info.plist
create mode 100644 Tun/PacketTunnelProvider.swift
create mode 100644 Tun/Tun.entitlements
diff --git a/Tun/Info.plist b/Tun/Info.plist
new file mode 100644
index 0000000..3059459
--- /dev/null
+++ b/Tun/Info.plist
@@ -0,0 +1,13 @@
+
+
+
+
+ NSExtension
+
+ NSExtensionPointIdentifier
+ com.apple.networkextension.packet-tunnel
+ NSExtensionPrincipalClass
+ $(PRODUCT_MODULE_NAME).PacketTunnelProvider
+
+
+
diff --git a/Tun/PacketTunnelProvider.swift b/Tun/PacketTunnelProvider.swift
new file mode 100644
index 0000000..35234c0
--- /dev/null
+++ b/Tun/PacketTunnelProvider.swift
@@ -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.
+ }
+}
diff --git a/Tun/Tun.entitlements b/Tun/Tun.entitlements
new file mode 100644
index 0000000..2856bb2
--- /dev/null
+++ b/Tun/Tun.entitlements
@@ -0,0 +1,18 @@
+
+
+
+
+ com.apple.developer.networking.networkextension
+
+ packet-tunnel-provider
+ app-proxy-provider
+ content-filter-provider
+
+ com.apple.security.app-sandbox
+
+ com.apple.security.network.client
+
+ com.apple.security.network.server
+
+
+
diff --git a/punchnet.xcodeproj/project.pbxproj b/punchnet.xcodeproj/project.pbxproj
index cc2f3ed..5f722a0 100644
--- a/punchnet.xcodeproj/project.pbxproj
+++ b/punchnet.xcodeproj/project.pbxproj
@@ -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 = "";
};
+ C8A77F2B2DD1E77B00195617 /* Tun */ = {
+ isa = PBXFileSystemSynchronizedRootGroup;
+ exceptions = (
+ C8A77F332DD1E77B00195617 /* Exceptions for "Tun" folder in "Tun" target */,
+ );
+ path = Tun;
+ sourceTree = "";
+ };
/* 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 = "";
@@ -88,10 +144,19 @@
C8A77EF32DD1E6D000195617 /* punchnet.app */,
C8A77F062DD1E6D100195617 /* punchnetTests.xctest */,
C8A77F102DD1E6D100195617 /* punchnetUITests.xctest */,
+ C8A77F272DD1E77B00195617 /* Tun.appex */,
);
name = Products;
sourceTree = "";
};
+ C8A77F282DD1E77B00195617 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ C8A77F292DD1E77B00195617 /* NetworkExtension.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "";
+ };
/* 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 */;
diff --git a/punchnet.xcodeproj/xcuserdata/anlicheng.xcuserdatad/xcschemes/xcschememanagement.plist b/punchnet.xcodeproj/xcuserdata/anlicheng.xcuserdatad/xcschemes/xcschememanagement.plist
index 6b93205..516c2c6 100644
--- a/punchnet.xcodeproj/xcuserdata/anlicheng.xcuserdatad/xcschemes/xcschememanagement.plist
+++ b/punchnet.xcodeproj/xcuserdata/anlicheng.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -4,6 +4,11 @@
SchemeUserState
+ Tun.xcscheme_^#shared#^_
+
+ orderHint
+ 1
+
punchnet.xcscheme_^#shared#^_
orderHint