9

I'm currently exploring creating a jailbreak tweak. I want to unlock the phone screen. How is this done? What private API can be used to achieve this on iOS 7?

radj
  • 4,360
  • 7
  • 26
  • 41

5 Answers5

9

If we are talking about jailbreak then you can write a SpringBoard tweak that does this (iOS 7 only)

[[objc_getClass("SBBacklightController") sharedInstance] turnOnScreenFullyWithBacklightSource:0];
[[objc_getClass("SBLockScreenManager") sharedInstance] unlockUIFromSource:0 withOptions:nil];

Without passcode lock the code will turn on the screen and unlock the device. With passcode it will turn on the screen and request passcode.

creker
  • 9,400
  • 1
  • 30
  • 47
  • 1
    I'm in the middle of another task. I'll try this out soon and let you know. – radj Feb 20 '14 at 09:01
  • Say, can this be used from a tool perspective and not a tweak? – radj Feb 24 '14 at 06:01
  • No, it can only be used in SpringBoard tweak. – creker Feb 24 '14 at 06:40
  • Hmmm. I guess I make a tweak that sets up a message port on SpringBoard that invokes the methods above. And the command line tool will just send a message to that port... – radj Feb 24 '14 at 09:56
  • 2
    You could use Darwin notifications for that. Every application can send those, even inside sandbox. You don't need to create any ports or anything. `CFNotificationCenterGetDarwinNotifyCenter`, `CFNotificationCenterPostNotification` and `CFNotificationCenterAddObserver` functions are everything you need. – creker Feb 24 '14 at 10:13
  • @creker It is possible to write something simillar for iOS using external BIG frameworks (Like QT)? -I am new in iOS development – Mazeryt Nov 17 '14 at 22:15
4

I use Activator from Cydia to wake and unlock the device via SSH. It works on IOS 10.1.

activator send libactivator.system.homebutton
activator send libactivator.system.homebutton

lock command is here:

activator send libactivator.system.sleepbutton

Good Luck Have Fun :)

August Lin
  • 1,249
  • 12
  • 11
3

My solution comes in two parts but it could be better:

  1. Power on screen by simulating a power button press with this code:

    VNCSendHIDEvent(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, mach_absolute_time(),
    kHIDPage_Consumer, kHIDUsage_Csmr_Power, 1, 0)); // Power button down
    VNCSendHIDEvent(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, mach_absolute_time(),
    kHIDPage_Consumer, kHIDUsage_Csmr_Power, 0, 0)); // Power button up
    
  2. After 1, the screen will light up and then you can use SimulateTouch's stouch tool to simulate a swipe from the command line.

For 1 above, your code needs to have the com.apple.private.hid.client.event-dispatch entitlement.

For more, you can also investigate how Activator performs the Unlock screen listener.

totymedli
  • 29,531
  • 22
  • 131
  • 165
radj
  • 4,360
  • 7
  • 26
  • 41
  • Is it possible to draw application's UI over entire screen in locked mode and substantially delay power save mode? – Brian Cannard Jul 22 '14 at 21:00
  • 1
    @avesus I'm not sure that can be done. Maybe you can ask that as a separate question here on SO. – radj Jul 23 '14 at 07:23
2

Maybe not a direct solution. You can use this tweak and library https://github.com/iolate/SimulateTouch to simulate a user swipe on the lockscreen to unlock the device.

cloudycliff
  • 299
  • 1
  • 8
  • Thank you for the answer but this doesn't work on iOS 7 anymore. The underlying API GSEvent no longer works on iOS 7. I edited my question to clarify for iOS 7. – radj Feb 18 '14 at 05:46
  • @radj The README on that project says it DOES support iOS 7. – Nicu Stiurca Feb 18 '14 at 06:38
  • @radj This tweak doesn't use GSEvent and it works fine on my iPhone4 running iOS7. – cloudycliff Feb 18 '14 at 07:54
  • Gotta check again. Wait. – radj Feb 18 '14 at 09:47
  • @cloudycliff How are you using it on your iPhone 4? – radj Feb 18 '14 at 09:48
  • 2
    I install the tweak and library from cydia, and call [SimulateTouch simulateSwipeFromPoint:fromPoint toPoint:toPoint duration:duration] from my tweak. Don't forget to copy libsimulatetouch.dylib(you can compile it yourself) to theos's lib dir and add XXX-LDFLAGS = -lsimulatetouch in Makefile. – cloudycliff Feb 18 '14 at 10:02
  • Also, this answer (assuming the swipe using ST works) lacks the part simulating a power/menu button so there is a working screen to swipe on. – radj Feb 18 '14 at 10:12
  • @cloudycliff This is a bit more complicated but just adding here for additional info. I've been looking for SimulateTouch in Cydia on the 5c and it doesn't appear but it appears on the Cydia for iPod touch 4th gen. I installed it on the iPod and it works by calling `stouch swipe` via ssh. The problem is I still need to power on the screen. – radj Feb 18 '14 at 10:15
  • My fault, I haven't thought about the power on part. Really have no idea how to power on the device programmatically. Maybe you can fake some events like notifications, messages, phone calls, alarm clock to wake the device? – cloudycliff Feb 18 '14 at 10:20
0

Call this code from the context of SpringBoard process. For some case, you may use tweak for that.
Note: ensure you're calling it from the Main thread

[[NSClassFromString(@"SBBacklightController") sharedInstance] turnOnScreenFullyWithBacklightSource:0];
[[NSClassFromString(@"SBLockScreenManager") sharedInstance] unlockUIFromSource:0xD withOptions:nil];

Without passcode lock the code will turn on the screen and unlock the device. With passcode it will turn on the screen and request passcode.