Android ADB Shell Commands Notes

Prints a list of all attached emulator/device

  1. >adb devices
  2. List of devices attached
  3. xxxxxxxxxx      device

Forward socket connections

  1. >adb forward tcp:10172 tcp:9999

Restarts the adbd daemon with Root permissions

>adb root

Put /system partition in Writable mode

>adb remount
remount succeeded

Upload a specified file from your computer to an emulator/device

  1. >adb -s xxxxxxxxxx push term_emv_clc2 /system/tmp

Shell command mode

  1. >adb shell

How to compile Lua for Android

Update lmathlib.c

  1. Index: lmathlib.c
  2. ===================================================================
  3. --- lmathlib.c	(revision 4050)
  4. +++ lmathlib.c	(revision 4051)
  5. @@ -183,10 +183,10 @@
  6.      res = l_mathop(log)(x);
  7.    else {
  8.      lua_Number base = luaL_checknumber(L, 2);
  9. -#if !defined(LUA_USE_C89)
  10. -    if (base == l_mathop(2.0))
  11. -      res = l_mathop(log2)(x); else
  12. -#endif
  13. +//#if !defined(LUA_USE_C89)
  14. +//    if (base == l_mathop(2.0))
  15. +//      res = l_mathop(log2)(x); else
  16. +//#endif
  17.      if (base == l_mathop(10.0))
  18.        res = l_mathop(log10)(x);
  19.      else

Update luaconf.h

  1. Index: luaconf.h
  2. ===================================================================
  3. --- luaconf.h	(revision 4050)
  4. +++ luaconf.h	(revision 4051)
  5. @@ -677,7 +677,7 @@
  6.  ** macro must include header 'locale.h'.)
  7.  */
  8.  #if !defined(lua_getlocaledecpoint)
  9. -#define lua_getlocaledecpoint()		(localeconv()->decimal_point[0])
  10. +#define lua_getlocaledecpoint()		('.')
  11.  #endif
  12.  
  13.  /* }================================================================== */

Android.mk

  1. #
  2. # Android.mk
  3. #
  4. # Lua
  5. #
  6. LOCAL_PATH := $(call my-dir)/../src
  7.  
  8. include $(CLEAR_VARS)
  9.  
  10. LOCAL_MODULE     := Lua
  11. LOCAL_CPPFLAGS   := -std=c++17
  12. LOCAL_SRC_FILES := \
  13.     $(LOCAL_PATH)/lapi.c \
  14.     $(LOCAL_PATH)/lauxlib.c \
  15.     $(LOCAL_PATH)/lbaselib.c \
  16.     $(LOCAL_PATH)/lbitlib.c \
  17.     $(LOCAL_PATH)/lcode.c \
  18.     $(LOCAL_PATH)/lcorolib.c \
  19.     $(LOCAL_PATH)/lctype.c \
  20.     $(LOCAL_PATH)/ldblib.c \
  21.     $(LOCAL_PATH)/ldebug.c \
  22.     $(LOCAL_PATH)/ldo.c \
  23.     $(LOCAL_PATH)/ldump.c \
  24.     $(LOCAL_PATH)/lfunc.c \
  25.     $(LOCAL_PATH)/lgc.c \
  26.     $(LOCAL_PATH)/linit.c \
  27.     $(LOCAL_PATH)/liolib.c \
  28.     $(LOCAL_PATH)/llex.c \
  29.     $(LOCAL_PATH)/lmathlib.c \
  30.     $(LOCAL_PATH)/lmem.c \
  31.     $(LOCAL_PATH)/loadlib.c \
  32.     $(LOCAL_PATH)/lobject.c \
  33.     $(LOCAL_PATH)/lopcodes.c \
  34.     $(LOCAL_PATH)/loslib.c \
  35.     $(LOCAL_PATH)/lparser.c \
  36.     $(LOCAL_PATH)/lstate.c \
  37.     $(LOCAL_PATH)/lstring.c \
  38.     $(LOCAL_PATH)/lstrlib.c \
  39.     $(LOCAL_PATH)/ltable.c \
  40.     $(LOCAL_PATH)/ltablib.c \
  41.     $(LOCAL_PATH)/ltm.c \
  42.     $(LOCAL_PATH)/lua.c \
  43.     $(LOCAL_PATH)/luac.c \
  44.     $(LOCAL_PATH)/lundump.c \
  45.     $(LOCAL_PATH)/lutf8lib.c \
  46.     $(LOCAL_PATH)/lvm.c \
  47.     $(LOCAL_PATH)/lzio.c
  48.  
  49. include $(BUILD_STATIC_LIBRARY)

Android NDK C++17 Support

build.gradle

  1. apply plugin: 'com.android.application'
  2.  
  3. android {
  4.     compileSdkVersion 29
  5.     buildToolsVersion "29.0.2"
  6.     defaultConfig {
  7.         applicationId "com.example.myapplication"
  8.         minSdkVersion 15
  9.         targetSdkVersion 29
  10.         versionCode 1
  11.         versionName "1.0"
  12.         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  13.         externalNativeBuild {
  14.             cmake {
  15.                 cppFlags "-std=c++17"
  16.             }
  17.         }
  18.     }
  19.     buildTypes {
  20.         release {
  21.             minifyEnabled false
  22.             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  23.         }
  24.     }
  25.     externalNativeBuild {
  26.         cmake {
  27.             path "src/main/cpp/CMakeLists.txt"
  28.             version "3.10.2"
  29.         }
  30.     }
  31. }
  32.  
  33. dependencies {
  34.     implementation fileTree(dir: 'libs', include: ['*.jar'])
  35.     implementation 'androidx.appcompat:appcompat:1.0.2'
  36.     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  37.     testImplementation 'junit:junit:4.12'
  38.     androidTestImplementation 'androidx.test:runner:1.1.1'
  39.     androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
  40. }

Calling a C Function From Lua

Prepare So

  1. #include <math.h>
  2. #include <lua.h>
  3. #include <lauxlib.h>
  4. #include <lualib.h>
  5.  
  6. static int my_sum(lua_State *L){
  7.     int d1 = luaL_checknumber(L, 1);
  8.     int d2 = luaL_checknumber(L, 2);
  9.     lua_pushnumber(L, d1+d2);
  10.     return 1;
  11. }
  12.  
  13. static int my_info(lua_State *L){
  14.     lua_pushstring(L, "qinuu");
  15.     return 1;
  16. }
  17.  
  18. static const struct luaL_Reg test_lib[] = {
  19.     {"my_sum" , my_sum},
  20.     {"my_info" , my_info},
  21.     {NULL, NULL}
  22. };
  23.  
  24. int luaopen_test_lib(lua_State *L){
  25.     //luaL_newlib(L, test_lib); // 5.2
  26.     luaL_register(L, "test_lib",test_lib); // lua 5.1
  27.     return 1;
  28. }

Test

  1. local my_lib = require "test_lib"
  2.  
  3. print(type(test_lib))
  4.  
  5. print(test_lib.my_sum(23,17))
  6.  
  7. print(test_lib.my_info())

How to Connect Internal and External Networks at the same time : Windows

Delete Default Route

route delete 0.0.0.0

Add Gateway : Internal

route add 192.168.10.0 mask 255.255.255.0 192.168.10.1 -p

Add Gateway : External

route add 0.0.0.0 mask 0.0.0.0 192.168.20.1 -p

Check It!

route print
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.20.254 192.168.20.151 55
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.103 45

===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
192.168.1.0 255.255.255.0 192.168.1.1 1
192.168.3.0 255.255.255.0 192.168.3.1 1