16

I need to run the following code to turn off my iphone screen .

On iOS6:

void (*BKSDisplayServicesSetScreenBlanked)(BOOL blanked) = (void (*)(BOOL blanked))dlsym(RTLD_DEFAULT, "BKSDisplayServicesSetScreenBlanked");

and then use:

BKSDisplayServicesSetScreenBlanked(1); // 1 to dim, 0 to undim

It doesnt work. Somebody told me that I need com.apple.backboard.client entitlements for this to work on my iphone. I dont know how to set these entitlements. I have seen several ways to set entitlements but they are very confusing to me, like this one.

Yes, you do need to code sign the entitlements. But, no, it doesn't have to be with an Apple certificate on jailbroken phones. You can fake code sign, by downloading the ldid executable, and doing

cd MyAppName.app 
ldid -Sentitlements.xml MyAppName

assuming your app is named MyAppName and you made the entitlements file entitlements.xml. I believe that this entitlements file would work for you, if you fake code-signed it with ldid.

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0">
   <dict>
     <key>com.apple.backboard.client</key>
     <true/>
   </dict> 
</plist>

Even with the above method, where do i place the above entitlements file?

Nate
  • 31,017
  • 13
  • 83
  • 207
zzzzz
  • 1,209
  • 2
  • 18
  • 45

2 Answers2

22

For a jailbreak app/entitlement, you need to do something like this. First, create a file named entitlements.xml (or whatever you like):

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>com.apple.backboard.client</key>
    <true/>
  </dict>
</plist>

You can add more entitlements if you need. This example file just grants the app the com.apple.backboard.client entitlement.

It doesn't really matter where you put this file. The key is:

  1. You will need to modify Xcode's SDKSettings.plist file, as shown here. CODE_SIGNING_REQUIRED should be set to NO.
  2. Do not code sign your app in Xcode. In Build Settings, make sure the code sign identity is set to Don't Code Sign.
  3. After you then Build your app for the iOS Device (not Simulator!), then go to the directory on your Mac where the output files are located. For an app named HelloWorld, you're looking for the HelloWorld.app folder. It can differ depending on your configuration, so I won't bother trying to tell you where that is. If in doubt, use the command line find command.
  4. Download ldid pre-built from this location, or as source from here.
  5. Copy the entitlements.xml file into the same directory as where HelloWorld.app is. (Note: you don't have to have it here ... if you put it somewhere else, just adjust the command line I show you below).
  6. Change directory to the directory where your entitlements.xml file is.
  7. Fake code-sign with this command:
$ldid -Sentitlements.xml HelloWorld.app/HelloWorld

After that point, you'll need to transfer the entire HelloWorld.app folder to install the app on your device. There's many ways to do that, and it sounds like you already have a way.

I have this whole process setup with a script, to make it easier.

Note: I am not stating whether or not this entitlement is the correct entitlement to use for the BKSDisplayServicesSetScreenBlanked() call on iOS 6. I haven't tested that. I do know that this entitlement works to allow you to use SBDimScreen() on lower iOS versions. But, this answer is just a description of how to add this kind of entitlement for a jailbreak app.

Nate
  • 31,017
  • 13
  • 83
  • 207
  • Can I get your skype id please? So I could email you next time I have a jailbreak type question – zzzzz Feb 15 '13 at 14:00
  • I cant sign it using ldid command.it says -bash: -Sentitlements.xml: command not found – zzzzz Feb 18 '13 at 07:57
  • 1
    I can't tell what the error message is, because you haven't used formatting. Please surround the **exact** output with tick marks (top left of most keyboards). It would also help if you showed **exactly** what command you tried (also formatted with code tick marks). – Nate Feb 18 '13 at 08:26
  • I am currently in the directory where screenoffios6.app is placed.entitlements file is also placed in the same directory where i run the command. Now the command I am using is `administrators-Mac-mini-3:debug-iphoneos me$ $ldid -s entitlements.xml screenoffios6.app/screenoffios6` It returns the following error `-bash: -s: command not found` – zzzzz Feb 18 '13 at 09:29
  • 1
    And, you really need to type the commands as I list them. The `-S` is uppercase, not lowercase, and there's no space between it and `entitlements.xml`. – Nate Feb 18 '13 at 09:36
  • Once I put the ./ldid i get the following error `-bash: $./ldid: No such file or directory` I used the following command `./ldid -Sentitlements.xml screenoffios6.app/screenoffios6` – zzzzz Feb 18 '13 at 09:37
  • you are right.I was accidentally typing a $ infront of the command.The command now works but I am getting the following message. `codesign_allocate: object: screenoffios6.app/screenoffios6 malformed object (unknown load command 10) util/ldid.cpp(584): _assert(0:WEXITSTATUS(status) == 0) Trace/BPT trap: 5` – zzzzz Feb 18 '13 at 09:46
  • 1
    Please navigate in Terminal to the directory where your build product is, and go into `screenoffios6.app/`. Inside that directory, issue the command `file screenoffios6` and tell me what the output is (please surround by ticks in your comment). Also, which version of `ldid` (which link I showed in my answer) did you use to get `ldid`? – Nate Feb 18 '13 at 21:52
  • I used the first link to download ldid and file screenoffios6 returned the following output `screenoffios6: Mach-O executable arm` – zzzzz Feb 20 '13 at 10:14
  • 1
    That looks ok, in terms of being one architecture only. Can you run this command: `lipo -info screenoffios6` in the same directory? Your system might not have `lipo`, but hopefully it does. – Nate Feb 20 '13 at 10:17
  • I got this output `Non-fat file: screenoffios6 is architecture: armv7` – zzzzz Feb 20 '13 at 10:24
  • 1
    That should be good, too. At this point, I'm not quite sure what could be wrong. The only thing I can think of is to post your binary on some other site and link to it so I can download the `screenoffios6` executable, and trying signing it myself. I would only need the executable, not any of the other resources needed to run your app (Info.plist, icons, etc.). That's all I can think to suggest at this point. – Nate Feb 20 '13 at 10:32
  • mac version is mac osx 10.7.5 – zzzzz Feb 20 '13 at 11:42
  • 1
    Me, too. I dunno. That exact executable signs successfully for me. The only thing I can suggest is go back and try it again, taking care to type everything in exactly as I listed it. Or google for your error message ... [similar error described here](https://github.com/kokoabim/iOSOpenDev/issues/40) – Nate Feb 20 '13 at 12:04
  • 1
    Also, maybe there's something I have installed that you don't. Try going to Xcode -> Preferences -> Downloads, and make sure **Command Line Tools** are installed. – Nate Feb 20 '13 at 12:04
  • 1
    One more option is to not do `ldid` signing on your Mac, but transfer the *unsigned* executable to the device, along with the entitlements.xml file. Go into Cydia and search for *ldid* and install it **on your phone**. Then, at the (ssh) command line, navigate to where you install your app, and try the `ldid -Sentitlements.xml screenoffios6` command again, **on the device**. – Nate Feb 20 '13 at 12:12
-1

The entitlements are set in either the Xcode project file or set in the entitlements file that the Xcode project chooses.

Look in the project settings in "Summary" or "Build Phases" for the setting or the name of the entitlements file

Walt Sellers
  • 3,806
  • 30
  • 35
  • 2
    (-1) this answer is wrong, or woefully incomplete. This *normal* process for adding entitlements does not work for adding this kind of entitlement for a **jailbreak** app. – Nate Feb 14 '13 at 22:32
  • 1
    I can confirm that it does not work for jailbreak app. (iOS 7.0.4) – 0x8BADF00D Jan 13 '14 at 22:51