[Sony Xperia Z Ultra] ShALLaX:
HowTo

Right, here goes. I originally wrote this guide from memory, but since ROM 475 was released, I have run through it again, so I can confirm that it works. This isn't really for the faint-hearted, but I've tried to be as detailed as possible so that most people should be able to get through it. This tutorial probably applies to any Sony device that uses the same FTF/ SIN flashing mechanism.

What's frustrated me with the Android community (that I've seen so far) is people wanting to look like "Gods" by providing one-click rooting/ flashing solutions but not provide the technical explanations. Anyone that has a fairly decent understanding of Linux would find what I've achieved with this to be trivial and simple. All I have done is learned how to use existing tools and examine file formats at a very, very high level with a hex editor.

With this tutorial, I wanted to empower people with the knowledge of how to actually achieve the outcome of a rooted (Sony?) device. Yes, this HowTo will still require a fairly decent level of knowledge of Linux, operating systems and general principles of software and security architecture. However, I hope that this will be helpful for budding developers, system administrators and enthusiasts. Give a man a fish or teach a man to fish and all that. I'm happy to answer any follow-up questions.

All the above fluffiness aside... If you break your Xperia Z Ultra, you only have your-(impatient)-self to blame. If any of this intimidates you, please wait for someone else to release a rooted ROM. However, throughout all of my experimenting, I have always been able to fix my device by reflashing a stock FTF - though this is not a guarantee of safety to you. If you proceed with following these instructions, then the risk is all on you.

YOU WILL LOSE ALL OF YOUR DATA IF YOU FOLLOW THIS TUTORIAL UNLESS YOU TAKE A BACKUP FIRST!

Wherever possible, I have given credit to the original authors of tools and works.

You will need:

1) A Windows computer (I used a 64bit installation, but this probably isn't essential).

2) A Linux computer (VM works fine). I used Ubuntu LTS, but am a Gentoo enthusiast - I just didn't have time to install Gentoo! I used a 64bit installation, this may be required if you download a pre-built make_ext4fs binary.

3) An FTF for the Xperia Z Ultra. This is a legal grey area. Technically, you are entitled to use this, but I doubt that re-distribution is permitted. Please understand your legal stance when you download this. I used this ROM: https://docs.google.com/file/d/0B3BbH280MSmoVy1STFRRRDJBQ1k/edit

4) Flashtool (thank you, Androxyde, for the nice Java wrapper): http://xdaforums.com/showthread.php?t=2229790

5) WinRAR (or anything that can unpack a .jar/ ftf). Thanks Alexander Roshal. Even though you make us pay for RAR, it's still one of the nicest compresion utilities for Windows.: http://www.rarlabs.com

6) ChainFire's "su" command. I'm sure ChainFire needs no introduction to seasoned members: http://download.chainfire.eu/345/SuperSU/UPDATE-SuperSU-v1.51.zip

7) make_ext4fs. Though I'm sure this isn't the primary concern of people, my conscience obligates me to let you know that this code is provided by Google as part of Android. The source is available here: https://android.googlesource.com/pl...4d4b4db09a7052fc5fa108ac21f1b1948/ext4_utils/. It is licensed under the Apache 2.0 licence. You can build this yourself if you have an Android build environment, or you can cheat and download a binary from here: https://github.com/EpicAOSP/make_ext4/raw/master/bin/make_ext4fs (do make sure you download it with no extension).

8) The Android SDK (for Windows for this tutorial). Of course, this is provided by Google: http://developer.android.com/sdk/index.html

9) A fair amount of disk space - the unpacked system.sin file is around about 2.3GiB in size and you need to make a copy of this whilst extending it. Additionally, you'll also need to repack it. If you keep all of these files around, that'll be about 7GiB of storage space required in Linux alone. I would do this with anything less than about 10GiB of free disk space both in Windows and in Linux before you start.

Steps:

[Windows]

1) Install FlashTool to C:\Flashtool.

2) Open up the FTF in WinRAR, extract "system.sin" - it's pretty large, so give it some time.

3) Open up FlashTool.

4) Choose "File > Switch Pro".

5) Choose "Tools > Sin Editor".

6) Browse to the extracted "system.sin"

7) Click "Extract data" and wait. This takes a while, but eventually a larger "system.elf" file will appear in the same directory as the "system.sin" file.

8) Copy this to your Linux box. The tutorial assumes you copy it to /tmp/system.elf

The problem with this extracted ELF is that it seems to be truncated in some way. So, you need to extend it so that the geometry matches the expectation of the ext4 file system contained within. My extract was 5,118 blocks short (a default ext4 block is 4KiB). So, we'll extend it now. I'm not sure if this is a deficiency in the SIN extractor or something else. You can verify how many blocks you are out by through running "dmesg," which will show you how many blocks the ext4 file system believes it occupies and how many blocks the actual loopback device takes up.

[Linux]

To make things easier, you can just do all of this as root to avoid permission issues (but be careful not to ruin your distro).

9) Copy make_ext4fs to /bin then run chmod 755 /bin/make_ext4fs

10) Copy UPDATE-SuperSU-v1.51.zip to /tmp, then run: cd /tmp; unzip UPDATE-SuperSU-v1.51.zip; mv system/xbin/su /tmp/su

11) To create the extension part of the filesystem, run: dd if=/dev/zero of=/tmp/moreZeroes bs=4096 count=5118

12) To append the extension to the ELF, run: cat /tmp/system.elf /tmp/moreZeroes > /tmp/system.fixed

You now have the /system file system available to mount.

13) Make a temporary mount point: mkdir /mnt/systemfs

14) Mount the file system: mount -o loop -t ext4 /tmp/system.fixed /mnt/systemfs

15) Change directories to the mounted file system: cd /mnt/systemfs

16) Delete the old "su" binary: rm -rf ./xbin/su

17) Put ChainFire's "su" binary into place: cp /tmp/su ./xbin/su

18) Set the owner, suid bit and file permissions for the hacked "su" binary so that we can obtain root by running the binary: chown 0.0 ./xbin/su; chmod 06755 ./xbin/su

19) Now, we need to make the new system.img. Run: cd /tmp; make_ext4fs -s -l 2048M -a system /tmp/system.img /mnt/systemfs

20) You should now have a /tmp/system.img file. Copy this back to your Windows system to C:\system.img

[Windows]

21) Copy the FTF ROM file to "C:\Flashtool\firmwares\"

22) Launch FlashTool

23) Click the "lightning bolt" (flash) button.

24) Choose "Flashmode".

25) Select the FTF ROM file.

26) Ensure that Wipe is ticked for "DATA", "CACHE" and "APPSLOG".

27) Ensure that no exclusions are ticked.

28) Wait until FlashTool asks you to plug in your device in Flashmode.

[Xperia Z Ultra]

29) Ensure the USB cable is disconnected.

30) Power off your device fully (hold the power button and press "Power Off", then confirm).

31) Hold down the Volume-down rocker then plug in the USB cable. The LED should cycle through the prime colours very quickly. FlashTool should begin flashing. Be patient, this takes a while (enable debug logging prior to this if you want more verbose output.

32) When flashing is completed, unplug your USB cable and power on your device.

33) go to "Settings > About phone" and relentlessly tap "Build number" until you are informed that "You are now a developer".

34) Go to "Settings > Developer options" and tick "USB debugging".

35) Ensure the USB cable is disconnected.

36) Power off your device fully (hold the power button and press "Power Off", then confirm).

37) Hold down the Volume-up rocker then plug in the USB cable. The LED should remain illuminated blue.

[Windows]

38) Unpack the Android SDK to C:\adt-bundle-windows-x86_64-20130729 (or similar).

39) Open a command prompt (cmd.exe)

40) Change directory to the Android SDK platform tools: cd C:\adt-bundle-windows-x86_64-20130729\sdk\platform-tools

41) Execute: "fastboot.exe flash system C:\system.img". Be patient, this will take a while.

42) When the shell returns, execute: "fastboot.exe continue". You will probably see the battery icon, if you do, hold down the power button to turn your device on. If your phone doesn't start up, try unplugging the USB cable and powering on. If this doesn't work, hold down the volume-up rocket and power button until you hear the vibration motor pulse three times. After this, try powering on as normal. If it's still dead, something went wrong and I apologise. You'll have to reflash your phone with the FTF (see step 22). You will still have lost all of your data.

[Xperia Z Ultra]

43) Ensure the USB cable is disconnected.

44) Power off your device fully (hold the power button and press "Power Off", then confirm).

[Windows]

45) Launch FlashTool.

46) Click the "lightning bolt" (flash) button.

47) Choose "Flashmode".

48) Select the FTF file.

49) Ensure that Wipe is ticked for "DATA", "CACHE" and "APPSLOG".

50) Ensure that ALL exclusions are ticked. If you do not do this, you're going to have to go back to step 22.

51) Wait until FlashTool asks you to plug in your device in Flashmode.

[Xperia Z Ultra]

52) Hold down the Volume-down rocker then plug in the USB cable. The LED should cycle through the prime colours very quickly. FlashTool should begin flashing. Be patient, this takes a while (enable debug logging prior to this if you want more verbose output.

53) When flashing is completed, unplug your USB cable and power on your device.

54) Log in to Google Play.

55) Install SuperSU.

56) Start up SuperSU. You will probably be prompted to update the "su" binary - do so!

57) Install SuperSU to /system. Follow the instructions carefully.

58) Install Root Checker.

You should be done.

I hope people are successful with rooting their devices and enjoy the freedom that it brings. Anyone is free to copy, adapt or correct this tutorial as they wish; there is no licence and there are no conditions provided with this HowTo. It'd be nice to receive credit if this work is re-published or re-used, but that's not something I can control. Please respect the contributions of the original authors of the tools used within - all I did was string them together.

Be good to each other and enjoy.