今天看到一篇博客讲到可以在apk文件末尾追加数据以防止反编译工具反编,测试了一下,发现不能阻止。但是有个意外收获,就是文件末尾添加的数据可以作为渠道号来使用!
添加方法可以自己找工具,我使用的是c32asm。
获取文件末尾数据方法,如下:
//获取安装后的文件路径
try {
ApplicationInfo info = getPackageManager()
.getApplicationInfo(this.getPackageName(),
PackageManager.GET_UNINSTALLED_PACKAGES);
System.out.println("" + info.sourceDir);
readFileByBytes(info.sourceDir, 14);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 读取文件最后几个字节
public void readFileByBytes(String fileName, int lSize) {
File file = new File(fileName);
InputStream in = null;
try {
in = new FileInputStream(file);
int fileSize = in.available();
System.out.println("fileSize:" + fileSize);
int offset = fileSize - lSize;
if (offset < 0) {
offset = 0;
}
System.out.println("offset:" + offset);
byte[] arrByte = new byte[lSize];
in.skip(offset);
in.read(arrByte);
//in.read(arrByte, 15, arrByte.length);
String sChannel = new String(arrByte);
System.out.println("最后" + lSize + "字节数据为:" + sChannel);
TextView tv = (TextView)findViewById(R.id.tv1);
tv.setText(sChannel);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e1) {
}
}
}
测试这个功能过程中发现了一个问题,FileInputStream的read(byte[] b, int offset, int len)这个方法好奇葩,offset竟然是指的byte数组b的偏移量,无语了,并且skip的函数竟然也不确定能不能正确跳过,再次无语,哪位大神知道,望指点我一下!