[Project] Decompile Apps to Java - Android Software Development

A little introduction:
I already created a project on GoogleCode with the goal to decompile Dalvik's bytecode to fully compilable java-sourcecode.
I know that's a complex thing and that there are some technical barriers like the fact that dalvik uses registers but I think this should and can be done.
There are already some projects like dex2jar or baksmali which does a very good job.
Dex2jar does only produce a readable java-code(not good for making changes and to recompile everything).
The smali-code produced by baksmali is a little bit hard to read but it's the best for making changes.
So I decided to use the sourcecode of baksmali so I don't need to write a smali or dex-parser and I can directly start converting the smali-language to java-code.
A clarification: I only want to make it possible to use code for studying or to recover your own code.
The goal of this project will never be to support piracy or code-stealing!!!
Click to expand...
Click to collapse
GoogleCode-Project:
http://code.google.com/p/bakjava/
Project-Status:
What's working?
Code:
Package-Names
Class-Definitions with extends and implements
Methods with return-types, accessors and parameters
Fields with data-type and accessors
What doesn't work?
Code:
Interfaces
Annotations
Generics
Variables
Instructions
Loops
everything else what I forgot...
I hope that there is any interest by the community and maybe some coders who wants to help.

I think this will be very, very hard. Disassembling or converting class and method names only is quite easy to do because they're 1:1 conversions. You have method with 2 int arguments? You write it as "someMethod(II)V" or "void someMethod(int p0, int p1)" - it's really easy.
But this is not the case for decompilation. Decompilation is a process of guessing how sources might look like before the compilation. This is not 1:1, it requires you to create an "intelligent" tool which supports thousands of different situations.
You see, JVM bytecode decompilers are developed for over ten years and they're still far from perfect. Now you want to create DVM bytecode decompiler just like that
I think dex2jar & JD is the way to go. You convert DVM to JVM only, which is nearly 1:1 and then use the power of years of experience on JVM decompilation.
Ahh, of course you can create simple decompiler which will output something like:
Code:
int r0 = 5;
int r1 = 8;
int r2 = r0 + r1;
r1 = 20;
r2 = r2 - r1;
But that's not better than smali. In fact it's even worse. And still it's quite hard to convert goto's to loops, if's, etc.

You're right. It's not easy but I want to give it a try.
BTW goto's doesn't exist in Java. Android-Apps which were directly written in smali aren't easy to compile.
But the purpose of this project is to decompile Apps which where written in Java.

m11kkaa said:
BTW goto's doesn't exist in Java. Android-Apps which were directly written in smali aren't easy to compile.
But the purpose of this project is to decompile Apps which where written in Java.
Click to expand...
Click to collapse
Goto's don't exist in Java source, but they do in the bytecode. All flow control instructions like if, else, while, do..while, for, switch, etc. are compiled to goto's (or to other types of jumps).

You're right
But I still want to try this just to test myself and to see what can be done.
Now instead of disussing the difficulty of this project let's start planning and coding
Would be great if anyone has some knowledge on complex algorithms and coding-algebra and wants to contribute to this project.

Maybe don't convert gotos to if/loop statements..
dex2jar creates lots of loops and their first instruction is a break/return -_-
If you convert everything but goto's, the code should already be much more readable, and at least goto is a reserverd java keyword.
On the downside this would require an extra compiler or the code is read-only.

I didn't test that logic but theoretically we could split the code at the goto's and write the blocks into method's.
This methods could be called instead of the goto's.
Would be less readable but it should work or am I wrong?
BTW: Currently I'm working on converting the standard-code into java. Theoretically simple but that's very much work. Would be really great if someone wants to help. baksmali is written in java so you don't need any c/c++-knowledges.

m11kkaa said:
I didn't test that logic but theoretically we could split the code at the goto's and write the blocks into method's.
This methods could be called instead of the goto's.
Would be less readable but it should work or am I wrong?
Click to expand...
Click to collapse
It will be much, much less readable than smali and it'll greatly decrease performance after recompilation. Methods has averagely 5-10 branches of code, so you would have to break them into very large number of methods.
Let's get for example very simple method:
Code:
private String someMethod(Object o) {
return o == null ? "" : o.toString();
}
In smali it would be something like:
Code:
if-nez p1, :cond_0
const-string v0, ""
:goto_0
return-object v0
:cond_0
invoke-virtual {p1}, Ljava/lang/Object;->toString()Ljava/lang/String;
move-result-object v0
goto :goto_0
As you can see it has 4 branches of code, so it would be decompiled into:
Code:
private String someMethod1(Object o) {
String ret;
if (o == null) {
ret = someMethod2();
} else {
ret = someMethod3(o);
}
return ret;
}
private String someMethod2() {
return "";
}
private String someMethod3(Object o) {
return o.toString();
}
I have already do some optimization, because I have decompiled 4 branches into 3 methods, not 4.
m11kkaa said:
Would be really great if someone wants to help. baksmali is written in java so you don't need any c/c++-knowledges.
Click to expand...
Click to collapse
I think I know how to do that, but for me it's a waste of time. It'll take many months to be able to decompile simple applications and still results will be poor.

Related

XBMC on ASUS Transformer

If you want to follow my progress and/or help me get it done.
http://forum.xbmc.org/showthread.php?tid=132043
Kafluke said:
If you want to follow my progress and/or help me get it done.
http://forum.xbmc.org/showthread.php?tid=132043
Click to expand...
Click to collapse
Hell yes I've been waiting for this forever. How can I help out?
Walk me through the steps to either:
- Compile XBMC on Ubuntu running on my Transformer (I think this requires a compiler built for the ARM7 processor which I'm not sure exists)
- Cross-compile it on my Ubuntu x86 laptop. I downloaded a cross-compiler for arm processors but don't know how to use it to compile xbmc for the Transformer.
Fantastic idea, I will be following your progress for sure, good luck!
I need some serious help here. I have over 18 years of Windows experience but I'm lost when it comes to Linux.
I'm not a programmer either so I'm stumbling all over myself trying to get this to work.
I need some developers to help me with the steps to compile XBMC for the Transformer.
I've compiled tons of **** in the past but never cross-compiled something, maybe this will help: http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html
I'm gonna put cross compiling on the shelf for right now and attempt something really stupid, compiling xbmc with the Transformer itself. LOL I doubt this will work.
can anyone post a compiled version? thks
Sent from my Transformer TF101 using XDA
Following this guide.
I'm on this step:
Code:
Here is the magic command to get the build dependencies (used to compile the version on the PPA).
$ sudo apt-get build-dep xbmc
After running this command I get this output
Code:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libglew1.6dev' instead of 'libglew-dev'
Note, selecting 'libjpeg62-dev' instead of 'libjpeg-dev'
Note, selecting 'libsamplerate0-dev' instead of 'libsamplerate-dev'
Note, selecting 'libfontconfig1-dev' instead of 'libfontconfig-dev'
Note, selecting 'libsdl1.2-dev' instead of 'libsdl-dev'
E: Build-Depends dependency for xmbc cannot be satisfied because the package libcec-dev cannot be found
I've looked and looked and can't figure out how to install "libcec-dev". I've added the Pulse Eight PPA and tried to install libcec-dev and it can't find the package to install. I don't know how to get past this.
Jhinta got it working in the Q&A Ubuntu thread:
http://forum.xda-developers.com/showpost.php?p=23532866&postcount=1726
MrMuffin said:
Jhinta got it working in the Q&A Ubuntu thread:
http://forum.xda-developers.com/showpost.php?p=23532866&postcount=1726
Click to expand...
Click to collapse
Thanks Mr Muffin! I tried to get help on the official xbmc forum but every reply was a tiny bit of help and the remaining 80% was "holier-than-thou" BS and lectures on why I shouldn't be asking in the first place. I hate jack-asses like that.
I built the xbmc source today, but I had to fix an error message like this:
Code:
WinSystemGLES.cpp: In constructor ‘CWinSystemGLES::CWinSystemGLES()’:
WinSystemGLES.cpp:35:14: warning: converting to non-pointer type ‘EGLNativeWindowType {aka long unsigned int}’ from NULL [-Wconversion-null]
WinSystemGLES.cpp: In member function ‘virtual bool CWinSystemGLES::InitWindowSystem()’:
WinSystemGLES.cpp:49:70: error: invalid conversion from ‘void*’ to ‘EGLNativeDisplayType {aka _XDisplay*}’ [-fpermissive]
/home/andrew/xbmc/xbmc/windowing/egl/WinEGLPlatformGeneric.h:38:31: error: initializing argument 1 of ‘virtual EGLNativeWindowType CWinEGLPlatformGeneric::InitWindowSystem(EGLNativeDisplayType, int, int, int)’ [-fpermissive]
WinSystemGLES.cpp: In member function ‘virtual bool CWinSystemGLES::DestroyWindowSystem()’:
WinSystemGLES.cpp:74:14: warning: converting to non-pointer type ‘EGLNativeWindowType {aka long unsigned int}’ from NULL [-Wconversion-null]
make[1]: *** [WinSystemGLES.o] Error 1
Seems like it worked with this workaround:
in xbmc/windowing/egl/WinSystemGLES.cpp on line 35: replace - line with + line (without + )
Code:
- m_window = NULL;
+ m_window = (EGLNativeWindowType) NULL;
on line 49:
Code:
- m_window = m_eglplatform->InitWindowSystem(m_display, 1920, 1080, 8);
+ m_window = m_eglplatform->InitWindowSystem((EGLNativeDisplayType) m_display, 1920, 1080, 8);
on line 74:
Code:
- m_window = NULL;
+ m_window = (EGLNativeWindowType) NULL;
Just wanted to share to help others

[Q] S4 i9502 Caller ID fix deodex framework.jar

Hi,
I'm trying to get the caller ID issue resolved on my i9502, as described in this thread:
http://forum.xda-developers.com/showthread.php?t=2268120
My i9502 has been flashed with this ROM:
http://pan.baidu.com/share/link?shareid=2302611&uk=3760742413
Everything is working fine with this ROM, except that CallerID doesn't correctly lookup contacts. It tries to find a contact name based on 11 matching digits.
When i try to follow the steps, as described in the thread above, to change the MIN_MATCH value
Check for and fix MIN_MATCH constant in telephony framework
1) Decompile framework.jar
2) Open smali/android/telephony/PhoneNumberUtils.smali
3) Search for MIN_MATCH constant and set it to 0x7
When running baksmali command i get the following errors:
C:\apktool\system\framework>java -jar baksmali.jar -x framework.odex
Error occured while loading boot class path files. Aborting.
org.jf.dexlib.Code.Analysis.ClassPath$ClassNotFoundException: Could not find int
erface Landroid/widget/AdapterView$OnItemClickListener;
at org.jf.dexlib.Code.Analysis.ClassPath$ClassDef.loadAllImplementedInte
rfaces(ClassPath.java:867)
at org.jf.dexlib.Code.Analysis.ClassPath$ClassDef.<init>(ClassPath.java:
692)
at org.jf.dexlib.Code.Analysis.ClassPath.loadClassDef(ClassPath.java:282
)
at org.jf.dexlib.Code.Analysis.ClassPath.initClassPath(ClassPath.java:16
3)
at org.jf.dexlib.Code.Analysis.ClassPath.InitializeClassPathFromOdex(Cla
ssPath.java:110)
at org.jf.baksmali.baksmali.disassembleDexFile(baksmali.java:104)
at org.jf.baksmali.main.main(main.java:297)
Error while loading class Landroid/accounts/ChooseAccountActivity$1; from file f
ramework.odex
Error while loading ClassPath class Landroid/accounts/ChooseAccountActivity$1;
And when running baksmali command against the framework.jar file:
C:\apktool\system\framework>java -jar baksmali.jar -x framework.jar
UNEXPECTED TOP-LEVEL EXCEPTION:
org.jf.dexlib.DexFile$NoClassesDexException: zip file framework.jar does not con
tain a classes.dex file
at org.jf.dexlib.DexFile.<init>(DexFile.java:298)
at org.jf.baksmali.main.main(main.java:269)
Anyone managed to deodex framework.jar of this ROM, and change the "smali/android/telephony/PhoneNumberUtils.smali" file to fix caller ID issue?
Did backsmali!
Hello,
I managed to backsmali framework.jar, what I did follows:
* Downloaded Backsmali-Manager_v1.5: http://forum.xda-developers.com/showthread.php?t=2311766
* Copied Phone's /system/framework folder to backsmali-manager folder.
* Run: java -jar tools\baksmali.jar -x -d framework put-file-here\framework.odex -o project\framework-jar
And that did the trick, but I think we need to follow the instructions from here: http://forum.xda-developers.com/showthread.php?t=1756953
luizfeliperj said:
Hello,
I managed to backsmali framework.jar, what I did follows:
* Downloaded Backsmali-Manager_v1.5: http://forum.xda-developers.com/showthread.php?t=2311766
* Copied Phone's /system/framework folder to backsmali-manager folder.
* Run: java -jar tools\baksmali.jar -x -d framework put-file-here\framework.odex -o project\framework-jar
And that did the trick, but I think we need to follow the instructions from here: http://forum.xda-developers.com/showthread.php?t=1756953
Click to expand...
Click to collapse
Hi,
Getting closer, but my phone was hanging after i put back the re-compiled framework.odex file.
I did the following:
1) de-compiled framework.odex:
C:\Baksmali-Manager_v1.5\system>java -jar ..\tools\baksmali.jar -x -d framework ..\put-file-here\framework.odex -o project\framework-jar
2) Edited the file: "smali/android/telephony/PhoneNumberUtils.smali ":
.field static final MIN_MATCH:I = 0x7
.field static final MIN_MATCH_CHINA:I = 0x7
.field static final MIN_MATCH_HK:I = 0x7
.field static final MIN_MATCH_TW:I = 0x7
3) Re-compiled again:
C:\Baksmali-Manager_v1.5\system>java -Xmx512M -jar ..\tools\smali.jar .\project\framework-jar -o new-framework.odex
4) re-named the file to "framework.odex"
And then put it back on my phone. I noticed that the re-compiled file is 6.98Mb vs. 7.41Mb the original framework.odex file.
Tried it anyway, but my phone was hanging at the Samsung logo on re-boot.
5) Re-flashed my phone with the rooted ROM. Now it starts up fine again
Did i miss something when de-compiling & compiling?
A look into the code
jompie said:
Hi,
3) Re-compiled again:
C:\Baksmali-Manager_v1.5\system>java -Xmx512M -jar ..\tools\smali.jar .\project\framework-jar -o new-framework.odex
4) re-named the file to "framework.odex"
And then put it back on my phone. I noticed that the re-compiled file is 6.98Mb vs. 7.41Mb the original framework.odex file.
Tried it anyway, but my phone was hanging at the Samsung logo on re-boot.
Did i miss something when de-compiling & compiling?
Click to expand...
Click to collapse
What you get back from smali is a regular jar, not an odexed one. When you run backsmali with '-x' argument, you tell backsmali to deodex the source file. So, Maybe, that was the problem.
But there are other points in the code we should pay attention. For your need, I don't think that you need to change anything in the original framework. You need that the MIN_MATCH variable set to 0x7. As far as I could understand from the smali code, if you change the sales code, you can accomplish that. And, as far as I know, sales code is a configuration directive, from one or more of the many xmls available in the /system directory.
I will substantiate what I said this some code snippets.
The MIN_MATCH* variables are defined as:
.field static final MIN_MATCH:I = 0x7
.field static final MIN_MATCH_CHINA:I = 0xb
.field static final MIN_MATCH_HK:I = 0x8
.field static final MIN_MATCH_TW:I = 0x9
In CompareLoosely method, there is a check for the sales_code "CHN" "CHU" "CHM" "CTC" "CHC"
.method public static compareLoosely(Ljava/lang/String;Ljava/lang/StringZ
(...)
const-string v11, "ro.csc.sales_code"
(...)
.local v9, "salesCode":Ljava/lang/String;
const-string v11, "CHN"
(...)
const-string v11, "CHU"
(...)
const-string v11, "CHM"
(...)
const-string v11, "CTC"
(...)
const-string v11, "CHC"
So, here is what I think. If CSC is defined as CHN (the default for this firmware), the MIN_MATCH_CHINA (0xb (11)) will be used, and that is really what is happening.
So we need test those others sales codes to check which one trigger which MIN_MATCH* variable. My guest is if you select any CSC not listed in the above list, the default case of 0x7 will be used. To change the CSC (I mean change the 'ro.csc.sales_code' property), we can use the method described by: http://www.geekzone.co.nz/forums.asp?forumid=97&topicid=109787.
UPDATE:
I misunderstood the smali code, the corresponding java code from the smali code follows:
String s2 = SystemProperties.get("ro.csc.sales_code");
if (!"CHN".equals(s2) && !"CHU".equals(s2) && !"CHM".equals(s2) && !"CTC".equals(s2) && !"CHC".equals(s2))
{
if (!"FET".equals(s2) && !"TWM".equals(s2) && !"CWT".equals(s2) && !"BRI".equals(s2))
{
if ("TGY".equals(s2))
{
So, if your sales code is not listed in any of the if's, you will use the the getMinMatch method, the corresponding java code follows.
public static int getMinMatch()
{
if (CscFeature.getInstance().getInteger("CscFeature_RIL_CallerIdMatchingDigit") == -1)
return 7;
else
return CscFeature.getInstance().getInteger("CscFeature_RIL_CallerIdMatchingDigit");
}
This CscFeature_RIL_CallerIdMatchingDigit is know and is located in the /system/csc/others.xml. What we need is a way to change the sales_code. I suppose that, if we change the /system/csc/sales_code.dat with any other unlisted code, like XEU, we would be fine.
UPDATE 2:
Changing the sales_code.dat did the trick, but now I have problems in dialer, I can't dial anyone, there is no button to press, they dissapeared.
Here what I did.
Edited the sales_code.dat, now it is XEU.
Reboot
Opened Config->Manage Apps->Contacts Stores->Cleaned everything (this will wipe all your contacts, back it up)
Reboot
Resynced my contacts with google, All my sms senders are now recognized!!! But I can't dial anyone...
UPDATE 3:
Modified the the smali code, recompiled, odexed using these instructions: http://forum.xda-developers.com/showthread.php?t=1208320
Result, no luck, will try again later.
UPDATE 4:
Did it!!! Works for me!
* Updated framework.odex [ Attached to this post ]
* Opened Config->Manage Apps->Contacts Store->Cleaned everything (this will wipe all your contacts, back it up)
* Reboot
Senders are now recognized !!
UPDATE 5:
To use this patched framework.odex you need to:
* Change the /system/framework/framework.odex with the one provided in the zip file
* Change the <CscFeature_RIL_CallerIdMatchingDigit> parameter inside the /system/csc/others.xml, remove the default value (11) and insert the desired one(ex. 8).
* Clean Contacts Store by opening Config->Manage Apps->Contacts Store and press the buttons destinated to clean everything.
* Reboot
* Resync contacts or restore Contacts from TitaniumBackup.
PS: There is no need to change sales_code.dat file, keep it intact.
SMS senders should now be recognized.
luizfeliperj said:
What you get back from smali is a regular jar, not an odexed one. When you run backsmali with '-x' argument, you tell backsmali to deodex the source file. So, Maybe, that was the problem.
UPDATE 4:
Did it!!! Works for me!
* Updated framework.odex [ Attached to this post ]
* Opened Config->Manage Apps->Contacts Stores->Cleaned everything (this will wipe all your contacts, back it up)
* Reboot
Senders are now recognized !!
Click to expand...
Click to collapse
anyone tried this? does it work?
luizfeliperj said:
What you get back from smali is a regular jar, not an odexed one. When you run backsmali with '-x' argument, you tell backsmali to deodex the source file. So, Maybe, that was the problem.
But there are other points in the code we should pay attention. For your need, I don't think that you need to change anything in the original framework. You need that the MIN_MATCH variable set to 0x7. As far as I could understand from the smali code, if you change the sales code, you can accomplish that. And, as far as I know, sales code is a configuration directive, from one or more of the many xmls available in the /system directory.
I will substantiate what I said this some code snippets.
The MIN_MATCH* variables are defined as:
.field static final MIN_MATCH:I = 0x7
.field static final MIN_MATCH_CHINA:I = 0xb
.field static final MIN_MATCH_HK:I = 0x8
.field static final MIN_MATCH_TW:I = 0x9
In CompareLoosely method, there is a check for the sales_code "CHN" "CHU" "CHM" "CTC" "CHC"
.method public static compareLoosely(Ljava/lang/String;Ljava/lang/StringZ
(...)
const-string v11, "ro.csc.sales_code"
(...)
.local v9, "salesCode":Ljava/lang/String;
const-string v11, "CHN"
(...)
const-string v11, "CHU"
(...)
const-string v11, "CHM"
(...)
const-string v11, "CTC"
(...)
const-string v11, "CHC"
So, here is what I think. If CSC is defined as CHN (the default for this firmware), the MIN_MATCH_CHINA (0xb (11)) will be used, and that is really what is happening.
So we need test those others sales codes to check which one trigger which MIN_MATCH* variable. My guest is if you select any CSC not listed in the above list, the default case of 0x7 will be used.
UPDATE:
I misunderstood the smali code, the corresponding java code from the smali code follows:
String s2 = SystemProperties.get("ro.csc.sales_code");
if (!"CHN".equals(s2) && !"CHU".equals(s2) && !"CHM".equals(s2) && !"CTC".equals(s2) && !"CHC".equals(s2))
{
if (!"FET".equals(s2) && !"TWM".equals(s2) && !"CWT".equals(s2) && !"BRI".equals(s2))
{
if ("TGY".equals(s2))
{
So, if your sales code is not listed in any of the if's, you will use the the getMinMatch method, the corresponding java code follows.
public static int getMinMatch()
{
if (CscFeature.getInstance().getInteger("CscFeature_RIL_CallerIdMatchingDigit") == -1)
return 7;
else
return CscFeature.getInstance().getInteger("CscFeature_RIL_CallerIdMatchingDigit");
}
This CscFeature_RIL_CallerIdMatchingDigit is know and is located in the /system/csc/others.xml. What we need is a way to change the sales_code. I suppose that, if we change the /system/csc/sales_code.dat with any other unlisted code, like XEU, we would be fine.
UPDATE 2:
Changing the sales_code.dat did the trick, but now I have problems in dialer, I can't dial anyone, there is no button to press, they dissapeared.
Here what I did.
Edited the sales_code.dat, now it is XEU.
Reboot
Opened Config->Manage Apps->Contacts Stores->Cleaned everything (this will wipe all your contacts, back it up)
Reboot
Resynced my contacts with google, All my sms senders are now recognized!!! But I can't dial anyone...
UPDATE 3:
Modified the the smali code, recompiled, odexed using this instructions: http://forum.xda-developers.com/showthread.php?t=1208320
Result, no luck, will try again later.
UPDATE 4:
Did it!!! Works for me!
* Updated framework.odex [ Attached to this post ]
* Opened Config->Manage Apps->Contacts Stores->Cleaned everything (this will wipe all your contacts, back it up)
* Reboot
Senders are now recognized !!
Click to expand...
Click to collapse
Thanks a lot for your work!!
I followed your steps, now it's working, i can now see who calls me. And also SMS still shows the right contact.
BTW, i didn't change sales_code.dat and even then it works. My region code should be SEA, but apparently it doesn't matter.
Now i can remove the Prefixer & Touchpal apps, that i used as a workaround.
Thanks again!
You are right, there is only framework.jar and framework2.jar, so i guess it wont work. but i have a hard time downloading the rooted chinese rom so i can try it, after downloading around 400+mb it stops as if finished and the speed starts very fast then slows down, would really appreaciate it if somebody could help...thank you...[/QUOTE]
If you use linux, you can use wget -c to continue the download from where it stopped. I had the very dame problem when the downloaded file hit 98%. I use wget to complete it
luizfeliperj said:
jimmyl19 said:
If you use linux, you can use wget -c to continue the download from where it stopped. I had the very dame problem when the downloaded file hit 98%. I use wget to complete it
Click to expand...
Click to collapse
i use a pc win7, any remedy? thanks...
PS. found a solution, i think, downloading now using a download manager, speed is to the max... thanks
Click to expand...
Click to collapse
Installing the chinese ROM
jimmyl19 said:
Hi, how did you install the chinese rom? do i have to flash samsung official firmware first? .. thanks...
Click to expand...
Click to collapse
I had CWM recovery, it was not an option to loose it. So here is what I did.
* Did a factory reset and a /system wipe using CWM.
* Got the chinese ROM tar file, extracted it, removed the recovery.img (rm recovery.img), repacked the tar file ( tar -cf fw.rar boot.img system.img csc.img sboot.bin... all the remaining files)
* Flashed the modified tar (fw.tar) using ODIN
With it, I had the chinese ROM installed and did not lose the CWM recovery.
Using Linux or OSX it is pretty straightforward, for windows, you need to download tar for windows, google for tar win32. It should point you to gnu tar project website. There they have a port of tar to the win32 OS.
luizfeliperj said:
I had CWM recovery, it was not an option to loose it. So here is what I did.
* Did a factory reset and a /system wipe using CWM.
* Got the chinese ROM tar file, extracted it, removed the recovery.img (rm recovery.img), repacked the tar file ( tar -cf fw.rar boot.img system.img csc.img sboot.bin... all the remaining files)
* Flashed the modified tar (fw.tar) using ODIN
With it, I had the chinese ROM installed and did not lose the CWM recovery.
Using Linux or OSX it is pretty straightforward, for windows, you need to download tar for windows, google for tar win32. It should point you to gnu tar project website. There they have a port of tar to the win32 OS.
Click to expand...
Click to collapse
Hi, your method is a little complicated. Can i just flash the chinese rom tar file using odin then flash CWM (w/c one do you use philz or cofface v3.0?) again using odin? thanks...
jimmyl19 said:
Hi, your method is a little complicated. Can i just flash the chinese rom tar file using odin then flash CWM (w/c one do you use philz or cofface v3.0?) again using odin? thanks...
Click to expand...
Click to collapse
For sure! You method is simpler. It's because I try to keep my flashing count at minimum, and reflashing the recovery is always scary. For recovery, I use philz, because of its exfat support.
luizfeliperj said:
For sure! You method is simpler. It's because I try to keep my flashing count at minimum, and reflashing the recovery is always scary. For recovery, I use philz, because of its exfat support.
Click to expand...
Click to collapse
Hi, finished flashing chinese rom, cleared cache, partition, reset. then install CWM cofface, then put the framework.odex in system/framework,and replace file, phone restart then change permission to rw,r,r. then sync google contact, call my phone from a 7 digit number, still does not match with caller id, so change 11 digit matching to 7 in csc/others.xml, clear data in contact storage, resync google contact, still not showing name of contact. Did i miss or done something wrong? thanks...
Hi, sorry... its working already. Thank you for the help, much appreciate it!!:good:
jimmyl19 said:
luizfeliperj said:
i use a pc win7, any remedy? thanks...
PS. found a solution, i think, downloading now using a download manager, speed is to the max... thanks
Click to expand...
Click to collapse
Uploaded the ROM here, if still needed:
http://www.fileconvoy.com/dfl.php?id=g3ac935230235665599932394609c1e80292419119
Click to expand...
Click to collapse
jompie said:
jimmyl19 said:
Uploaded the ROM here, if still needed:
http://www.fileconvoy.com/dfl.php?id=g3ac935230235665599932394609c1e80292419119
Click to expand...
Click to collapse
Hi Jompie, thank you very much for the upload. i also fixed mine already, caller id matching now working, thank you also for this fix, you started it.:good:
Click to expand...
Click to collapse
jompie said:
jimmyl19 said:
Uploaded the ROM here, if still needed:
http://www.fileconvoy.com/dfl.php?id=g3ac935230235665599932394609c1e80292419119
Click to expand...
Click to collapse
SO this Rom is caller ID fixed? or is it able to be fixed?
i downloaded the latest "rooted" chinese rom: I9502ZNUAME4_Rooted_JUFENG_4
is this the same? is there a simple way to fix the Caller ID problem?
Click to expand...
Click to collapse
jompie said:
Thanks a lot for your work!!
I followed your steps, now it's working, i can now see who calls me. And also SMS still shows the right contact.
BTW, i didn't change sales_code.dat and even then it works. My region code should be SEA, but apparently it doesn't matter.
Now i can remove the Prefixer & Touchpal apps, that i used as a workaround.
Thanks again!
Click to expand...
Click to collapse
"Opened Config->Manage Apps->Contacts Stores->Cleaned everything (this will wipe all your contacts, back it up)"
where do i find this? sorry for the dumb question but i cant really find "config" thanks!
Update:
found it. thanks anyway!
ronnylaborada said:
"Opened Config->Manage Apps->Contacts Stores->Cleaned everything (this will wipe all your contacts, back it up)"
where do i find this? sorry for the dumb question but i cant really find "config" thanks!
Update:
found it. thanks anyway!
Click to expand...
Click to collapse
late reply (better than never)
just go to settings> more> application manager> ALL
PS: it looks like you already got it. but hey it might help someone else...
omid_freesky said:
late reply (better than never)
just go to settings> more> application manager> ALL
PS: it looks like you already got it. but hey it might help someone else...
Click to expand...
Click to collapse
Hi, updated the ROM to MG2 at pan.baidu.com/share/link?shareid=3761575987&uk=3509615084
however seems like this caller id modification doesn't work anymore...
@jompie @luizfeliperj Thank you very much! Worked like a charm!
*Update: Celebrated too early. Phone is now stuck on Samsung logo. I'm on stock I9502ZNUCMF2 firmware. Is this the reason why it didn't work?
bryan_mmx said:
@jompie @luizfeliperj Thank you very much! Worked like a charm!
*Update: Celebrated too early. Phone is now stuck on Samsung logo. I'm on stock I9502ZNUCMF2 firmware. Is this the reason why it didn't work?
Click to expand...
Click to collapse
Was made for this rom: I9502ZNUAME4_Rooted_JUFENG.rar
Download from:
http://pan.baidu.com/share/link?shareid=2302611&uk=3760742413#dir/path=/rom/飓风行动/三星/I9502联通版

How does packed-switch work in apktool generated smali

Apologies if this belongs in other languages, I put it in Java as it's related to Java.
I just asked this over at stackoverflow.com but I'll try here too.
I'm trying to reverse engineer an apk with
Code:
apktool d
and the smali it produces contains packed-switch statements which I don't fully understand. A method contains:
Code:
packed-switch v0, :pswitch_data_0
Followed later in the code with labels like
Code:
:pswitch_X
where X is a number and at the end of the method with:
Code:
:pswitch_data_0
.packed-switch 0x7f060395
:pswitch_4
:pswitch_5
:pswitch_1
.end packed-switch
What exactly does this do? It looks like a list of places to jump to, but on what condition? What does it do with 0x7f060395?
Sent from my GT-N7100 using Tapatalk 4
RobPitt said:
Apologies if this belongs in other languages, I put it in Java as it's related to Java.
I just asked this over at stackoverflow.com but I'll try here too.
I'm trying to reverse engineer an apk with
Code:
apktool d
and the smali it produces contains packed-switch statements which I don't fully understand. A method contains:
Code:
packed-switch v0, :pswitch_data_0
Followed later in the code with labels like
Code:
:pswitch_X
where X is a number and at the end of the method with:
Code:
:pswitch_data_0
.packed-switch 0x7f060395
:pswitch_4
:pswitch_5
:pswitch_1
.end packed-switch
What exactly does this do? It looks like a list of places to jump to, but on what condition? What does it do with 0x7f060395?
Sent from my GT-N7100 using Tapatalk 4
Click to expand...
Click to collapse
I only know that the code 0x7....is an id
Sent from my GT-S5570 using xda app-developers app
I got an easy to understand reply on stackoverflow.com, from JesusFreke, I've copied it here without permission so people can see the answer within this forum:
Switches are in two parts, as you noticed. The second part you listed is the payload pseudo-instruction, that contains all the switch cases. The first part is a packed-switch instruction, which defines the register containing the value to check, and refers to a payload instruction using a label.
For a packed-switch, the case values in the payload pseudo-instruction are sequential, and only the first value is actually given (in this case, 0x7f060395)
For your example specifically, when the packed-switch instruction is executed, it will check the value of the v0 register against the 3 cases in the payload. If the value is 0x7f060395, it will jump to switch_4, if 0x7f060396, it will jump to switch_5, etc.
If the value of the register didn't match any of the cases, then execution will continue with the next instruction after the packed-switch instruction (the one with the register and label, not the payload pseudo-instruction).
The sparse-switch instruction is similar, except that its payload instruction has an explicit value associated with each case, of using sequential key values.
You can find all the nitty-gritty details in the dalvik-bytecode document.
RobPitt said:
I got an easy to understand reply on stackoverflow.com, from JesusFreke, I've copied it here without permission so people can see the answer within this forum:
Click to expand...
Click to collapse
I hereby grant you a non-revokable, unequivocal license in perpetuity to repost my SO answer here.

[How to] launch any deployed app within your own app

Hello again,
while I´m still working on my PDF to Office app I found out how to use <Capability Name="ID_CAP_OEM_DEPLOYMENT" />.
Using this capability lets you launch any deployed app within another app or lets you get the applist of all deployed apps (sadly less system apps like Office) including appname, uri, appicon and so on.
1. add
Code:
<Capability Name="ID_CAP_OEM_DEPLOYMENT" />
to your WMAppManifestXML
Add to your *xaml.cs file:
2.
Code:
using Windows.ApplicationModel;
using Windows.Phone.Management.Deployment;
3.
Code:
public Package GetPackageByID(string id)
{
return InstallationManager.FindPackages().FirstOrDefault(p => p.Id.ProductId.ToLower().Equals(id.ToLower()));
}
=> the code will return the package (app) you want to launch if it exists
4.
Code:
private void LaunchAR_Click(object sender, System.Windows.Input.GestureEventArgs e)
{
Package packageById = GetPackageByID("{134E363E-8811-44BE-B1E3-D8A0C60D4692}");
if (packageById != null)
{
packageById.Launch(string.Empty);
}
else
{
// do something if the app doesn´t exist
}
}
=> this sample code will launch Adobe Reader if the app is present on your device
With some simple modifications of the above code you will easyly be able to make visible the whole applist in a ScrollistViewer or Listbox.
=> this could be useful for coding a new AppData backup app for interop-unlocked devices.
Cheers
contable
contable said:
Hello again,
while I´m still working on my PDF to Office app I found out how to use <Capability Name="ID_CAP_OEM_DEPLOYMENT" />.
Using this capability lets you launch any deployed app within another app or lets you get the applist of all deployed apps (sadly less system apps like Office) including appname, uri, appicon and so on.
1. add
Code:
<Capability Name="ID_CAP_OEM_DEPLOYMENT" />
to your WMAppManifestXML
Add to your *xaml.cs file:
2.
Code:
using Windows.ApplicationModel;
using Windows.Phone.Management.Deployment;
3.
Code:
public Package GetPackageByID(string id)
{
using (List<Package>.Enumerator enumerator = new List<Package>(InstallationManager.FindPackages()).GetEnumerator())
{
while (enumerator.MoveNext())
{
Package current = enumerator.Current;
try
{
if (current.Id.ProductId.Contains(id))
return current;
}
catch (Exception ex)
{
}
}
}
return (Package)null;
}
=> the code will return the package (app) you want to launch if it exists
4.
Code:
private void LaunchAR_Click(object sender, System.Windows.Input.GestureEventArgs e)
{
Package packageById = GetPackageByID("{134E363E-8811-44BE-B1E3-D8A0C60D4692}");
if (packageById != null)
{
packageById.Launch(string.Empty);
}
else
{
// do something if the app doesn´t exist
}
}
=> this sample code will launch Adobe Reader if the app is present on your device
With some simple modifications of the above code you will easyly be able to make visible the whole applist in a ScrollistViewer or Listbox.
=> this could be useful for coding a new AppData backup app for interop-unlocked devices.
Cheers
contable
Click to expand...
Click to collapse
Yep! This is used in Samsung AppFolder
-W_O_L_F- said:
Yep! This is used in Samsung AppFolder
Click to expand...
Click to collapse
Exactly.
Do you you know how "InstallationManager.AddPackageAsync" works ?
contable said:
Exactly.
Do you you know how "InstallationManager.AddPackageAsync" works ?
Click to expand...
Click to collapse
I am hoping to learn that myself. I know that Nokia's "Extras & Info" app uses this API for their "SilentInstaller". Nokia's "SilentInstaller" has the ability to install interop-unlocked apps as long as they are fully and properly signed with the appropriate license.xml and wmprheader.xml.
Microsoft has some documentation about this API at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207248(v=vs.105).aspx
**EDIT**
Found it! (I think)
we can deploy apps with InstallationManager.AddPackageAsync(String title, Uri sourceLocation, String instanceId, String offerId, Uri license)
This info matches EVERYTHING that is included with a valid xap signed by Microsoft. All the data is contained in the xap's provxml, too (albeit in the wrong order)
Info about this "undocumented" api is at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662948(v=vs.105).aspx
The million-dollar questions are what privileges are required to access this API, and can we use it without interop unlock?
Really wishing I had my phone back! (won't be here until tomorrow)
Very nice, thanks for publishing! I was going to pull apart App Folder and see how it works myself; thanks for taking the time to do that for me and share it with us all!
For what it's worth, a foreach loop will read more cleanly than explicitly calling GetEnumerator() and then iterating over it, but the basic structure of the code is fine (and I think the MSIL is the same anyhow - foreach being just syntactic sugar - so they probably did it that way when actually writing the app and your decompiler just produced the more verbose version from the MSIL).
Note that this can also, of course, be used to create launcher apps. An alternative to the Start screen, potentially, even (with some other hackery to hook it in where needed). To use it in Backup apps, though, we'll need access to the app's storage folder too (or a way to activate the SeBackup privilege in the app's token...)
Well... already known when I decompiled samsung's app folder app.
---------- Post added at 12:37 PM ---------- Previous post was at 12:29 PM ----------
compu829 said:
I am hoping to learn that myself. I know that Nokia's "Extras & Info" app uses this API for their "SilentInstaller". Nokia's "SilentInstaller" has the ability to install interop-unlocked apps as long as they are fully and properly signed with the appropriate license.xml and wmprheader.xml.
Microsoft has some documentation about this API at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207248(v=vs.105).aspx
**EDIT**
Found it! (I think)
we can deploy apps with InstallationManager.AddPackageAsync(String title, Uri sourceLocation, String instanceId, String offerId, Uri license)
This info matches EVERYTHING that is included with a valid xap signed by Microsoft. All the data is contained in the xap's provxml, too (albeit in the wrong order)
Info about this "undocumented" api is at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662948(v=vs.105).aspx
The million-dollar questions are what privileges are required to access this API, and can we use it without interop unlock?
Really wishing I had my phone back! (won't be here until tomorrow)
Click to expand...
Click to collapse
see nokia extra+info app's capability
You can use Shell Chrome API directly to launch any URI, just 2 lines code
reker said:
You can use Shell Chrome API directly to launch any URI, just 2 lines code
Click to expand...
Click to collapse
So please post the two lines of code so that I can launch any URI without using a Toast.
DELETED
GoodDayToDie said:
Very nice, thanks for publishing! I was going to pull apart App Folder and see how it works myself; thanks for taking the time to do that for me and share it with us all!
For what it's worth, a foreach loop will read more cleanly than explicitly calling GetEnumerator() and then iterating over it, but the basic structure of the code is fine (and I think the MSIL is the same anyhow - foreach being just syntactic sugar - so they probably did it that way when actually writing the app and your decompiler just produced the more verbose version from the MSIL).
Note that this can also, of course, be used to create launcher apps. An alternative to the Start screen, potentially, even (with some other hackery to hook it in where needed). To use it in Backup apps, though, we'll need access to the app's storage folder too (or a way to activate the SeBackup privilege in the app's token...)
Click to expand...
Click to collapse
Here an improved code:
Code:
public Package GetPackageByID(string id)
{
List<Package> packages = new List<Package>(InstallationManager.FindPackages());
foreach (var cpackage in packages)
{
if (cpackage.Id.ProductId.Contains(id))
return cpackage;
}
return (Package)null;
}
Indeed to create an AppData Backup app we need access to the app´s storage folder first. Atm we only can copy files from the app´s storage folder with another RPCComponent discovered by -W_O_L_F-. But when the time comes a Backup app can be created in a few hours...
Oneliner (untested)
Code:
public Package LinqGetPackageByID(string id)
{
return InstallationManager.FindPackages().FirstOrDefault(p => p.Id.ProductId.ToLower().Equals(id.ToLower()));
}
jessenic said:
Oneliner (untested)
Code:
public Package LinqGetPackageByID(string id)
{
return InstallationManager.FindPackages().FirstOrDefault(p => p.Id.ProductId.ToLower().Equals(id.ToLower()));
}
Click to expand...
Click to collapse
Thanks. The oneliner works fine. :good:
Edit:
post #1 updated with the oneliner....
jessenic said:
Oneliner (untested)
Code:
public Package LinqGetPackageByID(string id)
{
return InstallationManager.FindPackages().FirstOrDefault(p => p.Id.ProductId.ToLower().Equals(id.ToLower()));
}
Click to expand...
Click to collapse
Is it also possible to check if an app is installed and if yes, which version? that would be nice...
gipfelgoas said:
Is it also possible to check if an app is installed and if yes, which version? that would be nice...
Click to expand...
Click to collapse
Yes. With this method you can get all informations about an installed package: version, publisher and so on...

Shared Preferences with Xposed

I try to get shared preferences in the exposed class.
This is a straight forward issue in android java. I do not know whether the permissions are the problem but things are not as straight with Xposed.
Xposed asks to provide the name of the file and the package at init Zigote. I have tried many versions and none of them seems to work. Also, the file which I make may not be available when init Zygote is called, however, I take XposedBridge wants to just register the name of the file and, probably, to prepare to override some permissions when the file is created.
I also try to double the call to the Xposed Shared Method inside the hooked method. I check for the existence of the shared preference file before. Everything is there but the reload method does not seem to reload and the file is not read but defaults are loaded by getInt and getFloat.
There is probably something more to be done, although the examples I have seen do not do anything, yet they override other methods inside init Zygote which I do not need to do.
All I need is to read a simple file from an Xposed Module.
PLEASE, INFORM.
Here is what I have tried :
I have tried many different variation and XposedBridge methods for 4 hours. I have also
tried many name variations with and without .xml.
In the standard Java for Android, there is just one get method to read a shared
preferences file. This does not seem to be the case with exposed.
I do have :
@override
public void initZygote(StartupParam startupParam) throws Throwable {
MODULE_PATH = startupParam.modulePath;
prefs = new XSharedPreferences("PackageName", "SharedPreferenceFileNameWithotDotXml");
}
MODULE_PATH is not used, although I have tried many other methods where was.
Because the file changes on the fly, I called :
prefs.reload();
before I read the data. I tried without this call too. I also tried to get another
prefs before the reload :
prefs = new XSharedPreferences("PackageName", "SharedPreferenceFileNameWithotDotXml");
prefs.reload();
Then I try to read the data from the file :
theStart=prefs.getInt("Start", 2);
theValue=prefs.getFloat("Value", 102.0f);
I always get the defaults 2 and 102.0 although the file is there and the values of the
file are different. I have read the file.
In standard java for android philosophy, just the initialisation in init zygote and
prefs.reload() are sufficient to load the changing values of the shared preferences
file into prefs and then into the variables.
Xposed seems to be different.
I have been told there is a way to read the data from the file. I have tried most
anything and cannot. What is the way to do so. Must be simple and straight as in the
standard java for android. I must not do everything necessary.
Please, inform.
I have also tried to read the file manually from the Xposed class. Access denied. Tried
just in cases. Access denied, again.
Tried to make the shared preferences file with Activity.MODE_WORLD_READABLE. Still
access denied to be read manually.
Even with Activity.MODE_WORLD_READABLE, Xposed cannot read the file as previously
explained.
Tried :
@override
public void initZygote(StartupParam startupParam) throws Throwable {
prefs = new XSharedPreferences(TheNameOfTheXposedClass.class.getPackage().getName
());
prefs.makeWorldReadable();
}
Then, in the hooked method :
prefs.reload();
theStart = prefs.getInt("Start", 2);
theValue = prefs.getFloat("Value", 102.0f);
Still returns only the default, although the file is there. I think, in all attempts,
XSharedPreferences() cannot get the name of the package and or or the name of the file.
The file is in /data/data/NameOfPackage/shared_prefs/NameOfFile.xml
Tried :
@override
public void initZygote(StartupParam startupParam) throws Throwable {
prefs = new XSharedPreferences
("/data/data/NameOfPackage/shared_prefs/NameOfFile.xml");
prefs.makeWorldReadable();
}
with and without .xml
Still nothing.
PROBLEM SOLVED.
Thank you for your reply. Everything was WORLD READABLE : in the non Xposed class and in the Xposed class on a number of occasions.
Also, I have used the hard values for the package and path.
The problem was not related to Java and Android but to Android arrangements and how much Xposed can cope with. The Android permissions for to access the file from the Xposed class had to be elevated which is unusual but this is what solved the problem, I think. Someone also reported the same problem and the same solution : http://forum.xda-developers.com/xposed/development-xsharedpreferences-issue-t2931396
In the non Xposed class, I have used the same solution just with a hard coded path and file. After I make the shared preferences file in the non Xposed class, I gave more permissions by :
File theSharedPrefsFile;
theSharedPrefsFile = new File("/data/data/PackageName/shared_prefs/FileName.xml");
theSharedPrefsFile.setReadable(true, false);
This seems to have solved the problem.
I am not sure of how reliable the solution is, though. I still check in the Xposed class whethere there is such a file or not. I have not tested what happens when the file is not there initially. Must do.
theXposedCommunicationPreferenceFile = new File("/data/data/PackageName/shared_prefs/FileName.xml");
if (theXposedCommunicationPreferenceFile.exists() == false) XposedBridge.log("Check in hooked method cannot find the file");
Hope everything would be OK.
Even though everything should be OK, I am not sure how reliable the dependence of permissions is.
I have also tried the secure reload :
StrictMode.ThreadPolicy oldPolicy;
oldPolicy = StrictMode.allowThreadDiskReads();
try {
prefs.reload();
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
I am not sure how reliable this is either so I put another simple reload on top :
prefs.reload();
StrictMode.ThreadPolicy oldPolicy;
oldPolicy = StrictMode.allowThreadDiskReads();
try {
prefs.reload();
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
I think, neither of these has made any difference and the real solution was the higher permissions to access the shared preference file given in the non Xposed class, again :
File theSharedPrefsFile;
theSharedPrefsFile = new File("/data/data/PackageName/shared_prefs/FileName.xml");
theSharedPrefsFile.setReadable(true, false);
Pretty nasty problem and difficult to find solution although published in the XDA Forum the searchability of post in the said forum is not very good.
Yet another sleepless night.
StevenStanleyBayes said:
I think, neither of these has made any difference and the real solution was the higher permissions to access the shared preference file given in the non Xposed class, again :
Click to expand...
Click to collapse
I know this is a pretty old thread but I have elevated the permission level to 777 of both the dir and preferences file and yet cannot access the file from the xposedClass is there any chance you are still developing xposed modules and can help

Categories

Resources