Sunday, May 12, 2013

Some adb Commands for Android Debugging

  • Stop an Android app
    $adb shell am force-stop com.my.app.pkg
    
  • Uninstall a package
    $adb uninstall com.my.app.pkg
    
  • Install a package
    $adb install path/to/pkg/com.my.app.pkg
    

Get Started with JNI

Step 1: Create a Java test file JNITest.java
public class JNITest {
    public native void printString();

    static {
        System.loadLibrary("printstr");
    }   

    public void print() {
        printString();
    }   

    public static void main(String args[]) {
        (new JNITest()).print();
    }   
}
Step 2: Compile the Java file and generate a header file JNITest.h
$javac JNITest.java
$javah -jni JNITest
Step 3: Create a C test file printstr.c
#include <stdio.h>
#include <jni.h>
#include "JNITest.h"

JNIEXPORT void JNICALL Java_JNITest_printString (JNIEnv* env, jobject obj)
{
    printf("Hello, World!\n");
}
Step 4: Compile C file to produce the native lib "libprintstr.jnilib"
$gcc -dynamiclib -o libprintstr.jnilib -I/System/Library/Frameworks/JavaVM.framework/Headers printstr.c -framework JavaVM
Step 5: Run the Java test, which would show "Hello World!"
$java JNITest

Friday, May 10, 2013

First Try of Inserting Source Codes

Hightlight the source code with google code-prettify in two simple steps:
  1. add the following script to the HTML file:
    <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
  2. wrap the code piece with <pre class="prettyprint"> </pre> tag pair
Hello World in Java
public class Test {
  public static void main(String args[]) {
    System.out.println("Hello World!");
  }
}
Hello World in C
include <stdio.h>

int main() {
  printf("Hello World!");
  return 0;
}
Hello World in C++
include <iostream>
using namespace std;

int main() {
  cout<<"Hello World!";
  return 0;
}
HelloWorld in Assembly:
section .text
global _start
(ld)

_start:

  mov edx,len
  mov ecx,msg
  mov ebx,1
  mov eax,4
  int 0x80
  
  mov eax,1
  int 0x80

section .data

msg db 'Hello, World!',0xa
len equ $ - msg
HelloWorld in Python:
print "Hello World!"

Friday, March 9, 2012

Forgot to Think

Some time today, I realized that I haven't really "thought" for a long time. That is not good. A good procedure of life should be like this, do something, feel it, think it, then memorize your thoughts. Usually, I stopped after the first or second stage. One good example is living with my wife. Many times, I felt happiness when we were sharing something, like delicious food, moving movies, playing sports, or even just walking together on the way home. But usually, before I "really" felt it. It was interrupted by some other thing. When you lost it, you really lost.

Life does not seem to be a long long time that you do not need to worry about. Sometime, I worry about my life. To me, it is not a long one. I didn't mean that I could not live as long as others. I mean I do have limited time to do different things I want to do, to feel different emotions I enjoy, to get the ideas I haven't thought of. Some people are not afraid of death, but the opportunities, the opportunities that they do not have to do the things that they wanted. If that is the case, people may be dying even they are physically healthy, but losing the opportunities to do the things they wanted. On the other side, if a person is almost dead, but he think he has finished all the things he wanted to do. Then his death is just physical.

Just a friendly reminder that I should not stop thinking. That's it.

Saturday, December 24, 2011