# [APK][Flash zips WITHOUT a recovery]Flash Gordon : an Edify to Bash parser & translator [Open-Source]



## Androguide.fr

Mod Type:: Application

Difficulty:: Very Easy

Mod Status:: Alpha

Apply In:: Other (See Description)

Requires Root:: Yes

Source:: https://github.com/Androguide/FlashGordon
*THIS IS A WORK IN PROGRESS, CURRENTLY AT A VERY EARLY STAGE OF DEVELOPMENT*​
*What is Flash Gordon ?*

In laymen's words, Flash Gordon is an apk which allows you to flash any flashable zip (except for Roms) without having a recovery installed.
You just point it to the zip you want to flash, (be it a kernel, a mod, gapps, a modem, a RIL...) and it will interpret the updater-script of this package and install its content just like a recovery would.

*How does it work ?*

Here is what happens step by step :


You tap the "select a zip" button, select the built-in file explorer to select the zip you want to flash
Flash Gordon will first extract this zip, depending on its size it can take a little time
When you press the "Flash Now" button, Flash Gordon will locate the updater-script and start translating it into shell code, line by line
It will output the resulting translated bash script on your sdcard and execute it, thus installing the zip's content
The app creates a notification, just tap on it to reboot

In order to achieve those last 2 steps, I'm writing a full Edify to Bash parser and translator.
Here is the list of all the Edify commands this parser can currently process and what their respective bash translation is (under), using examples:
_(more will be added over time, this is really just a draft)_

By no means am I a bash expert, so if you have suggestions for better bash equivalents of any edify commands please post them



Code:


package_extract_file("path/to/source/file.txt", "/path/to/destination/file.txt");<br />
busybox cp -fp /path/to/source/file.txt /path/to/destination/file.txt<br />
<br />
package_extract_dir("/source/folder", "/destination/folder");<br />
busybox cp -rfp /source/folder/* /destination/folder<br />
<br />
set_perm(0, 2000, 0755, "/file/or/folder");<br />
]chown 0:2000 /file/or/folder<br />
chmod 0755 /file/or/folder<br />
<br />
set_perm_recursive(0, 2000, 0644, 0755, "/path/to/set/permissions/recursively);<br />
chown 0:2000 /path/to/set/permissions/recursively<br />
chown 0:2000 /path/to/set/permissions<br />
chown 0:2000 /path/to/set<br />
chown 0:2000 /path/to<br />
chown 0:2000 /path<br />
chmod 0644 /path/to/set/permissions/recursively<br />
chmod 0755 /path/to/set/permissions<br />
chmod 0755 /path/to/set<br />
chmod 0755 /path/to<br />
chmod 0755 /path<br />
<br />
delete("file/to/delete");<br />
busybox rm -f /file/to/delete<br />
<br />
run_program("/script/to/run.sh");<br />
sh /script/to/run.sh<br />
<br />
mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");<br />
busybox mount -o rw,remount -t auto /system<br />
(will soon change to -t mmcblk0p9 or whichever mount point is in the updater-script)<br />
<br />
unmount("/system");<br />
busybox mount -o remount,ro /system<br />
<br />
symlink("busybox", "/system/xbin/[", "/system/xbin/[[",<br />
		"/system/xbin/adjtimex", "/system/xbin/arp", "/system/xbin/ash",<br />
		"/system/xbin/awk", "/system/xbin/base64", "/system/xbin/basename",<br />
		"/system/xbin/bbconfig", "/system/xbin/blkid", "/system/xbin/blockdev",<br />
		"/system/xbin/brctl", "/system/xbin/bunzip2", "/system/xbin/bzcat",<br />
		"/system/xbin/bzip2", "/system/xbin/cal", "/system/xbin/cat",<br />
		"/system/xbin/catv", "/system/xbin/chattr", "/system/xbin/chgrp",<br />
		"/system/xbin/chmod", "/system/xbin/chown", "/system/xbin/chroot",<br />
		"/system/xbin/clear", "/system/xbin/cmp", "/system/xbin/comm",<br />
		"/as/many/lines/as/you/want");<br />
ln -s busybox  /system/xbin/[ /system/xbin/[[<br />
		/system/xbin/adjtimex /system/xbin/arp /system/xbin/ash<br />
		/system/xbin/awk /system/xbin/base64 /system/xbin/basename<br />
		/system/xbin/bbconfig /system/xbin/blkid /system/xbin/blockdev<br />
		/system/xbin/brctl /system/xbin/bunzip2 /system/xbin/bzcat<br />
		/system/xbin/bzip2 /system/xbin/cal /system/xbin/cat<br />
		/system/xbin/catv /system/xbin/chattr /system/xbin/chgrp<br />
		/system/xbin/chmod /system/xbin/chown /system/xbin/chroot<br />
		/system/xbin/clear /system/xbin/cmp /system/xbin/comm<br />
		/as/many/lines/as/you/want<br />
<br />
write_raw_image("/tmp/boot.img", "mmcblk0p5");<br />
dd if=/tmp/boot.img of=/dev/block/mmcblk0p5

This is just a proof of concept for the moment, I'm aiming at adding all the possible Edify commands, and maybe doing it backwards (Bash2Edify) in the future, too.

*Screenshots*
This is from the apk I use for debugging, so the UI is pretty barebones atm, it will quickly evolve to something more fancy and featureful


























































*Contribute*
Flash Gordon is fully Open-Source, and contributions are more than welcome!
You can check-out the full source code on my github at : https://github.com/A...ide/FlashGordon

This app depends on the following Open-Source libraries :
My fork of the CardsUI library by Nadav Fima
aFileChooser by Paul Burke
*Frequently Asked Questions*

*Q: * Why can't I flash a Rom with Flash Gordon ?
*A: *Because when some system files are replaced while the device is running, it causes it to crash and will stop in the middle of the installation, resulting in a bootloop.

*Q: * Where can I see the bash script translation of the package I selected ?
*A: *After tapping the Flash Now button, head to _/sdcard/RecoveryEmulator/tmp/flash_gordon.sh_
The full translation is also output to the logcat while flashing.

*Q: *I select a flashable zip but it tells me it is not valid or that it's not a zip package, why ?
*A: *Make sure that there is no whitespace in the name of the zip package you're trying to flash, otherwise it won't be recognized.
If your package has no whitespace but the app still gives this error, try to shorten its name.

*Q: *Which versions of Android are supported ?
*A: *From Froyo (2.2) up to the latest JellyBean (4.2.2)

*Q: *Why is this app useful?
*A: *Some people might not be able to install a custom recovery on their device, either because there is no custom recovery for this model, or maybe their bootloader is locked. Flash Gordon allows them to flash packages even then.
Or maybe you're simply lazy and you don't want to have to reboot to recovery to flash that new kernel or that new cool flashable mod ? Then Flash Gordon is for you too.
Or maybe just for the heck of it ?^^

*Disclaimer*
*If you're going to test this app, make sure you have a nandroid backup handy as it is very far from stable.
I won't be held responsible for any damage done to anything whatsoever. You use this tool at your own risk.*

*Download*
The first preview/pre-alpha/proof-of-concept/work-in-progress/whatever-but-stable apk can be downloaded here : http://pimpmyrom.org...oncept-v1.1.apk
*Again, make sure to have a nandroid backup before flashing anything through Flash Gordon for the moment.*


----------

