Separate JNI glue from actual C code, move CMakeLists file

This commit is contained in:
tonymanou 2017-01-22 00:37:53 +01:00 committed by topjohnwu
parent 84c8ecb372
commit 5d8bb897db
6 changed files with 43 additions and 28 deletions

View File

@ -1,5 +0,0 @@
cmake_minimum_required(VERSION 3.6)
add_library(zipadjust SHARED src/main/jni/zipadjust.c)
find_library(libz z)
find_library(liblog log)
target_link_libraries(zipadjust ${libz} ${liblog})

View File

@ -38,7 +38,7 @@ android {
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
path 'src/main/jni/CMakeLists.txt'
}
}
}

View File

@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.6)
add_library(zipadjust SHARED
jni_glue.c
zipadjust.c)
find_library(libz z)
find_library(liblog log)
target_link_libraries(zipadjust ${libz} ${liblog})

View File

@ -0,0 +1,23 @@
//
// Java entry point
//
#include <jni.h>
#include <stdlib.h>
#include "zipadjust.h"
JNIEXPORT jbyteArray JNICALL
Java_com_topjohnwu_magisk_utils_ZipUtils_zipAdjust(JNIEnv *env, jclass type, jbyteArray jbytes, jint size) {
fin = (*env)->GetPrimitiveArrayCritical(env, jbytes, NULL);
insize = (size_t) size;
zipadjust(0);
(*env)->ReleasePrimitiveArrayCritical(env, jbytes, fin, 0);
jbyteArray ret = (*env)->NewByteArray(env, outsize);
(*env)->SetByteArrayRegion(env, ret, 0, outsize, (const jbyte*) fout);
free(fout);
return ret;
}

View File

@ -1,35 +1,16 @@
#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
#include <zlib.h>
#include <android/log.h>
#include "zipadjust.h"
#define LOG_TAG "zipadjust"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
size_t insize, outsize = 0, alloc = 0;
unsigned char *fin, *fout;
int zipadjust(int decompress) ;
JNIEXPORT jbyteArray JNICALL
Java_com_topjohnwu_magisk_utils_ZipUtils_zipAdjust(JNIEnv *env, jclass type, jbyteArray jbytes,
jint size) {
fin = (*env)->GetPrimitiveArrayCritical(env, jbytes, NULL);
insize = (size_t) size;
zipadjust(0);
(*env)->ReleasePrimitiveArrayCritical(env, jbytes, fin, 0);
jbyteArray ret = (*env)->NewByteArray(env, outsize);
(*env)->SetByteArrayRegion(env, ret, 0, outsize, (const jbyte*) fout);
free(fout);
return ret;
}
size_t insize = 0, outsize = 0, alloc = 0;
unsigned char *fin = NULL, *fout = NULL;
#pragma pack(1)
struct local_header_struct {

View File

@ -0,0 +1,9 @@
#ifndef MAGISKMANAGER_ZIPADJUST_H_H
#define MAGISKMANAGER_ZIPADJUST_H_H
int zipadjust(int decompress);
extern size_t insize, outsize, alloc;
extern unsigned char *fin, *fout;
#endif //MAGISKMANAGER_ZIPADJUST_H_H