h2so4t / cosmo Goto Github PK
View Code? Open in Web Editor NEWAutomatically instrument gradle-based applications and generate code coverage reports
License: MIT License
Automatically instrument gradle-based applications and generate code coverage reports
License: MIT License
Hi guys,
I tried to run COSMO in black box mode using a very simple BMI Calculator app (https://f-droid.org/packages/com.zola.bmi/). First, I decompiled the APK using apktool, inserted the debuggable attribute in the AndroidManifest.xml and re-packaged it (https://gist.github.com/nstarke/615ca3603fdded8aee47fab6f4917826). After that, I executed python cli.py com.zola.bmi.apk
:
$ python cli.py com.zola.bmi.apk
29/09/2023 22:06:32> [INFO][apk_instrumenter][run_instrumentation()] Instrumenting apk file "com.zola.bmi.apk"
29/09/2023 22:06:32> [INFO][apk_instrumenter][instrument_apk()] Converting to Java bytecode with dex2jar command "C:\Users\Michael\Downloads\dex2jar-2.0\dex2jar-2.0\d2j-dex2jar.bat -f -e nul C:\Users\Michael\App
Data\Local\Temp\tmp9l34xgz2\com.zola.bmi.apk -o C:\Users\Michael\AppData\Local\Temp\tmp9l34xgz2\com.zola.bmi.jar"
29/09/2023 22:06:35> [INFO][apk_instrumenter][instrument_apk()] Instrumenting with Java command "C:\Users\Michael\.jdks\openjdk-15.0.2\bin\java.EXE -jar C:\Users\Michael\git\COSMO\lib\jacococli.jar instrument C:
\Users\Michael\AppData\Local\Temp\tmp9l34xgz2\com.zola.bmi.jar --dest C:\Users\Michael\AppData\Local\Temp\tmp9l34xgz2\jacoco"
29/09/2023 22:06:37> [INFO][apk_instrumenter][instrument_apk()] Converting Java to Dalvik with command "E:\Android\Android\Sdk\build-tools\31.0.0-rc3\dx.BAT -JXmx4g --dex --multi-dex --output=C:\Users\Michael\Ap
pData\Local\Temp\tmp9l34xgz2\dex C:\Users\Michael\AppData\Local\Temp\tmp9l34xgz2\jacoco C:\Users\Michael\git\COSMO\lib\jacocoagent.jar"
29/09/2023 22:06:43> [INFO][apk_instrumenter][instrument_apk()] Running sign command with default debug key "E:\Android\Android\Sdk\build-tools\31.0.0-rc3\apksigner.BAT sign --ks-pass pass:android --ks C:\Users\
Michael\git\COSMO\lib\debug.keystore C:\Users\Michael\AppData\Local\Temp\tmp9l34xgz2\com.zola.bmi.apk"
29/09/2023 22:06:44> [INFO][apk_instrumenter][instrument_apk()] Running align command "E:\Android\Android\Sdk\build-tools\31.0.0-rc3\zipalign.EXE -v -p -f 4 C:\Users\Michael\AppData\Local\Temp\tmp9l34xgz2\com.zo
la.bmi.apk.copy C:\Users\Michael\AppData\Local\Temp\tmp9l34xgz2\com.zola.bmi.apk"
29/09/2023 22:06:44> [INFO][apk_instrumenter][instrument_apk()] Files for apk "com.zola.bmi" saved in "C:\Users\Michael\git\COSMO\output_apks" directory
The instrumenation process looks fine. After that, I had to re-sign the instrumented APK since the installation failed and complained about a stripped signature:
$ adb install -g output_apks/com.zola.bmi.apk
Performing Streamed Install
adb: failed to install output_apks/com.zola.bmi.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed to collect certificates from /data/app/vmdl90500489.tmp/base.apk: META-INF/ANDROIDD.SF indicates /data/app/vmdl90500489.tmp/base.apk is signed using APK Signature Scheme v2, but no such signature was found. Signature stripped?]
I suppose you are using some outdated signing scheme, but I could fix that by using my own keystore and after re-signing the installation succeeded. However, when I try to launch the app on the emulator the app crashes immediately with the following stack trace:
2023-09-29 22:08:38.854 3008-3008/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.zola.bmi, PID: 3008
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.zola.bmi/com.zola.bmi.BMIMain}: java.lang.RuntimeException: Failed to initialize JaCoCo.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.RuntimeException: Failed to initialize JaCoCo.
at org.jacoco.agent.rt.internal_0000000.Offline.getRuntimeData(Offline.java:41)
at org.jacoco.agent.rt.internal_0000000.Offline.getProbes(Offline.java:60)
at com.zola.bmi.BMIMain.$jacocoInit(Unknown Source)
at com.zola.bmi.BMIMain.<init>(Unknown Source)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.io.FileNotFoundException: / (Is a directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at org.jacoco.agent.rt.internal_0000000.output.FileOutput.openFile(FileOutput.java:68)
at org.jacoco.agent.rt.internal_0000000.output.FileOutput.startup(FileOutput.java:50)
at org.jacoco.agent.rt.internal_0000000.Agent.startup(Agent.java:129)
at org.jacoco.agent.rt.internal_0000000.Agent.getInstance(Agent.java:54)
at org.jacoco.agent.rt.internal_0000000.Offline.getRuntimeData(Offline.java:39)
at org.jacoco.agent.rt.internal_0000000.Offline.getProbes(Offline.java:60)
at com.zola.bmi.BMIMain.$jacocoInit(Unknown Source)
at com.zola.bmi.BMIMain.<init>(Unknown Source)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
I am using a Nexus_5_API_25 emulator and the un-instrumented APK works as expected. Is this failure known to you? I will try to update to a more recent dex2jar
version but since the instrumentation logs looked promising, I thought this was not necessary.
Or do I need to grant some additional permissions in the AndroidManifest.xml?
Thanks in advance.
command: python .\cli.py path_to_my.apk
(I tried several apps, official and my own. Both got the error below.)
18/10/2022 22:52:40> [ERROR][apk_instrumenter][instrument_apk()] Error during Java to Dalvik conversion command: Uncaught translation error: com.android.dx.cf.code.SimException: expected type long[] but found double[]
1 error; aborting
Ciao, ho provato il tool e mi sono imbattuto in un problema nella fase finale, ovvero la fase in cui si va a generare il report HTML.
Quando vado a lanciare il comando ./gradlew jacocoInstrumenterReport
, ottengo il seguente errore:
`> Task :app:jacocoInstrumenterReport FAILED
FAILURE: Build failed with an exception.
Could not read path '/Users/francesco/Desktop/coverage'.`
Se puoi servire, lascio anche le informazioni relative al 1) build.gradle (Project :Personal_Health_Monitor)
, al 2) build.gradle (Module :app)
e al file 3) jacoco-instrumenter-coverage.gradle
:
1)
Invece le informazioni relative a gradle
sono le seguenti:
Ti ringrazio anticipatamente per la disponibilità.
Hi, the experimental results link the in the readme are no longer working.
I also noticed that in the code (apk_instrumenter.py) the apk is being signed (with apksigner) before aligning (with zipalign). I saw in apksigner's documentation that you should first align and then sign.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.