[Q] DexMerger not working? - Android Q&A, Help & Troubleshooting

I've always searched for a way to dex jar libraries once and then simply merge them when building the Android app.
Now the current version of dx (from the Android SDK 4.1.1) contains a DexMerger class.
You can call it directly with java -cp com.android.merge.DexMerger to merge 2 .dex files together.
dx itself uses this class when you dex a directory with .class files and there are archives (.zip, .jar, .apk) containing a classes.dex file. These classes.dex files are then merged with the dex file to be built from the .class files.
The problem is that dex files created with DexMerger do not work. APKs built this way are not installed.
Does anyone know how to make this work?
Where could I contact the Android SDK developers to ask them directly?
Tom

Related

Android's .so files

OK, So I've gotten to breaking down and recompiling those pesky .dex files, but I've run into a new problem.
This is a noob question, I'm sure, but .so files look like unformatted, binary files. How do I open then, edit them, etc? I need to read whats going on in my libs. :-(
Are these X11? I'm running ubuntu 10.04 x64 - so those could be difficult.
ie - unreliable 64 bit support.
$ sudo ln -s /usr/lib32/libX11.so.6 /usr/lib32/libX11.so
Click to expand...
Click to collapse
They're native library files, so platform specific machine code I imagine. Look for an ARM disassembler. I'm not familiar with linux internals, so don't know how you find the entry points, but it obviously will be widely documented. Is it impossible to obtain the source code? Assuming most are written in C/C++, reverse engineering from the machine code is not something I'd describe as a pleasant experience. If the source was well written assembly language & not too big, it can be almost enjoyable I guess. But then TBH walking through a randomly selected programmer's source, let alone object, files scares me, in a Tim Burton inspired bad trip kinda way. If you can find the source, it will be an order of magnitude less painful.
Try IDA Decompiler, it should disassemble all so files!
Most of the libs are open source in the aosp. Some are proprietary blobs with the only solution to them being reverse engineering.
.so disassembly
i know how to disassemble it
you will need orion's easy apk disassembler and apk manager
i've tested it once and it worked, but thereĀ“s a problem, i dont know how to re-assemble
1- rename the file .so to .apk like "libtestlib.so" to "libtestlib.apk"
2- put in the folder "place-apk-here-for-modding" of apk manager
3- open script.bat (or something like this) from Apk manager
4- use extract apk option
in the beggining my images inside the lib was corrupted so i used step 5 to fix
5- use option optimise images inside to fix images
6- go to project folder and copy classes.dex file to the root of easy apk disassembler's folder
7- open EasyApkDisassembler.EN.bat and use the "DISASSEMBLY a classes.dex with smali" option
8- give a name to the folder (like "libtestlib")
9- it will create a folder (like "out_libtestlib") with the disassembled files
Orion's easy apk disassembler http://forum.xda-developers.com/showthread.php?p=5826401
Apk multi tool (almost the same as apk manager) http://forum.xda-developers.com/showthread.php?t=1310151
I've tried to open libsurfaceflinger.so from my device with 7zip, and it worked too
thats it
@gkillershots
not working
i renamed .so to .apk and used extract option but getted error :
Processing archive: C:\APKMultiTools\place-apk-here-for-modding\libnative-lib.apk
Error: Can not open file as archive
"An Error Occurred, Please Check The Log (option 26)"

Is it possible to use baksmali on the device

Basically I want to be able to decompile apks. And jar files directly on my phone. Can I do that?
Yes, you can. At least, for the most part. The main constraining factor is the small amount of memory available on the device.
1. run the dx util on baksmali.jar, to produce a classes.dex file
2. add the classes.dex file to a new jar (or you can just add it to baksmali.jar)
3. push the jar containing classes.dex to the device somewhere (let's say /data/local/baksmali.jar)
4. dalvikvm -classpath /data/local/baksmali.jar org.jf.baksmali.baksmali <normal baksmali options>
5. bonus points if you then proceded to run baksmali on baksmali.jar (and then the universe implodes)
note: I just tried this with the latest version of baksmali, and there's some weird issue with the baksmali jar file, where it contains duplicate entries of every class file, which causes dx to choke on it. I'll see if I can get that fixed soon, and get a new build out. In the meantime, you can probably find an older version without that problem.
Sweet, thanks for your input. I was out last night and I had this idea for an edit to make, only to become sad because I didn't have access to a computer.
This will help me out a lot.
JesusFreke said:
Yes, you can. At least, for the most part. The main constraining factor is the small amount of memory available on the device.
1. run the dx util on baksmali.jar, to produce a classes.dex file
2. add the classes.dex file to a new jar (or you can just add it to baksmali.jar)
3. push the jar containing classes.dex to the device somewhere (let's say /data/local/baksmali.jar)
4. dalvikvm -classpath /data/local/baksmali.jar org.jf.baksmali.baksmali <normal baksmali options>
5. bonus points if you then proceded to run baksmali on baksmali.jar (and then the universe implodes)
note: I just tried this with the latest version of baksmali, and there's some weird issue with the baksmali jar file, where it contains duplicate entries of every class file, which causes dx to choke on it. I'll see if I can get that fixed soon, and get a new build out. In the meantime, you can probably find an older version without that problem.
Click to expand...
Click to collapse
The problem seems to be within the buildprocess as the generated classes for baksmali and smali are added twice to the *-dev-jar-with-dependencies.jar. As I'm not familar with maven I didn't fixed the source of the error but I managed to get it working.
I attached a small pythonscript which is able to remove the dublicated files within the jar. Just run it over the file and get a fixed version which is processable by dx.
The script:
Code:
#!/usr/bin/python
import sys
from zipfile import *
if len(sys.argv) != 3:
print("Usage: %s input.jar output.jar" % sys.argv[0]);
sys.exit(-1)
input = ZipFile(sys.argv[1], "r")
output = ZipFile(sys.argv[2], "w")
seen = []
for file in input.namelist():
if file not in seen:
output.writestr(file, input.read(file))
seen.append(file)
else:
print("dub found: %s" % file)
input.close()
output.close()
sorry ...
Wrong place
JesusFreke said:
Yes, you can. At least, for the most part. The main constraining factor is the small amount of memory available on the device.
1. run the dx util on baksmali.jar, to produce a classes.dex file
2. add the classes.dex file to a new jar (or you can just add it to baksmali.jar)
3. push the jar containing classes.dex to the device somewhere (let's say /data/local/baksmali.jar)
4. dalvikvm -classpath /data/local/baksmali.jar org.jf.baksmali.baksmali <normal baksmali options>
5. bonus points if you then proceded to run baksmali on baksmali.jar (and then the universe implodes)
note: I just tried this with the latest version of baksmali, and there's some weird issue with the baksmali jar file, where it contains duplicate entries of every class file, which causes dx to choke on it. I'll see if I can get that fixed soon, and get a new build out. In the meantime, you can probably find an older version without that problem.
Click to expand...
Click to collapse
I realize this is a very old thread, but it is exactly what I am looking for However, it seems there are Java 8 features in smali/baksmali now and dx does not work. Is there a workaround for this or any other way to run smali/baksmali from terminal on Android? Thanks!
The older versions of smali may still work for you. Or what I've done is use Termux and download the jdk for arm64 and used the ndk to compile smali on my device.
Delgoth said:
The older versions of smali may still work for you. Or what I've done is use Termux and download the jdk for arm64 and used the ndk to compile smali on my device.
Click to expand...
Click to collapse
Thanks for the reply
However, I am not trying to compile smali on my device. I am trying to run the latest smali/baksmali on my device in Termux. Unfortunately, the older versions will not work for my needs. If you can help I would really appreciate it
But compiling the latest build of small on the device will allow you to use the latest build of smali.

[Q] APK modding Deskclock - Please Help

So i have this Deskclock.apk and i want to add this.
No Problem with the ".xml" Files. I can edit them easily after i decompile the apk with the "apkTool". But where will i find the ".java" Files? After decompiling the apk i only see ".smali".
So i found out that the ".java" files are in "classes.dex" from the apk.
I use "dex2jar" to get a ".jar" File.
Then i use "jd-gui" to get ".java" Files.
So i can edit it and put the needed Strings in the .java files.
But how to put them back to a "classes.dex" File which i can put back to the apk??
I hope i get a bit help here.
You can use APKTool. It will automaticly extract all the classes (.dex), resources (.asrc), then it will convert binary XML to human-readable XML, and it will also dissassemble the classes for you.
Just tell APKTool to decode the APK into a directory, then modify what you want, and finally encode it back to an APK. That's all.
Important: APKTool dissassembles. It doesn't decompile. The generated code won't be Java source. But you should be able to read it, and even edit it if you're familiar with jasmin. If you want Java source, please go over the Manual way.
Sent from my VS910 4G using XDA
Thx...I know how to use APKTool but i need to put the ".java" Files back into the "classes.dex". Thats my Problem.
There's info on the process here: http://stackoverflow.com/questions/10261147/converting-java-back-to-classes-dex
Essentially it looks like you need to compile the .java to .class files with javac and then create classes.dex with dx. Hope this link is helpful.

adding java files to an decompressed apk and make a new apk afterward

hi everyone,
just for more information i've used ionic framework to write my application and phonegap build to build it. cause of the ionic app structure it's impossible to add java files there. now that i decompressed it i can see java files in android folder. can i now add some extra java files here and build it again e.g. in android studio?

FIPS META-INF/HMAC.SHA256 (DEX modifies) ERROR

Hi,
I have a signed jar that cannot be allowed to be modified.
By adding it to the /libs folder in Android Studio, when the app is built into an .apk because of it (the .jar) being included in classes.dex the checksum changes and the jar's classes will crash.
Is there a way to import a jar into a project and ensure it does not get obfuscated/compressed/changed etc or kept outside of classes.dex and able to run the apk without problems?
I would have added it to the developers forum but I have a low post count.
Thanks in advance.

Categories

Resources