0

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 ! :)

MisterX
  • 49
  • 3
  • 9
  • It sounds to me like you are trying to add to an application you haven't created by decompiling the `.apk` file. If you have access to the java files, why not just edit those and recompile? – Ed Holloway-George Nov 19 '14 at 21:41
  • of course i don't have access to the java files of the original app, it would be too easy ! i want to add my activity to an app i didn't created. For example, my activity could show "Are you sure you are 18+" and then the OnclickListener wil start the main activity of the app i didn't created :) – MisterX Nov 19 '14 at 21:56

1 Answers1

1

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 :)

zapl
  • 63,179
  • 10
  • 123
  • 154
  • OMG this sounds great ! I will try this, i just hope i will not have a lot of problems with the conflicts... Thanks a lot bro. – MisterX Nov 19 '14 at 22:05
  • There is a little error i don't know how to fix... to start the original mainactivity of the app, i do : String package =this.getResources().getString(R.string.Package); final Class> class = Class.forName(package); and in Strings.xml i do com.package.Activity. I have a "Unhandled exception type ClassNotFoundException" error concerning Class.forName. It also doesn't work when i just put the package like this final Class> c654 = Class.forName("com.package.Activity");. Of course i created a class named Activity in src/com/package/. Do you have an idea ? – MisterX Nov 21 '14 at 15:34
  • That should in theory work. If there is `src/com/package/Activity.java` or smali – zapl Nov 21 '14 at 18:26
  • I try to compile my app with an .java file in this folder, i don't why it doesn't work ... :( – MisterX Nov 22 '14 at 15:45
  • If you're still having a normal app, make sure that there is also a class with the correct name in there. Maybe add it to the manifest – zapl Nov 22 '14 at 18:19