Modifying apk on android

Decompile and Modify APKs on the go with APKTool for Android [XDA Spotlight]

APKTool is a powerful piece of software developed by XDA Senior Member ibotpeaches. The tool allows you to reverse engineer APK files, allowing you to decode resource files so you can modify them and then recompile the application.

It is extremely difficult to qualify just how important this tool is to the Android community, but a list of some of its more popular use cases should give you a great idea why the tool and its developer are held in such high regard. APKTool is used to port applications to previously unsupported devices, theme some of your favorite applications, look into the strings of APK files to see what may be coming in future updates, and provide translations for applications. On the other hand, it can also be used nefariously to hide and distribute malware or in the converse used for Android application penetration testing in Kali Linux.

APKTool has been available on Linux/GNU distributions and Microsoft Windows operating systems since initial release, but Android support for the tool has been missing for quite some time. Limited support for Android devices was available for a few months, but updates to the official Android version of the tool ceased in 2013, making it useless for reverse engineering any modern APK file. However, a developer by the name of Andro Black has been independently releasing updated versions of APKTool for Android, so you can decompile and modify APK files on the go with any rooted Android device.

XDA-Developers does not condone using APKTool for any kind of application piracy. There are many reasons to use APKTool, but modifying an application for piracy purposes should not be one of them.

APKTool for Android

The application itself is a little rough around the edges as it contains a few spelling mistakes and a rather buggy theme switcher, but honestly I could care less since there is no other tool on Android that can accomplish this functionality. APKTool for Android does exactly what its big brother PC version does – reverse engineer APK files. You can decompile and recompile applications straight on your phone, which can be useful if you want to quickly modify an APK’s resources without having to get in front of your desktop. This can be especially useful for themers who may find themselves constantly editing an APK file and sending it over to their device for live testing. Be warned though, the APKTool application cannot be used for actually editing the decompiled files, for that you need a text editor on your device.

The settings menu allows you to change the theme of the application as mentioned previously, but more importantly you can select the AAPT and APKtool versions that you want to use when decompiling an APK file. There is also a check mark for “root” in the settings, without this checked you cannot compile applications properly (and it’s not checked by default.)

To work with applications you have two menus, one is displayed on a short tap and the other is displayed on a long press. The single tap menu as shown below displays the functions you can use to work with an APK file, the main ones being Decompile All and Sign. There are a number of other functions here, but these shouldn’t be unfamiliar to you provided you have prior experience with APKTool.

After decompiling an APK, you can browse its contents by simply tapping on the folder with the APK’s name to display its contents. Tapping a file will load the default Android behavior and ask which application you want to open the file with, which at this point you would use your chosen text or image editor if you are attempting to modify a resource.

Once you have finished tinkering with the APK you can install your modified version from inside the APKTool application as well. The long press menu allows you to delete/rename files and folders, but it’s also context aware so when you long press a folder you will get the option to compile all of the resources and smalis into an APK file again.

I found the tool quite useful for quick changes to an existing application as I was able to decompile an existing application, change the strings.xml file, and recompile the application again to view the changes. How fast the tool performs these actions, though, depends on your device. On my Google Nexus 6P, decompiling an APK file took around 2 minutes while re-compiling an APK took around another 2 minutes, so I personally wouldn’t want to be using APKTool from my phone all that often.

Читайте также:  Музыкальный плеер для андроид самсунг

Working with APK files on your phone is not the most straight forward process, but APKTool tool makes it do-able. I wouldn’t recommend developers switch to exclusively modifying APKs on their Android phone given that it’s both slow and more difficult to manage, but if you own an Android tablet and are looking for a more convenient way to make frequent small modifications and test them on a live device, then APKTool for Android is your best bet.

Источник

[GUIDE] How to easily edit/modify .apk files! (Simple, Noob Friendly)

littlejoelgriffo

Senior Member

Hey Guys an’ Girls!
Anyway, so when I first learnt how to decompile, modify then recompile .apks I found it was a rather slow process and figured out a far faster way.I searched google and xda many times and couldn’t find my method anywhere. So without further ado, let’s go through an easy, simple, step by step guide on how to modify .apk files!

Step 1 — Getting the .apk

Firstly, of course, you will need to obtain the .apk file that you want to edit. There are two methods to do this:

a) If you have the recovery flashable zip for the rom you are currently on, simply open it up, navigate to the file you want to edit (in my case system -> app -> settings.apk) and drag the .apk file onto your desktop.

b) Using root browser or a similar app on your device, navigate to the .apk you wish to edit and copy it onto your sdcard. Then connect to your computer and copy the file from your phone to the computer.

Step 2 — Editing/Modifying your .apk

Now is the important part. Install Winrar by clicking the link. http://www.win-rar.com/download.html?&L=0 Then open the .apk by right clicking the file -> open with -> WinRar. Now you can look around the .apk file. Find a file inside the .apk you wish to edit. (In my case I’m going to navigate to res -> mipmap-hdpi -> ic_launcher_settings.png). Just drag the file from the .apk and edit to your liking.

NOTE: It is recommended never to completely take everything out of the .apk and then put it all back in. Just do one file at a time.

Then when your finished, select the old file in the .apk and press the delete button. Now drag in the new edited file into where you found it. Easy!

Step 3 — Putting the new .apk back where it belongs

Now of course, your going to have to put it back on your device to see the changes in effect, there’s no point having it on your computer! There are two ways to go about this:

a) Open up your rom and navigate to the place where you took your .apk file from. Click on the old .apk file and press the delete button. Now drag your new edited .apk file into the zip. Then connect your device to your computer and drag the rom onto the sdcard and flash it via recovery. Now reboot the system and see your change/s in effect!

b) Copy your new .apk file from your computer to your device. Then, using Root browser or a similar app, navigate to the old .apk file and look at the permisions. (eg. RW—r—) Now delete the old file and replace with the new, but make sure to set the permissions the same as they were before. Now Simply reboot and see your change/s in effect!

Источник

[GUIDE][INDEX]How to modify an apk

Forum Moderator

Intro:
I’ve done several threads about how to theme and other similar topics but the info is sparse, so this ultimate guide/index will seat proudly in the theme section of XDA and will be updated when new things come, and as I learn more. This isn’t a beginners guide, I’m here trying to be as complete as possible, with links, references, .
This initial version of the thread isn’t here to stay, if you could contribute to this thread, it would mean the world to me, and would clearly help the community (of course I’ll mention you for your contribution )

And keep at mind that I’m just an enthusiast, nothing more, and that this thread has been made only by me, so it’s far from perfect. If I made any mistakes or if you want to add something please let me know.

Читайте также:  Quick gallery android 444

Legal aspect:
Using this knowledge to infringe copyright is not only illegal, it’s detrimental to the community. The only legal case, and the only usage of this info condoned, is using it to theme OPEN SOURCE apps (because most of the time, commercial apps forbid reverse engineering in their policies). So don’t worry, theming AOSP is legal. You can always ask the permission of the devs for an authorization to customize their apps, make sure to ask before modding, and distributing the result.

Now I’m not a lawyer, but you can learn more on the legal aspect of reverse engineering on this Stackexchange post.

Источник

How to modify a compiled Android application (.apk file)

Today I’d like to share with you my findings about how an existing .apk file can be modified.

An .apk file represents the mobile application as it is installed on a mobile device, like smartphone, tablet, wearable, etc.

Such an .apk file is a simple archive that can be opened with any packager like e.g. WinRAR

So you can easily open it and view the files – although viewing most of the files won’t make you happy, because you’ll realize that they’re compiled, in binary format, etc

… but this is a different story.

Anyways, you can open the archive and then modify any resource file and save the modification in the archive.

But if you afterwards try to install the .apk on the smartphone (or tablet or similar), you’ll get an error.

The following screenshot displays the error when installing the modified sample application myApp.apk on an Android device:

The reason is that after the modification, the checksum and the signature are not valid anymore.

Thus, simply changing an .apk file is not possible.

However, there’s still the valid use case to modify or replace files inside an existing .apk.

– files which are placed in the assets folder

– property files containing configuration data

– images which can be replaced

– styling information resources

My personal use case was:

I had created an Android application using SAP Netweaver Gateway Productivity Accelerator.

I had to deliver the application to my users as .apk file.

But there was the requirement that they wanted to modify the ready application (change configuration data).

So I had to figure out how to achieve that: modify the app without having access to the source code.

Below, I’m sharing the required steps with you.

The description is based on the following software and versions:

Android current API 19

Java 7

Windows 7

If you aren’t familiar with Android, but wish to be, you might want to check the documents [1] and [2]

All prerequisites for understanding this blog are explained there.

In order to execute the commands described below, you need to have Java on your PATH variable of your Windows system (see [1] for an explanation).

Overview

There are 3 steps that need to be followed in order to modify an existing .apk file:

1. Do the actual desired modifications inside the .apk file

3. Install the .apk on the device

1. Change the resource in the .apk

Open the .apk file with WinRAR (if that doesn’t work, rename the file extension .apk to .zip)

Change the resource in the archive as desired (packager tools allow to change files without the need to extract the archive)

Once you’re done with your changes, you have to take care about the signature files that are part of the .apk:

Inside the archive, go to folder META-INF

Delete the existing *.RSA and *.SF files

The following screenshot displays the content of the META-INF folder in an .apk file:

Now the archive can be closed.

In case you had changed the file extension before, you now have to change it back to .apk

2. Sign the .apk

Android doesn’t allow to install an application (apk) that isn’t signed.

When developing an app in Eclipse, the ADT (“Android Developer Tools”, the extension to Eclipse that supports development for Android) takes care of signing the app with a default certificate, before installing in on the device.

That’s comfortable, but with the following description, everybody is able to sign an application.

Signing the .apk is done in 2 steps:

a) create the certificate

b) sign the .apk with the created certificate

Both steps are done with commands on the command line

a) Generate a certificate

If you’re working in a Java environment, you have the JDK on your file system.

Читайте также:  Робокоп против терминатора сега для андроид

The JDK comes with a tool to manage certificates: the keytool.

You can find it in the …/bin folder of your JDK installation.

On my machine it is here:

Now you can generate a certificate using below command.

However, before executing it, please check the notes below, in order to adapt the parameters

Please note that you have to adapt some of the parameters of the above command to your personal needs:

keystore

Here, you can provide an arbitrary name for your keystore.

The name that you provide here will be the name of the keystore-file that will be created.

The file will be created in the current directory.

(I haven’t tried it, but probably you can enter the name of an existing keystore file, in order to store the new certificate there)

alias

Here as well, you can provide an arbitrary name for the alias.

It is meant for you to recognize it.

The alias is the human readable name of the certificate which will be created and stored in the keystore.

validity 1000

This is the number of desired days.

You can enter any number you wish.

I think it should be high enough in order to avoid trouble with expiration.

Note that the parameters sigalg and keyalg are required by JDK 7, so it shouldn’t be necessary to add them if you’re using JDK 6

When executing the command, you’ll get several prompts on the command line, asking for password, username, organization, city, etc

You can enter any arbitrary data here, you only have to make sure to remember the password.

After you’ve executed the command, you’ll see the generated keystore file on your file system in the current directory (from where you’ve executed the command)

Now you can proceed with signing the .apk using the newly created certificate.

Before signing the .apk file, you have to make sure that there are no certificates available in the .apk.

This is described in step 1 above.

For signing an archive, we use the jarsigner tool, which is provided with JDK, and which can be found in the same location like the keytool.

The following command is used for signing an apk.

Please note that you have to adapt some of the parameters of the above command to fit your personal needs:

keystore

Here you have to enter the name that you have given in the previous step a)

In order to keep the command line short, I recommend to temporarily copy the keystore file to the same location where you’re executing the command.

Here you have to enter the name of the apk file which you want to sign

In order to keep the command line short, I recommend to temporarily copy the .apk file to the same location where you’re executing the command.

Here you have to enter the name of the alias that you’ve provided when generating the certificate

Note that the parameters sigalg and digestalg are required by JDK 7, so it shouldn’t be necessary to add them if you’re using JDK 6

After you’ve executed the command, you can check the result inside the .apk file:

Open the archive, go to the folder …/META-INF and check if the files CERT.RSA and CERT.SF have been created.

3. Install the apk on the device

Now that the .apk file is signed, you can install it on your device.

BTW: This procedure is also called side-load.

For Android applications the installation is done on the command line, using the adb command.

adb stands for Android Debug Bridge

adb.exe is a piece of software that connects the PC with the Android device.

It allows access to the device, allows to trigger operations, transfer files, etc.

In order to install the .apk on the device, you have to connect the device to your PC via USB cable,

then execute following command

In order to keep the command line short, you can temporarily copy the apk file to the same location where you’re executing the command.

The result should be “success” message on command prompt.

If not, any of the previous steps may have failed.

You can find the application in the apps folder of your smartphone.

This procedure worked for me on WIN7 and JDK 7.

It wasn’t required to rebuild the app, nor to generate new checksum or similar.

Links

Please refer to the following documents for lot of information for beginners.

They also contain lots of additional links for further reading.

Источник

Оцените статью