remove unused
This commit is contained in:
@@ -90,8 +90,6 @@
|
||||
54CA02952426B2FD003A5E04 /* DNSEnums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02242426B2FC003A5E04 /* DNSEnums.swift */; };
|
||||
54CA02962426B2FD003A5E04 /* PacketProtocolParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02262426B2FC003A5E04 /* PacketProtocolParser.swift */; };
|
||||
54CA02972426B2FD003A5E04 /* IPPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02272426B2FC003A5E04 /* IPPacket.swift */; };
|
||||
54CA02982426B2FD003A5E04 /* IPMutablePacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02282426B2FC003A5E04 /* IPMutablePacket.swift */; };
|
||||
54CA02992426B2FD003A5E04 /* TCPMutablePacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02292426B2FC003A5E04 /* TCPMutablePacket.swift */; };
|
||||
54CA029A2426B2FD003A5E04 /* Observer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA022B2426B2FC003A5E04 /* Observer.swift */; };
|
||||
54CA029C2426B2FD003A5E04 /* AdapterSocketEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA022E2426B2FC003A5E04 /* AdapterSocketEvent.swift */; };
|
||||
54CA029D2426B2FD003A5E04 /* ProxyServerEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA022F2426B2FC003A5E04 /* ProxyServerEvent.swift */; };
|
||||
@@ -106,8 +104,6 @@
|
||||
54CA02A72426B2FD003A5E04 /* DirectAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA023B2426B2FC003A5E04 /* DirectAdapter.swift */; };
|
||||
54CA02A82426B2FD003A5E04 /* SOCKS5Adapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA023C2426B2FC003A5E04 /* SOCKS5Adapter.swift */; };
|
||||
54CA02A92426B2FD003A5E04 /* RejectAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA023D2426B2FC003A5E04 /* RejectAdapter.swift */; };
|
||||
54CA02AA2426B2FD003A5E04 /* SpeedAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA023F2426B2FC003A5E04 /* SpeedAdapterFactory.swift */; };
|
||||
54CA02AB2426B2FD003A5E04 /* ShadowsocksAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02402426B2FC003A5E04 /* ShadowsocksAdapterFactory.swift */; };
|
||||
54CA02AC2426B2FD003A5E04 /* AuthenticationServerAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02412426B2FC003A5E04 /* AuthenticationServerAdapterFactory.swift */; };
|
||||
54CA02AD2426B2FD003A5E04 /* RejectAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02422426B2FC003A5E04 /* RejectAdapterFactory.swift */; };
|
||||
54CA02AE2426B2FD003A5E04 /* AdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02432426B2FD003A5E04 /* AdapterFactory.swift */; };
|
||||
@@ -116,10 +112,6 @@
|
||||
54CA02B12426B2FD003A5E04 /* ServerAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02462426B2FD003A5E04 /* ServerAdapterFactory.swift */; };
|
||||
54CA02B22426B2FD003A5E04 /* AdapterFactoryManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02472426B2FD003A5E04 /* AdapterFactoryManager.swift */; };
|
||||
54CA02B32426B2FD003A5E04 /* HTTPAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02482426B2FD003A5E04 /* HTTPAdapterFactory.swift */; };
|
||||
54CA02B42426B2FD003A5E04 /* StreamObfuscater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024A2426B2FD003A5E04 /* StreamObfuscater.swift */; };
|
||||
54CA02B52426B2FD003A5E04 /* CryptoStreamProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024B2426B2FD003A5E04 /* CryptoStreamProcessor.swift */; };
|
||||
54CA02B62426B2FD003A5E04 /* ProtocolObfuscater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024C2426B2FD003A5E04 /* ProtocolObfuscater.swift */; };
|
||||
54CA02B72426B2FD003A5E04 /* ShadowsocksAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024D2426B2FD003A5E04 /* ShadowsocksAdapter.swift */; };
|
||||
54CA02B82426B2FD003A5E04 /* HTTPProxySocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024F2426B2FD003A5E04 /* HTTPProxySocket.swift */; };
|
||||
54CA02B92426B2FD003A5E04 /* DirectProxySocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02502426B2FD003A5E04 /* DirectProxySocket.swift */; };
|
||||
54CA02BA2426B2FD003A5E04 /* ProxySocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02512426B2FD003A5E04 /* ProxySocket.swift */; };
|
||||
@@ -242,8 +234,6 @@
|
||||
54CA02242426B2FC003A5E04 /* DNSEnums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DNSEnums.swift; sourceTree = "<group>"; };
|
||||
54CA02262426B2FC003A5E04 /* PacketProtocolParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PacketProtocolParser.swift; sourceTree = "<group>"; };
|
||||
54CA02272426B2FC003A5E04 /* IPPacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPPacket.swift; sourceTree = "<group>"; };
|
||||
54CA02282426B2FC003A5E04 /* IPMutablePacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPMutablePacket.swift; sourceTree = "<group>"; };
|
||||
54CA02292426B2FC003A5E04 /* TCPMutablePacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TCPMutablePacket.swift; sourceTree = "<group>"; };
|
||||
54CA022B2426B2FC003A5E04 /* Observer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Observer.swift; sourceTree = "<group>"; };
|
||||
54CA022E2426B2FC003A5E04 /* AdapterSocketEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdapterSocketEvent.swift; sourceTree = "<group>"; };
|
||||
54CA022F2426B2FC003A5E04 /* ProxyServerEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProxyServerEvent.swift; sourceTree = "<group>"; };
|
||||
@@ -258,8 +248,6 @@
|
||||
54CA023B2426B2FC003A5E04 /* DirectAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirectAdapter.swift; sourceTree = "<group>"; };
|
||||
54CA023C2426B2FC003A5E04 /* SOCKS5Adapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SOCKS5Adapter.swift; sourceTree = "<group>"; };
|
||||
54CA023D2426B2FC003A5E04 /* RejectAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RejectAdapter.swift; sourceTree = "<group>"; };
|
||||
54CA023F2426B2FC003A5E04 /* SpeedAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeedAdapterFactory.swift; sourceTree = "<group>"; };
|
||||
54CA02402426B2FC003A5E04 /* ShadowsocksAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowsocksAdapterFactory.swift; sourceTree = "<group>"; };
|
||||
54CA02412426B2FC003A5E04 /* AuthenticationServerAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthenticationServerAdapterFactory.swift; sourceTree = "<group>"; };
|
||||
54CA02422426B2FC003A5E04 /* RejectAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RejectAdapterFactory.swift; sourceTree = "<group>"; };
|
||||
54CA02432426B2FD003A5E04 /* AdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdapterFactory.swift; sourceTree = "<group>"; };
|
||||
@@ -268,10 +256,6 @@
|
||||
54CA02462426B2FD003A5E04 /* ServerAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerAdapterFactory.swift; sourceTree = "<group>"; };
|
||||
54CA02472426B2FD003A5E04 /* AdapterFactoryManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdapterFactoryManager.swift; sourceTree = "<group>"; };
|
||||
54CA02482426B2FD003A5E04 /* HTTPAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPAdapterFactory.swift; sourceTree = "<group>"; };
|
||||
54CA024A2426B2FD003A5E04 /* StreamObfuscater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StreamObfuscater.swift; sourceTree = "<group>"; };
|
||||
54CA024B2426B2FD003A5E04 /* CryptoStreamProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CryptoStreamProcessor.swift; sourceTree = "<group>"; };
|
||||
54CA024C2426B2FD003A5E04 /* ProtocolObfuscater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProtocolObfuscater.swift; sourceTree = "<group>"; };
|
||||
54CA024D2426B2FD003A5E04 /* ShadowsocksAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowsocksAdapter.swift; sourceTree = "<group>"; };
|
||||
54CA024F2426B2FD003A5E04 /* HTTPProxySocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPProxySocket.swift; sourceTree = "<group>"; };
|
||||
54CA02502426B2FD003A5E04 /* DirectProxySocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirectProxySocket.swift; sourceTree = "<group>"; };
|
||||
54CA02512426B2FD003A5E04 /* ProxySocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProxySocket.swift; sourceTree = "<group>"; };
|
||||
@@ -582,8 +566,6 @@
|
||||
children = (
|
||||
54CA02262426B2FC003A5E04 /* PacketProtocolParser.swift */,
|
||||
54CA02272426B2FC003A5E04 /* IPPacket.swift */,
|
||||
54CA02282426B2FC003A5E04 /* IPMutablePacket.swift */,
|
||||
54CA02292426B2FC003A5E04 /* TCPMutablePacket.swift */,
|
||||
);
|
||||
path = Packet;
|
||||
sourceTree = "<group>";
|
||||
@@ -631,7 +613,6 @@
|
||||
54CA023C2426B2FC003A5E04 /* SOCKS5Adapter.swift */,
|
||||
54CA023D2426B2FC003A5E04 /* RejectAdapter.swift */,
|
||||
54CA023E2426B2FC003A5E04 /* Factory */,
|
||||
54CA02492426B2FD003A5E04 /* Shadowsocks */,
|
||||
);
|
||||
path = AdapterSocket;
|
||||
sourceTree = "<group>";
|
||||
@@ -639,8 +620,6 @@
|
||||
54CA023E2426B2FC003A5E04 /* Factory */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
54CA023F2426B2FC003A5E04 /* SpeedAdapterFactory.swift */,
|
||||
54CA02402426B2FC003A5E04 /* ShadowsocksAdapterFactory.swift */,
|
||||
54CA02412426B2FC003A5E04 /* AuthenticationServerAdapterFactory.swift */,
|
||||
54CA02422426B2FC003A5E04 /* RejectAdapterFactory.swift */,
|
||||
54CA02432426B2FD003A5E04 /* AdapterFactory.swift */,
|
||||
@@ -653,17 +632,6 @@
|
||||
path = Factory;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
54CA02492426B2FD003A5E04 /* Shadowsocks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
54CA024A2426B2FD003A5E04 /* StreamObfuscater.swift */,
|
||||
54CA024B2426B2FD003A5E04 /* CryptoStreamProcessor.swift */,
|
||||
54CA024C2426B2FD003A5E04 /* ProtocolObfuscater.swift */,
|
||||
54CA024D2426B2FD003A5E04 /* ShadowsocksAdapter.swift */,
|
||||
);
|
||||
path = Shadowsocks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
54CA024E2426B2FD003A5E04 /* ProxySocket */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -826,7 +794,6 @@
|
||||
54CA025D2426B2FD003A5E04 /* HTTPHeader.swift in Sources */,
|
||||
54CA02832426B2FD003A5E04 /* DNSSessionMatchResult.swift in Sources */,
|
||||
54CA02862426B2FD003A5E04 /* RuleManager.swift in Sources */,
|
||||
54CA02B52426B2FD003A5E04 /* CryptoStreamProcessor.swift in Sources */,
|
||||
54CA02B82426B2FD003A5E04 /* HTTPProxySocket.swift in Sources */,
|
||||
54CA02C32426DCCD003A5E04 /* GCDAsyncSocket.m in Sources */,
|
||||
54CA02752426B2FD003A5E04 /* IPRange.swift in Sources */,
|
||||
@@ -836,7 +803,6 @@
|
||||
54CA02C42426DCCD003A5E04 /* GCDAsyncUdpSocket.m in Sources */,
|
||||
54CA02BA2426B2FD003A5E04 /* ProxySocket.swift in Sources */,
|
||||
54CA025E2426B2FD003A5E04 /* ResponseGeneratorFactory.swift in Sources */,
|
||||
54CA02982426B2FD003A5E04 /* IPMutablePacket.swift in Sources */,
|
||||
54CA02892426B2FD003A5E04 /* Tunnel.swift in Sources */,
|
||||
54CA029F2426B2FD003A5E04 /* ProxySocketEvent.swift in Sources */,
|
||||
54CA027D2426B2FD003A5E04 /* GlobalIntializer.swift in Sources */,
|
||||
@@ -847,10 +813,8 @@
|
||||
54CA029E2426B2FD003A5E04 /* EventType.swift in Sources */,
|
||||
54CA02912426B2FD003A5E04 /* DNSMessage.swift in Sources */,
|
||||
54CA02712426B2FD003A5E04 /* UInt128.swift in Sources */,
|
||||
54CA02B62426B2FD003A5E04 /* ProtocolObfuscater.swift in Sources */,
|
||||
54CA02882426B2FD003A5E04 /* QueueFactory.swift in Sources */,
|
||||
54CA02A12426B2FD003A5E04 /* RuleMatchEvent.swift in Sources */,
|
||||
54CA02AB2426B2FD003A5E04 /* ShadowsocksAdapterFactory.swift in Sources */,
|
||||
54CA02BE2426D4F3003A5E04 /* DDLog.swift in Sources */,
|
||||
54CA02962426B2FD003A5E04 /* PacketProtocolParser.swift in Sources */,
|
||||
54CA02932426B2FD003A5E04 /* DNSServer.swift in Sources */,
|
||||
@@ -864,7 +828,6 @@
|
||||
54CA026B2426B2FD003A5E04 /* GCDTCPSocket.swift in Sources */,
|
||||
54CA028E2426B2FD003A5E04 /* IPStackProtocol.swift in Sources */,
|
||||
54CA01D52426B252003A5E04 /* SafeDict.swift in Sources */,
|
||||
54CA02992426B2FD003A5E04 /* TCPMutablePacket.swift in Sources */,
|
||||
54CA027B2426B2FD003A5E04 /* HTTPAuthentication.swift in Sources */,
|
||||
54CA02762426B2FD003A5E04 /* IPAddress.swift in Sources */,
|
||||
54CA02B02426B2FD003A5E04 /* SecureHTTPAdapterFactory.swift in Sources */,
|
||||
@@ -882,8 +845,6 @@
|
||||
54CA027E2426B2FD003A5E04 /* DomainListRule.swift in Sources */,
|
||||
54CA02782426B2FD003A5E04 /* BinaryDataScanner.swift in Sources */,
|
||||
54CA02B12426B2FD003A5E04 /* ServerAdapterFactory.swift in Sources */,
|
||||
54CA02B42426B2FD003A5E04 /* StreamObfuscater.swift in Sources */,
|
||||
54CA02AA2426B2FD003A5E04 /* SpeedAdapterFactory.swift in Sources */,
|
||||
54CA02952426B2FD003A5E04 /* DNSEnums.swift in Sources */,
|
||||
54CA02802426B2FD003A5E04 /* DNSSessionMatchType.swift in Sources */,
|
||||
54CA02A22426B2FD003A5E04 /* ObserverFactory.swift in Sources */,
|
||||
@@ -907,7 +868,6 @@
|
||||
546063E523FEFAFE008F505A /* SQDB.swift in Sources */,
|
||||
54CA02872426B2FD003A5E04 /* IPRangeListRule.swift in Sources */,
|
||||
54CA02922426B2FD003A5E04 /* DNSSession.swift in Sources */,
|
||||
54CA02B72426B2FD003A5E04 /* ShadowsocksAdapter.swift in Sources */,
|
||||
54CA026D2426B2FD003A5E04 /* Opt.swift in Sources */,
|
||||
54CA02B32426B2FD003A5E04 /* HTTPAdapterFactory.swift in Sources */,
|
||||
54CA02702426B2FD003A5E04 /* HTTPStreamScanner.swift in Sources */,
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
//import Foundation
|
||||
//
|
||||
//enum ChangeType {
|
||||
// case Address, Port
|
||||
//}
|
||||
//
|
||||
//public class IPMutablePacket {
|
||||
// // Support only IPv4 for now
|
||||
//
|
||||
// let version: IPVersion
|
||||
// let proto: TransportType
|
||||
// let IPHeaderLength: Int
|
||||
// var sourceAddress: IPv4Address {
|
||||
// get {
|
||||
// return IPv4Address(fromBytesInNetworkOrder: payload.bytes.advancedBy(12))
|
||||
// }
|
||||
// set {
|
||||
// setIPv4Address(sourceAddress, newAddress: newValue, at: 12)
|
||||
// }
|
||||
// }
|
||||
// var destinationAddress: IPv4Address {
|
||||
// get {
|
||||
// return IPv4Address(fromBytesInNetworkOrder: payload.bytes.advancedBy(16))
|
||||
// }
|
||||
// set {
|
||||
// setIPv4Address(destinationAddress, newAddress: newValue, at: 16)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let payload: NSMutableData
|
||||
//
|
||||
// public init(payload: NSData) {
|
||||
// let vl = UnsafePointer<UInt8>(payload.bytes).memory
|
||||
// version = IPVersion(rawValue: vl >> 4)!
|
||||
// IPHeaderLength = Int(vl & 0x0F) * 4
|
||||
// let p = UnsafePointer<UInt8>(payload.bytes.advancedBy(9)).memory
|
||||
// proto = TransportType(rawValue: p)!
|
||||
// self.payload = NSMutableData(data: payload)
|
||||
// }
|
||||
//
|
||||
// func updateChecksum(oldValue: UInt16, newValue: UInt16, type: ChangeType) {
|
||||
// if type == .Address {
|
||||
// updateChecksum(oldValue, newValue: newValue, at: 10)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // swiftlint:disable:next variable_name
|
||||
// internal func updateChecksum(oldValue: UInt16, newValue: UInt16, at: Int) {
|
||||
// let oldChecksum = UnsafePointer<UInt16>(payload.bytes.advancedBy(at)).memory
|
||||
// let oc32 = UInt32(~oldChecksum)
|
||||
// let ov32 = UInt32(~oldValue)
|
||||
// let nv32 = UInt32(newValue)
|
||||
// var newChecksum32 = oc32 &+ ov32 &+ nv32
|
||||
// newChecksum32 = (newChecksum32 & 0xFFFF) + (newChecksum32 >> 16)
|
||||
// newChecksum32 = (newChecksum32 & 0xFFFF) &+ (newChecksum32 >> 16)
|
||||
// var newChecksum = ~UInt16(newChecksum32)
|
||||
// payload.replaceBytesInRange(NSRange(location: at, length: 2), withBytes: &newChecksum, length: 2)
|
||||
// }
|
||||
//
|
||||
// // swiftlint:disable:next variable_name
|
||||
// private func foldChecksum(checksum: UInt32) -> UInt32 {
|
||||
// var checksum = checksum
|
||||
// while checksum > 0xFFFF {
|
||||
// checksum = (checksum & 0xFFFF) + (checksum >> 16)
|
||||
// }
|
||||
// return checksum
|
||||
// }
|
||||
//
|
||||
// // swiftlint:disable:next variable_name
|
||||
// private func setIPv4Address(oldAddress: IPv4Address, newAddress: IPv4Address, at: Int) {
|
||||
// payload.replaceBytesInRange(NSRange(location: at, length: 4), withBytes: newAddress.bytesInNetworkOrder, length: 4)
|
||||
// updateChecksum(UnsafePointer<UInt16>(oldAddress.bytesInNetworkOrder).memory, newValue: UnsafePointer<UInt16>(newAddress.bytesInNetworkOrder).memory, type: .Address)
|
||||
// updateChecksum(UnsafePointer<UInt16>(oldAddress.bytesInNetworkOrder).advancedBy(1).memory, newValue: UnsafePointer<UInt16>(newAddress.bytesInNetworkOrder).advancedBy(1).memory, type: .Address)
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -1,32 +0,0 @@
|
||||
//import Foundation
|
||||
//
|
||||
//class TCPMutablePacket: IPMutablePacket {
|
||||
// var sourcePort: Port {
|
||||
// get {
|
||||
// return Port(bytesInNetworkOrder: payload.bytes.advancedBy(IPHeaderLength))
|
||||
// }
|
||||
// set {
|
||||
// setPort(sourcePort, newPort: newValue, at: 0)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// var destinationPort: Port {
|
||||
// get {
|
||||
// return Port(bytesInNetworkOrder: payload.bytes.advancedBy(IPHeaderLength + 2))
|
||||
// }
|
||||
// set {
|
||||
// setPort(destinationPort, newPort: newValue, at: 2)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override func updateChecksum(oldValue: UInt16, newValue: UInt16, type: ChangeType) {
|
||||
// super.updateChecksum(oldValue, newValue: newValue, type: type)
|
||||
// updateChecksum(oldValue, newValue: newValue, at: IPHeaderLength + 16)
|
||||
// }
|
||||
//
|
||||
// // swiftlint:disable:next variable_name
|
||||
// private func setPort(oldPort: Port, newPort: Port, at: Int) {
|
||||
// payload.replaceBytesInRange(NSRange(location: at + IPHeaderLength, length: 2), withBytes: newPort.bytesInNetworkOrder, length: 2)
|
||||
// updateChecksum(oldPort.valueInNetworkOrder, newValue: newPort.valueInNetworkOrder, type: .Port)
|
||||
// }
|
||||
//}
|
||||
@@ -1,28 +0,0 @@
|
||||
//import Foundation
|
||||
//
|
||||
///// Factory building Shadowsocks adapter.
|
||||
//open class ShadowsocksAdapterFactory: ServerAdapterFactory {
|
||||
// let protocolObfuscaterFactory: ShadowsocksAdapter.ProtocolObfuscater.Factory
|
||||
// let cryptorFactory: ShadowsocksAdapter.CryptoStreamProcessor.Factory
|
||||
// let streamObfuscaterFactory: ShadowsocksAdapter.StreamObfuscater.Factory
|
||||
//
|
||||
// public init(serverHost: String, serverPort: Int, protocolObfuscaterFactory: ShadowsocksAdapter.ProtocolObfuscater.Factory, cryptorFactory: ShadowsocksAdapter.CryptoStreamProcessor.Factory, streamObfuscaterFactory: ShadowsocksAdapter.StreamObfuscater.Factory) {
|
||||
// self.protocolObfuscaterFactory = protocolObfuscaterFactory
|
||||
// self.cryptorFactory = cryptorFactory
|
||||
// self.streamObfuscaterFactory = streamObfuscaterFactory
|
||||
// super.init(serverHost: serverHost, serverPort: serverPort)
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// Get a Shadowsocks adapter.
|
||||
//
|
||||
// - parameter session: The connect session.
|
||||
//
|
||||
// - returns: The built adapter.
|
||||
// */
|
||||
// override open func getAdapterFor(session: ConnectSession) -> AdapterSocket {
|
||||
// let adapter = ShadowsocksAdapter(host: serverHost, port: serverPort, protocolObfuscater: protocolObfuscaterFactory.build(), cryptor: cryptorFactory.build(), streamObfuscator: streamObfuscaterFactory.build(for: session))
|
||||
// adapter.socket = RawSocketFactory.getRawSocket()
|
||||
// return adapter
|
||||
// }
|
||||
//}
|
||||
@@ -1,26 +0,0 @@
|
||||
//import Foundation
|
||||
//
|
||||
///// Factory building speed adapter.
|
||||
//open class SpeedAdapterFactory: AdapterFactory {
|
||||
// open var adapterFactories: [(AdapterFactory, Int)]!
|
||||
//
|
||||
// public override init() {}
|
||||
//
|
||||
// /**
|
||||
// Get a speed adapter.
|
||||
//
|
||||
// - parameter session: The connect session.
|
||||
//
|
||||
// - returns: The built adapter.
|
||||
// */
|
||||
// override open func getAdapterFor(session: ConnectSession) -> AdapterSocket {
|
||||
// let adapters = adapterFactories.map { adapterFactory, delay -> (AdapterSocket, Int) in
|
||||
// let adapter = adapterFactory.getAdapterFor(session: session)
|
||||
// adapter.socket = RawSocketFactory.getRawSocket()
|
||||
// return (adapter, delay)
|
||||
// }
|
||||
// let speedAdapter = SpeedAdapter()
|
||||
// speedAdapter.adapters = adapters
|
||||
// return speedAdapter
|
||||
// }
|
||||
//}
|
||||
@@ -1,133 +0,0 @@
|
||||
//import Foundation
|
||||
//
|
||||
//extension ShadowsocksAdapter {
|
||||
// public class CryptoStreamProcessor {
|
||||
// public class Factory {
|
||||
// let password: String
|
||||
// let algorithm: CryptoAlgorithm
|
||||
// let key: Data
|
||||
//
|
||||
// public init(password: String, algorithm: CryptoAlgorithm) {
|
||||
// self.password = password
|
||||
// self.algorithm = algorithm
|
||||
// key = CryptoHelper.getKey(password, methodType: algorithm)
|
||||
// }
|
||||
//
|
||||
// public func build() -> CryptoStreamProcessor {
|
||||
// return CryptoStreamProcessor(key: key, algorithm: algorithm)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public weak var inputStreamProcessor: StreamObfuscater.StreamObfuscaterBase!
|
||||
// public weak var outputStreamProcessor: ProtocolObfuscater.ProtocolObfuscaterBase!
|
||||
//
|
||||
// var readIV: Data!
|
||||
// let key: Data
|
||||
// let algorithm: CryptoAlgorithm
|
||||
//
|
||||
// var sendKey = false
|
||||
//
|
||||
// var buffer = Buffer(capacity: 0)
|
||||
//
|
||||
// lazy var writeIV: Data = {
|
||||
// [unowned self] in
|
||||
// CryptoHelper.getIV(self.algorithm)
|
||||
// }()
|
||||
// lazy var ivLength: Int = {
|
||||
// [unowned self] in
|
||||
// CryptoHelper.getIVLength(self.algorithm)
|
||||
// }()
|
||||
// lazy var encryptor: StreamCryptoProtocol = {
|
||||
// [unowned self] in
|
||||
// self.getCrypto(.encrypt)
|
||||
// }()
|
||||
// lazy var decryptor: StreamCryptoProtocol = {
|
||||
// [unowned self] in
|
||||
// self.getCrypto(.decrypt)
|
||||
// }()
|
||||
//
|
||||
// init(key: Data, algorithm: CryptoAlgorithm) {
|
||||
// self.key = key
|
||||
// self.algorithm = algorithm
|
||||
// }
|
||||
//
|
||||
// func encrypt(data: inout Data) {
|
||||
// return encryptor.update(&data)
|
||||
// }
|
||||
//
|
||||
// func decrypt(data: inout Data) {
|
||||
// return decryptor.update(&data)
|
||||
// }
|
||||
//
|
||||
// public func input(data: Data) throws {
|
||||
// var data = data
|
||||
//
|
||||
// if readIV == nil {
|
||||
// buffer.append(data: data)
|
||||
// readIV = buffer.get(length: ivLength)
|
||||
// guard readIV != nil else {
|
||||
// try inputStreamProcessor!.input(data: Data())
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// data = buffer.get() ?? Data()
|
||||
// buffer.release()
|
||||
// }
|
||||
//
|
||||
// decrypt(data: &data)
|
||||
// try inputStreamProcessor!.input(data: data)
|
||||
// }
|
||||
//
|
||||
// public func output(data: Data) {
|
||||
// var data = data
|
||||
// encrypt(data: &data)
|
||||
// if sendKey {
|
||||
// return outputStreamProcessor!.output(data: data)
|
||||
// } else {
|
||||
// sendKey = true
|
||||
// var out = Data(capacity: data.count + writeIV.count)
|
||||
// out.append(writeIV)
|
||||
// out.append(data)
|
||||
//
|
||||
// return outputStreamProcessor!.output(data: out)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private func getCrypto(_ operation: CryptoOperation) -> StreamCryptoProtocol {
|
||||
// switch algorithm {
|
||||
// case .AES128CFB, .AES192CFB, .AES256CFB:
|
||||
// switch operation {
|
||||
// case .decrypt:
|
||||
// return CCCrypto(operation: .decrypt, mode: .cfb, algorithm: .aes, initialVector: readIV, key: key)
|
||||
// case .encrypt:
|
||||
// return CCCrypto(operation: .encrypt, mode: .cfb, algorithm: .aes, initialVector: writeIV, key: key)
|
||||
// }
|
||||
// case .CHACHA20:
|
||||
// switch operation {
|
||||
// case .decrypt:
|
||||
// return SodiumStreamCrypto(key: key, iv: readIV, algorithm: .chacha20)
|
||||
// case .encrypt:
|
||||
// return SodiumStreamCrypto(key: key, iv: writeIV, algorithm: .chacha20)
|
||||
// }
|
||||
// case .SALSA20:
|
||||
// switch operation {
|
||||
// case .decrypt:
|
||||
// return SodiumStreamCrypto(key: key, iv: readIV, algorithm: .salsa20)
|
||||
// case .encrypt:
|
||||
// return SodiumStreamCrypto(key: key, iv: writeIV, algorithm: .salsa20)
|
||||
// }
|
||||
// case .RC4MD5:
|
||||
// var combinedKey = Data(capacity: key.count + ivLength)
|
||||
// combinedKey.append(key)
|
||||
// switch operation {
|
||||
// case .decrypt:
|
||||
// combinedKey.append(readIV)
|
||||
// return CCCrypto(operation: .decrypt, mode: .rc4, algorithm: .rc4, initialVector: nil, key: MD5Hash.final(combinedKey))
|
||||
// case .encrypt:
|
||||
// combinedKey.append(writeIV)
|
||||
// return CCCrypto(operation: .encrypt, mode: .rc4, algorithm: .rc4, initialVector: nil, key: MD5Hash.final(combinedKey))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -1,371 +0,0 @@
|
||||
//import Foundation
|
||||
//
|
||||
//extension ShadowsocksAdapter {
|
||||
// public struct ProtocolObfuscater {
|
||||
// public class Factory {
|
||||
// public init() {}
|
||||
//
|
||||
// public func build() -> ProtocolObfuscaterBase {
|
||||
// return ProtocolObfuscaterBase()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class ProtocolObfuscaterBase {
|
||||
// public weak var inputStreamProcessor: CryptoStreamProcessor!
|
||||
// public weak var outputStreamProcessor: ShadowsocksAdapter!
|
||||
//
|
||||
// public func start() {}
|
||||
// public func input(data: Data) throws {}
|
||||
// public func output(data: Data) {}
|
||||
//
|
||||
// public func didWrite() {}
|
||||
// }
|
||||
//
|
||||
// public class OriginProtocolObfuscater: ProtocolObfuscaterBase {
|
||||
//
|
||||
// public class Factory: ProtocolObfuscater.Factory {
|
||||
// public override init() {}
|
||||
//
|
||||
// public override func build() -> ShadowsocksAdapter.ProtocolObfuscater.ProtocolObfuscaterBase {
|
||||
// return OriginProtocolObfuscater()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public override func start() {
|
||||
// outputStreamProcessor.becomeReadyToForward()
|
||||
// }
|
||||
//
|
||||
// public override func input(data: Data) throws {
|
||||
// try inputStreamProcessor.input(data: data)
|
||||
// }
|
||||
//
|
||||
// public override func output(data: Data) {
|
||||
// outputStreamProcessor.output(data: data)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class HTTPProtocolObfuscater: ProtocolObfuscaterBase {
|
||||
//
|
||||
// public class Factory: ProtocolObfuscater.Factory {
|
||||
// let method: String
|
||||
// let hosts: [String]
|
||||
// let customHeader: String?
|
||||
//
|
||||
// public init(method: String = "GET", hosts: [String], customHeader: String?) {
|
||||
// self.method = method
|
||||
// self.hosts = hosts
|
||||
// self.customHeader = customHeader
|
||||
// }
|
||||
//
|
||||
// public override func build() -> ShadowsocksAdapter.ProtocolObfuscater.ProtocolObfuscaterBase {
|
||||
// return HTTPProtocolObfuscater(method: method, hosts: hosts, customHeader: customHeader)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static let headerLength = 30
|
||||
// static let userAgent = ["Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0",
|
||||
// "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/44.0",
|
||||
// "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36",
|
||||
// "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Ubuntu/11.10 Chromium/27.0.1453.93 Chrome/27.0.1453.93 Safari/537.36",
|
||||
// "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0",
|
||||
// "Mozilla/5.0 (compatible; WOW64; MSIE 10.0; Windows NT 6.2)",
|
||||
// "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",
|
||||
// "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)",
|
||||
// "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko",
|
||||
// "Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/BuildID) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36",
|
||||
// "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
|
||||
// "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"]
|
||||
//
|
||||
// let method: String
|
||||
// let hosts: [String]
|
||||
// let customHeader: String?
|
||||
//
|
||||
// var readingFakeHeader = false
|
||||
// var sendHeader = false
|
||||
// var remaining = false
|
||||
//
|
||||
// var buffer = Buffer(capacity: 8192)
|
||||
//
|
||||
// public init(method: String = "GET", hosts: [String], customHeader: String?) {
|
||||
// self.method = method
|
||||
// self.hosts = hosts
|
||||
// self.customHeader = customHeader
|
||||
// }
|
||||
//
|
||||
// private func generateHeader(encapsulating data: Data) -> String {
|
||||
// let ind = Int(arc4random_uniform(UInt32(hosts.count)))
|
||||
// let host = outputStreamProcessor.port == 80 ? hosts[ind] : "\(hosts[ind]):\(outputStreamProcessor.port)"
|
||||
// var header = "\(method) /\(hexlify(data: data)) HTTP/1.1\r\nHost: \(host)\r\n"
|
||||
// if let customHeader = customHeader {
|
||||
// header += customHeader
|
||||
// } else {
|
||||
// let ind = Int(arc4random_uniform(UInt32(HTTPProtocolObfuscater.userAgent.count)))
|
||||
// header += "User-Agent: \(HTTPProtocolObfuscater.userAgent[ind])\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nDNT: 1\r\nConnection: keep-alive"
|
||||
// }
|
||||
// header += "\r\n\r\n"
|
||||
// return header
|
||||
// }
|
||||
//
|
||||
// private func hexlify(data: Data) -> String {
|
||||
// var result = ""
|
||||
// for i in data {
|
||||
// result = result.appendingFormat("%%%02x", i)
|
||||
// }
|
||||
// return result
|
||||
// }
|
||||
//
|
||||
// public override func start() {
|
||||
// readingFakeHeader = true
|
||||
// outputStreamProcessor.becomeReadyToForward()
|
||||
// }
|
||||
//
|
||||
// public override func input(data: Data) throws {
|
||||
// if readingFakeHeader {
|
||||
// buffer.append(data: data)
|
||||
// if buffer.get(to: Utils.HTTPData.DoubleCRLF) != nil {
|
||||
// readingFakeHeader = false
|
||||
// if let remainData = buffer.get() {
|
||||
// try inputStreamProcessor.input(data: remainData)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// try inputStreamProcessor.input(data: Data())
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// try inputStreamProcessor.input(data: data)
|
||||
// }
|
||||
//
|
||||
// public override func output(data: Data) {
|
||||
// if sendHeader {
|
||||
// outputStreamProcessor.output(data: data)
|
||||
// } else {
|
||||
// var fakeRequestDataLength = inputStreamProcessor.key.count + HTTPProtocolObfuscater.headerLength
|
||||
// if data.count - fakeRequestDataLength > 64 {
|
||||
// fakeRequestDataLength += Int(arc4random_uniform(64))
|
||||
// } else {
|
||||
// fakeRequestDataLength = data.count
|
||||
// }
|
||||
//
|
||||
// var outputData = generateHeader(encapsulating: data.subdata(in: 0 ..< fakeRequestDataLength)).data(using: .utf8)!
|
||||
// outputData.append(data.subdata(in: fakeRequestDataLength ..< data.count))
|
||||
// sendHeader = true
|
||||
// outputStreamProcessor.output(data: outputData)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class TLSProtocolObfuscater: ProtocolObfuscaterBase {
|
||||
//
|
||||
// public class Factory: ProtocolObfuscater.Factory {
|
||||
// let hosts: [String]
|
||||
//
|
||||
// public init(hosts: [String]) {
|
||||
// self.hosts = hosts
|
||||
// }
|
||||
//
|
||||
// public override func build() -> ShadowsocksAdapter.ProtocolObfuscater.ProtocolObfuscaterBase {
|
||||
// return TLSProtocolObfuscater(hosts: hosts)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let hosts: [String]
|
||||
// let clientID: Data = {
|
||||
// var id = Data(count: 32)
|
||||
// Utils.Random.fill(data: &id)
|
||||
// return id
|
||||
// }()
|
||||
//
|
||||
// private var status = 0
|
||||
//
|
||||
// private var buffer = Buffer(capacity: 1024)
|
||||
//
|
||||
// init(hosts: [String]) {
|
||||
// self.hosts = hosts
|
||||
// }
|
||||
//
|
||||
// public override func start() {
|
||||
// handleStatus0()
|
||||
// outputStreamProcessor.socket.readDataTo(length: 129)
|
||||
// }
|
||||
//
|
||||
// public override func input(data: Data) throws {
|
||||
// switch status {
|
||||
// case 8:
|
||||
// try handleInput(data: data)
|
||||
// case 1:
|
||||
// outputStreamProcessor.becomeReadyToForward()
|
||||
// default:
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public override func output(data: Data) {
|
||||
// switch status {
|
||||
// case 8:
|
||||
// handleStatus8(data: data)
|
||||
// return
|
||||
// case 1:
|
||||
// handleStatus1(data: data)
|
||||
// return
|
||||
// default:
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private func authData() -> Data {
|
||||
// var time = UInt32(Date.init().timeIntervalSince1970).bigEndian
|
||||
// var output = Data(count: 32)
|
||||
// var key = inputStreamProcessor.key
|
||||
// key.append(clientID)
|
||||
//
|
||||
// withUnsafeBytes(of: &time) {
|
||||
// output.replaceSubrange(0 ..< 4, with: $0)
|
||||
// }
|
||||
//
|
||||
// Utils.Random.fill(data: &output, from: 4, length: 18)
|
||||
// output.withUnsafeBytes {
|
||||
// output.replaceSubrange(22 ..< 32, with: HMAC.final(value: $0.baseAddress!, length: 22, algorithm: .SHA1, key: key).subdata(in: 0..<10))
|
||||
// }
|
||||
// return output
|
||||
// }
|
||||
//
|
||||
// private func pack(data: Data) -> Data {
|
||||
// var output = Data()
|
||||
// var left = data.count
|
||||
// while left > 0 {
|
||||
// let blockSize = UInt16(min(Int(arc4random_uniform(UInt32(UInt16.max))) % 4096 + 100, left))
|
||||
// var blockSizeBE = blockSize.bigEndian
|
||||
// output.append(contentsOf: [0x17, 0x03, 0x03])
|
||||
// withUnsafeBytes(of: &blockSizeBE) {
|
||||
// output.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
|
||||
// }
|
||||
// output.append(data.subdata(in: data.count - left ..< data.count - left + Int(blockSize)))
|
||||
// left -= Int(blockSize)
|
||||
// }
|
||||
// return output
|
||||
// }
|
||||
//
|
||||
// private func handleStatus8(data: Data) {
|
||||
// outputStreamProcessor.output(data: pack(data: data))
|
||||
// }
|
||||
//
|
||||
// private func handleStatus0() {
|
||||
// status = 1
|
||||
//
|
||||
// var outData = Data()
|
||||
// outData.append(contentsOf: [0x03, 0x03])
|
||||
// outData.append(authData())
|
||||
// outData.append(0x20)
|
||||
// outData.append(clientID)
|
||||
// outData.append(contentsOf: [0x00, 0x1c, 0xc0, 0x2b, 0xc0, 0x2f, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0x14, 0xcc, 0x13, 0xc0, 0x0a, 0xc0, 0x14, 0xc0, 0x09, 0xc0, 0x13, 0x00, 0x9c, 0x00, 0x35, 0x00, 0x2f, 0x00, 0x0a])
|
||||
// outData.append("0100".data(using: .utf8)!)
|
||||
//
|
||||
// var extData = Data()
|
||||
// extData.append(contentsOf: [0xff, 0x01, 0x00, 0x01, 0x00])
|
||||
// let hostData = hosts[Int(arc4random_uniform(UInt32(hosts.count)))].data(using: .utf8)!
|
||||
//
|
||||
// var sniData = Data(capacity: hosts.count + 2 + 1 + 2 + 2 + 2)
|
||||
//
|
||||
// sniData.append(contentsOf: [0x00, 0x00])
|
||||
//
|
||||
// var _lenBE = UInt16(hostData.count + 5).bigEndian
|
||||
// withUnsafeBytes(of: &_lenBE) {
|
||||
// sniData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
|
||||
// }
|
||||
//
|
||||
// _lenBE = UInt16(hostData.count + 3).bigEndian
|
||||
// withUnsafeBytes(of: &_lenBE) {
|
||||
// sniData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
|
||||
// }
|
||||
//
|
||||
// sniData.append(0x00)
|
||||
//
|
||||
// _lenBE = UInt16(hostData.count).bigEndian
|
||||
// withUnsafeBytes(of: &_lenBE) {
|
||||
// sniData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
|
||||
// }
|
||||
//
|
||||
// sniData.append(hostData)
|
||||
//
|
||||
// extData.append(sniData)
|
||||
//
|
||||
// extData.append(contentsOf: [0x00, 0x17, 0x00, 0x00, 0x00, 0x23, 0x00, 0xd0])
|
||||
//
|
||||
// var randomData = Data(count: 208)
|
||||
// Utils.Random.fill(data: &randomData)
|
||||
// extData.append(randomData)
|
||||
//
|
||||
// extData.append(contentsOf: [0x00, 0x0d, 0x00, 0x16, 0x00, 0x14, 0x06, 0x01, 0x06, 0x03, 0x05, 0x01, 0x05, 0x03, 0x04, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x03, 0x02, 0x01, 0x02, 0x03])
|
||||
// extData.append(contentsOf: [0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00])
|
||||
// extData.append(contentsOf: [0x00, 0x12, 0x00, 0x00])
|
||||
// extData.append(contentsOf: [0x75, 0x50, 0x00, 0x00])
|
||||
// extData.append(contentsOf: [0x00, 0x0b, 0x00, 0x02, 0x01, 0x00])
|
||||
// extData.append(contentsOf: [0x00, 0x0a, 0x00, 0x06, 0x00, 0x04, 0x00, 0x17, 0x00, 0x18])
|
||||
//
|
||||
// _lenBE = UInt16(extData.count).bigEndian
|
||||
// withUnsafeBytes(of: &_lenBE) {
|
||||
// outData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
|
||||
// }
|
||||
// outData.append(extData)
|
||||
//
|
||||
// var outputData = Data(capacity: outData.count + 9)
|
||||
// outputData.append(contentsOf: [0x16, 0x03, 0x01])
|
||||
// _lenBE = UInt16(outData.count + 4).bigEndian
|
||||
// withUnsafeBytes(of: &_lenBE) {
|
||||
// outputData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
|
||||
// }
|
||||
// outputData.append(contentsOf: [0x01, 0x00])
|
||||
// _lenBE = UInt16(outData.count).bigEndian
|
||||
// withUnsafeBytes(of: &_lenBE) {
|
||||
// outputData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
|
||||
// }
|
||||
// outputData.append(outData)
|
||||
// outputStreamProcessor.output(data: outputData)
|
||||
// }
|
||||
//
|
||||
// private func handleStatus1(data: Data) {
|
||||
// status = 8
|
||||
//
|
||||
// var outputData = Data()
|
||||
// outputData.append(contentsOf: [0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x16, 0x03, 0x03, 0x00, 0x20])
|
||||
// var random = Data(count: 22)
|
||||
// Utils.Random.fill(data: &random)
|
||||
// outputData.append(random)
|
||||
//
|
||||
// var key = inputStreamProcessor.key
|
||||
// key.append(clientID)
|
||||
// outputData.withUnsafeBytes {
|
||||
// outputData.append(HMAC.final(value: $0.baseAddress!, length: outputData.count, algorithm: .SHA1, key: key).subdata(in: 0..<10))
|
||||
// }
|
||||
//
|
||||
// outputData.append(pack(data: data))
|
||||
//
|
||||
// outputStreamProcessor.output(data: outputData)
|
||||
// }
|
||||
//
|
||||
// private func handleInput(data: Data) throws {
|
||||
// buffer.append(data: data)
|
||||
// var unpackedData = Data()
|
||||
// while buffer.left > 5 {
|
||||
// buffer.skip(3)
|
||||
// var length: Int = 0
|
||||
// buffer.withUnsafeBytes { (ptr: UnsafePointer<UInt16>) in
|
||||
// length = Int(ptr.pointee.byteSwapped)
|
||||
// }
|
||||
// buffer.skip(2)
|
||||
// if buffer.left >= length {
|
||||
// unpackedData.append(buffer.get(length: length)!)
|
||||
// continue
|
||||
// } else {
|
||||
// buffer.setBack(length: 5)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// buffer.squeeze()
|
||||
// try inputStreamProcessor.input(data: unpackedData)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
@@ -1,112 +0,0 @@
|
||||
//import Foundation
|
||||
//import CommonCrypto
|
||||
//
|
||||
///// This adapter connects to remote through Shadowsocks proxy.
|
||||
//public class ShadowsocksAdapter: AdapterSocket {
|
||||
// enum ShadowsocksAdapterStatus {
|
||||
// case invalid,
|
||||
// connecting,
|
||||
// connected,
|
||||
// forwarding,
|
||||
// stopped
|
||||
// }
|
||||
//
|
||||
// enum EncryptMethod: String {
|
||||
// case AES128CFB = "AES-128-CFB", AES192CFB = "AES-192-CFB", AES256CFB = "AES-256-CFB"
|
||||
//
|
||||
// static let allValues: [EncryptMethod] = [.AES128CFB, .AES192CFB, .AES256CFB]
|
||||
// }
|
||||
//
|
||||
// public let host: String
|
||||
// public let port: Int
|
||||
//
|
||||
// var internalStatus: ShadowsocksAdapterStatus = .invalid
|
||||
//
|
||||
// private let protocolObfuscater: ProtocolObfuscater.ProtocolObfuscaterBase
|
||||
// private let cryptor: CryptoStreamProcessor
|
||||
// private let streamObfuscator: StreamObfuscater.StreamObfuscaterBase
|
||||
//
|
||||
// public init(host: String, port: Int, protocolObfuscater: ProtocolObfuscater.ProtocolObfuscaterBase, cryptor: CryptoStreamProcessor, streamObfuscator: StreamObfuscater.StreamObfuscaterBase) {
|
||||
// self.host = host
|
||||
// self.port = port
|
||||
// self.protocolObfuscater = protocolObfuscater
|
||||
// self.cryptor = cryptor
|
||||
// self.streamObfuscator = streamObfuscator
|
||||
//
|
||||
// super.init()
|
||||
//
|
||||
// protocolObfuscater.inputStreamProcessor = cryptor
|
||||
// protocolObfuscater.outputStreamProcessor = self
|
||||
//
|
||||
// cryptor.inputStreamProcessor = streamObfuscator
|
||||
// cryptor.outputStreamProcessor = protocolObfuscater
|
||||
//
|
||||
// streamObfuscator.inputStreamProcessor = self
|
||||
// streamObfuscator.outputStreamProcessor = cryptor
|
||||
// }
|
||||
//
|
||||
// override public func openSocketWith(session: ConnectSession) {
|
||||
// super.openSocketWith(session: session)
|
||||
//
|
||||
// do {
|
||||
// internalStatus = .connecting
|
||||
// try socket.connectTo(host: host, port: port, enableTLS: false, tlsSettings: nil)
|
||||
// } catch let error {
|
||||
// observer?.signal(.errorOccured(error, on: self))
|
||||
// disconnect()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override public func didConnectWith(socket: RawTCPSocketProtocol) {
|
||||
// super.didConnectWith(socket: socket)
|
||||
//
|
||||
// internalStatus = .connected
|
||||
//
|
||||
// protocolObfuscater.start()
|
||||
// }
|
||||
//
|
||||
// override public func didRead(data: Data, from socket: RawTCPSocketProtocol) {
|
||||
// super.didRead(data: data, from: socket)
|
||||
//
|
||||
// do {
|
||||
// try protocolObfuscater.input(data: data)
|
||||
// } catch {
|
||||
// disconnect()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public override func write(data: Data) {
|
||||
// streamObfuscator.output(data: data)
|
||||
// }
|
||||
//
|
||||
// public func write(rawData: Data) {
|
||||
// super.write(data: rawData)
|
||||
// }
|
||||
//
|
||||
// public func input(data: Data) {
|
||||
// delegate?.didRead(data: data, from: self)
|
||||
// }
|
||||
//
|
||||
// public func output(data: Data) {
|
||||
// write(rawData: data)
|
||||
// }
|
||||
//
|
||||
// override public func didWrite(data: Data?, by socket: RawTCPSocketProtocol) {
|
||||
// super.didWrite(data: data, by: socket)
|
||||
//
|
||||
// protocolObfuscater.didWrite()
|
||||
//
|
||||
// switch internalStatus {
|
||||
// case .forwarding:
|
||||
// delegate?.didWrite(data: data, by: self)
|
||||
// default:
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func becomeReadyToForward() {
|
||||
// internalStatus = .forwarding
|
||||
// observer?.signal(.readyForForward(self))
|
||||
// delegate?.didBecomeReadyToForwardWith(socket: self)
|
||||
// }
|
||||
//}
|
||||
@@ -1,167 +0,0 @@
|
||||
//import Foundation
|
||||
//
|
||||
//extension ShadowsocksAdapter {
|
||||
// public struct StreamObfuscater {
|
||||
// public class Factory {
|
||||
// public init() {}
|
||||
//
|
||||
// public func build(for session: ConnectSession) -> StreamObfuscaterBase {
|
||||
// return StreamObfuscaterBase(for: session)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class StreamObfuscaterBase {
|
||||
// public weak var inputStreamProcessor: ShadowsocksAdapter!
|
||||
// private weak var _outputStreamProcessor: CryptoStreamProcessor!
|
||||
// public var outputStreamProcessor: CryptoStreamProcessor! {
|
||||
// get {
|
||||
// return _outputStreamProcessor
|
||||
// }
|
||||
// set {
|
||||
// _outputStreamProcessor = newValue
|
||||
// key = _outputStreamProcessor?.key
|
||||
// writeIV = _outputStreamProcessor?.writeIV
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public var key: Data?
|
||||
// public var writeIV: Data?
|
||||
//
|
||||
// let session: ConnectSession
|
||||
//
|
||||
// init(for session: ConnectSession) {
|
||||
// self.session = session
|
||||
// }
|
||||
//
|
||||
// func output(data: Data) {}
|
||||
// func input(data: Data) throws {}
|
||||
// }
|
||||
//
|
||||
// public class OriginStreamObfuscater: StreamObfuscaterBase {
|
||||
// public class Factory: StreamObfuscater.Factory {
|
||||
// public override init() {}
|
||||
//
|
||||
// public override func build(for session: ConnectSession) -> ShadowsocksAdapter.StreamObfuscater.StreamObfuscaterBase {
|
||||
// return OriginStreamObfuscater(for: session)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private var requestSend = false
|
||||
//
|
||||
// private func requestData(withData data: Data) -> Data {
|
||||
// let hostLength = session.host.utf8.count
|
||||
// let length = 1 + 1 + hostLength + 2 + data.count
|
||||
// var response = Data(count: length)
|
||||
// response[0] = 3
|
||||
// response[1] = UInt8(hostLength)
|
||||
// response.replaceSubrange(2..<2+hostLength, with: session.host.utf8)
|
||||
// var beport = UInt16(session.port).bigEndian
|
||||
// withUnsafeBytes(of: &beport) {
|
||||
// response.replaceSubrange(2+hostLength..<4+hostLength, with: $0)
|
||||
// }
|
||||
// response.replaceSubrange(4+hostLength..<length, with: data)
|
||||
// return response
|
||||
// }
|
||||
//
|
||||
// public override func input(data: Data) throws {
|
||||
// inputStreamProcessor!.input(data: data)
|
||||
// }
|
||||
//
|
||||
// public override func output(data: Data) {
|
||||
// if requestSend {
|
||||
// return outputStreamProcessor!.output(data: data)
|
||||
// } else {
|
||||
// requestSend = true
|
||||
// return outputStreamProcessor!.output(data: requestData(withData: data))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class OTAStreamObfuscater: StreamObfuscaterBase {
|
||||
// public class Factory: StreamObfuscater.Factory {
|
||||
// public override init() {}
|
||||
//
|
||||
// public override func build(for session: ConnectSession) -> ShadowsocksAdapter.StreamObfuscater.StreamObfuscaterBase {
|
||||
// return OTAStreamObfuscater(for: session)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private var count: UInt32 = 0
|
||||
//
|
||||
// private let DATA_BLOCK_SIZE = 0xFFFF - 12
|
||||
//
|
||||
// private var requestSend = false
|
||||
//
|
||||
// private func requestData() -> Data {
|
||||
// var response: [UInt8] = [0x13]
|
||||
// response.append(UInt8(session.host.utf8.count))
|
||||
// response += [UInt8](session.host.utf8)
|
||||
// response += [UInt8](Utils.toByteArray(UInt16(session.port)).reversed())
|
||||
// var responseData = Data(bytes: UnsafePointer<UInt8>(response), count: response.count)
|
||||
// var keyiv = Data(count: key!.count + writeIV!.count)
|
||||
//
|
||||
// keyiv.replaceSubrange(0..<writeIV!.count, with: writeIV!)
|
||||
// keyiv.replaceSubrange(writeIV!.count..<writeIV!.count + key!.count, with: key!)
|
||||
// responseData.append(HMAC.final(value: responseData, algorithm: .SHA1, key: keyiv).subdata(in: 0..<10))
|
||||
// return responseData
|
||||
// }
|
||||
//
|
||||
// public override func input(data: Data) throws {
|
||||
// inputStreamProcessor!.input(data: data)
|
||||
// }
|
||||
//
|
||||
// public override func output(data: Data) {
|
||||
// let fullBlockCount = data.count / DATA_BLOCK_SIZE
|
||||
// var outputSize = fullBlockCount * (DATA_BLOCK_SIZE + 10 + 2)
|
||||
// if data.count > fullBlockCount * DATA_BLOCK_SIZE {
|
||||
// outputSize += data.count - fullBlockCount * DATA_BLOCK_SIZE + 10 + 2
|
||||
// }
|
||||
//
|
||||
// let _requestData: Data = requestData()
|
||||
// if !requestSend {
|
||||
// outputSize += _requestData.count
|
||||
// }
|
||||
//
|
||||
// var outputData = Data(count: outputSize)
|
||||
// var outputOffset = 0
|
||||
// var dataOffset = 0
|
||||
//
|
||||
// if !requestSend {
|
||||
// requestSend = true
|
||||
// outputData.replaceSubrange(0..<_requestData.count, with: _requestData)
|
||||
// outputOffset += _requestData.count
|
||||
// }
|
||||
//
|
||||
// while outputOffset != outputSize {
|
||||
// let blockLength = min(data.count - dataOffset, DATA_BLOCK_SIZE)
|
||||
// var len = UInt16(blockLength).bigEndian
|
||||
// withUnsafeBytes(of: &len) {
|
||||
// outputData.replaceSubrange(outputOffset..<outputOffset+2, with: $0)
|
||||
// }
|
||||
//
|
||||
// var kc = Data(count: writeIV!.count + MemoryLayout.size(ofValue: count))
|
||||
// kc.replaceSubrange(0..<writeIV!.count, with: writeIV!)
|
||||
// var c = count.bigEndian
|
||||
// let ms = MemoryLayout.size(ofValue: c)
|
||||
// withUnsafeBytes(of: &c) {
|
||||
// kc.replaceSubrange(writeIV!.count..<writeIV!.count+ms, with: $0)
|
||||
// }
|
||||
//
|
||||
// data.withUnsafeBytes {
|
||||
// outputData.replaceSubrange(outputOffset+2..<outputOffset+12, with: HMAC.final(value: $0.baseAddress!.advanced(by: dataOffset), length: blockLength, algorithm: .SHA1, key: kc).subdata(in: 0..<10))
|
||||
// }
|
||||
//
|
||||
// data.withUnsafeBytes {
|
||||
// outputData.replaceSubrange(outputOffset+12..<outputOffset+12+blockLength, with: $0.baseAddress!.advanced(by: dataOffset), count: blockLength)
|
||||
// }
|
||||
//
|
||||
// count += 1
|
||||
// outputOffset += 12 + blockLength
|
||||
// dataOffset += blockLength
|
||||
// }
|
||||
//
|
||||
// return outputStreamProcessor!.output(data: outputData)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user