android-tools
android-tools copied to clipboard
ZipAlign
Please build libzipalign.so
Hi @TimScriptov , you can find zipalign here for android-11.
https://github.com/JonForShort/android-tools/tree/master/build/android-11.0.0_r33/zipalign
Hi @JonForShort
https://developer.android.com/about/versions/10/behavior-changes-10
Untrusted apps that target Android 10 cannot invoke exec() on files within the app's home directory. This execution of files from the writable app home directory is a W^X violation. Apps should load only the binary code that's embedded within an app's APK file.
Need used libzipalign.so for Android 10+
C++:
#include <cstdlib>
#include <jni.h>
#include <zipalign/ZipAlign.h>
using namespace android;
extern "C"
JNIEXPORT jboolean
JNICALL Java_com_android_zipalign_ZipAlign_process
(JNIEnv *env, jclass clazz, jstring inZipFile, jstring outZipFile, jint alignment, jboolean force, jboolean zopfli, jboolean pageAlignSharedLibs) {
const char *inFileName = env->GetStringUTFChars(inZipFile, nullptr);
const char *outFileName = env->GetStringUTFChars(outZipFile, nullptr);
if(!inFileName || !outFileName) {
return JNI_FALSE;
}
if (process(inFileName, outFileName, alignment, force, zopfli, pageAlignSharedLibs) == 0) return JNI_TRUE;
return JNI_FALSE;
}
extern "C"
JNIEXPORT jboolean
JNICALL Java_com_android_zipalign_ZipAlign_verify
(JNIEnv *env, jclass clazz, jstring inZipFile, jint alignment, jboolean verbose, jboolean pageAlignSharedLibs) {
const char *inFileName = env->GetStringUTFChars(inZipFile, nullptr);
if(!inFileName) {
return JNI_FALSE;
}
if(verify(inFileName, alignment, verbose, pageAlignSharedLibs) == 0) return JNI_TRUE;
return JNI_FALSE;
}
Java:
package com.android.zipalign;
public class ZipAlign {
static {
System.loadLibrary("zipalign");
}
public static native boolean process(String inZipFile, String outZipFile, int alignment, boolean force, boolean pageAlignSharedLibs);
public static native boolean verify(String inZipFile, int alignment, boolean verbose, boolean pageAlignSharedLibs);
}
Thanks @TimScriptov . I can add this as well. I am currently working on getting aapt working for android-11, but I'll work on your request next.
Just a quick question regarding the home app restriction, have you tried executing it from your app's cache directory? Technically, this is different than your home directory but just something I was curious about.
For my own reference, this is the target that will need to be built.
https://android.googlesource.com/platform/build/+/master/tools/zipalign/Android.bp#21
Thanks @TimScriptov . I can add this as well. I am currently working on getting
aaptworking for android-11, but I'll work on your request next.Just a quick question regarding the home app restriction, have you tried executing it from your app's cache directory? Technically, this is different than your home directory but just something I was curious about.
Thanks, aapt it cool!
I myself have already assembled the code I need, but I'm not sure about 100% of the assembly's performance. I will be looking forward to your further updates.
Just a quick question regarding the home app restriction, have you tried executing it from your app's cache directory? Technically, this is different than your home directory but just something I was curious about.
If TargetSdk is 28 or less, then binaries work.
If TargetSdk is 29 or higher then binaries do not work (Permission denied)
@TimScriptov as far i know in new api you can only execute binaries from app root folder (data/data/com.whatever.idk/files/
if you know sketchware it can execute binaries from root folder with context.getFilesDir() , you can check out the modded source and see how AAPT and AAPT2 get executed : https://github.com/Sketchware-Pro/Sketchware-Pro/blob/75d4a528a8d01ef12647d07ed68cbb835f30de54/app/src/main/java/a/a/a/Dp.java#L116
this work even in API 30
yes, working
I have already said that you cannot run binaries on API 29 (If targetSdkVersion=29+)