View Single Post
Old 08-02-2017, 05:52 PM   #11
machinogodzilla
Addict
machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.machinogodzilla can program the VCR without an owner's manual.
 
machinogodzilla's Avatar
 
Posts: 208
Karma: 176052
Join Date: Dec 2008
Device: PBook 902† Kindle† Nook SimpleTouch† Onyx M92† i86† M96 N96ML NotePro
I'm sorry for not responding earlier, busy with other things lately...

The steps are basically what plusz listed but I will dump my notes from when I was playing with ColorDict anyway, even though there is an overlap, in case that helps somebody.

The steps are only to get to the guts of an app and then put it back together. Once you've accessed the internals you will need Android Studio for making the actual changes to the look of the app. This editor comes with a visual editor that makes it easier to manipulate the XML files that define the UI of the app, that's all you need this editor for. Here is an example screenshot (the definition file, one of many, is on the left and the preview on the right).

Once reassembled you will probably want to install and try your app on a phone as it is less painful than using an ereader for this, especially that it is likely you will go over this process multiple times before you get the look you are after.

The Process

Get the apk file, for example, colordict.apk.

APK is nothing more than a ZIP with compiled source code of the app. You can extract the archive but everything will be garbled, even resource text files such as XML files will be unreadable. You need to disassemble resources to nearly original form with apktool:

Code:
$ apktool d colordict.apk 
I: Using Apktool 2.1.1 on colordict.apk
...
Now you can open the unpacked directory in Android Studio and tinker with the content.

Once you've finished editing the UI you have to rebuild the app:

Code:
$ apktool b colordict
// builds colordict folder into colordict/dist/colordict.apk file
In order to run the rebuilt application you must resign it. You can sign the app from the command line using standard tools from the Android SDK and the JDK.

Generate a private key using keytool:
Code:
$ keytool -genkey -v -keystore <my-release-key>.keystore -alias <some-alias> -keyalg RSA -keysize 2048 -validity 10000

// for example

$ keytool -genkey -v -keystore release_key.keystore -alias modified_app -keyalg RSA -keysize 2048 -validity 10000
This example prompts you for passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called release_key.keystore. The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app.

Sign your app with your private key using jarsigner:

Code:
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore release_key.keystore colordict.apk modified_app
This example prompts you for passwords for the keystore and key. It then modifies the APK in-place to sign it.

Verify that your APK is signed. For example:

Code:
$ jarsigner -verify -verbose -certs colordict.apk
Align the final APK package using zipalign.

Code:
$ zipalign -v 4 colordict.apk colordict_aligned.apk
zipalign ensures that all uncompressed data starts with a particular byte alignment relative to the start of the file, which reduces the amount of RAM consumed by an app.

You can install and run the app now.

To make it easier to yourself you can bundle all these commands into a single script:

Code:
#!/bin/bash

apktool b colordict
cp colordict/dist/colordict.apk .
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore release_key.keystore colordict.apk modified_app
rm colordict_aligned.apk
zipalign -v 4 colordict.apk colordict_aligned.apk
echo "DONE!"

Last edited by machinogodzilla; 08-02-2017 at 06:34 PM.
machinogodzilla is offline   Reply With Quote