pilgun / acvtool

ACVTool (Android Code Coverage Tool) is a tool to measure fine-grained code coverage of 3rd-party Android apps.
Apache License 2.0
102 stars 30 forks source link

Error when Instrumenting an apk #33

Closed francescolupo closed 6 months ago

francescolupo commented 1 year ago

Hello, I am a Macbook pro owner with an Apple Silicon processor. I have tried to test ACV with various apks When I run the acv instrument <path> command, I get different but similar errors each time. For example:

acv instrument shazam-13-27-0-230420.apk

The working directory exists and may contain data: /Users/francesco/acvtool/acvtool_working_dir
Overwrite (y/n)? y
decompiled com.shazam.android
parsing /Users/francesco/acvtool/acvtool_working_dir/apktool/com.shazam.android/smali...
saving instrumented smali:  /Users/francesco/acvtool/acvtool_working_dir/apktool/com.shazam.android/smali...
pickle file saved: /Users/francesco/acvtool/acvtool_working_dir/metadata/shazam-13-27-0-230420.pickle
instrumented
Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred while writing code_item for method Ltool/acv/AcvReporter;->saveExternalPublicFile(Ljava/io/File;)V
    at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:917)
    at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:341)
    at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:297)
    at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:61)
    at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:36)
    at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:418)
    at brut.androlib.Androlib.buildSources(Androlib.java:349)
    at brut.androlib.Androlib.build(Androlib.java:301)
    at brut.androlib.Androlib.build(Androlib.java:268)
    at brut.apktool.Main.cmdBuild(Main.java:251)
    at brut.apktool.Main.main(Main.java:79)
Caused by: org.jf.util.ExceptionWithContext: Unsigned short value out of range: 69311
    at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116)
    at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1212)
    at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:913)
    ... 10 more

built
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py27/bin/acv", line 11, in <module>
    load_entry_point('acvtool', 'console_scripts', 'acv')()
  File "/Users/francesco/Desktop/acvtool/acvtool.py", line 217, in main
    run_actions(parser, args)
  File "/Users/francesco/Desktop/acvtool/acvtool.py", line 52, in run_actions
    mem_stats=args.memstats)
  File "/Users/francesco/Desktop/acvtool/smiler/instrumenting/utils.py", line 107, in wrapper
    result = method(*args, **kwargs)
  File "/Users/francesco/Desktop/acvtool/smiler/smiler.py", line 186, in instrument_apk
    sign_align_apk(instrumented_package_path, instrumented_apk_path)
  File "/Users/francesco/Desktop/acvtool/smiler/smiler.py", line 277, in sign_align_apk
    request_pipe(align_cmd)
  File "/Users/francesco/Desktop/acvtool/smiler/smiler.py", line 47, in request_pipe
    Out: %s\nError: %s" % (out, err))
Exception: ----------------------------------------------------
Out:
Error: Unable to open '/Users/francesco/acvtool/acvtool_working_dir/shazam-13-27-0-230420.apk' as zip archive

I would appreciate it if you could help me.

Thank you so much.

pilgun commented 1 year ago

Hey Francesco,

The exception basically says that that dex file is too packed (more than ~65k methods don't fit in). So this acvtool version can't deal with Shazam. I have planned to publish the new version long ago but it is still not published 😇

On Sat, 15 Jul 2023, 17:33 fvlk, @.***> wrote:

Hello, I am a Macbook pro owner with an Apple Silicon processor. I have tried to test ACV with various apks When I run the acv instrument command, I get different but similar errors each time. For example: `acv instrument shazam-13-27-0-230420.apk

The working directory exists and may contain data: /Users/francesco/acvtool/acvtool_working_dir Overwrite (y/n)? y decompiled com.shazam.android parsing /Users/francesco/acvtool/acvtool_working_dir/apktool/com.shazam.android/smali... saving instrumented smali: /Users/francesco/acvtool/acvtool_working_dir/apktool/com.shazam.android/smali... pickle file saved: /Users/francesco/acvtool/acvtool_working_dir/metadata/shazam-13-27-0-230420.pickle instrumented Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred while writing code_item for method Ltool/acv/AcvReporter;->saveExternalPublicFile(Ljava/io/File;)V at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:917) at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:341) at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:297) at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:61) at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:36) at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:418) at brut.androlib.Androlib.buildSources(Androlib.java:349) at brut.androlib.Androlib.build(Androlib.java:301) at brut.androlib.Androlib.build(Androlib.java:268) at brut.apktool.Main.cmdBuild(Main.java:251) at brut.apktool.Main.main(Main.java:79) Caused by: org.jf.util.ExceptionWithContext: Unsigned short value out of range: 69311 at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116) at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1212) at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:913) ... 10 more

built Traceback (most recent call last): File "/opt/homebrew/Caskroom/miniforge/base/envs/py27/bin/acv", line 11, in load_entry_point('acvtool', 'console_scripts', 'acv')() File "/Users/francesco/Desktop/acvtool/acvtool.py", line 217, in main run_actions(parser, args) File "/Users/francesco/Desktop/acvtool/acvtool.py", line 52, in run_actions mem_stats=args.memstats) File "/Users/francesco/Desktop/acvtool/smiler/instrumenting/utils.py", line 107, in wrapper result = method(*args, **kwargs) File "/Users/francesco/Desktop/acvtool/smiler/smiler.py", line 186, in instrument_apk sign_align_apk(instrumented_package_path, instrumented_apk_path) File "/Users/francesco/Desktop/acvtool/smiler/smiler.py", line 277, in sign_align_apk request_pipe(align_cmd) File "/Users/francesco/Desktop/acvtool/smiler/smiler.py", line 47, in request_pipe Out: %s\nError: %s" % (out, err)) Exception: ---------------------------------------------------- Out: Error: Unable to open '/Users/francesco/acvtool/acvtool_working_dir/shazam-13-27-0-230420.apk' as zip archive`

I would appreciate it if you could help me.

Thank you so much.

— Reply to this email directly, view it on GitHub https://github.com/pilgun/acvtool/issues/33, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOACXAXFZYWRUHVKXFZSPTXQKZ3NANCNFSM6AAAAAA2LLK4HE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

francescolupo commented 1 year ago

Thank you for the answer. Could you list me some apks with which I can test acvtool?

pilgun commented 1 year ago

Most of single dex apps should work well. Single DEX APKS are usually more less simple apps, you may find many o them on FDroid.

In this demo we used AIMP https://www.youtube.com/watch?v=xyaR4Ivrij0 (could still work)

Also you could try compile an APK yourself, for example this one https://github.com/pilgun/TimeBomb

To get the quick idea of reports please feel free to checkout these ones https://report.debloat.app/