Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions StikDebug.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
DC5716242D9564760099302E /* em_proxy.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = em_proxy.xcframework; sourceTree = "<group>"; };
DC6F1D372D94EADD0071B2B6 /* StikDebug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StikDebug.app; sourceTree = BUILT_PRODUCTS_DIR; };
DC6F1D482D94EADF0071B2B6 /* StikDebugTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StikDebugTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DC6F1D522D94EADF0071B2B6 /* StikDebugUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StikDebugUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -62,6 +61,7 @@
1775D3612D9644FD00DFA8E0 /* Exceptions for "StikJIT" folder in "StikDebug" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
idevice/libem_proxy.a,
Info.plist,
);
target = DC6F1D362D94EADD0071B2B6 /* StikDebug */;
Expand Down Expand Up @@ -163,7 +163,6 @@
DC6F1D752D94EB620071B2B6 /* Frameworks */ = {
isa = PBXGroup;
children = (
DC5716242D9564760099302E /* em_proxy.xcframework */,
DCA690112DAF660E007C91A8 /* NetworkExtension.framework */,
);
name = Frameworks;
Expand Down
80 changes: 30 additions & 50 deletions StikJIT/StikJITApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -520,39 +520,32 @@ struct HeartbeatApp: App {
LoadingView(showAlert: $show_alert, alertTitle: $alert_title, alertMessage: $alert_string)
.onAppear {
dnsChecker.checkDNS()

startProxy() { result, error in
checkVPNConnection() { result, vpn_error in
if result {
checkVPNConnection() { result, vpn_error in
if result {
if FileManager.default.fileExists(atPath: URL.documentsDirectory.appendingPathComponent("pairingFile.plist").path) {
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
if pubHeartBeat {
isLoading2 = false
timer.invalidate()
if FileManager.default.fileExists(atPath: URL.documentsDirectory.appendingPathComponent("pairingFile.plist").path) {
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
if pubHeartBeat {
isLoading2 = false
timer.invalidate()
} else {
if let error {
if error == -9 { // InvalidHostID is -9
isPairing = true
} else {
if let error {
if error == -9 { // InvalidHostID is -9
isPairing = true
} else {
startHeartbeatInBackground()
}
self.error = nil
}
startHeartbeatInBackground()
}
self.error = nil
}
startHeartbeatInBackground()
} else {
isLoading2 = false
}
} else if let vpn_error {
showAlert(title: "Error", message: "EM Proxy failed to connect: \(vpn_error)", showOk: true) { _ in
exit(0)
}
}
startHeartbeatInBackground()
} else {
isLoading2 = false
}
} else if let vpn_error {
showAlert(title: "Error", message: "EM Proxy failed to connect: \(vpn_error)", showOk: true) { _ in
exit(0)
}
} else if let error {
showAlert(title: "Error", message: "EM Proxy Failed to start \(error)", showOk: true) { _ in }
}
}
}
Expand Down Expand Up @@ -658,24 +651,6 @@ struct HeartbeatApp: App {
}
}

func startProxy(callback: @escaping (Bool, Int?) -> Void) {
let port = 51820
let bindAddr = "127.0.0.1:\(port)"

DispatchQueue.global(qos: .background).async {
let result = start_emotional_damage(bindAddr)
DispatchQueue.main.async {
if result == 0 {
print("DEBUG: em_proxy started successfully on port \(port)")
callback(true, nil)
} else {
print("DEBUG: Failed to start em_proxy")
callback(false, Int(result))
}
}
}
}

private func checkVPNConnection(callback: @escaping (Bool, String?) -> Void) {
let host = NWEndpoint.Host("10.7.0.1")
let port = NWEndpoint.Port(rawValue: 62078)!
Expand Down Expand Up @@ -948,10 +923,12 @@ struct LoadingView: View {
}
}

public func showAlert(title: String, message: String, showOk: Bool, showTryAgain: Bool = false, primaryButtonText: String? = nil, completion: @escaping (Bool) -> Void) {
public func showAlert(title: String, message: String, showOk: Bool, showTryAgain: Bool = false, primaryButtonText: String? = nil, messageType: MessageType = .error, completion: @escaping (Bool) -> Void) {
DispatchQueue.main.async {
let rootViewController = UIApplication.shared.windows.last?.rootViewController

guard let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene else {
return
}
let rootViewController = scene.windows.first?.rootViewController
if showTryAgain {
let customErrorView = CustomErrorView(
title: title,
Expand All @@ -964,7 +941,8 @@ public func showAlert(title: String, message: String, showOk: Bool, showTryAgain
primaryButtonText: primaryButtonText ?? "Try Again",
onPrimaryButtonTap: {
completion(true)
}
},
messageType: messageType
)
let hostingController = UIHostingController(rootView: customErrorView)
hostingController.modalPresentationStyle = .overFullScreen
Expand All @@ -984,7 +962,8 @@ public func showAlert(title: String, message: String, showOk: Bool, showTryAgain
onPrimaryButtonTap: {
rootViewController?.presentedViewController?.dismiss(animated: true)
completion(true)
}
},
messageType: messageType
)
let hostingController = UIHostingController(rootView: customErrorView)
hostingController.modalPresentationStyle = .overFullScreen
Expand All @@ -999,7 +978,8 @@ public func showAlert(title: String, message: String, showOk: Bool, showTryAgain
rootViewController?.presentedViewController?.dismiss(animated: true)
completion(false)
},
showButton: false
showButton: false,
messageType: messageType
)
let hostingController = UIHostingController(rootView: customErrorView)
hostingController.modalPresentationStyle = .overFullScreen
Expand Down
11 changes: 6 additions & 5 deletions StikJIT/Views/Custom Error View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

import SwiftUI

public enum MessageType {
case error
case success
case info
}

struct CustomErrorView: View {
var title: String
var message: String
Expand All @@ -32,11 +38,6 @@ struct CustomErrorView: View {
}
}

enum MessageType {
case error
case success
case info
}

var body: some View {
ZStack {
Expand Down
85 changes: 85 additions & 0 deletions StikJIT/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ struct HomeView: View {
@State private var showingConsoleLogsView = false
@State private var importProgress: Float = 0.0

@State private var pidTextAlertShow = false
@State private var pidStr = ""

@State private var viewDidAppeared = false
@State private var pendingBundleIdToEnableJIT : String? = nil
@State private var pendingPIDToEnableJIT : Int? = nil

private var accentColor: Color {
if customAccentColorHex.isEmpty {
Expand Down Expand Up @@ -99,6 +103,27 @@ struct HomeView: View {
}
.padding(.horizontal, 20)

if pairingFileExists {
Button(action: {
pidTextAlertShow = true
}) {
HStack {
Image(systemName: "cable.connector.horizontal")
.font(.system(size: 20))
Text("Connect by PID")
.font(.system(.title3, design: .rounded))
.fontWeight(.semibold)
}
.frame(maxWidth: .infinity)
.padding()
.background(accentColor)
.foregroundColor(accentColor.contrastText())
.cornerRadius(16)
.shadow(color: accentColor.opacity(0.3), radius: 8, x: 0, y: 4)
}
.padding(.horizontal, 20)
}

Button(action: {
showingConsoleLogsView = true
}) {
Expand Down Expand Up @@ -271,6 +296,28 @@ struct HomeView: View {
startJITInBackground(with: selectedBundle)
}
}
.textFieldAlert(
isPresented: $pidTextAlertShow,
title: "Please enter the PID of the process you want to connect to",
text: $pidStr,
placeholder: "",
action: { newText in

guard let pidStr = newText, pidStr != "" else {
return
}

guard let pid = Int(pidStr) else {
showAlert(title: "", message: "Invalid PID", showOk: true, completion: { _ in })
return
}
startJITInBackground(with: pid)

},
actionCancel: {_ in
pidStr = ""
}
)
.onOpenURL { url in
print(url.path())
if url.host() != "enable-jit" {
Expand All @@ -284,6 +331,12 @@ struct HomeView: View {
} else {
pendingBundleIdToEnableJIT = bundleId
}
} else if let pidStr = components?.queryItems?.first(where: { $0.name == "pid" })?.value, let pid = Int(pidStr) {
if viewDidAppeared {
startJITInBackground(with: pid)
} else {
pendingPIDToEnableJIT = pid
}
}

}
Expand All @@ -293,6 +346,10 @@ struct HomeView: View {
startJITInBackground(with: pendingBundleIdToEnableJIT)
self.pendingBundleIdToEnableJIT = nil
}
if let pendingPIDToEnableJIT {
startJITInBackground(with: pendingPIDToEnableJIT)
self.pendingPIDToEnableJIT = nil
}
}
}

Expand Down Expand Up @@ -342,6 +399,34 @@ struct HomeView: View {
}
}
}

private func startJITInBackground(with pid: Int) {
isProcessing = true

// Add log message
LogManager.shared.addInfoLog("Starting JIT for pid \(pid)")

DispatchQueue.global(qos: .background).async {

let success = JITEnableContext.shared.debugApp(withPID: Int32(pid), logger: { message in

if let message = message {
// Log messages from the JIT process
LogManager.shared.addInfoLog(message)
}
})

DispatchQueue.main.async {
LogManager.shared.addInfoLog("JIT process completed for \(pid)")
showAlert(title: "Success", message: "JIT has been enabled for pid \(pid).", showOk: true, messageType: .success, completion: { _ in })
isProcessing = false

if success && doAutoQuitAfterEnablingJIT {
exit(0)
}
}
}
}
}

class InstalledAppsViewModel: ObservableObject {
Expand Down
Loading
Loading