@@ -21,16 +21,18 @@ func sockaddr_cast(_ p: UnsafeMutableRawPointer) -> UnsafeMutablePointer<sockadd
21
21
return p. assumingMemoryBound ( to: sockaddr. self)
22
22
}
23
23
24
- protocol Kinded {
24
+ protocol EntryInfo {
25
25
var offset : Int32 { get }
26
26
var kind : Int32 { get }
27
27
}
28
28
29
29
open class AndroidInjection {
30
30
31
+ static var injectionNumber = 0
32
+
31
33
open class func connectAndRun( forMainThread: @escaping ( @escaping ( ) -> ( ) ) -> ( ) ) {
32
34
if androidInjectionHost == " NNN.NNN.NNN.NNN " {
33
- NSLog ( " Injection: androidInjectionHost has not been updated, try build again " )
35
+ NSLog ( " Injection: AndroidInjectionHost.swift has not been updated, please build again. " )
34
36
return
35
37
}
36
38
@@ -74,6 +76,7 @@ open class AndroidInjection {
74
76
else {
75
77
return loaderSocket
76
78
}
79
+
77
80
close ( loaderSocket)
78
81
return - 1
79
82
}
@@ -101,7 +104,7 @@ open class AndroidInjection {
101
104
fflush ( serverWrite)
102
105
103
106
let serverRead = fdopen ( serverSocket, " r " )
104
- var compressedLength : Int32 = 0 , uncompressedLength : Int32 = 0 , injectionNumber = 0
107
+ var compressedLength : Int32 = 0 , uncompressedLength : Int32 = 0
105
108
106
109
while fread ( & compressedLength, 1 , valueLength, serverRead) == valueLength &&
107
110
fread ( & uncompressedLength, 1 , valueLength, serverRead) == valueLength,
@@ -126,8 +129,8 @@ open class AndroidInjection {
126
129
break
127
130
}
128
131
129
- injectionNumber += 1
130
- let libraryPath = NSTemporaryDirectory ( ) + " injection \( injectionNumber) .so "
132
+ AndroidInjection . injectionNumber += 1
133
+ let libraryPath = NSTemporaryDirectory ( ) + " injection \( AndroidInjection . injectionNumber) .so "
131
134
let libraryFILE = fopen ( libraryPath, " w " )
132
135
if libraryFILE == nil ||
133
136
fwrite ( uncompressedBuffer, 1 , Int ( uncompressedLength) , libraryFILE) != uncompressedLength {
@@ -176,7 +179,7 @@ open class AndroidInjection {
176
179
177
180
var processed = [ UnsafeMutablePointer < UInt8 > : Bool ] ( )
178
181
179
- struct TypeEntry : Kinded {
182
+ struct TypeEntry : EntryInfo {
180
183
let offset : Int32
181
184
let kind : Int32
182
185
}
@@ -185,7 +188,7 @@ open class AndroidInjection {
185
188
entrySymbol: " .swift2_type_metadata_start " ,
186
189
entryType: TypeEntry . self, processed: & processed)
187
190
188
- struct Conformance : Kinded {
191
+ struct Conformance : EntryInfo {
189
192
let skip1 : Int32
190
193
let offset : Int32
191
194
let skip2 : Int32
@@ -194,14 +197,14 @@ open class AndroidInjection {
194
197
195
198
process ( libHandle: libHandle, mainHandle: mainHandle,
196
199
entrySymbol: " .swift2_protocol_conformances_start " ,
197
- entryType: Conformance . self, pointerOffset: pointerSize , processed: & processed)
200
+ entryType: Conformance . self, pointerOffset: MemoryLayout < Int32 > . size , processed: & processed)
198
201
199
202
return nil
200
203
}
201
204
202
- class func process< T: Kinded > ( libHandle: UnsafeMutableRawPointer , mainHandle: UnsafeMutableRawPointer ,
203
- entrySymbol: String , entryType: T . Type , pointerOffset: Int = 0 ,
204
- processed: inout [ UnsafeMutablePointer < UInt8 > : Bool ] ) {
205
+ class func process< T: EntryInfo > ( libHandle: UnsafeMutableRawPointer , mainHandle: UnsafeMutableRawPointer ,
206
+ entrySymbol: String , entryType: T . Type , pointerOffset: Int = 0 ,
207
+ processed: inout [ UnsafeMutablePointer < UInt8 > : Bool ] ) {
205
208
guard let conformance = dlsym ( libHandle, entrySymbol) else {
206
209
NSLog ( " Could not locate \( entrySymbol) entries " )
207
210
return
0 commit comments