souramoo / Needle

Android framework injection made easy
GNU General Public License v3.0
100 stars 28 forks source link

Unable to patch Android 5.1 (Fairphone 2) #32

Open Roboe opened 8 years ago

Roboe commented 8 years ago

Was working (multiple times) before the bunch of recent updates, :confused: Seems to be related with the new version/use of Apktool, from my point of view.

Log:

$ ./patch.py 
 *** Selected device xXXXxXxX
 *** Device detected! proceeding...
 *** Working dir: /tmp/tmpfkuhbdx0
 *** Rooting adbd...
adbd is already running as root
remount succeeded
 *** Pulling framework from device...
5857 KB/s (5426893 bytes in 0.904s)
 *** Disassembling framework...
 *** Done. Now this won't hurt a bit...
 *** Injection successful. Reassembling smali...
output:classes.dex

UNEXPECTED TOP-LEVEL EXCEPTION:
org.jf.util.ExceptionWithContext: Unsigned short value out of range: 65536
    at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116)
    at org.jf.dexlib2.writer.InstructionWriter.write(InstructionWriter.java:315)
    at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1025)
    at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:801)
    at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:250)
    at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:228)
    at org.jf.smali.main.main(main.java:293)

Traceback (most recent call last):
  File "./patch.py", line 140, in <module>
    subprocess.check_call(["java", "-jar", os.path.join(SCRIPT_DIR, "tools", "smali.jar"), "classes", "-o", "classes.dex"])
  File "/usr/lib/python3.5/subprocess.py", line 581, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['java', '-jar', '/home/ubuntu-gnome/Documentos/android/Needle/tools/smali.jar', 'classes', '-o', 'classes.dex']' returned non-zero exit status 2

(Note that I've replaced device id with exes: xXXXxXxX)

Host (Ubuntu Gnome):

$ lsb_release -d
Description:    Ubuntu 16.04.1 LTS

$ python --version`
Python 3.5.2

$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

(Just in case: Fairphone Open OS is based on CodeAurora sources. Sources for the OS are available at http://code.fairphone.com/)

Roboe commented 8 years ago

Works without troubles in the 19913c8 revision.

Log:

$ git checkout 19913c8
HEAD is now at 19913c8... Update README.md

$ ./patch.py 
 *** Selected device xXXXxXxX
 *** Device detected! proceeding...
 *** Working dir: /tmp/tmps_9lfw53
 *** Rooting adbd...
adbd is already running as root
remount succeeded
 *** Pulling framework from device...
3551 KB/s (5426893 bytes in 1.492s)
 *** Disassembling framework...
I: Using Apktool 2.0.2 on framework.jar
I: Baksmaling classes.dex...
I: Baksmaling classes2.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
 *** Done. Now this won't hurt a bit...
 *** Injection successful. Reassembling smali...
I: Using Apktool 2.0.2
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes2 folder into classes2.dex...
W: Could not find resources
I: Building apk file...
 *** Putting things back like nothing ever happened...
updating: classes.dex (deflated 60%)
 *** Pushing changes to device...
5922 KB/s (5459325 bytes in 0.900s)
 *** All done! :)

(Note that I've replaced device id with exes: xXXXxXxX)

ale5000-git commented 8 years ago

I have a workaround for this problem in Tingle, could you please test if it is working?

Roboe commented 8 years ago

I did a backup of my OS and reinstalled clean FP Open OS:

$ python3 main.py 
MENU

    1 - Patch file from a device (adb)
    2 - Patch file from the input folder

> 1

ERROR: Missing executable => 7za

ERROR CODE: 67

What should I install? I installed the p7zip package and error still appear.

ale5000-git commented 8 years ago

On Linux it need p7zip-full (not p7zip).

Lanchon commented 8 years ago

UNEXPECTED TOP-LEVEL EXCEPTION: org.jf.util.ExceptionWithContext: Unsigned short value out of range: 65536 at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116) at org.jf.dexlib2.writer.InstructionWriter.write(InstructionWriter.java:315) at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1025) at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:801) at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:250) at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:228) at org.jf.smali.main.main(main.java:293)

this means that the resulting dex file is too big and it has to be written using multidex.

ale5000-git commented 8 years ago

@Lanchon: My workaround just move some methods from one dex to the last dex and reassemble.

Roboe commented 8 years ago

Sorry, @ale5000-git, I haven't had the time to try Tingle yet. FP2 is my daily phone and I must take care of its data before tinkering with it, so I need some spare time. Maybe tomorrow night or friday's.

ale5000-git commented 8 years ago

Do not worry there isn't any time limit :)

Roboe commented 8 years ago

It seems to be working great! Oli.sax, from the Fairphone Community, tested it on his FP2. Relevant link: https://forum.fairphone.com/t/how-to-be-able-to-install-and-use-any-app-on-fp-open-os-experimental/22327/20?u=roboe

ale5000-git commented 8 years ago

Good, thanks :) I don't know Fairphone too much but I have heard there are more than one type with different versions on Android (one with KitKat and one with an older version).

I would like to know, if possible, when you have time, if it works on both versions. Tingle in theory should work correctly also on old versions of Android but I cannot test it.

Roboe commented 8 years ago

There are two Fairphone devices:

I only own a FP2, running FP Open OS (just like Oli.sax's one), thus I can't try Tingle on the FP1… :(

Roboe commented 8 years ago

Hey, just tried tingle with the new FP Open OS update (16.10.0) and, just like Oli.sax said, it worked like a charm! Thank you, :)

ale5000-git commented 8 years ago

Good, thanks for the test :)