diff --git a/.idea/dictionaries/rumia.xml b/.idea/dictionaries/rumia.xml index 36de78b..095863d 100644 --- a/.idea/dictionaries/rumia.xml +++ b/.idea/dictionaries/rumia.xml @@ -1,6 +1,7 @@ + cpubit fumiama lzma diff --git a/app/build.gradle b/app/build.gradle index 0be7fc7..99a7ce7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "top.fumiama.base16384" minSdkVersion 23 targetSdkVersion 30 - versionCode 11 - versionName '2.1.1' + versionCode 12 + versionName '3.0' resConfigs "zh", "en" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/release/app-release.aab b/app/release/app-release.aab index c7ce866..19273ff 100644 Binary files a/app/release/app-release.aab and b/app/release/app-release.aab differ diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 2531313..a8ee70a 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 65de5f1..a7ec91a 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -10,8 +10,8 @@ { "type": "SINGLE", "filters": [], - "versionCode": 11, - "versionName": "2.1.1", + "versionCode": 12, + "versionName": "3.0", "outputFile": "app-release.apk" } ] diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 7206b71..070deb4 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -2,5 +2,5 @@ cmake_minimum_required(VERSION 3.10.2) project("base16384") -add_subdirectory(base2_14) +add_subdirectory(base14) add_subdirectory(lzma1900) diff --git a/app/src/main/cpp/base14/32/CMakeLists.txt b/app/src/main/cpp/base14/32/CMakeLists.txt new file mode 100644 index 0000000..b8ccaac --- /dev/null +++ b/app/src/main/cpp/base14/32/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.0.0) +project(base1432 VERSION 2.0) + +add_library(base1432 ./base1432le.c) diff --git a/app/src/main/cpp/base14/32/base1432le.c b/app/src/main/cpp/base14/32/base1432le.c new file mode 100644 index 0000000..2cc7120 --- /dev/null +++ b/app/src/main/cpp/base14/32/base1432le.c @@ -0,0 +1,151 @@ +//base1432le.c +//fumiama 20210408 +#include +#include +#include "base1432le.h" + +//#define DEBUG + +LENDAT* encode(const uint8_t* data, const u_int32_t len) { + LENDAT* encd = (LENDAT*)malloc(sizeof(LENDAT)); + uint32_t outlen = len / 7 * 8; + uint8_t offset = len % 7; + switch(offset) { //算上偏移标志字符占用的2字节 + case 0: break; + case 1: outlen += 4; break; + case 2: + case 3: outlen += 6; break; + case 4: + case 5: outlen += 8; break; + case 6: outlen += 10; break; + default: break; + } + #ifdef DEBUG + printf("outlen: %llu, offset: %u, malloc: %llu\n", outlen, offset, outlen + 8); + #endif + encd->data = (uint8_t*)malloc(outlen + 8); //冗余的8B用于可能的结尾的覆盖 + encd->len = outlen; + uint32_t* vals = (uint32_t*)(encd->data); + uint32_t n = 0; + uint32_t i = 0; + for(; i < len; i += 7) { + register uint32_t sum = 0x0000003f & ((uint32_t)data[i] >> 2); + sum |= ((((uint32_t)data[i + 1] >> 2) | (data[i] << 6)) << 8) & 0x0000ff00; + sum |= ((((uint32_t)data[i + 1] << 4) | ((uint32_t)data[i + 2] >> 4)) << 16) & 0x003f0000; + sum |= ((((uint32_t)data[i + 2] << 4) | ((uint32_t)data[i + 3] >> 4)) << 24) & 0xff000000; + sum += 0x004e004e; + vals[n++] = sum; + #ifdef DEBUG + printf("n: %u, add sum: %08x\n", n, sum); + #endif + sum = ((((uint32_t)data[i + 3] << 2) | ((uint32_t)data[i + 4] >> 6))) & 0x0000003f; + sum |= ((((uint32_t)data[i + 4] << 2) | ((uint32_t)data[i + 5] >> 6)) << 8) & 0x0000ff00; + sum |= ((uint32_t)data[i + 5] << 16) & 0x003f0000; + sum |= ((uint32_t)data[i + 6] << 24) & 0xff000000; + sum += 0x004e004e; + vals[n++] = sum; + #ifdef DEBUG + printf("n: %u, add sum: %08x\n", n, sum); + #endif + } + if(offset > 0) { + register uint32_t sum = 0x0000003f & (data[i] >> 2); + sum |= (((uint32_t)data[i] << 6) << 8) & 0x0000c000; + if(offset > 1) { + sum |= (((uint32_t)data[i + 1] >> 2) << 8) & 0x00003f00; + sum |= (((uint32_t)data[i + 1] << 4) << 16) & 0x00300000; + if(offset > 2) { + sum |= (((uint32_t)data[i + 2] >> 4) << 16) & 0x000f0000; + sum |= (((uint32_t)data[i + 2] << 4) << 24) & 0xf0000000; + if(offset == 2) { + sum += 0x004e004e; + vals[n++] = sum; + } + if(offset > 3) { + sum |= (((uint32_t)data[i + 3] >> 4) << 24) & 0x0f000000; + sum += 0x004e004e; + vals[n++] = sum; + sum = (((uint32_t)data[i + 3] << 2)) & 0x0000003c; + if(offset > 4) { + sum |= (((uint32_t)data[i + 4] >> 6)) & 0x00000003; + sum |= (((uint32_t)data[i + 4] << 2) << 8) & 0x0000fc00; + if(offset > 5) { + sum |= (((uint32_t)data[i + 5] >> 6) << 8) & 0x00000300; + sum |= ((uint32_t)data[i + 5] << 16) & 0x003f0000; + } + } + sum += 0x004e004e; + vals[n] = sum; + } + } + } + encd->data[outlen - 2] = '='; + encd->data[outlen - 1] = offset; + } + return encd; +} + +LENDAT* decode(const uint8_t* data, const u_int32_t len) { + LENDAT* decd = (LENDAT*)malloc(sizeof(LENDAT)); + uint32_t outlen = len; + uint8_t offset = 0; + if(data[len-2] == '=') { + offset = data[len-1]; + switch(offset) { //算上偏移标志字符占用的2字节 + case 0: break; + case 1: outlen -= 4; break; + case 2: + case 3: outlen -= 6; break; + case 4: + case 5: outlen -= 8; break; + case 6: outlen -= 10; break; + default: break; + } + } + outlen = outlen / 8 * 7 + offset; + decd->data = (uint8_t*)malloc(outlen); + decd->len = outlen; + uint32_t* vals = (uint32_t*)data; + uint32_t n = 0; + uint32_t i = 0; + for(; n < len / 4; n++) { //n实际每次自增2 + register uint32_t sum = vals[n++]; + sum -= 0x004e004e; + decd->data[i++] = ((sum & 0x0000003f) << 2) | ((sum & 0x0000c000) >> 14); + decd->data[i++] = ((sum & 0x00003f00) >> 6) | ((sum & 0x00300000) >> 20); + decd->data[i++] = ((sum & 0x000f0000) >> 12) | ((sum & 0xf0000000) >> 28); + decd->data[i] = ((sum & 0x0f000000) >> 20); + sum = vals[n]; + sum -= 0x004e004e; + decd->data[i++] |= ((sum & 0x0000003c) >> 2); + decd->data[i++] = ((sum & 0x00000003) << 6) | ((sum & 0x0000fc00) >> 10); + decd->data[i++] = ((sum & 0x00000300) >> 2) | ((sum & 0x003f0000) >> 16); + decd->data[i++] = ((sum & 0xff000000) >> 24); + } + if(offset > 0) { + register uint32_t sum = vals[n++]; + sum -= 0x0000004e; + decd->data[i++] = ((sum & 0x0000003f) << 2) | ((sum & 0x0000c000) >> 14); + if(offset > 1) { + sum -= 0x004e0000; + decd->data[i++] = ((sum & 0x00003f00) >> 6) | ((sum & 0x00300000) >> 20); + if(offset > 2) { + decd->data[i++] = ((sum & 0x000f0000) >> 12) | ((sum & 0xf0000000) >> 28); + if(offset > 3) { + decd->data[i++] = (sum & 0x0f000000) >> 20; + sum = vals[n]; + sum -= 0x0000004e; + decd->data[i++] |= (sum & 0x0000003c) >> 2; + if(offset > 4) { + decd->data[i++] = ((sum & 0x00000003) << 6) | ((sum & 0x0000fc00) >> 10); + if(offset > 5) { + sum -= 0x004e0000; + decd->data[i++] = ((sum & 0x00000300) >> 2) | ((sum & 0x003f0000) >> 16); + } + } + } + } + } + } + return decd; +} diff --git a/app/src/main/cpp/base14/32/base1432le.h b/app/src/main/cpp/base14/32/base1432le.h new file mode 100644 index 0000000..c946b24 --- /dev/null +++ b/app/src/main/cpp/base14/32/base1432le.h @@ -0,0 +1,13 @@ +//base1432le.h +//fumiama 20210408 +#include + +#define B14BUFSIZ 8192 +struct LENDAT { + uint8_t* data; + uint32_t len; +}; +typedef struct LENDAT LENDAT; + +LENDAT* encode(const uint8_t* data, const u_int32_t len); +LENDAT* decode(const uint8_t* data, const u_int32_t len); diff --git a/app/src/main/cpp/base14/64/CMakeLists.txt b/app/src/main/cpp/base14/64/CMakeLists.txt new file mode 100644 index 0000000..8ee6dec --- /dev/null +++ b/app/src/main/cpp/base14/64/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.0.0) +project(base1464 VERSION 2.0) + +add_library(base1464 ./base1464le.c) diff --git a/app/src/main/cpp/base14/64/base1464le.c b/app/src/main/cpp/base14/64/base1464le.c new file mode 100644 index 0000000..48e357e --- /dev/null +++ b/app/src/main/cpp/base14/64/base1464le.c @@ -0,0 +1,138 @@ +//base1464le.c +//fumiama 20210407 +#include +#include +#include "base1464le.h" + +//#define DEBUG + +LENDAT* encode(const uint8_t* data, const u_int64_t len) { + LENDAT* encd = (LENDAT*)malloc(sizeof(LENDAT)); + uint64_t outlen = len / 7 * 8; + uint8_t offset = len % 7; + switch(offset) { //算上偏移标志字符占用的2字节 + case 0: break; + case 1: outlen += 4; break; + case 2: + case 3: outlen += 6; break; + case 4: + case 5: outlen += 8; break; + case 6: outlen += 10; break; + default: break; + } + #ifdef DEBUG + printf("outlen: %llu, offset: %u, malloc: %llu\n", outlen, offset, outlen + 8); + #endif + encd->data = (uint8_t*)malloc(outlen + 8); //冗余的8B用于可能的结尾的覆盖 + encd->len = outlen; + uint64_t* vals = (uint64_t*)(encd->data); + uint64_t n = 0; + uint64_t i = 0; + for(; i < len; i += 7) { + register uint64_t sum = 0x000000000000003f & ((uint64_t)data[i] >> 2); + sum |= ((((uint64_t)data[i + 1] >> 2) | (data[i] << 6)) << 8) & 0x000000000000ff00; + sum |= ((((uint64_t)data[i + 1] << 4) | ((uint64_t)data[i + 2] >> 4)) << 16) & 0x00000000003f0000; + sum |= ((((uint64_t)data[i + 2] << 4) | ((uint64_t)data[i + 3] >> 4)) << 24) & 0x00000000ff000000; + sum |= ((((uint64_t)data[i + 3] << 2) | ((uint64_t)data[i + 4] >> 6)) << 32) & 0x0000003f00000000; + sum |= ((((uint64_t)data[i + 4] << 2) | ((uint64_t)data[i + 5] >> 6)) << 40) & 0x0000ff0000000000; + sum |= ((uint64_t)data[i + 5] << 48) & 0x003f000000000000; + sum |= ((uint64_t)data[i + 6] << 56) & 0xff00000000000000; + sum += 0x004e004e004e004e; + vals[n++] = sum; + #ifdef DEBUG + printf("i: %llu, add sum: %016llx\n", i, sum); + #endif + } + if(offset > 0) { + register uint64_t sum = 0x000000000000003f & (data[i] >> 2); + sum |= (((uint64_t)data[i] << 6) << 8) & 0x000000000000c000; + if(offset > 1) { + sum |= (((uint64_t)data[i + 1] >> 2) << 8) & 0x0000000000003f00; + sum |= (((uint64_t)data[i + 1] << 4) << 16) & 0x0000000000300000; + if(offset > 2) { + sum |= (((uint64_t)data[i + 2] >> 4) << 16) & 0x00000000000f0000; + sum |= (((uint64_t)data[i + 2] << 4) << 24) & 0x00000000f0000000; + if(offset > 3) { + sum |= (((uint64_t)data[i + 3] >> 4) << 24) & 0x000000000f000000; + sum |= (((uint64_t)data[i + 3] << 2) << 32) & 0x0000003c00000000; + if(offset > 4) { + sum |= (((uint64_t)data[i + 4] >> 6) << 32) & 0x0000000300000000; + sum |= (((uint64_t)data[i + 4] << 2) << 40) & 0x0000fc0000000000; + if(offset > 5) { + sum |= (((uint64_t)data[i + 5] >> 6) << 40) & 0x0000030000000000; + sum |= ((uint64_t)data[i + 5] << 48) & 0x003f000000000000; + } + } + } + } + } + sum += 0x004e004e004e004e; + vals[n] = sum; + #ifdef DEBUG + printf("i: %llu, add sum: %016llx\n", i, sum); + #endif + encd->data[outlen - 2] = '='; + encd->data[outlen - 1] = offset; + } + return encd; +} + +LENDAT* decode(const uint8_t* data, const u_int64_t len) { + LENDAT* decd = (LENDAT*)malloc(sizeof(LENDAT)); + uint64_t outlen = len; + uint8_t offset = 0; + if(data[len-2] == '=') { + offset = data[len-1]; + switch(offset) { //算上偏移标志字符占用的2字节 + case 0: break; + case 1: outlen -= 4; break; + case 2: + case 3: outlen -= 6; break; + case 4: + case 5: outlen -= 8; break; + case 6: outlen -= 10; break; + default: break; + } + } + outlen = outlen / 8 * 7 + offset; + decd->data = (uint8_t*)malloc(outlen); + decd->len = outlen; + uint64_t* vals = (uint64_t*)data; + uint64_t n = 0; + uint64_t i = 0; + for(; n < len / 8; n++) { + register uint64_t sum = vals[n]; + sum -= 0x004e004e004e004e; + decd->data[i++] = ((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14); + decd->data[i++] = ((sum & 0x0000000000003f00) >> 6) | ((sum & 0x0000000000300000) >> 20); + decd->data[i++] = ((sum & 0x00000000000f0000) >> 12) | ((sum & 0x00000000f0000000) >> 28); + decd->data[i++] = ((sum & 0x000000000f000000) >> 20) | ((sum & 0x0000003c00000000) >> 34); + decd->data[i++] = ((sum & 0x0000000300000000) >> 26) | ((sum & 0x0000fc0000000000) >> 42); + decd->data[i++] = ((sum & 0x0000030000000000) >> 34) | ((sum & 0x003f000000000000) >> 48); + decd->data[i++] = ((sum & 0xff00000000000000) >> 56); + } + if(offset > 0) { + register uint64_t sum = vals[n]; + sum -= 0x000000000000004e; + decd->data[i++] = ((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14); + if(offset > 1) { + sum -= 0x00000000004e0000; + decd->data[i++] = ((sum & 0x0000000000003f00) >> 6) | ((sum & 0x0000000000300000) >> 20); + if(offset > 2) { + decd->data[i++] = ((sum & 0x00000000000f0000) >> 12) | ((sum & 0x00000000f0000000) >> 28); + if(offset > 3) { + sum -= 0x0000004e00000000; + decd->data[i++] = ((sum & 0x000000000f000000) >> 20) | ((sum & 0x0000003c00000000) >> 34); + if(offset > 4) { + decd->data[i++] = ((sum & 0x0000000300000000) >> 26) | ((sum & 0x0000fc0000000000) >> 42); + if(offset > 5) { + sum -= 0x004e000000000000; + decd->data[i++] = ((sum & 0x0000030000000000) >> 34) | ((sum & 0x003f000000000000) >> 48); + } + } + } + } + } + } + return decd; +} diff --git a/app/src/main/cpp/base14/64/base1464le.h b/app/src/main/cpp/base14/64/base1464le.h new file mode 100644 index 0000000..ff08fb8 --- /dev/null +++ b/app/src/main/cpp/base14/64/base1464le.h @@ -0,0 +1,13 @@ +//base1464le.h +//fumiama 20210408 +#include + +#define B14BUFSIZ 16384 +struct LENDAT { + uint8_t* data; + uint64_t len; +}; +typedef struct LENDAT LENDAT; + +LENDAT* encode(const uint8_t* data, const u_int64_t len); +LENDAT* decode(const uint8_t* data, const u_int64_t len); diff --git a/app/src/main/cpp/base14/CMakeLists.txt b/app/src/main/cpp/base14/CMakeLists.txt new file mode 100644 index 0000000..7bb5f86 --- /dev/null +++ b/app/src/main/cpp/base14/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.10.2) + +project("base16384") + +add_library(base14 SHARED base16384.cpp) + +add_library(base14c STATIC base16384.c) + +IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + add_definitions("-DCPUBIT64") + add_subdirectory("./64") + target_link_libraries(base14c base1464) +ELSE() + add_definitions("-DCPUBIT32") + add_subdirectory("./32") + target_link_libraries(base14c base1432) +ENDIF() + +target_link_libraries(base14 base14c) diff --git a/app/src/main/cpp/base14/base16384.c b/app/src/main/cpp/base14/base16384.c new file mode 100644 index 0000000..1ca03f0 --- /dev/null +++ b/app/src/main/cpp/base14/base16384.c @@ -0,0 +1,98 @@ +#include +#include +#include "base16384.h" + +int encode_file(const char* input, const char* output) { + FILE* fp = NULL; + fp = fopen(input, "rb"); + if(fp) { + FILE* fpo = NULL; + fpo = fopen(output, "wb"); + if(fpo) { + char* bufi = (char*)malloc(B14BUFSIZ/7*7); + if(bufi) { + int cnt; + fputc(0xFE, fpo); + fputc(0xFF, fpo); + fflush(fpo); + while((cnt = fread(bufi, sizeof(char), B14BUFSIZ/7*7, fp))) { + LENDAT* ld = encode(bufi, cnt); + if(fwrite(ld->data, ld->len, 1, fpo) <= 0) { + puts("Write file error!"); + return 1; + } + free(ld); + } + free(bufi); + } else { + puts("Allocate input buffer error!"); + return 2; + } + fclose(fpo); + } else { + puts("Open output file error!"); + return 3; + } + fclose(fp); + return 0; + } else { + puts("Open input file error!"); + return 4; + } +} + +void rm_head(FILE* fp) { + int ch = fgetc(fp); + if(ch == 0xFE) fgetc(fp); + else rewind(fp); +} + +static int is_next_end(FILE* fp) { + int ch = fgetc(fp); + if(ch == '=') return fgetc(fp); + else { + ungetc(ch, fp); + return 0; + } +} + +int decode_file(const char* input, const char* output) { + FILE* fp = NULL; + fp = fopen(input, "rb"); + if(fp) { + FILE* fpo = NULL; + fpo = fopen(output, "wb"); + if(fpo) { + char* bufi = (char*)malloc(B14BUFSIZ/8*8 + 2); //+2避免漏检结束偏移标志 + if(bufi) { + int cnt, end; + rm_head(fp); + while((cnt = fread(bufi, sizeof(char), B14BUFSIZ/8*8, fp))) { + if((end = is_next_end(fp))) { + bufi[cnt++] = '='; + bufi[cnt++] = (char)end; + } + LENDAT* ld = decode(bufi, cnt); + if(fwrite(ld->data, ld->len, 1, fpo) <= 0) { + puts("Write file error!"); + return 1; + } + free(ld); + } + free(bufi); + } else { + puts("Allocate input buffer error!"); + return 2; + } + fclose(fpo); + } else { + puts("Open output file error!"); + return 3; + } + fclose(fp); + return 0; + } else { + puts("Open input file error!"); + return 4; + } +} diff --git a/app/src/main/cpp/base14/base16384.cpp b/app/src/main/cpp/base14/base16384.cpp new file mode 100644 index 0000000..0784195 --- /dev/null +++ b/app/src/main/cpp/base14/base16384.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include "base16384.h" + +#define execute(function){\ + const char *inputFileDir = env->GetStringUTFChars(sf, JNI_FALSE);\ + const char *outputFileDir = env->GetStringUTFChars(df, JNI_FALSE);\ + int re = function(inputFileDir, outputFileDir);\ + env->ReleaseStringUTFChars(sf, inputFileDir);\ + env->ReleaseStringUTFChars(df, outputFileDir);\ + return re;\ +} + +extern "C" int encode_file(const char* input, const char* output); +extern "C" int decode_file(const char* input, const char* output); + +extern "C" JNIEXPORT int JNICALL +Java_top_fumiama_base16384_MainActivity_encode(JNIEnv* env, jobject, jstring sf, jstring df) execute(encode_file) + +extern "C" JNIEXPORT int JNICALL +Java_top_fumiama_base16384_MainActivity_decode(JNIEnv* env, jobject, jstring sf, jstring df) execute(decode_file) \ No newline at end of file diff --git a/app/src/main/cpp/base14/base16384.h b/app/src/main/cpp/base14/base16384.h new file mode 100644 index 0000000..67f17a3 --- /dev/null +++ b/app/src/main/cpp/base14/base16384.h @@ -0,0 +1,11 @@ +#ifndef CPUBIT32 + #ifndef CPUBIT64 + #define CPUBIT32 + #endif +#endif +#ifdef CPUBIT32 + #include "./32/base1432le.h" +#endif +#ifdef CPUBIT64 + #include "./64/base1464le.h" +#endif diff --git a/app/src/main/cpp/base2_14/CMakeLists.txt b/app/src/main/cpp/base2_14/CMakeLists.txt deleted file mode 100644 index 60f8558..0000000 --- a/app/src/main/cpp/base2_14/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# For more information about using CMake with Android Studio, read the -# documentation: https://d.android.com/studio/projects/add-native-code.html - -# Sets the minimum version of CMake required to build the native library. - -cmake_minimum_required(VERSION 3.10.2) - -# Declares and names the project. - -project("base16384") - -# Creates and names a library, sets it as either STATIC -# or SHARED, and provides the relative paths to its source code. -# You can define multiple libraries, and CMake builds them for you. -# Gradle automatically packages shared libraries with your APK. - -add_library( # Sets the name of the library. - 2_14 - - # Sets the library as a shared library. - SHARED - - # Provides a relative path to your source file(s). - base16384.cpp ) - -# Searches for a specified prebuilt library and stores the path as a -# variable. Because CMake includes system libraries in the search path by -# default, you only need to specify the name of the public NDK library -# you want to add. CMake verifies that the library exists before -# completing its build. - -find_library( # Sets the name of the path variable. - log-lib - - # Specifies the name of the NDK library that - # you want CMake to locate. - log ) - -# Specifies libraries CMake should link to your target library. You -# can link multiple libraries, such as libraries you define in this -# build script, prebuilt third-party libraries, or system libraries. - -target_link_libraries( # Specifies the target library. - 2_14 - # Links the target library to the log library - # included in the NDK. - ${log-lib} ) \ No newline at end of file diff --git a/app/src/main/cpp/base2_14/base16384.cpp b/app/src/main/cpp/base2_14/base16384.cpp deleted file mode 100644 index d7b36de..0000000 --- a/app/src/main/cpp/base2_14/base16384.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include "base16384.h" - -FILE *fp, *fpo; - -#define execute(function){\ - const char *inputFileDir = env->GetStringUTFChars(sf, JNI_FALSE);\ - const char *outputFileDir = env->GetStringUTFChars(df, JNI_FALSE);\ - fp = fpo = nullptr;\ - fp = fopen(inputFileDir, "rb");\ - fpo = fopen(outputFileDir, "wb");\ - if(fp != nullptr && fpo != nullptr){\ - function(fp, fpo);\ - env->ReleaseStringUTFChars(sf, inputFileDir);\ - env->ReleaseStringUTFChars(df, outputFileDir);\ - fclose(fp);\ - fclose(fpo);\ - return 0;\ - }else return 1;\ -} - -extern "C" JNIEXPORT int JNICALL -Java_top_fumiama_base16384_MainActivity_encode(JNIEnv* env, jobject, jstring sf, jstring df) execute(encode) - -extern "C" JNIEXPORT int JNICALL -Java_top_fumiama_base16384_MainActivity_decode(JNIEnv* env, jobject, jstring sf, jstring df) execute(decode) \ No newline at end of file diff --git a/app/src/main/cpp/base2_14/base16384.h b/app/src/main/cpp/base2_14/base16384.h deleted file mode 100644 index 76e411c..0000000 --- a/app/src/main/cpp/base2_14/base16384.h +++ /dev/null @@ -1,78 +0,0 @@ -// -// Created by rumia on 2020/12/16. -// - -#ifndef BASE16384_BASE16384_H -#define BASE16384_BASE16384_H - -//base16384.h -//MIT fumiama 20200416 -#include "bitio.h" -#define HEAD 0x4E -BIT outbuf; -unsigned char buf[BUFSIZ]; -void push(int istrue, FILE *fpo, int offset){ - if(!~pushbit(&outbuf, istrue)){ - if(offset) for(int i = 0; i < BITBUFSIZE; i += 2) outbuf.b[i] += offset; - fwrite(outbuf.b, sizeof(char), BITBUFSIZE, fpo); - outbuf.p = 0; - pushbit(&outbuf, istrue); - } -} -#define setoffset(x, offset){\ - char flag = 0;\ - ch1 = ch2 = x;\ - while(!feof(fp) && (ch1 = fgetc(fp)) == x && (ch2 = fgetc(fp)) == x) {cnt8 -= offset; flag++;}\ - if(ch2 != x) {ungetc(ch2, fp); ch2 = x;}\ - if(ch1 != x) {ungetc(ch1, fp); ch1 = x;}\ - while(feof(fp) && buf[cnt - 1] == x && buf[cnt - 2] == x) {cnt8 -= offset; cnt -= 2; flag++;}\ - if(flag) cnt8 -= 8;\ -} -void encode(FILE *fp, FILE *fpo){ - int cnt; - - memset(&outbuf, 0, sizeof(BIT)); - fputc(0xFE, fpo); - fputc(0xFF, fpo); - while((cnt = fread(buf, sizeof(char), BUFSIZ, fp))){ - for(int i = 0; i < cnt * 8; i++){ - if(!(outbuf.p % 16)){ - push(0, fpo, HEAD); - push(0, fpo, HEAD); - } - push(buf[i / 8] & (128u >> (i % 8)), fpo, HEAD); - } - } - if(outbuf.p){ - outbuf.b[outbuf.p / 8] &= ~(255u >> outbuf.p % 8); - for(int i = 0; i < outbuf.p / 8 + 1; i += 2) outbuf.b[i] += HEAD; - fwrite(outbuf.b, sizeof(char), (outbuf.p % 8)?outbuf.p / 8 + 1:outbuf.p / 8 , fpo); - if(((outbuf.p % 8)?outbuf.p / 8 + 1:outbuf.p / 8) % 2){ - fputc(0, fpo); - fputc('>', fpo); - fputc('>', fpo); - } - for(int i = 0; i < outbuf.p % 8; i++) fputc('=', fpo); - } -} -void decode(FILE *fp, FILE *fpo){ - int cnt, cnt8; - char ch1, ch2; - memset(&outbuf, 0, sizeof(BIT)); - while((cnt = fread(buf, sizeof(char), BUFSIZ, fp))){ - cnt8 = cnt * 8; - setoffset('=', 14) - setoffset('>', 16) - - for(int i = ((buf[0] == 0xFE)?16:0); i < cnt8; i++){ - if(!(i % 16)){ - buf[i / 8] -= HEAD; - i += 2; - } - push(buf[i / 8] & (128u >> (i % 8)), fpo, 0); - } - } - if(outbuf.p) fwrite(outbuf.b, sizeof(char), (outbuf.p % 8)?outbuf.p / 8 + 1:outbuf.p / 8, fpo); -} - -#endif //BASE16384_BASE16384_H diff --git a/app/src/main/cpp/base2_14/bitio.h b/app/src/main/cpp/base2_14/bitio.h deleted file mode 100644 index 47d7084..0000000 --- a/app/src/main/cpp/base2_14/bitio.h +++ /dev/null @@ -1,53 +0,0 @@ -// -// Created by rumia on 2020/12/16. -// - -#ifndef BASE16384_BITIO_H -#define BASE16384_BITIO_H -//bitio.h -//made by fumiama -//20200413 -#ifndef BITBUFSIZE -#define BITBUFSIZE 1024 -#endif -struct BIT{ - char b[BITBUFSIZE]; - int p; -}; -typedef struct BIT BIT; - -int pushbit(BIT *buffer, const int isture){ - if(buffer->p >= BITBUFSIZE * 8) return EOF; - else if(isture) buffer->b[buffer->p / 8] |= 128u >> buffer->p % 8; - else buffer->b[buffer->p / 8] &= ~(128u >> buffer->p % 8); - buffer->p++; - return isture; -} - -int fpushbit(BIT *buffer, FILE *fp){ - memset(buffer, 0, sizeof(BIT)); - if((buffer->p = fread(buffer->b, sizeof(char), BITBUFSIZE, fp)) && feof(fp)) - buffer->p = (buffer->p - 2) * 8 + buffer->b[buffer->p - 1] + 1; - else buffer->p *= 8; - return buffer->p; -} - -int changebit(BIT *buffer, const int isture, const int position){ - if(position >= buffer->p) return EOF; - else if(isture) buffer->b[position / 8] |= 128u >> position % 8; - else buffer->b[position / 8] &= ~(128u >> position % 8); - buffer->p++; - return isture; -} - -int readbit(const BIT *buffer, const int position){ - if(position >= buffer->p) return EOF; - else return buffer->b[position / 8] & (128u >> position % 8); -} - -int popbit(BIT *buffer){ - if(buffer->p >= BITBUFSIZE * 8 || buffer->p < 0) return EOF; - buffer->p--; - return buffer->b[(buffer->p+1) / 8] & (128u >> (buffer->p+1) % 8); -} -#endif //BASE16384_BITIO_H diff --git a/app/src/main/java/top/fumiama/base16384/MainActivity.kt b/app/src/main/java/top/fumiama/base16384/MainActivity.kt index 6d288aa..4d4244b 100644 --- a/app/src/main/java/top/fumiama/base16384/MainActivity.kt +++ b/app/src/main/java/top/fumiama/base16384/MainActivity.kt @@ -172,7 +172,7 @@ class MainActivity : Activity() { private fun base16(isEncode: Boolean, sf: String, of: String, makeToast: Boolean = false): String { var re = "" - var bre = 0 + val bre: Int if(sl.isChecked) { val tf = generateCacheFile("lzma_temp").absolutePath if(isEncode) re += lzma(sf, tf, true) @@ -251,7 +251,7 @@ class MainActivity : Activity() { companion object { // Used to load libraries on application startup. init { - System.loadLibrary("2_14") + System.loadLibrary("base14") System.loadLibrary("lzma") } } diff --git a/build.gradle b/build.gradle index 83ef5c9..e8e3d5d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.31' + ext.kotlin_version = '1.4.32' repositories { google() jcenter() @@ -8,7 +8,7 @@ buildscript { maven { url 'https://maven.google.com' } } dependencies { - classpath "com.android.tools.build:gradle:4.1.2" + classpath 'com.android.tools.build:gradle:4.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" //classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.20'