8000 Not converting string encoding in JNI layer · passy/android-database-sqlcipher@bf513a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf513a5

Browse files
Not converting string encoding in JNI layer
1 parent 6681a4b commit bf513a5

File tree

6 file< 8000 !-- -->s changed

+59
-49
lines changed

6 files changed

+59
-49
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
.DS_Store
12
build.xml
23
proguard-project.txt
34
local.properties
45
external/android-libs
5-
obj
6+
obj
7+
jni/libs

jni/Android.mk

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SQLCIPHER_SRC := $(SQLCIPHER_DIR)/sqlite3.c
77

88
LOCAL_CFLAGS += $(SQLCIPHER_CFLAGS) -DOS_PATH_SEPARATOR="'/'" -DHAVE_SYS_UIO_H
99
LOCAL_C_INCLUDES := $(SQLCIPHER_DIR) $(LOCAL_PATH) $(LOCAL_PATH)/include
10-
LOCAL_LDLIBS := -llog -lc
10+
LOCAL_LDLIBS := -llog
1111
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/android-libs/$(TARGET_ARCH_ABI) -fuse-ld=bfd
1212
LOCAL_STATIC_LIBRARIES += static-libcrypto
1313
LOCAL_MODULE := libsqlcipher
@@ -16,6 +16,11 @@ LOCAL_SRC_FILES := $(SQLCIPHER_SRC) \
1616
net_sqlcipher_database_SQLiteCompiledSql.cpp \
1717
net_sqlcipher_database_SQLiteDatabase.cpp \
1818
net_sqlcipher_database_SQLiteProgram.cpp \
19+
net_sqlcipher_database_SQLiteQuery.cpp \
20+
net_sqlcipher_database_SQLiteStatement.cpp \
21+
net_sqlcipher_CursorWindow.cpp \
22+
CursorWindow.cpp
23+
1924
# net_sqlcipher_database_SQLiteQuery.cpp \
2025
# atomic-android-sh.c \
2126
# SharedBuffer.cpp \
@@ -24,15 +29,6 @@ LOCAL_SRC_FILES := $(SQLCIPHER_SRC) \
2429
# net_sqlcipher_CursorWindow.cpp \
2530
# CursorWindow.cpp
2631

27-
# LOCAL_SRC_FILES := $(SQLCIPHER_SRC) \
28-
# net_sqlcipher_database_SQLiteCompiledSql.cpp \
29-
# net_sqlcipher_database_SQLiteDatabase.cpp \
30-
# net_sqlcipher_database_SQLiteProgram.cpp \
31-
# net_sqlcipher_database_SQLiteQuery.cpp \
32-
# net_sqlcipher_database_SQLiteStatement.cpp \
33-
# net_sqlcipher_CursorWindow.cpp \
34-
# CursorWindow.cpp
35-
3632
include $(BUILD_SHARED_LIBRARY)
3733

3834
include $(CLEAR_VARS)

jni/Application.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
APP_PROJECT_PATH := $(shell pwd)
2-
# APP_ABI := armeabi armeabi-v7a x86
3-
APP_ABI := armeabi
2+
APP_ABI := armeabi armeabi-v7a x86
3+
# APP_ABI := armeabi
44
APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk

jni/net_sqlcipher_CursorWindow.cpp

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
#include "jni_elements.h"
3333
#include "jni_exception.h"
3434
#include "sqlite3_exception.h"
35-
#include <utils/String16.h>
35+
//#include <utils/String16.h>
3636

3737
namespace sqlcipher {
38-
38+
3939
static jfieldID gWindowField;
4040
static jfieldID gBufferField;
4141
static jfieldID gSizeCopiedField;
@@ -323,13 +323,18 @@ LOG_WINDOW("Getting string for %d,%d from %p", row, column, window);
323323
if (type == FIELD_TYPE_STRING) {
324324
uint32_t size = field.data.buffer.size;
325325
if (size > 0) {
326-
#if WINDOW_STORAGE_UTF8
327-
// Pass size - 1 since the UTF8 is null terminated and we don't want a null terminator on the UTF16 string
328-
android::String16 utf16((char const *)window->offsetToPtr(field.data.buffer.offset), size - 1);
329-
return env->NewString((jchar const *)utf16.string(), utf16.size());
330-
#else
331-
return env->NewString((jchar const *)window->offsetToPtr(field.data.buffer.offset), size / 2);
332-
#endif
326+
return env->NewString((jchar const*)window->offsetToPtr(field.data.buffer.offset), size);
327+
// #if WINDOW_STORAGE_UTF8
328+
329+
// // std::wstring_convert<std::codecvt<char16_t,char,std::mbstate_t>,char16_t> convert;
330+
// // std::u16string utf16 = convert.from_bytes(window->offsetToPtr(field.data.buffer.offset));
331+
332+
// // Pass size - 1 since the UTF8 is null terminated and we don't want a null terminator on the UTF16 string
333+
// android::String16 utf16((char const *)window->offsetToPtr(field.data.buffer.offset), size - 1);
334+
// return env->NewString((jchar const *)utf16.string(), utf16.size());
335+
// #else
336+
// return env->NewString((jchar const *)window->offsetToPtr(field.data.buffer.offset), size / 2);
337+
// #endif
333338
} else {
334339
return env->NewStringUTF("");
335340
}
@@ -404,26 +409,39 @@ LOG_WINDOW("Copying string for %d,%d from %p", row, column, window);
404409
if (type == FIELD_TYPE_STRING) {
405410
uint32_t size = field.data.buffer.size;
406411
if (size > 0) {
407-
#if WINDOW_STORAGE_UTF8
408-
// Pass size - 1 since the UTF8 is null terminated and we don't want a null terminator on the UTF16 string
409-
android::String16 utf16((char const *)window->offsetToPtr(field.data.buffer.offset), size - 1);
410-
int32_t strSize = utf16.size();
411-
if (strSize > bufferSize || dst == NULL) {
412-
newArray = env->NewCharArray(strSize);
413-
env->SetCharArrayRegion(newArray, 0, strSize, (jchar const *)utf16.string());
414-
} else {
415-
memcpy(dst, (jchar const *)utf16.string(), strSize * 2);
416-
}
417-
sizeCopied = strSize;
418-
#else
419-
sizeCopied = size/2 + size % 2;
412+
420413
if (size > bufferSize * 2 || dst == NULL) {
421414
newArray = env->NewCharArray(sizeCopied);
422415
memcpy(newArray, (jchar const *)window->offsetToPtr(field.data.buffer.offset), size);
423416
} else {
424417
memcpy(dst, (jchar const *)window->offsetToPtr(field.data.buffer.offset), size);
425418
}
426-
#endif
419+
420+
421+
// #if WINDOW_STORAGE_UTF8
422+
423+
// // std::wstring_convert<std::codecvt<char16_t,char,std::mbstate_t>,char16_t> convert;
424+
// // std::u16string utf16 = convert.from_bytes(window->offsetToPtr(field.data.buffer.offset));
425+
426+
// // Pass size - 1 since the UTF8 is null terminated and we don't want a null terminator on the UTF16 string
427+
// android::String16 utf16((char const *)window->offsetToPtr(field.data.buffer.offset), size - 1);
428+
// int32_t strSize = utf16.size();
429+
// if (strSize > bufferSize || dst == NULL) {
430+
// newArray = env->NewCharArray(strSize);
431+
// env->SetCharArrayRegion(newArray, 0, strSize, (jchar const *)utf16.string());
432+
// } else {
433+
// memcpy(dst, (jchar const *)utf16.string(), strSize * 2);
434+
// }
435+
// sizeCopied = strSize;
436+
// #else
437+
// sizeCopied = size/2 + size % 2;
438+
// if (size > bufferSize * 2 || dst == NULL) {
439+
// newArray = env->NewCharArray(sizeCopied);
440+
// memcpy(newArray, (jchar const *)window->offsetToPtr(field.data.buffer.offset), size);
441+
// } else {
442+
// memcpy(dst, (jchar const *)window->offsetToPtr(field.data.buffer.offset), size);
443+
// }
444+
// #endif
427445
}
428446
} else if (type == FIELD_TYPE_INTEGER) {
429447
int64_t value;

jni/net_sqlcipher_database_SQLiteDatabase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,10 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
659659

660660
register_android_database_SQLiteDatabase(env);
661661
register_android_database_SQLiteCompiledSql(env);
662-
// register_android_database_SQLiteQuery(env);
663-
// register_android_database_SQLiteProgram(env);
664-
// register_android_database_SQLiteStatement(env);
665-
// register_android_database_CursorWindow(env);
662+
register_android_database_SQLiteQuery(env);
663+
register_android_database_SQLiteProgram(env);
664+
register_android_database_SQLiteStatement(env);
665+
register_android_database_CursorWindow(env);
666666

667667
//register_android_database_SQLiteDebug(env);
668668

jni/net_sqlcipher_database_SQLiteStatement.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@
1919
#define LOG_TAG "Cursor"
2020

2121
#include <jni.h>
22-
#include <JNIHelp.h>
23-
#include <android_runtime/AndroidRuntime.h>
24-
2522
#include <sqlite3.h>
26-
27-
#include <utils/Log.h>
28-
2923
#include <stdio.h>
3024
#include <string.h>
3125
#include <unistd.h>
3226

27+
#include "log.h"
28+
#include "jni_elements.h"
3329
#include "sqlite3_exception.h"
3430

3531
namespace sqlcipher {
@@ -142,9 +138,7 @@ int register_android_database_SQLiteStatement(JNIEnv * env)
142138
LOGE("Error locating fields");
143139
return -1;
144140
}
145-
146-
return android::AndroidRuntime::registerNativeMethods(env,
147-
"net/sqlcipher/database/SQLiteStatement", sMethods, NELEM(sMethods));
141+
return env->RegisterNatives(clazz, sMethods, NELEM(sMethods));
148142
}
149143

150144

0 commit comments

Comments
 (0)
0