技术文章

A collection of 24 posts

Dec 21, 2016

Efficient Thread-safe Singleton in Java

Single-threaded Version class Foo { private static Helper helper; public static Helper getHelper() { if (helper == null) { helper = new Helper(); } return helper; } } The code works fine in single thread case. If multiple threads access getHelper(

Dec 8, 2016

Avoid Memory Leaks in Android

Java is a garbage-collecting-language, the garbage collector deals with memory properly on most cases. But we may still encounter memory leaks due to some logical bugs. I'll list some common cases that cause

Dec 2, 2016

Monitor Android Looper

As I write in the previous post Android Message Handling Mechanism, all messages dispatched to main thread will be handled in the looper of main thread. If a message cost a long time,

Nov 22, 2016

Android Message Handling Mechanism

I've been working on a performance monitor library for some time. While I'm implementing the looper-monitor feature, I found it's necessary to get clear on the Android message handling mechanism. In this article,

Aug 25, 2016

Android SQLite Insertion Optimization

Preface Recently, I've been working on a technical story which inserts more than 100,000 records at startup. The whole application relies on these data, so I have to make the insertion synchronous,

Jul 21, 2016

Object Initialization in Java

Preface Before we get started, let's see a snippet first. public class Foo { { bar = 1; } private int bar = 3; private static int baz = 4; static { baz = 2; } public Foo() { bar = 5; } public static

May 12, 2016

Analyzing Multidex Source Code

Recently I read the source code of Google's multidex library due to some reasons. I'll focus on how to load multiple dex files rather than how to split classes into multiple dex files

Apr 7, 2016

Android GOT Hook

Preface In this post, I assumed the readers have basic knowledge of ELF file format. I'm gonna talk about the dynamic linking and relocation in this post. Although it's the beginner level, basic

Mar 28, 2016

ARM and Thumb Instruction Set

Recently, I've been asked about the code in "TinyInjector". The code for calling fuctions in remote process made somebody confused. Let's take a look at the code. regs.ARM_pc = function_

Mar 22, 2016

Bypass SELinux on Android

Background As I wrote in the previous post "Shared Library Injection in Android", I've made an injection util on Android. The injection util works perfectly on Android 4.0 device, but

Mar 22, 2016

Shared Library Injection in Android

Introduction Injection is a technique that enable us running our code inside a remote process. Usually, we compile the code into a shared library and force the remote process to load it, so