/**
* Quick GPT viewing/editing tool - 03/07/2018
*
* By Jonathan Levin (@Morpheus______), http://NewAndroidBook.com
*
* I coded this because I grew frustrated with GNU parted while doing
* some Android research. I reused a lot of code from my MacOS (H)FSleuth
* tool (http://NewOSXBook.com), and since this is POSIX code I ended up
* with a generic tool that works on all architectures. Hypothetically
* this would also work on Windows through cygwin or Linux subsystem,
* if you can get the raw device.. This was tested on several Android
* devices (Samsung Tab S3, Nexus 6P and Pixel) as well as (naturally) MacOS.
*
Usage:
Examples:
Consider a Nexus 6P (angler). The default partitioning is:
Using jpt, you can list the partitions:
To resize, we provide the partition number (44, since jpt counts from 1, like the 'mmcblk0p1..') and either the size in LBA, or "-" with the last LBA. Putting it at 34,000,000, it looks like this:
sync and reboot, and you're all done!
NOTE THIS WILL DESTROY YOUR /data, so it has the effect of a factory reset. But it's easy to backup and restore. Indeed, rebooting and re-rooting we see:
And what can we do after we reduce a partition to half? Why, add another partition, of course. Using 'add' with no arguments will auto-fill:
You can always rename the partition, and you can of course remove and add as many times as you want.
Rebooting, we then see the new partition show up in /proc/partitions:
LICENSE
* License: Free for personal use, provided you give credit. DO NOT put this
* on GitHUB after you've cut/pasted my code and comments about, and
* try to pass this as your own. That's plagiarism, and it's bad karma.
* NOT free for commercial use. If you want to do so, ask me first.
* Open source != (Obtain Free && Close && Profit)
*
* Disclaimer: All code abides by Lubarsky's Law of Cybernetic Entomology.
* I therefore assume ABSOLUTELY NO responsibility WHAT-SO-EVER if,
* through using any part of this code, running this code or
* even being remotely inspired by it, you end up nuking your
* partition table, or suffer ANY data loss, of 1 bit or more.
*
Requests
* Request: If you do find a bug, PLEASE report it to me, and do keep in mind -
* This was really quick and dirty. But just A) fussing about them
* over social media or B) discovering exploitable overflows or
* C) keeping them to yourself won't really help. This was built
* around my (very specific) use-cases, and therefore I could neither
* i) be aware of all the other use cases nor ii) know (or care much)
* about the crazy abuse cases.
*
* Ditto for feature requests. I will be happy to incorporate more
* features, if it's not too much code. If you want to help, a good
* idea is compiling more GPT Partition type GUIDs. It's a lousy job,
* but a community effort might amortize it. Also a portable i18n
* for those (quite common, but not in US) cases where labels are
* not in English.
*
Other notes:
* And - you might want to check out HFSleuth (if you're a Mac/iOS user) or
* the upcoming FSleuth (which will be made public in or around MOXiI
* Volume II). Either tool goes past the partition table and into filesystems,
* and the latter is especially useful with Apple's new (and as yet
* undocumented) APFS.
*
* Free advice: watch out for the baobabs!
* Or for any tree if, when laden with snow, it may fall on your house.
*
FAQ:
Why not GNU parted?: Try running it on a Pixel, with an LBA size of 0x1000, and see for yourself:
The tool crashes! I LOST DATA! Shows you haven't read the license... or the usage note. If you want to report a bug, I'll be happy to fix it.
Download link - Contains Android, Linux and MacOS binaries. For Android, static binaries (useful for recovery mode) are included as well!