Sunday, March 13, 2016

Jailbreaking a Samsung Galaxy Core Prime


Note #3: Updated in November 2016 with instructions on how to root and commentary on bootloading.

Note #1: I'm writing this article in March 2016. I estimate it's shelf-life to be about three months. Sometime around mid-summer the rot will set in: links will stop working, Verizon will push an OS update, a better phone will come out, a new exploit discovered...

Note #2: The OS for a phone is specific for each carrier. This post contains information specific to the Verizon SM-360V. If your carrier is T-Mobile, you have a SM-360H (lucky you.)

In order to truly "own" your phone, you need two types of privilege escalation:
  • the ability to modify any file in the Operating System (root access)
  • the ability to control what happens when turn on the power (bootloader access)
The process of asserting ownership is called "jailbreaking".  This is related to, but different from, unlocking the phone.  Jailbreaking allows you to customize the software running on the phone.  Unlocking the SIM card allows the phone to connect to a new cellphone provider.

Companies that sell you the phone don't want you to have either form of access.  They don't want you to unlock and switch to a competing service provider.  They don't want you to jailbreak and remove all the "bloatware" and advertising they were paid to install on the phone.  But there's this pesky thing called "Open Source", which legally mandates that corporations give you -- the owner of the computer -- these rights if you buy an Android phone (which is based on the Linux OS).

Because that's what you're holding in your hand.  While most people look at it and think "phone", it actually is a computer that happens to be able to make phone calls.  (Likewise, a Tesla is, when you come right down to it, just a computer on wheels with a ginormous battery pack.)  So when I write, "computer", you can think "the silicon chips inside the phone."  (Not to be confused with the silicon chips inside her head.)

Apple works rather hard to stop people from jailbreaking their iHardware, and their OS updates deliberately close exploits.  I expect Microsoft does likewise for their phones.  But there is an extensive developer community hacking the Android ecosystem.  This does not mean that it is easy to jailbreak, but there is a central place to talk about it.  The XDA Forum has a subforum for every phone out there.  If you are at all interested in customizing your phone at the OS level, join up!

A caveat: jailbreaking your phone voids the warranty.  On the other hand, you can usually "un-root" the phone so the carrier will not know.  Except with the newer Samsung phones that allow you to use your phone as a credit card -- most root access hacks will short out a resistor and permanently disable that feature.  Which makes sense, if you consider the implications.

At $160, the Samsung Galaxy Core Prime from Verizon looks like a good deal.  It has all the functionality expected from a low-end smartphone.  I bought an iPad Pro for entertainment (gameplaying, streaming video, anything cpu-intensive), and wanted a phone with a small form-factor.  Thus, I did not need a big touchscreen, a blazingly fast CPU, or a zetapixel camera.

But if you are looking for an Android phone to jailbreak, I do not recommend the SM-360V.  Or any Verizon phone, for that matter.  Verizon has a reputation for excessive bloatware (50% of the internal disk is already filled!), and Verizon does not fulfill their GPL obligations in a timely manner.  They do not directly support the Google Nexus line (which should be your first choice).  There are social engineering methods unlock a Nexus if you absolutely need Verizon's service that you can find via the usual methods.

The rest of this article will describe how I hacked my SM-360V.  

Jailbreaking means that you are editing the computer files that are control how the phone starts up.  If you change what the vendor provided, you run the risk of "bricking" the phone -- of creating a state where the phone's computer will not boot up.  Instead, you get your phone's equivalent of a"Blue Screen Of Death".  At which point, your expensive handheld device is as useful as a brick.  There are ways to unbrick your phone, but they are highly dependent on the vendor, carrier, and OS version.

The best "brick protection" is a NANDroid backup. (A portmanteau of "NAND memory" and "Android").  This is a bit-for-bit copy of the computer's filesystem which is stored in a different part of the phone's memory card.  If you brick the phone, you hold down some buttons while turning it on, and direct the bootloader to restore a previous backup.

In a perfect world, you would take a NANDroid backup before doing any customization of your phone.  But it's not that easy on the SM-360V.  In order to fully install either of the two incompatible NANDroid software applications (CWM, TWRP), you need to jailbreak the bootloader.  Which requires root!  

For Samsung phones, there's another way -- by sideloading a "stock image".  You run a program on your PC (laptop or desktop), plug the cord you usually charge your phone in with into one of the USB ports, and overwrite the phone's disk drive.  A few years ago Odin, a Samsung development program, was leaked into the wild.  And about six months after Verizon released the SM-360V, they fulfilled their GPL obligations by making it possible to acquire a stock image.  Someone from the XDA forums tediously grabbed it and made it available.  (If that link doesn't work for you, check the SM-360V thread there for further information.)

While you're downloading things to your laptop/desktop, you'll need the Samsung USB drivers for the SM-360V.  Once installed, you will see a new folder in Explorer: SAMSUNG-SM-G360V.  This will allow you to browse your phone's disk drive, as well as a second SIM card if you bought one.  This is one way to copy ringtones to the phone, or offload photos.

Another useful tool is DeBloater.  This will allow you to "turn off" packages inside the Android OS, even ones that you cannot drag into the trash in the phone's interface.  I immediately removed all the Amazon bloat, and recovered an entire screen.

Next, grab the official Android Debugging Tools (ADT) that Google has released.    If you understand how to use a Linux command line, you can now fire up a Cygwin shell on your PC and type, "adb shell".  This will remotely log you into your Android phone, where you will see a prompt like:
mylaptop $ adb shell
shell@coreprimeltevzw:/ $
A limited number of Linux commands like ls, cd, df, and so on, are now available.  But you won't be able to do much customization because... you have no root access.  There is no sudo command.  The filesystem is mounted "read-only".  (Mounting it read-write requires bootloader access.)

Installing and running any of the above tools will not void your warranty.  They allow you to customize the phone to the extent that the Verizon allows.  The next step, rooting your phone, will.

What is rooting?  The "root" or superuser in a Linux system is the equivalent of the Windows admin user.  Root access allows you to edit any file.  Since the vendor did not install the Linux program "sudo", you have to get root the same way a black hat cracker does -- by attacking the Linux operating system using known security flaws in the various programs.  As soon as one of them works, you "have root" and can install a sudo program.

Update 11/16: instructions on rooting.
The web site OneClickRoot works really hard at rooting every phone.  Browse that URL from your phone, push the button, and they'll give it a go.  Unfortunately, this does not work for the SM-360V.  What does work is KingRoot, but there are concerns about this app.  (And it is easily confused with Kingoroot, which has an even sketchier reputation.)  KingRoot may or may not send data to China.  It certainly does install adds on your lock screen.

So the next step is to pry open your wallet and pay for Super-Sume Pro.  It will cheerfully remove KingRoot while leaving your phone rooted.  When you think you've rooted your phone, you can install Root Checker (for free) and it will verify for you.

At this point, I could do the following from my PC:
mylaptop $ adb shell
shell@coreprimeltevzw:/ $ su -c /system/bin/sh
root@coreprimeltevzw:/ # id
uid=0(root) gid=0(root) context=u:r:init_shell:s0

Up yours, Verizon.

The next step is getting bootloader access.  Unfortunately, no one has yet unlocked the bootloader for the SM-360V.  It has been done for the T-Mobile version SM-360H.  If someone posts to the SM-360V thread how to do it, I might write a future post on my further customization adventures.
Update 11/16: Apparently, Verizon works very hard using strong encryption to ensure that their phones cannot be bootloaded.  If you want to totally control your phone, either use a different carrier or try and "bring your own already-rooted device" to the Verizon network.

Once you've rooted your phone, you have the ability to remove all the Verizon and Amazon bloatware that came on your phone and is sucking up the megabytes.