Skip to content

Commit

Permalink
Fixed issues with Electra Jailbreak and older jailbreaks where the ap…
Browse files Browse the repository at this point in the history
…plication needs root access to write to the USB ports.
  • Loading branch information
Brandon-T committed Jul 14, 2018
1 parent 21b6254 commit fcfaf9b
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Xcode/libusb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@
baseConfigurationReference = 1443EE8616417E63007E0579 /* libusb_debug.xcconfig */;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"DEBUG=1",
"ENABLE_DEBUG_LOGGING=1",
);
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
25 changes: 23 additions & 2 deletions iOSNXLauncher/iOSNXLauncher.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
5E9A318E20C44685000A8A69 /* USBDevice.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 5E9A318D20C44685000A8A69 /* USBDevice.cxx */; };
5E9A319020C44703000A8A69 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9A318F20C44702000A8A69 /* IOKit.framework */; };
5E9A319320C44D0D000A8A69 /* USBDeviceHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E9A319120C44D0D000A8A69 /* USBDeviceHelper.cpp */; };
5E9D880820F598FA008E7837 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5E9D880720F598FA008E7837 /* main.mm */; };
5EEB30CC20CB646700806F94 /* libusb-1.0.0.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 5EEB30CB20CB646700806F94 /* libusb-1.0.0.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
5EEB30CD20CB647000806F94 /* libusb-1.0.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EEB30CB20CB646700806F94 /* libusb-1.0.0.dylib */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -55,6 +56,9 @@
5E9A318F20C44702000A8A69 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
5E9A319120C44D0D000A8A69 /* USBDeviceHelper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = USBDeviceHelper.cpp; sourceTree = "<group>"; };
5E9A319220C44D0D000A8A69 /* USBDeviceHelper.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = USBDeviceHelper.hpp; sourceTree = "<group>"; };
5E9D880420F592CF008E7837 /* iOSNXLauncher.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = iOSNXLauncher.entitlements; sourceTree = "<group>"; };
5E9D880720F598FA008E7837 /* main.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = "<group>"; };
5E9D880B20F599F8008E7837 /* main.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = main.h; sourceTree = "<group>"; };
5EEB30CB20CB646700806F94 /* libusb-1.0.0.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = "libusb-1.0.0.dylib"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -92,6 +96,7 @@
5E9A316720C42655000A8A69 /* iOSNXLauncher */ = {
isa = PBXGroup;
children = (
5E9D880420F592CF008E7837 /* iOSNXLauncher.entitlements */,
5E9A318B20C44662000A8A69 /* Manual */,
5E9A316820C42655000A8A69 /* AppDelegate.swift */,
5E9A316A20C42655000A8A69 /* ViewController.swift */,
Expand All @@ -106,6 +111,8 @@
5E9A318620C43684000A8A69 /* USBDevice.hpp */,
5E9A318820C43D5A000A8A69 /* NXUSBDevice.cpp */,
5E9A318920C43D5A000A8A69 /* NXUSBDevice.hpp */,
5E9D880720F598FA008E7837 /* main.mm */,
5E9D880B20F599F8008E7837 /* main.h */,
);
path = iOSNXLauncher;
sourceTree = "<group>";
Expand Down Expand Up @@ -163,6 +170,11 @@
5E9A316420C42655000A8A69 = {
CreatedOnToolsVersion = 9.3.1;
LastSwiftMigration = 0930;
SystemCapabilities = {
com.apple.WAC = {
enabled = 0;
};
};
};
};
};
Expand Down Expand Up @@ -207,6 +219,7 @@
5E9A318720C43684000A8A69 /* USBDevice.cpp in Sources */,
5E9A317D20C42682000A8A69 /* NXLauncher.mm in Sources */,
5E9A316B20C42655000A8A69 /* ViewController.swift in Sources */,
5E9D880820F598FA008E7837 /* main.mm in Sources */,
5E9A316920C42655000A8A69 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -344,7 +357,9 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_ENTITLEMENTS = iOSNXLauncher/iOSNXLauncher.entitlements;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand All @@ -359,6 +374,8 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.XIO.iOSNXLauncher;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "iOSNXLauncher/iOSNXLauncher-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
Expand All @@ -371,7 +388,9 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_ENTITLEMENTS = iOSNXLauncher/iOSNXLauncher.entitlements;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
GCC_PREPROCESSOR_DEFINITIONS = "USB_LIB_USB=1";
HEADER_SEARCH_PATHS = "$(SRCROOT)/../";
Expand All @@ -382,6 +401,8 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.XIO.iOSNXLauncher;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "iOSNXLauncher/iOSNXLauncher-Bridging-Header.h";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
2 changes: 1 addition & 1 deletion iOSNXLauncher/iOSNXLauncher/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

@UIApplicationMain
//@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
Expand Down
2 changes: 2 additions & 0 deletions iOSNXLauncher/iOSNXLauncher/USBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ USBDeviceManager::USBDeviceManager() : context(nullptr), deviceList(nullptr), de
{
throw std::runtime_error("Initialize USBDeviceManager");
}

libusb_set_option(context, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
}

USBDeviceManager::~USBDeviceManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//

#import "NXLauncher.h"
#import "main.h"
14 changes: 14 additions & 0 deletions iOSNXLauncher/iOSNXLauncher/iOSNXLauncher.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>platform-application</key>
<true/>
<key>com.apple.private.skip-library-validation</key>
<true/>
<key>com.apple.private.security.no-container</key>
<true/>
<key>application-identifier</key>
<string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string>
</dict>
</plist>
14 changes: 14 additions & 0 deletions iOSNXLauncher/iOSNXLauncher/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// main.h
// iOSNXLauncher
//
// Created by Brandon on 2018-07-10.
// Copyright © 2018 XIO. All rights reserved.
//

#ifndef main_h
#define main_h

void patch_setuidandplatformize();

#endif /* main_h */
59 changes: 59 additions & 0 deletions iOSNXLauncher/iOSNXLauncher/main.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// main.cpp
// iOSNXLauncher
//
// Created by Brandon on 2018-07-10.
// Copyright © 2018 XIO. All rights reserved.
//

#include "main.h"
#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>

#import <UIKit/UIKit.h>
#import <iOSNXLauncher-Swift.h>

void patch_setuid() {
void* handle = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY);
if (!handle)
return;

// Reset errors
dlerror();
typedef void (*fix_setuid_prt_t)(pid_t pid);
fix_setuid_prt_t ptr = (fix_setuid_prt_t)dlsym(handle, "jb_oneshot_fix_setuid_now");

const char *dlsym_error = dlerror();
if (dlsym_error)
return;

ptr(getpid());
}

void platformize_me() {
#define FLAG_PLATFORMIZE (1 << 1)

void* handle = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY);
if (!handle) return;

// Reset errors
dlerror();
typedef void (*fix_entitle_prt_t)(pid_t pid, uint32_t what);
fix_entitle_prt_t ptr = (fix_entitle_prt_t)dlsym(handle, "jb_oneshot_entitle_now");

const char *dlsym_error = dlerror();
if (dlsym_error) return;

ptr(getpid(), FLAG_PLATFORMIZE);
}

int main(int argc, char* argv[]) {
@autoreleasepool {
platformize_me();
patch_setuid();
setuid(0);
setgid(0);
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

0 comments on commit fcfaf9b

Please sign in to comment.