2016年6月18日 星期六

[SQLITE] Compile OpenSSL in Android

Compile OpenSSL

!!Note!! Have to upgrade OpenSSL with version higher than 1.02f/1.01r, otherwise has security issue.
https://support.google.com/faqs/answer/6376725

My NDK version is r10d.

# export LIBRARY_PATH=/your/library/path

ARM platform

# $NDK_ROOT/build/tools/make-standalone-toolchain.sh --arch=arm --install-dir=toolchain --platform=android-19

armeabi

# cd src
# export ANDROID_DEV=$NDK_ROOT/platforms/android-19/arch-arm/usr
# CROSS_COMPILE_PREFIX=$LIBRARY_PATH/OpenSSL/toolchain/bin/arm-linux-androideabi-
# PREFIX=$LIBRARY_PATH/OpenSSL/dest/armeabi
# ./Configure --prefix=$PREFIX --cross-compile-prefix=$CROSS_COMPILE_PREFIX android threads no-shared
# make -s && make install

armeabi-v7a

# PREFIX=$LIBRARY_PATH/OpenSSL/dest/armeabi-v7a
# make clean
# ./Configure --prefix=$PREFIX --cross-compile-prefix=$CROSS_COMPILE_PREFIX android-armv7 threads no-shared
# make -s && make install

x86 platform

# $NDK_ROOT/build/tools/make-standalone-toolchain.sh --arch=x86 --install-dir=toolchainx86 --platform=android-19

x86

# make clean
# export ANDROID_DEV=$NDK_ROOT/platforms/android-19/arch-x86/usr
# CROSS_COMPILE_PREFIX=$LIBRARY_PATH/OpenSSL/toolchainx86/bin/i686-linux-android-
# PREFIX=$LIBRARY_PATH/OpenSSL/dest/x86
# cd src
# ./Configure --prefix=$PREFIX --cross-compile-prefix=$CROSS_COMPILE_PREFIX android threads no-shared
# make -s && make install

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include/sqlcipher

LOCAL_MODULE := sqlcipher
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libsqlcipher.a
include $(PREBUILT_STATIC_LIBRARY)

Modify Android.mk & Application.mk

[MMO] Cocos2D-x ~ MMO

AppWarp: Cocos2DX Multiplayer Game DevelopmentNinjaFight (tutorial)
planeshift
photon: VMware
KBEngine: Example

The Mana World
Worldforge

AnyNDK: EarthWarrior3D


2016年6月12日 星期日

[SQLITE] sqlite3 encryption/decryption

SQLite3 Simple works

sqlite3 commands.
http://www.runoob.com/sqlite/sqlite-syntax.html

SQLite Manager on Firefox. (Of course, it's free.)
https://addons.mozilla.org/zh-tw/firefox/addon/sqlite-manager/
https://dotblogs.com.tw/toysboy21/2014/04/21/144813

Android SQLite Database Tutorial.
http://www.tutorialspoint.com/android/android_sqlite_database.htm

SQLite for iOS.
http://pro.ctlok.com/2010/07/iphone-ipad-with-sqlite.html
https://www.facebook.com/teacherchi/posts/359338594127416

SQLite for Android.
https://github.com/sqlcipher/android-database-sqlcipher

CopyFiles.
http://www.iforce2d.net/cc2dxres/fileutils

SQLite Manager
http://www.sqlabs.com/sqlitemanager.php

SQLite3 Encryption/Decryption

Types of sqlite3 encryption/decryption

sqlcipher_export() to make plain text database to be encrypted.
https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export

SQL Cipher is free but need some works.
Here is SQL Cipher official web site:

sqlcipher gits:

Make Sqlcipher available on iOS and Android.
To Make Sqlcipher available on iOS.

To Make Sqlcipher available on Android.

Reference web sites:
My Solution:
1. Use SQLiteManager to encrypt the database.


2. To decrypt the database in code.

2014年10月13日 星期一

[Google Interview] No. 31 - Binary Search Tree Verification

Question: How to verify whether a binary tree is a binary search tree?

For example, the tree in Figure 1 is a binary search tree.
Figure 1: A binary search tree

A node in binary tree is defined as:

struct BinaryTreeNode
{
    int                    nValue;
    BinaryTreeNode*        pLeft; 
    BinaryTreeNode*        pRight;
};

[Google Interview] No. 30 - Median in Stream

Question: How to get the median from a stream of numbers at any time? The median is middle value of numbers. If the count of numbers is even, the median is defined as the average value of the two numbers in middle.

2014年10月3日 星期五

[Google Interview] No. 28 - A Pair with the Maximal Difference

Problem: A pair contains two numbers, and its second number is on the right side of the first one in an array. The difference of a pair is the minus result while subtracting the second number from the first one. Please implement a function which gets the maximal difference of all pairs in an array. For example, the maximal difference in the array {2, 4, 1, 16, 7, 5, 11, 9} is 11, which is the minus result of pair (16, 5).