Separate JNI glue from actual C code, move CMakeLists file
This commit is contained in:
parent
84c8ecb372
commit
5d8bb897db
@ -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})
|
|
@ -38,7 +38,7 @@ android {
|
|||||||
}
|
}
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
path 'CMakeLists.txt'
|
path 'src/main/jni/CMakeLists.txt'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
app/src/main/jni/CMakeLists.txt
Normal file
7
app/src/main/jni/CMakeLists.txt
Normal 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})
|
23
app/src/main/jni/jni_glue.c
Normal file
23
app/src/main/jni/jni_glue.c
Normal 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;
|
||||||
|
}
|
@ -1,35 +1,16 @@
|
|||||||
#include <jni.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
#include "zipadjust.h"
|
||||||
|
|
||||||
#define LOG_TAG "zipadjust"
|
#define LOG_TAG "zipadjust"
|
||||||
|
|
||||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
||||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
||||||
|
|
||||||
size_t insize, outsize = 0, alloc = 0;
|
size_t insize = 0, outsize = 0, alloc = 0;
|
||||||
unsigned char *fin, *fout;
|
unsigned char *fin = NULL, *fout = NULL;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
struct local_header_struct {
|
struct local_header_struct {
|
||||||
|
9
app/src/main/jni/zipadjust.h
Normal file
9
app/src/main/jni/zipadjust.h
Normal 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
|
Loading…
Reference in New Issue
Block a user