Classes.dex patch help with smali/baksmali - Xperia SP Q&A, Help & Troubleshooting

Hello everyone!
I'm using an Xperia SP with ViperOS (Android 7.1.2) and wanted to patch Framework.jar with some smali files to port Xperia stock camera for AOSP. I successfully decompiled my classes.dex file which found within the framework.jar, and I replaced the necessary files in order to patch that framework which is in the attached file. (storagemanager.zip). But when recompiling with smali it gives me following error.
Code:
UNEXPECTED TOP-LEVEL EXCEPTION:
org.jf.util.ExceptionWithContext: Unsigned short value out of range: 65537
at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116)
at org.jf.dexlib2.writer.InstructionWriter.write(InstructionWriter.java:329)
at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1027)
at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:803)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:252)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:230)
at org.jf.smali.main.run(main.java:176)
at org.jf.smali.main.main(main.java:265)
I tried with many smali.jar versions but no help. So I think to upload my classes.dex file and the files I need to replace with files (storagemanager.zip) after decompiling classes.dex. Files should be copied to android\os\storage which get after doing baksmali for classes.dex.
If anyone can successfully patch my classes.dex I would really appreciate.
Thanks in advance

Related

Dexopt Wrapper

I'm sure most of you know that optimization using dexopt wrapper creates an odex file but removes the classes.dex file in the apk. My question is, how do you remove that .odex file and change it back to a classes.dex file? I'm wondering because once I have a classes.dex file I'm going to disassemble it with baksmali see what I can do and figure out. Any help is appreciated, thanks.
alritewhadeva said:
I'm sure most of you know that optimization using dexopt wrapper creates an odex file but removes the classes.dex file in the apk. My question is, how do you remove that .odex file and change it back to a classes.dex file? I'm wondering because once I have a classes.dex file I'm going to disassemble it with baksmali see what I can do and figure out. Any help is appreciated, thanks.
Click to expand...
Click to collapse
dexopt-wrapper does not remove the dex file from the apk, unless we do it different ways, i run dexopt-wrapper ***.apk ***.odex from adb. how do you do it? and anyway, if you used dexopt-wrapper, just get the rom you flashed before doing dexopt-wrapper and you should have the full apks already in there
I'm trying to get a classes.dex file from the Phone.apk from hero builds .As you can see in my signature I'm working on porting the HTC Dialer to cupcake builds. The Phone.apk included in JaCHero2.63 just doesn't have the .dex file ,but it has the .odex file. All apks in that build that are optimized with odex do NOT have a classes.dex file in the original apk file. I'm wondering if it's possible to merge the .odex and the .apk so i can get a workable classes.dex file.

[Q] stat_sys_battery.xml

Hi!
what i try to do is to make my battery icon increase in 1% or 5% increments.
i got my icons and stat_sys_battery.xml from the "HTC Desire" post below
http://208.100.42.21/showthread.php?t=724778
however, after a few days trying it, i found i couldn't just drag and drop the icons to the "drawable-hdpi" folder and also not the XML files to the "drawable" folder.
"i think" this is because my OWN original XML files are all compiled and the XML copy from the HTC Desire post haven't compile, so when i replace the XML files it doesn't know how to locate the new battery PNGs
then further reading i found out "Apktool" which allows me to decompile the framework-res.apk so i can edit the XMLs
now ... my question is when i compile the folder i have the error:
w: could not find sources
i guess it's obvious that it can't find my folder ... so what the command so be?
the decompile folder is c:\apktool\test2
my compile command is apktool b test2
please help ... please explain a bit more your reply ... i am not a programmer/developer ... thanks.
kakyoin said:
Hi!
what i try to do is to make my battery icon increase in 1% or 5% increments.
i got my icons and stat_sys_battery.xml from the "HTC Desire" post below
http://208.100.42.21/showthread.php?t=724778
however, after a few days trying it, i found i couldn't just drag and drop the icons to the "drawable-hdpi" folder and also not the XML files to the "drawable" folder.
"i think" this is because my OWN original XML files are all compiled and the XML copy from the HTC Desire post haven't compile, so when i replace the XML files it doesn't know how to locate the new battery PNGs
then further reading i found out "Apktool" which allows me to decompile the framework-res.apk so i can edit the XMLs
now ... my question is when i compile the folder i have the error:
w: could not find sources
i guess it's obvious that it can't find my folder ... so what the command so be?
the decompile folder is c:\apktool\test2
my compile command is apktool b test2
please help ... please explain a bit more your reply ... i am not a programmer/developer ... thanks.
Click to expand...
Click to collapse
Im not exactly sure what errors you're getting... But heres two things that might help.
1. If you're using an already themed framework-res.apk to decompile/edit/recompile, don't. Apk Tool needs a clean version of your framework-res.apk. So use a clean version, decompile it, edit your xml, recompile, and finally copy/extract the edited xml file and put it into the framework-res.apk of your choosing.
2. Side Note: Sometimes Apk Tool will say something like "resources could not be found". I believe this is because apk tool tries to reverse engineer the apk to source, which it can't exactly do without all of the java resource files that was used to compile the apk. For XML files however, apk tool is sufficient.

[Q] Framework Jar File

I am trying to create a reboot option for my galaxy tablet. I am in the proccess of using smali/baksmali to edit some files...the problem is when I adb pull the framework jar there is no classes file in the zip. The only thing in there is the META-INF obviously and a file called preloaded classes...this is considered just a file, not a class file. Should I not have a .class file?
EDIT-------------------------------------------------
I looked, what I mean is that there is no classes.dex file
Thanks
Found the problem. I am using a stock rom that hasn't been deodexed. I had to use baksmali to deodex the framework.odex file. Of course if you do this you have to have the right bootclasses in the folder or the file will not decompile right, and from what I have read you need that to happen in order to compile it back into a odex file. I should deodex the whole rom, but I am still new at this and don't want to create a boot loop
-Peace

Assistance is NEEDED - Editing APK

I'm having the most difficult time editing apks. I've followed this tutorial: http://forum.xda-developers.com/showthread.php?t=1365810
and I can't even setup a simple middle clock centered mod or custom carrier logo. I decompile the systemUI settings after installing framework-res. I edit the xml EXACTLY how the tutorial says to. I have the png made and put it in /res/drawable-hdpi/
I recompile the systemUI and sign it, zipit, flash it - it flashes.
Now the following has happened to me, I either get stuck on a boot loop or I try the tutorial all over again without signing the apk, flash it, boots up fine but NO MODS HELP!!!!
i don't edit the center clock on some ROMs anymore b/c they come with an option to center it in the settings... if the ROM you are using has this option, following the directions in that thread might not work or mess something up!
-=NMV4G[03.15B]=- does not unfortunately have this feature, it does have the pm/am clock mods but not the color selector or center mod feature
read this guide first : http://forum.xda-developers.com/showpost.php?p=9126643#post9126643
i think your problem is in this part :
Rebuild the apk using the following command:
Code:
java -jar apktool.jar b framework-res out\framework-res.apk
This will create a new framework-res.apk in a subfolder out.
IMPORTANT: Do not push this apk to your phone unless you want to reflash
Extract the xml files and images from the newly generated apk (you can use the original images, but the xml files must be the newly compiled ones from the new apk). Add these files to the original framework-res.apk that you want to push to your phone (see the previous post).
Extract the resources.arsc from the root of the apk
Rename the original framework-res.apk from your theme to framework-res.zip
Right-click the extracted resources.arsc and choose the 7zip menu item ‘Add to archive’
In the dialog that appears set the achive field at the top to the framework-res.zip from step 7. And set the archive format to zip. Now set the Compression level to store and click OK(if you do not do this your phone will not boot). The settings are in the attached screenshot.
Rename framework-res.zip to framework-res.apk and double check that the compressed size or resources.arsc is the same as the original size (see screenshot)
Done. Push the new framework to your phone.
Click to expand...
Click to collapse
I tried the command you posted and it didnt work because it said it couldn't find the file specified: framework-res so I tried the command from the tutorial you (evilisto) posted, I got a framework-res folder that is empty, now I'm a bit confused, am I supposed to have xmls, in that folder or do I need to decompile the SystemUI.apk now?
ebs512 said:
I tried the command you posted and it didnt work because it said it couldn't find the file specified: framework-res so I tried the command from the tutorial you (evilisto) posted, I got a framework-res folder that is empty, now I'm a bit confused, am I supposed to have xmls, in that folder or do I need to decompile the SystemUI.apk now?
Click to expand...
Click to collapse
you have to use your folder name...
ok then here is simple guide about apk file modifying.
-------------------------------------------------------
1) decompile apk. for example...
Code:
java -jar apktool.jar d SystemUI.apk /(folder_name)
2) edit what you want.
3) recompile apk.
Code:
java -jar apktool.jar b /(folder_name) SystemUI.apk
4) copy what you modified from new SystemUI.apk to original SystemUI.apk
so if you changed something in /res/values, copy new resources.arsc to original SystemUI.apk. (using 7-zip or other program)
if you modified /res/layout or other resources files, copy those to original apk file too.
5) use modified original SystemUI.apk file.
-------------------------------------------------------
basically same to above guide that i quoted.
everytime I decompile the framework-res it puts a subdirectory out of framework-res with nothing in it, I decompile the systemui.apk and there is no res folder, just a bunch of smali code, even when I go back and try to install the framework-res before decompiling, I get:
W: Config size >32
W: Config size >32
W: Config size >32
W: Config size >32
W: Config size >32
W: Config size >32
Exception in thread "main" brut.androlib.AndrolibException: Multiple Resources
ebs512 said:
everytime I decompile the framework-res it puts a subdirectory out of framework-res with nothing in it, I decompile the systemui.apk and there is no res folder, just a bunch of smali code, even when I go back and try to install the framework-res before decompiling, I get:
W: Config size >32
W: Config size >32
W: Config size >32
W: Config size >32
W: Config size >32
W: Config size >32
Exception in thread "main" brut.androlib.AndrolibException: Multiple Resources
Click to expand...
Click to collapse
That's a bug with android 4.0.3. Use google, there is a bug report and an attached updated test apktool.jar for 4.0.3
Sent from my Nexus S 4G using xda premium

[INFO]Editing system files (smali,dex,apks)

NOTE: If you want to edit framework-res.apk or systemui.apk, follow this guide, it's the best available:good:
http://forum.xda-developers.com/showthread.php?t=2086771
Now, lets start
smali, dex....whaaat?
It's simple our odexed ROMs have .apk which use .odex files which contain cache. When the ROM is deodexed the .apk contains classes.dex which now contains information present in the .odex files!:good:
Smali is nothing but disassembled .dex file! The .dex file is disassembled into java code which can be edited via Notepad ++( simple notepad works too)
WHY?
Why do you need to edit classes.dex !
For me, i was trying to make CRT on/off animation which required editing classes.dex in service.jar!
More edits where classes.dex inside services.jar is needed
- Changing status bar clock color
- Changing text color in notification bar
- More? Tell Me!:highfive:
HOW?
Requirements: Java SDK!
I have APK Multi Tool, although it decompiles .apk and .dex files inside the apk, it doesn't provide option to decompile a separate classes.dex!
Still it's best software for decompiling apks and more!
Smali-Me 1.0
Download and Instructions:
http://www.wrapcode.com/android/baksmali-smali-dex-files/
ROM Tools by iamareebjamal - More noob friendly
http://forum.xda-developers.com/showthread.php?t=2163286
Once you have decompiled classes.dex, you'll get various folder with various files. Edit the files required and then recompile!
So after generating new classes.dex, put it back to services.jar by opening the file in winzip!:good:
ONE MORE THING
Make your own flashable zip
The recompiled systemui.apk or framework-res.apk, when pushed via root explorer give lot of force closes. This is normal, however if u wish to avoid it u can create a cwm flashable zip for the same!:good:
I'm attaching the sample.zip here and u can add your files in the specified folders. For more details read the source forum:
http://forum.xda-developers.com/showthread.php?t=1721680
Reserved- for more stuff!
Subscribed.. will see what it is later
Hey, add this to your guide, i far more easier and nice to look at too than smali me
http://forum.xda-developers.com/showthread.php?p=40435351#post40435351

Categories

Resources