Skip to content

Commit

Permalink
Assortment of changes after testing on Monterey (johnno1962#22)
Browse files Browse the repository at this point in the history
* New hidden prefix.

* Testing on Monterey
  • Loading branch information
johnno1962 authored Jun 27, 2021
1 parent c6bc11c commit d05790f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
//
// $Id: //depot/HotReloading/Package.swift#55 $
// $Id: //depot/HotReloading/Package.swift#56 $
//

import PackageDescription
Expand All @@ -18,13 +18,13 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/johnno1962/SwiftTrace",
.upToNextMinor(from: "7.4.3")),
.upToNextMinor(from: "7.4.4")),
.package(url: "https://github.com/johnno1962/SwiftRegex5",
.upToNextMinor(from: "5.2.1")),
.package(url: "https://github.com/johnno1962/XprobePlugin",
.upToNextMinor(from: "2.4.1")),
.package(url: "https://github.com/johnno1962/Remote",
.upToNextMinor(from: "2.3.1")),
.upToNextMinor(from: "2.3.2")),
],
targets: [
.target(name: "HotReloading", dependencies: ["HotReloadingGuts",
Expand Down
14 changes: 11 additions & 3 deletions Sources/HotReloading/InjectionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 02/24/2021.
// Copyright © 2021 John Holdsworth. All rights reserved.
//
// $Id: //depot/HotReloading/Sources/HotReloading/InjectionClient.swift#23 $
// $Id: //depot/HotReloading/Sources/HotReloading/InjectionClient.swift#24 $
//
// Client app side of HotReloading started by +load
// method in HotReloadingGuts/ClientBoot.mm
Expand Down Expand Up @@ -76,9 +76,17 @@ public class InjectionClient: SimpleSocket {

SwiftTrace.swizzleFactory = SwiftTrace.LifetimeTracker.self

while let command = InjectionCommand(rawValue: readInt()),
command != .EOF {
commandLoop:
while true {
let commandInt = readInt()
guard let command = InjectionCommand(rawValue: commandInt) else {
print("\(APP_PREFIX)Invalid commandInt: \(commandInt)")
break
}
switch command {
case .EOF:
print("\(APP_PREFIX)EOF received from server..")
break commandLoop
case .signed:
writer.write(readString() ?? "0")
case .traceFramework:
Expand Down
5 changes: 4 additions & 1 deletion Sources/HotReloading/SwiftInjection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 05/11/2017.
// Copyright © 2017 John Holdsworth. All rights reserved.
//
// $Id: //depot/HotReloading/Sources/HotReloading/SwiftInjection.swift#43 $
// $Id: //depot/HotReloading/Sources/HotReloading/SwiftInjection.swift#44 $
//
// Cut-down version of code injection in Swift. Uses code
// from SwiftEval.swift to recompile and reload class.
Expand Down Expand Up @@ -331,6 +331,9 @@ public class SwiftInjection: NSObject {
#endif
}) + vtabled == 0 {
print("\(APP_PREFIX)⚠️ Injection may have failed. Have you added -Xlinker -interposable to the \"Other Linker Flags\" of the executable/framework? ⚠️")
if #available(iOS 15.0, tvOS 15.0, macOS 12.0, *) {
print("\(APP_PREFIX)⚠️ Unfortunately, interposing Swift symbols is not availble when targetting iOS 15+ ⚠️")
}
}
#else
// Using array of new interpose structs
Expand Down
16 changes: 12 additions & 4 deletions Sources/HotReloadingGuts/SimpleSocket.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 06/11/2017.
// Copyright © 2017 John Holdsworth. All rights reserved.
//
// $Id: //depot/HotReloading/Sources/HotReloadingGuts/SimpleSocket.mm#8 $
// $Id: //depot/HotReloading/Sources/HotReloadingGuts/SimpleSocket.mm#10 $
//

#import "SimpleSocket.h"
Expand Down Expand Up @@ -145,9 +145,15 @@ - (void)runInBackground {
}

- (int)readInt {
int32_t anint;
if (read(clientSocket, &anint, sizeof anint) != sizeof anint)
int32_t anint = ~0;
size_t length = sizeof anint, rd, ptr = 0;
while (ptr < length &&
(rd = read(clientSocket, (char *)&anint+ptr, length-ptr)) > 0)
ptr += rd;
if (ptr < length) {
NSLog(@"[%@ readInt] error: %lu, %s", self, ptr, strerror(errno));
return ~0;
}
SLog(@"#%d <- %d", clientSocket, anint);
return anint;
}
Expand All @@ -159,8 +165,10 @@ - (NSData *)readData {
while (ptr < length &&
(rd = read(clientSocket, bytes+ptr, length-ptr)) > 0)
ptr += rd;
if (ptr < length)
if (ptr < length) {
NSLog(@"[%@ readString] error: %lu < %d, %s", self, ptr, length, strerror(errno));
return nil;
}
return [NSData dataWithBytesNoCopy:bytes length:length freeWhenDone:YES];
}

Expand Down
9 changes: 5 additions & 4 deletions Sources/HotReloadingGuts/Unhide.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// (default argument generators) so they can be referenced
// in a file being dynamically loaded.
//
// $Id: //depot/HotReloading/Sources/HotReloadingGuts/Unhide.mm#10 $
// $Id: //depot/HotReloading/Sources/HotReloadingGuts/Unhide.mm#11 $
//

#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -104,9 +104,10 @@ int unhide_symbols(const char *framework, const char *linkFileList, FILE *log, t
// Default argument generators have a suffix ANN_
symend = symname + strlen(symname);
BOOL isDefaultArgument = (symend[-1] == '_' &&
(symend[-2] == 'A' || (symend[-3] == 'A' && isdigit(symend[-2])) ||
(symend[-4] == 'A' && isdigit(symend[-3]) && isdigit(symend[-2])))) ||
strcmp(symend-4, "QOMg") == 0 || strcmp(symend-3, "vau") == 0;
(symend[-2] == 'A' || (isdigit(symend[-2] &&
(symend[-3] == 'A' || (isdigit(symend[-3] &&
symend[-4] == 'A'))))))) || strcmp(symend-4, "QOMg") == 0 ||
strcmp(symend-3, "vau") == 0 || strcmp(symend-2, "FZ") == 0;

// The following reads: If symbol is for a default argument
// and it is the definition (not a reference) and we've not
Expand Down
5 changes: 4 additions & 1 deletion Sources/injectiond/Experimental.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by User on 20/10/2020.
// Copyright © 2020 John Holdsworth. All rights reserved.
//
// $Id: //depot/HotReloading/Sources/injectiond/Experimental.swift#18 $
// $Id: //depot/HotReloading/Sources/injectiond/Experimental.swift#19 $
//

import Cocoa
Expand Down Expand Up @@ -339,6 +339,9 @@ extension AppDelegate {
"""
#else
let loadInjection = """
guard objc_getClass("InjectionClient") == nil else {
return
}
#if os(macOS)
let bundleName = "macOSInjection.bundle"
#elseif os(tvOS)
Expand Down
5 changes: 3 additions & 2 deletions Sources/injectiond/InjectionServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 06/11/2017.
// Copyright © 2017 John Holdsworth. All rights reserved.
//
// $Id: //depot/HotReloading/Sources/injectiond/InjectionServer.swift#25 $
// $Id: //depot/HotReloading/Sources/injectiond/InjectionServer.swift#26 $
//

import Cocoa
Expand Down Expand Up @@ -63,7 +63,7 @@ public class InjectionServer: SimpleSocket {
// tell client app the inferred project being watched
NSLog("Connection for project file: \(projectFile)")

if readInt() != INJECTION_SALT || readString() != INJECTION_KEY {
if readInt() != INJECTION_SALT || readString() != INJECTION_KEY && true {
NSLog("*** Error: SALT or KEY invalid. Are you running start_daemon.sh or InjectionIII.app from the right directory?")
write("/tmp")
write(InjectionCommand.invalid.rawValue)
Expand Down Expand Up @@ -91,6 +91,7 @@ public class InjectionServer: SimpleSocket {
builder.tmpDir = builder.frameworks
}
write(builder.tmpDir)
NSLog("Using tmp dir: \(builder.tmpDir)")

// log errors to client
builder.evalError = {
Expand Down

0 comments on commit d05790f

Please sign in to comment.