[APK][Flash Zips WITHOUT a Recovery!]Flash Gordon: an Edify to Bash parser/translator

Search This thread

Androguide.fr

Account currently disabled
Jul 21, 2012
2,056
7,236
GB
meettomy.site
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, a gapps package, a modem, a RIL, a recovery...) 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 :

  1. You tap the "select a zip" button, select the built-in file explorer to select the zip you want to flash
  2. Flash Gordon will first extract this zip, depending on its size it can take a little time
  3. When you press the "Flash Now" button, Flash Gordon will locate the updater-script and start translating it into shell code, line by line
  4. It will output the resulting translated bash script on your sdcard and execute it, thus installing the zip's content
  5. 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 (in green), 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");
[COLOR="DarkGreen"]busybox cp -fp /path/to/source/file.txt /path/to/destination/file.txt[/COLOR]

package_extract_dir("/source/folder", "/destination/folder");
[COLOR="DarkGreen"]busybox cp -rfp /source/folder/* /destination/folder[/COLOR]

set_perm(0, 2000, 0755, "/file/or/folder");
[COLOR="DarkGreen"]chown 0:2000 /file/or/folder
chmod 0755 /file/or/folder[/COLOR]

set_perm_recursive(0, 2000, 0644, 0755, "/path/to/set/permissions/recursively");
[COLOR="DarkGreen"]chown -R 0:2000 /path/to/set/permissions/recursively
chmod 0644 /path/to/set/permissions/recursively
chmod -R 0755 /path/to/set/permissions/recursively
[/COLOR]

delete("file/to/delete");
[COLOR="DarkGreen"]busybox rm -f /file/to/delete[/COLOR]

run_program("/script/to/run.sh");
[COLOR="DarkGreen"]sh /script/to/run.sh[/COLOR]

mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");
[COLOR="DarkGreen"]busybox mount -o rw,remount -t auto /system [I](will soon change to -t mmcblk0p9 or whichever mount point is in the updater-script)[/I][/COLOR]

unmount("/system");
[COLOR="DarkGreen"]busybox mount -o remount,ro /system[/COLOR]

symlink("busybox", "/system/xbin/[", "/system/xbin/[[",
        "/system/xbin/adjtimex", "/system/xbin/arp", "/system/xbin/ash",
        "/system/xbin/awk", "/system/xbin/base64", "/system/xbin/basename",
        "/system/xbin/bbconfig", "/system/xbin/blkid", "/system/xbin/blockdev",
        "/system/xbin/brctl", "/system/xbin/bunzip2", "/system/xbin/bzcat",
        "/system/xbin/bzip2", "/system/xbin/cal", "/system/xbin/cat",
        "/system/xbin/catv", "/system/xbin/chattr", "/system/xbin/chgrp",
        "/system/xbin/chmod", "/system/xbin/chown", "/system/xbin/chroot",
        "/system/xbin/clear", "/system/xbin/cmp", "/system/xbin/comm",
        "/as/many/lines/as/you/want");
[COLOR="DarkGreen"]ln -s busybox  /system/xbin/[ /system/xbin/[[
        /system/xbin/adjtimex /system/xbin/arp /system/xbin/ash
        /system/xbin/awk /system/xbin/base64 /system/xbin/basename
        /system/xbin/bbconfig /system/xbin/blkid /system/xbin/blockdev
        /system/xbin/brctl /system/xbin/bunzip2 /system/xbin/bzcat
        /system/xbin/bzip2 /system/xbin/cal /system/xbin/cat
        /system/xbin/catv /system/xbin/chattr /system/xbin/chgrp
        /system/xbin/chmod /system/xbin/chown /system/xbin/chroot
        /system/xbin/clear /system/xbin/cmp /system/xbin/comm
        /as/many/lines/as/you/want
(not sure about this one, please correct me if I'm wrong, I could change to [I]ln -s argument/number/1 argument/number/2[/I] as many times as required if needed)[/COLOR]

write_raw_image("/tmp/boot.img", "mmcblk0p5");
[COLOR="DarkGreen"]dd if=/tmp/boot.img of=/dev/block/mmcblk0p5[/COLOR]
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
flash2r.png
flash3n.png
flash4.png
flash5t.png
flash6.png
flash8q.png
flash1bz.png
flashib.png



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/Androguide/FlashGordon

This app depends on the following Open-Source libraries :


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 ?^^


Requirements

All you need is a rooted Android device with a proper busybox installed. Required applets include :
  • mount
  • sed
  • unzip
  • rm
  • cp


Changelog
  • 25/04/2013 : Initial release
  • 26/04/2013 : Added a few fixes and regex corrections. (Github commit)
  • 26/04/2013 : Hotfix for some flashable zips mistakenly identified as unvalid + Hotfix for kernels where the updater-script uses package_extract_file(); instead of write_raw_image(); (Github commit)


To Do List
  • Using a private version of busybox to remove having busybox installed/installing new applets as a requirement for the user
  • Implementing an equivalent of nandroid backups (zipping the content of the defined partition(s) and generating an updater-script to allow the user to restore the backup either through recovery or through Flash Gordon
  • Translating ui_print(); to echo in bash and make the "Flashing" ProgressDialog's message display the content of those ui_print();


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
A preview/pre-alpha/proof-of-concept/work-in-progress/whatever-but-stable apk is attached to this post.
Again, make sure to have a nandroid backup before flashing anything through Flash Gordon for the moment.


If you like this project, please press the "Tip us?" button so that more people can know about it.
 

Attachments

  • FlashGordon.apk
    1,005.1 KB · Views: 348,276
Last edited:

dirtyreturn

Senior Member
Aug 14, 2011
1,138
252
Nexus 7
Huawei Nexus 6P
For the gsm galaxy nexus at least, choosing two zips (recovery, kernel) brings back a 'file not valid'. Looking forward to the "final" version.
Edit- if this helps.. twrp 2.5.5.0 and trinity kernel. If there is something for me to do please ask.
 
  • Like
Reactions: Androguide.fr

Androguide.fr

Account currently disabled
Jul 21, 2012
2,056
7,236
GB
meettomy.site
For the gsm galaxy nexus at least, choosing two zips (recovery, kernel) brings back a 'file not valid'. Looking forward to the "final" version.
Edit- if this helps.. twrp 2.5.5.0 and trinity kernel. If there is something for me to do please ask.
Make sure there is no whitespace in the name of the zip, otherwise the app won't be able to pick it up.
If it still doesn't work, try shortening the name of the zips, for some reason I had the same issue with files which have long names

Flashed a XXEMB6 I9300 Modem+RIL with no problems.
Thanks a lot for the feedback
 
  • Like
Reactions: dirtyreturn

Androguide.fr

Account currently disabled
Jul 21, 2012
2,056
7,236
GB
meettomy.site
Make sure there is no whitespace in the name of the zip, otherwise the app won't be able to pick it up.
If it still doesn't work, try shortening the name of the zips, for some reason I had the same issue with files which have long names


I gave shortening the file names a try with no success. And no spaces.

That's weird, can you please give me a link to the zip you're trying to flash or attach it here ?
Would be very helpful for me to try and track the problem down
 

Androguide.fr

Account currently disabled
Jul 21, 2012
2,056
7,236
GB
meettomy.site

Attachments

  • FlashGordon-proof_of_concept-v1.1.apk
    795.4 KB · Views: 1,380

dirtyreturn

Senior Member
Aug 14, 2011
1,138
252
Nexus 7
Huawei Nexus 6P
Thanks a lot :good:
I tried them both after removing flashing from the app and they got extracted and translated properly on my device.
Please make sure you have a proper busybox install, if you do, please give me the output of this command in terminal :
Code:
unzip


I made a few fixes and corrections, here is the apk (the one in the OP was updated too)

I have busybox v1.20.2-Stericson installed... in /system/xbin. .. in terminal running .unzip. gives the busybox info, 'Usage', followed by extract files from ZIP archives with other options. I am on CM10.1 if that makes a difference. edit- checked the applet manager section and 'unzip' is installed. And had installed updated apk. sorry this post is not much help.
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 354
    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, a gapps package, a modem, a RIL, a recovery...) 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 :

    1. You tap the "select a zip" button, select the built-in file explorer to select the zip you want to flash
    2. Flash Gordon will first extract this zip, depending on its size it can take a little time
    3. When you press the "Flash Now" button, Flash Gordon will locate the updater-script and start translating it into shell code, line by line
    4. It will output the resulting translated bash script on your sdcard and execute it, thus installing the zip's content
    5. 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 (in green), 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");
    [COLOR="DarkGreen"]busybox cp -fp /path/to/source/file.txt /path/to/destination/file.txt[/COLOR]
    
    package_extract_dir("/source/folder", "/destination/folder");
    [COLOR="DarkGreen"]busybox cp -rfp /source/folder/* /destination/folder[/COLOR]
    
    set_perm(0, 2000, 0755, "/file/or/folder");
    [COLOR="DarkGreen"]chown 0:2000 /file/or/folder
    chmod 0755 /file/or/folder[/COLOR]
    
    set_perm_recursive(0, 2000, 0644, 0755, "/path/to/set/permissions/recursively");
    [COLOR="DarkGreen"]chown -R 0:2000 /path/to/set/permissions/recursively
    chmod 0644 /path/to/set/permissions/recursively
    chmod -R 0755 /path/to/set/permissions/recursively
    [/COLOR]
    
    delete("file/to/delete");
    [COLOR="DarkGreen"]busybox rm -f /file/to/delete[/COLOR]
    
    run_program("/script/to/run.sh");
    [COLOR="DarkGreen"]sh /script/to/run.sh[/COLOR]
    
    mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");
    [COLOR="DarkGreen"]busybox mount -o rw,remount -t auto /system [I](will soon change to -t mmcblk0p9 or whichever mount point is in the updater-script)[/I][/COLOR]
    
    unmount("/system");
    [COLOR="DarkGreen"]busybox mount -o remount,ro /system[/COLOR]
    
    symlink("busybox", "/system/xbin/[", "/system/xbin/[[",
            "/system/xbin/adjtimex", "/system/xbin/arp", "/system/xbin/ash",
            "/system/xbin/awk", "/system/xbin/base64", "/system/xbin/basename",
            "/system/xbin/bbconfig", "/system/xbin/blkid", "/system/xbin/blockdev",
            "/system/xbin/brctl", "/system/xbin/bunzip2", "/system/xbin/bzcat",
            "/system/xbin/bzip2", "/system/xbin/cal", "/system/xbin/cat",
            "/system/xbin/catv", "/system/xbin/chattr", "/system/xbin/chgrp",
            "/system/xbin/chmod", "/system/xbin/chown", "/system/xbin/chroot",
            "/system/xbin/clear", "/system/xbin/cmp", "/system/xbin/comm",
            "/as/many/lines/as/you/want");
    [COLOR="DarkGreen"]ln -s busybox  /system/xbin/[ /system/xbin/[[
            /system/xbin/adjtimex /system/xbin/arp /system/xbin/ash
            /system/xbin/awk /system/xbin/base64 /system/xbin/basename
            /system/xbin/bbconfig /system/xbin/blkid /system/xbin/blockdev
            /system/xbin/brctl /system/xbin/bunzip2 /system/xbin/bzcat
            /system/xbin/bzip2 /system/xbin/cal /system/xbin/cat
            /system/xbin/catv /system/xbin/chattr /system/xbin/chgrp
            /system/xbin/chmod /system/xbin/chown /system/xbin/chroot
            /system/xbin/clear /system/xbin/cmp /system/xbin/comm
            /as/many/lines/as/you/want
    (not sure about this one, please correct me if I'm wrong, I could change to [I]ln -s argument/number/1 argument/number/2[/I] as many times as required if needed)[/COLOR]
    
    write_raw_image("/tmp/boot.img", "mmcblk0p5");
    [COLOR="DarkGreen"]dd if=/tmp/boot.img of=/dev/block/mmcblk0p5[/COLOR]
    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
    flash2r.png
    flash3n.png
    flash4.png
    flash5t.png
    flash6.png
    flash8q.png
    flash1bz.png
    flashib.png



    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/Androguide/FlashGordon

    This app depends on the following Open-Source libraries :


    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 ?^^


    Requirements

    All you need is a rooted Android device with a proper busybox installed. Required applets include :
    • mount
    • sed
    • unzip
    • rm
    • cp


    Changelog
    • 25/04/2013 : Initial release
    • 26/04/2013 : Added a few fixes and regex corrections. (Github commit)
    • 26/04/2013 : Hotfix for some flashable zips mistakenly identified as unvalid + Hotfix for kernels where the updater-script uses package_extract_file(); instead of write_raw_image(); (Github commit)


    To Do List
    • Using a private version of busybox to remove having busybox installed/installing new applets as a requirement for the user
    • Implementing an equivalent of nandroid backups (zipping the content of the defined partition(s) and generating an updater-script to allow the user to restore the backup either through recovery or through Flash Gordon
    • Translating ui_print(); to echo in bash and make the "Flashing" ProgressDialog's message display the content of those ui_print();


    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
    A preview/pre-alpha/proof-of-concept/work-in-progress/whatever-but-stable apk is attached to this post.
    Again, make sure to have a nandroid backup before flashing anything through Flash Gordon for the moment.


    If you like this project, please press the "Tip us?" button so that more people can know about it.
    24
    I modified this awesome app, for easier installation of recovery. No need to install busybox before using it.

    mod edit - link removed FlashGordonBB