How to add some stuff from java files to smali files?

4.7k views Asked by At

I'll try to be as clear as possible :) I would like to add an activity (let's call it X not to do confusions) to an app in order to do this when the app start :

  • First of all, start my activity X and show the layout that contains a button.
  • The OnClickListener of the button starts the main activity of the original app.

I have the activity X in an eclypse project, so i can turn my java files to smali. I have the app in smali files + a yml file (by backsmaling).

How can i turn the main activity of the app to a normal activity ? How can i add my activity X to the app ? Which folder of the smali folder ? Do I need to change something in the yml file ? What happens for the xml files ?

Any kind of help will be very appreciated ! :)

1

There are 1 answers

5
zapl On BEST ANSWER

Editing the smali files is hard & it's kind of not inteded that you can add buttons to existing activities that way. smali is an assemly-like language that allows for some debugging but is more or less equivalent to the android dalvik bytecode.

You can however wrap apps with different start activites since that doesn't require changes in the apps. It's even automatable and abused by shady 3rd party marketplaces to put malware into the launch activity of other apps.

If you wanted to do that on your own you could probably do it like:

  • Make a simple app in Eclipse that contains the X activity & the resources you want to add.
  • Compile that app into an apk.
  • Take another app you want to modify as apk.
  • Decompile both using apktool into smali + resources.
  • Merge everything into the app you're editing
  • Use apktool to build an apk.

Some important steps in between:

Your new X Activity needs to call startActivity using an Intent setup from Strings since you don't have .class files you could compile against. You'll obviously need to know package and class names of the other app starting activity. Apart from that, just make it the way you'd do any Activity with buttons.

The merging of two decompiled apps is mostly simple copy & paste. Copy over the src folder, nothing should conflict here. For the res folder you'll need to know what resources you need, but you can mostly just copy them. For layouts and other named resources make sure not to use conflicting names in your X activity project in the first place. To "merge" 2 strings.xml files just rename one of them, the filename should be irrelevant.

Most importantly merge the AndroidManifest.xml. You'll need to add your X activity, including the "android.intent.category.LAUNCHER" / ...MAIN intent filter. That's what determines which activity can be started directly from the launcher. Also remove the filter from the other start activity that should no longer be started.

Rebuild an apk and that's it.

Note: I didn't test this in details. I assume it works though :)