2年前为了 了解 dex 文件格式. 顺手写了一个 dex 解析器. 支持 dex 的反汇编功能.
同时也支持把 dex 中的 java 类 导出一个类似 C/C++ 语言的头文件功能.
类似下面的头文件
class com_android_internal_os_ProcessStats
{
private:
const boolean DEBUG = false;
const int[] LOAD_AVERAGE_FORMAT = NULL;
const int[] PROCESS_FULL_STATS_FORMAT = NULL;
public:
const int PROCESS_FULL_STAT_MAJOR_FAULTS = 02 ;
const int PROCESS_FULL_STAT_MINOR_FAULTS = 01 ;
const int PROCESS_FULL_STAT_STIME = 04 ;
const int PROCESS_FULL_STAT_UTIME = 03 ;
const int PROCESS_FULL_STAT_VSIZE = 05 ;
private:
const int[] PROCESS_STATS_FORMAT = NULL;
public:
const int PROCESS_STAT_MAJOR_FAULTS = 01 ;
const int PROCESS_STAT_MINOR_FAULTS = 00 ;
const int PROCESS_STAT_STIME = 03 ;
const int PROCESS_STAT_UTIME = 02 ;
private:
const int[] SYSTEM_CPU_FORMAT = NULL;
const String TAG = "ProcessStats";
const boolean localLOGV = 0;
const Comparator sLoadComparator = 0;
////////////////////////////////////////////////////////
private:
long mBaseIdleTime;
long mBaseIoWaitTime;
long mBaseIrqTime;
long mBaseSoftIrqTime;
long mBaseSystemTime;
long mBaseUserTime;
byte[] mBuffer;
long[] mCpuSpeedTimes;
long[] mCpuSpeeds;
int[] mCurPids;
int[] mCurThreadPids;
long mCurrentSampleRealTime;
long mCurrentSampleTime;
boolean mFirst;
private:
boolean mIncludeThreads;
private:
long mLastSampleRealTime;
long mLastSampleTime;
float mLoad1;
float mLoad15;
float mLoad5;
private:
float[] mLoadAverageData;
ArrayList mProcStats;
long[] mProcessFullStatsData;
String[] mProcessFullStatsStringData;
long[] mProcessStatsData;
private:
long[] mRelCpuSpeedTimes;
int mRelIdleTime;
int mRelIoWaitTime;
int mRelIrqTime;
int mRelSoftIrqTime;
int mRelSystemTime;
int mRelUserTime;
private:
long[] mSinglePidStatsData;
long[] mSystemCpuData;
ArrayList mWorkingProcs;
private:
boolean mWorkingProcsSorted;
public:
void <clinit>();
public:
void <init>(boolean includeThreads);
private:
int[] collectStats(String statsFile,int parentPid,boolean first,int[] curPids,ArrayList);
long[] getCpuSpeedTimes(long[] out);
void getName(ProcessStats$Stats st,String cmdlineFile);
void printProcessCPU(PrintWriter pw,String prefix,int pid,String label,int totalTime,int user,int system,int iowait,int irq,int softIrq,int minFaults,int majFaults);
void printRatio(PrintWriter pw,long numerator,long denominator);
String readFile(String file,char endChar);
//////////////////////virtual method//////////////////////////////////
public:
virtual void buildWorkingProcs();
public:
virtual int countStats();
virtual int countWorkingStats();
public:
virtual long getCpuTimeForPid(int pid);
virtual long[] getLastCpuSpeedTimes();
public:
virtual int getLastIdleTime();
virtual int getLastIoWaitTime();
virtual int getLastIrqTime();
virtual int getLastSoftIrqTime();
virtual int getLastSystemTime();
virtual int getLastUserTime();
virtual ProcessStats$Stats getStats(int index);
virtual float getTotalCpuPercent();
virtual ProcessStats$Stats getWorkingStats(int index);
public:
virtual void init();
virtual void onLoadChanged(float load1,float load5,float load15);
virtual int onMeasureProcessName(String name);
public:
virtual String printCurrentLoad();
virtual String printCurrentState(long now);
public:
virtual void update();
}
dex 解析输出类似以下信息:
void android.media.videoeditor.AudioTrack::extractAudioWaveform(android.media.videoeditor.ExtractAudioWaveformProgressListener)
registers_size :0000000d: 13
insns_size :0000009e: 158
debug_info_off :0089ba78: 9026168
ins_size :00000002: 2
outs_size :00000009: 9
tries_size :00000000: 0
insns :002c9da0: 2923936
tries :00000000: 0
handlers :00000000: 0
002c9da0: 1208 |0000: const/4 v8 , 0
002c9da2: 54b0 9035 |0001: iget-object v0 , v11 , field@mAudioWaveformFilename //java.lang.String mAudioWaveformFilename
002c9da6: 3900 6300 |0003: if-nez v0 , 0066
002c9daa: 54b0 9935 |0005: iget-object v0 , v11 , field@mMANativeHelper //android.media.videoeditor.MediaArtistNativeHelper mMANativeHelper
002c9dae: 6e10 5342 0000 |0007: invoke-virtual v0 , meth@getProjectPath //java.lang.String android.media.videoeditor.MediaArtistNativeHelper::getProjectPath()
002c9db4: 0c0a |000a: move-result-object v10
002c9db6: 2200 0e17 |000b: new-instance v0 , type@Ljava/lang/StringBuilder;
002c9dba: 7010 e0eb 0000 |000d: invoke-direct v0 , meth@<init> //void java.lang.StringBuilder::<init>()
002c9dc0: 6e20 eceb a000 |0010: invoke-virtual v0 , v10 , meth@append //java.lang.StringBuilder java.lang.StringBuilder::append(java.lang.String)
002c9dc6: 0c00 |0013: move-result-object v0
002c9dc8: 1a01 6a0e |0014: const-string v1 , "/audioWaveformFile-"
002c9dcc: 6e20 eceb 1000 |0016: invoke-virtual v0 , v1 , meth@append //java.lang.StringBuilder java.lang.StringBuilder::append(java.lang.String)
002c9dd2: 0c00 |0019: move-result-object v0
002c9dd4: 6e10 e741 0b00 |001a: invoke-virtual v11 , meth@getId //java.lang.String android.media.videoeditor.AudioTrack::getId()
002c9dda: 0c01 |001d: move-result-object v1
002c9ddc: 6e20 eceb 1000 |001e: invoke-virtual v0 , v1 , meth@append //java.lang.StringBuilder java.lang.StringBuilder::append(java.lang.String)
002c9de2: 0c00 |0021: move-result-object v0
002c9de4: 1a01 2a0e |0022: const-string v1 , ".dat"
002c9de8: 6e20 eceb 1000 |0024: invoke-virtual v0 , v1 , meth@append //java.lang.StringBuilder java.lang.StringBuilder::append(java.lang.String)
002c9dee: 0c00 |0027: move-result-object v0
002c9df0: 6e10 feeb 0000 |0028: invoke-virtual v0 , meth@toString //java.lang.String java.lang.StringBuilder::toString()
002c9df6: 0c00 |002b: move-result-object v0
002c9df8: 2381 471b |002c: new-array v1 , v8 , type@[Ljava/lang/Object;
002c9dfc: 7120 a1eb 1000 |002e: invoke-static v0 , v1 , meth@format //java.lang.String java.lang.String::format(java.lang.String,java.lang.Object[])
002c9e02: 0c03 |0031: move-result-object v3
002c9e04: 54b0 9935 |0032: iget-object v0 , v11 , field@mMANativeHelper //android.media.videoeditor.MediaArtistNativeHelper mMANativeHelper
002c9e08: 52b1 8f35 |0034: iget v1 , v11 , field@mAudioType //int mAudioType
002c9e0c: 6e20 4442 1000 |0036: invoke-virtual v0 , v1 , meth@getAudioCodecType //int android.media.videoeditor.MediaArtistNativeHelper::getAudioCodecType(int)
002c9e12: 0a09 |0039: move-result v9
002c9e14: 2b09 5000 0000 |003a: packed-switch v9 , string@80
002c9e1a: 2200 f016 |003d: new-instance v0 , type@Ljava/lang/IllegalStateException;
002c9e1e: 2201 0e17 |003f: new-instance v1 , type@Ljava/lang/StringBuilder;
002c9e22: 7010 e0eb 0100 |0041: invoke-direct v1 , meth@<init> //void java.lang.StringBuilder::<init>()
002c9e28: 1a02 52a4 |0044: const-string v2 , "Unsupported codec type: "
002c9e2c: 6e20 eceb 2100 |0046: invoke-virtual v1 , v2 , meth@append //java.lang.StringBuilder java.lang.StringBuilder::append(java.lang.String)
002c9e32: 0c01 |0049: move-result-object v1
002c9e34: 6e20 e7eb 9100 |004a: invoke-virtual v1 , v9 , meth@append //java.lang.StringBuilder java.lang.StringBuilder::append(int)
002c9e3a: 0c01 |004d: move-result-object v1
002c9e3c: 6e10 feeb 0100 |004e: invoke-virtual v1 , meth@toString //java.lang.String java.lang.StringBuilder::toString()
002c9e42: 0c01 |0051: move-result-object v1
002c9e44: 7020 fdea 1000 |0052: invoke-direct v0 , v1 , meth@<init> //void java.lang.IllegalStateException::<init>(java.lang.String)
002c9e4a: 2700 |0055: throw v0
002c9e4c: 1254 |0056: const/4 v4 , 5
002c9e4e: 1306 a000 |0057: const/16 v6 , 160
002c9e52: 54b0 9935 |0059: iget-object v0 , v11 , field@mMANativeHelper //android.media.videoeditor.MediaArtistNativeHelper mMANativeHelper
002c9e56: 54b1 9d35 |005b: iget-object v1 , v11 , field@mUniqueId //java.lang.String mUniqueId
002c9e5a: 54b2 9635 |005d: iget-object v2 , v11 , field@mFilename //java.lang.String mFilename
002c9e5e: 1225 |005f: const/4 v5 , 2
002c9e60: 07c7 |0060: move-object v7 , v12
002c9e62: 7409 3d42 0000 |0061: invoke-virtual/range
002c9e68: 5bb3 9035 |0064: iput-object v3 , v11 , field@mAudioWaveformFilename //java.lang.String mAudioWaveformFilename
002c9e6c: 2200 2017 |0066: new-instance v0 , type@Ljava/lang/ref/SoftReference;
002c9e70: 2201 e406 |0068: new-instance v1 , type@Landroid/media/videoeditor/WaveformData;
002c9e74: 54b2 9035 |006a: iget-object v2 , v11 , field@mAudioWaveformFilename //java.lang.String mAudioWaveformFilename
002c9e78: 7020 c943 2100 |006c: invoke-direct v1 , v2 , meth@<init> //void android.media.videoeditor.WaveformData::<init>(java.lang.String)
002c9e7e: 7020 36ec 1000 |006f: invoke-direct v0 , v1 , meth@<init> //void java.lang.ref.SoftReference::<init>(java.lang.Object)
002c9e84: 5bb0 9f35 |0072: iput-object v0 , v11 , field@mWaveformData //java.lang.ref.SoftReference mWaveformData
002c9e88: 0e00 |0074: return-void
002c9e8a: 1304 0a00 |0075: const/16 v4 , 10
002c9e8e: 1306 4001 |0077: const/16 v6 , 320
002c9e92: 28e0 |0079: goto 0059
002c9e94: 1304 2000 |007a: const/16 v4 , 32
002c9e98: 1306 0004 |007c: const/16 v6 , 1024
002c9e9c: 28db |007e: goto 0059
002c9e9e: 1304 2400 |007f: const/16 v4 , 36
002c9ea2: 1306 8004 |0081: const/16 v6 , 1152
002c9ea6: 28d6 |0083: goto 0059
002c9ea8: 1304 4000 |0084: const/16 v4 , 64
002c9eac: 1306 0008 |0086: const/16 v6 , 2048
002c9eb0: 28d1 |0088: goto 0059
002c9eb2: 0000 |0089: nop
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!