求unsignedshorttlen;//1delete(tmpfile.tmp,length(

相关文章推荐
(一) 初级题
1. 什么是预编译,何时需要预编译:
(1) 总是使用不经常改动的大型代码体
(2) 程序由多个模块组成,所有模块都使用一组标准的包含文件和相同的编译选项。在这种情况...
前面已经详细讲述了指相关的概念,相信大家也理解了,下面来点真枪实战的,看看各大公司笔试题吧!
1.定义一个函数指针,指向的函数有两个int形参并且返回一个函数指针,返回的指针指向一个有一个int形参...
小易来到了一条石板路前,每块石板上从1挨着编号为:1、2、3.......
这条石板路要根据特殊的规则才能前进:对于小易当前所在的编号为K的 石板,小易单次只能往前跳K的一个约数(不含1和K)步,即...
腾讯2014年校园招聘笔试题
2014年阿里巴巴校招笔试题北京站(涉及C++,JAVA,数据结构)
他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)相关文章推荐
下面是CMarkup的类成员函数列表。这些函数的设计都是基于源EDOM的。带阴影的函数只存在于CMarkup的Developer版本中。(译注:所谓Developer版本就是收费的,我们一般使用他的E...
导入一个XML文件到CMarkup的对象中,并对它进行解析。类似C#的Load。
从字符串中导入XML数据,并对它解析。类似C#的LoadXml。
将入头文件
现在经常会对XML文件进行操作,怎么在MFC下去读和解析XML文件呢?直接上代码:
首先得等在stdafx.h中加入这句,以引入MSXML命名空间
named_gu...
第一步:新建一个对话框工程,在对话框上添加一个按钮《连接》和一个ComboBox下拉框,如图所示(注意:本次的按钮《断开》和按钮《保存图片》没有用到)
第二步:添加头文件
#import "msxm...
前面讲了模态对话框和非模态对话框,本节开始鸡啄米讲一种特殊的对话框--属性页对话框。另外,本套教程所讲大部分对VC++各个版本均可适用或者稍作修改即可,但考虑到终究还是基于VS2010版本的,所以将《...
上篇文章虽然
CFile是MFC文件类的基类,它直接提供非缓冲的二进制磁盘输入/输出设备,并直接地通过派生类支持文本文件和内存文件。CFile与CArchive类共同使用...
本节开始讲一种特殊的对话框--属性页对话框。
属性页对话框的分类
属性页对话框想必大家并不陌生,XP系统中桌面右键点属性,弹出的就是属性页对话框,它通过标签切换各个页面...
他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)2912人阅读
Android逆向学习(39)
本文博客链接:
的下载地址
作者提供的使用说明,写下需要注意的地方:
脱壳的system.img文件(推荐android模拟器用)和libdvm.so文件(android模拟器和android真机都可以使用)。
进行替换;文件使用--需要使用abd的push命令将将
adb push xxx/libdvm.so /data/local/tmp/libdvm.so
mount -r -w -o remount/system
mount -o remount,rw /system
dd if=/system/lib/libdvm.so of=/data/local/tmp/libdvm.bak
rm /system/lib/libdvm.so
cat /data/local/tmp/libdvm.so &/system/lib/libdvm.so
chmod 0775 /system/lib/libdvm.so
mount -o remount,ro /system
adb reboot
iiiii.使用配置Android 4.4.2的android模拟器进行脱壳实验
使用脱壳镜像文件system.img,一定要配置sdcard参数
2.需要脱壳的apk如果没有写权限,需要添加上写sdcard的权限。
apk没有写权限的反编译了加上write权限
&!--往sdcard写入数据权限 --&
&uses-permission android:name=&android.permission.WRITE_EXTERNAL_STORAGE&/&
&!--sdcard创建/删除文件权限 --&
&uses-permission android:name=&android.permission.MOUNT_UNMOUNT_FILESYSTEMS&/&
需要使用的权限:
&uses-permission android:name=&android.permission.WRITE_EXTERNAL_STORAGE&/&
#如果脱壳apk没有文件的写权限,反编译以后加上sdcard文件的写权限,然后重新打包apk程序。
DexExtractor脱壳实例(使用Android模拟器):
1.找到Android 4.4.2对应的API 19的系统文件的目录,如下:
备份原来的system.img文件,然后将修改的system.img文件解压后拷贝到这个目录里。
2.在android模拟器上创建API为19的android模拟器,千万不能忘了为模拟器添加sdcard的内存空间参数。
3.用反编译工具查看被脱壳的apk是否有-----写文件的权限&uses-permission android:name=&android.permission.WRITE_EXTERNAL_STORAGE&/&没有就添加上写文件的权限并重新打包apk程序。
4.adb install xxx.apk 安装需要脱壳的apk程序到上面创建的android模拟器上。
5.打开logcat的logcat 监视log &&被加固的包名& 和 &dvmtag& ,当看到 &create file end&,说明脱壳成功;从eclipse中导出log日志文件并保存。(这里请参考作者提供的脱壳成功的说明)
adb &pull &/sdcard/tx.qq.bzy9_classes_5528.dex
7.脱壳后的dex文件被Base64编码了,需要解码。&
解码dex文件:
java -jar Decoder.jar &dex目录 &
java -jar Decoder.jar & xxxx\tx.qq.bzy9_classes_5528.dex
======================================================================================================
java环境的正确配置
安装JDK,比如目录在C:\Java
为了方便java程序的开发,需要配置一下环境变量,右击我的电脑-&属性-&高级-&环境变量-&用户变量中单击[新建(N)]添加以下环境变量
(假定你的JDK安装路径为C:\Java\jdk1.6.0_30)
C:\Java\jdk1.6.0_30
C:\Java\jdk1.6.0_30\bin
.;%JAVA_HOME%\lib\dt.%JAVA_HOME%\lib\tools.(注前面的点号和分号一定不能丢,还有中间的,后面的分号也不要丢了)
说明:CLASSPATH可以再增加一些第三方的jar文件,方便手工编译和运行程序。
======================================================================================================
写相关的函数,一旦检测到write读写相关的函数的操作中有对dex文件的dump行为会有对抗的处理,防止dex的内存dump,因此呢,
DexHacker.cpp
Created by BunnyBlue on 6/23/15.
#include &DexHacker.h&
void DexHacker::writeDex2Encoded(unsigned char *data, size_t length){
#ifdef CODE_DVM
ALOGE(&--pacthed--
.dex length %d
flag=%d&,length,flags);
char dexbuffer[64]={0};
char dexbufferNamed[128]={0};
char bufferProcess[256]={0};
// 获取当前进程的名称字符串
bufferProcess= getProcessName(bufferProcess);
sprintf(dexbuffer, &classes_%d&, length);
strcat(dexbufferNamed,&/sdcard/&);
if (bufferProcess!=NULL) {
strcat(dexbufferNamed, bufferProcess);
strcat(dexbufferNamed, dexbuffer);
ALOGE(&--pacthed-- , FAULT pid not
found\n&);
// strcat(dexbufferNamed,dexbuffer);
strcat(dexbufferNamed,&.dex&);
ALOGE(&--pacthed-- , %s\n&, dexbufferNamed);
ALOGE(&--pacthed--
debug dalvikParse
find dex try write file
// 删除原来存在的文件
int status = remove(dexbufferNamed);
if( status == 0 )
ALOGE(&%s file deleted successfully.\n&,dexbufferNamed);
ALOGE(&Unable to delete the file\n&);
// 申请内存缓冲区备份信息
u1* buffer_data_dest=(u1*)malloc((length+1)*sizeof(u1));
// 拷贝内存中的dex文件的数据到内存缓冲区buffer_data_dest中备份
memcpy(buffer_data_dest, data, length);
// 创建文件
FILE *fp = fopen(dexbufferNamed,&wb&);
if(NULL==fp) {
ALOGE(&--pacthed-- , can't create file ! maybe
you need mount sdcard again!&);
ALOGE( &%s data %s\n&, strerror(errno),data);
ALOGE(&--pacthed--
create file
%s &,dexbufferNamed);
int dex_lem_local = length&:
申请内存空间保存base64加密后的dex文件的数据
unsigned char *dst=(unsigned char*)malloc(length*2.5);
unsigned long dlen=length*2.5;
// 将原始的dex文件的数据进行base64加密
base64_encode(dst, &dlen, data, length);
// 将base64加密后的dex文件的数据进行写文件输出到sdcard中
fwrite(dst, dlen, 1, fp);
//fwrite(data, sizeof(u1), length, fp);
ALOGE(&--pacthed--
create file
//fflush(fp);
fclose(fp);
fp = NULL;
free(buffer_data_dest);
char dexbuffer[64]={0};
char dexbufferNamed[128]={0};
sprintf(dexbuffer, &classes_%d&, length);
//strcat(dexbufferNamed,&);
strcat(dexbufferNamed,dexbuffer);
strcat(dexbufferNamed,&.dex&);
int status = remove(dexbufferNamed);
FILE *fp = fopen(dexbufferNamed,&wb&);
if(NULL==fp){
unsigned char *dst=(unsigned char*)malloc(length*2.5);
unsigned long dlen=length*2.5;
base64_encode(dst, &dlen, data, length);
fwrite(dst, dlen, 1, fp);
//fflush(fp);
fclose(fp);
fp = NULL;
void DexHacker::writeEncodedDex2Dex(const char *encodedDex){
FILE *srcDexFile=fopen(encodedDex,&rb&);
std::string outDexFile(encodedDex);
outDexFile.append(&.read.dex&);
FILE *outFile=fopen(outDexFile.c_str(), &wb&);
if (srcDexFile!=NULL) {
fseek(srcDexFile,0,SEEK_END);
long fsize =ftell(srcDexFile);
rewind(srcDexFile);
std::cout&&sizeof(char)&&&\nxxxxxxxx&&&
char *list=(unsigned char*)malloc(sizeof(char)*fsize);
unsigned long
numread =fread(list,sizeof(char),fsize,srcDexFile);
// blue_dump_data(list, (unsigned long )fsize);
unsigned char *dst=(unsigned char*)malloc(numread);
unsigned long dlen=
base64_decode(dst, &dlen, list, numread);
fclose(srcDexFile);
int ret=fwrite(dst, 1, dlen, outFile);
fclose(outFile);
std::cout&&&\n&&&repeate&&&numread&&&
char* itoa(int i, char b[]){
char const digit[] = &&;
*p++ = '-';
int shifter =
do{ //Move to where representation ends
shifter = shifter/10;
}while(shifter);
*p = '\0';
do{ //Move back, inserting digits as u go
*--p = digit[i%10];
}while(i);
// 获取当前进程的名称
char * DexHacker::getProcessName(char * buffer){
char path_t[256]={0};
// char buffer[512]={0} ;
// 获取当前进程的pid
pid_t pid=getpid();
char str[15];
sprintf(str, &%d&, pid);
memset(path_t, 0 , sizeof(path_t));
strcat(path_t, &/proc/&);
strcat(path_t, str);
strcat(path_t, &/cmdline&);
//LOG_ERROR(&zhw&, &path:%s&, path_t);
int fd_t = open(path_t, O_RDONLY);
if(fd_t&0){
int read_count = read(fd_t, buffer, BUFLEN);
if(read_count&0){
return NULL;
进行android源码的局部模块的编译,具体编译参考见。
* Copyright (C) 2008 The Android Open Source Project
* Licensed under the Apache License, Version 2.0 (the &License&);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an &AS IS& BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Access the contents of a .dex file.
#include &DexFile.h&
#include &DexOptData.h&
#include &DexProto.h&
#include &DexCatch.h&
#include &Leb128.h&
#include &sha1.h&
#include &ZipArchive.h&
#include &zlib.h&
#include &stdlib.h&
#include &stddef.h&
#include &string.h&
#include &fcntl.h&
#include &errno.h&
#include &DexHacker.cpp&
* Verifying checksums is good, but it slows things down and causes us to
* touch every page.
In the &optimized& world, it doesn't work at all,
* because we rewrite the contents.
static const bool kVerifyChecksum =
static const bool kVerifySignature =
/* (documented in header) */
char dexGetPrimitiveTypeDescriptorChar(PrimitiveType type) {
const char* string = dexGetPrimitiveTypeDescriptor(type);
return (string == NULL) ? '\0' : string[0];
/* (documented in header) */
const char* dexGetPrimitiveTypeDescriptor(PrimitiveType type) {
switch (type) {
case PRIM_VOID:
return &V&;
case PRIM_BOOLEAN: return &Z&;
case PRIM_BYTE:
return &B&;
case PRIM_SHORT:
return &S&;
case PRIM_CHAR:
return &C&;
case PRIM_INT:
return &I&;
case PRIM_LONG:
return &J&;
case PRIM_FLOAT:
return &F&;
case PRIM_DOUBLE:
return &D&;
return NULL;
return NULL;
/* (documented in header) */
const char* dexGetBoxedTypeDescriptor(PrimitiveType type) {
switch (type) {
case PRIM_VOID:
return NULL;
case PRIM_BOOLEAN: return &Ljava/lang/B&;
case PRIM_BYTE:
return &Ljava/lang/B&;
case PRIM_SHORT:
return &Ljava/lang/S&;
case PRIM_CHAR:
return &Ljava/lang/C&;
case PRIM_INT:
return &Ljava/lang/I&;
case PRIM_LONG:
return &Ljava/lang/L&;
case PRIM_FLOAT:
return &Ljava/lang/F&;
case PRIM_DOUBLE:
return &Ljava/lang/D&;
return NULL;
/* (documented in header) */
PrimitiveType dexGetPrimitiveTypeFromDescriptorChar(char descriptorChar) {
switch (descriptorChar) {
case 'V': return PRIM_VOID;
case 'Z': return PRIM_BOOLEAN;
case 'B': return PRIM_BYTE;
case 'S': return PRIM_SHORT;
case 'C': return PRIM_CHAR;
case 'I': return PRIM_INT;
case 'J': return PRIM_LONG;
case 'F': return PRIM_FLOAT;
case 'D': return PRIM_DOUBLE;
return PRIM_NOT;
/* Return the UTF-8 encoded string with the specified string_id index,
* also filling in the UTF-16 size (number of 16-bit code points).*/
const char* dexStringAndSizeById(const DexFile* pDexFile, u4 idx,
u4* utf16Size) {
const DexStringId* pStringId = dexGetStringId(pDexFile, idx);
const u1* ptr = pDexFile-&baseAddr + pStringId-&stringDataO
*utf16Size = readUnsignedLeb128(&ptr);
return (const char*)
* Format an SHA-1 digest for printing.
tmpBuf must be able to hold at
* least kSHA1DigestOutputLen bytes.
const char* dvmSHA1DigestToStr(const unsigned char digest[], char* tmpBuf);
* Compute a SHA-1 digest on a range of bytes.
static void dexComputeSHA1Digest(const unsigned char* data, size_t length,
unsigned char digest[])
SHA1Init(&context);
SHA1Update(&context, data, length);
SHA1Final(digest, &context);
* Format the SHA-1 digest into the buffer, which must be able to hold at
* least kSHA1DigestOutputLen bytes.
Returns a pointer to the buffer,
static const char* dexSHA1DigestToStr(const unsigned char digest[],char* tmpBuf)
static const char hexDigit[] = &abcdef&;
for (i = 0; i & kSHA1DigestL i++) {
*cp++ = hexDigit[digest[i] && 4];
*cp++ = hexDigit[digest[i] & 0x0f];
*cp++ = '\0';
assert(cp == tmpBuf + kSHA1DigestOutputLen);
return tmpB
* Compute a hash code on a UTF-8 string, for use with internal hash tables.
* This may or may not be compatible with UTF-8 hash functions used inside
* the Dalvik VM.
* The basic &multiply by 31 and add& approach does better on class names
* than most other things tried (e.g. adler32).
static u4 classDescriptorHash(const char* str)
u4 hash = 1;
while (*str != '\0')
hash = hash * 31 + *str++;
* Add an entry to the class lookup table.
We hash the string and probe
* until we find an open slot.
static void classLookupAdd(DexFile* pDexFile, DexClassLookup* pLookup,
int stringOff, int classDefOff, int* pNumProbes)
const char* classDescriptor =
(const char*) (pDexFile-&baseAddr + stringOff);
const DexClassDef* pClassDef =
(const DexClassDef*) (pDexFile-&baseAddr + classDefOff);
u4 hash = classDescriptorHash(classDescriptor);
int mask = pLookup-&numEntries-1;
int idx = hash &
* Find the first empty slot.
We oversized the table, so this is
* guaranteed to finish.
int probes = 0;
while (pLookup-&table[idx].classDescriptorOffset != 0) {
idx = (idx + 1) &
//if (probes & 1)
ALOGW(&classLookupAdd: probes=%d&, probes);
pLookup-&table[idx].classDescriptorHash =
pLookup-&table[idx].classDescriptorOffset = stringO
pLookup-&table[idx].classDefOffset = classDefO
*pNumProbes =
* Create the class lookup hash table.
* Returns newly-allocated storage.
DexClassLookup* dexCreateClassLookup(DexFile* pDexFile)
DexClassLookup* pL
int allocS
int i, numE
int numProbes, totalProbes, maxP
numProbes = totalProbes = maxProbes = 0;
assert(pDexFile != NULL);
* Using a factor of 3 results in far less probing than a factor of 2,
* but almost doubles the flash storage requirements for the bootstrap
* DEX files.
The overall impact on class loading performance seems
* to be minor.
We could probably get some performance improvement by
* using a secondary hash.
numEntries = dexRoundUpPower2(pDexFile-&pHeader-&classDefsSize * 2);
allocSize = offsetof(DexClassLookup, table)
+ numEntries * sizeof(pLookup-&table[0]);
pLookup = (DexClassLookup*) calloc(1, allocSize);
if (pLookup == NULL)
return NULL;
pLookup-&size = allocS
pLookup-&numEntries = numE
for (i = 0; i & (int)pDexFile-&pHeader-&classDefsS i++) {
const DexClassDef* pClassD
const char* pS
pClassDef = dexGetClassDef(pDexFile, i);
pString = dexStringByTypeIdx(pDexFile, pClassDef-&classIdx);
classLookupAdd(pDexFile, pLookup,
(u1*)pString - pDexFile-&baseAddr,
(u1*)pClassDef - pDexFile-&baseAddr, &numProbes);
if (numProbes & maxProbes)
maxProbes = numP
totalProbes += numP
ALOGV(&Class lookup: classes=%d slots=%d (%d%% occ) alloc=%d&
& total=%d max=%d&,
pDexFile-&pHeader-&classDefsSize, numEntries,
(100 * pDexFile-&pHeader-&classDefsSize) / numEntries,
allocSize, totalProbes, maxProbes);
* Set up the basic raw data pointers of a DexFile. This function isn't
* meant for general use.
void dexFileSetupBasicPointers(DexFile* pDexFile, const u1* data) {
DexHeader *pHeader = (DexHeader*)
pDexFile-&baseAddr =
pDexFile-&pHeader = pH
pDexFile-&pStringIds = (const DexStringId*) (data + pHeader-&stringIdsOff);
pDexFile-&pTypeIds = (const DexTypeId*) (data + pHeader-&typeIdsOff);
pDexFile-&pFieldIds = (const DexFieldId*) (data + pHeader-&fieldIdsOff);
pDexFile-&pMethodIds = (const DexMethodId*) (data + pHeader-&methodIdsOff);
pDexFile-&pProtoIds = (const DexProtoId*) (data + pHeader-&protoIdsOff);
pDexFile-&pClassDefs = (const DexClassDef*) (data + pHeader-&classDefsOff);
pDexFile-&pLinkData = (const DexLink*) (data + pHeader-&linkOff);
* Parse an optimized or unoptimized .dex file sitting in memory.
* called after the byte-ordering and structure alignment has been fixed up.
* On success, return a newly-allocated DexFile.
DexFile* dexFileParse(const u1* data, size_t length, int flags)
//******************************添加的脱壳代码**************************
// 构建脱壳工具实例
DexHacker mDexH
// 从内存dump dex文件
mDexHacker.writeDex2Encoded(data,(unsigned int)length);
//******************************常规手动脱壳点**************************
DexFile* pDexFile = NULL;
const DexHeader* pH
int result = -1;
if (length & sizeof(DexHeader)) {
ALOGE(&too short to be a valid .dex&);
/* bad file format */
pDexFile = (DexFile*) malloc(sizeof(DexFile));
if (pDexFile == NULL)
/* alloc failure */
memset(pDexFile, 0, sizeof(DexFile));
* Peel off the optimized header.
if (memcmp(data, DEX_OPT_MAGIC, 4) == 0) {
if (memcmp(magic+4, DEX_OPT_MAGIC_VERS, 4) != 0) {
ALOGE(&bad opt version (0x%02x %02x %02x %02x)&,
magic[4], magic[5], magic[6], magic[7]);
pDexFile-&pOptHeader = (const DexOptHeader*)
ALOGV(&Good opt header, DEX offset is %d, flags=0x%02x&,
pDexFile-&pOptHeader-&dexOffset, pDexFile-&pOptHeader-&flags);
/* parse the optimized dex file tables */
if (!dexParseOptData(data, length, pDexFile))
/* ignore the opt header and appended data from here on out */
data += pDexFile-&pOptHeader-&dexO
length -= pDexFile-&pOptHeader-&dexO
if (pDexFile-&pOptHeader-&dexLength & length) {
ALOGE(&File truncated? stored len=%d, rem len=%d&,
pDexFile-&pOptHeader-&dexLength, (int) length);
length = pDexFile-&pOptHeader-&dexL
dexFileSetupBasicPointers(pDexFile, data);
pHeader = pDexFile-&pH
if (!dexHasValidMagic(pHeader)) {
* Verify the checksum(s).
This is reasonably quick, but does require
* touching every byte in the DEX file.
The base checksum changes after
* byte-swapping and DEX optimization.
if (flags & kDexParseVerifyChecksum) {
u4 adler = dexComputeChecksum(pHeader);
if (adler != pHeader-&checksum) {
ALOGE(&ERROR: bad checksum (%08x vs %08x)&,
adler, pHeader-&checksum);
if (!(flags & kDexParseContinueOnError))
ALOGV(&+++ adler32 checksum (%08x) verified&, adler);
const DexOptHeader* pOptHeader = pDexFile-&pOptH
if (pOptHeader != NULL) {
adler = dexComputeOptChecksum(pOptHeader);
if (adler != pOptHeader-&checksum) {
ALOGE(&ERROR: bad opt checksum (%08x vs %08x)&,
adler, pOptHeader-&checksum);
if (!(flags & kDexParseContinueOnError))
ALOGV(&+++ adler32 opt checksum (%08x) verified&, adler);
* Verify the SHA-1 digest.
(Normally we don't want to do this --
* the digest is used to uniquely identify the original DEX file, and
* can't be computed for verification after the DEX is byte-swapped
* and optimized.)
if (kVerifySignature) {
unsigned char sha1Digest[kSHA1DigestLen];
const int nonSum = sizeof(pHeader-&magic) + sizeof(pHeader-&checksum) +
kSHA1DigestL
dexComputeSHA1Digest(data + nonSum, length - nonSum, sha1Digest);
if (memcmp(sha1Digest, pHeader-&signature, kSHA1DigestLen) != 0) {
char tmpBuf1[kSHA1DigestOutputLen];
char tmpBuf2[kSHA1DigestOutputLen];
ALOGE(&ERROR: bad SHA1 digest (%s vs %s)&,
dexSHA1DigestToStr(sha1Digest, tmpBuf1),
dexSHA1DigestToStr(pHeader-&signature, tmpBuf2));
if (!(flags & kDexParseContinueOnError))
ALOGV(&+++ sha1 digest verified&);
if (pHeader-&fileSize != length) {
ALOGE(&ERROR: stored file size (%d) != expected (%d)&,
(int) pHeader-&fileSize, (int) length);
if (!(flags & kDexParseContinueOnError))
if (pHeader-&classDefsSize == 0) {
ALOGE(&ERROR: DEX file has no classes in it, failing&);
* Success!
result = 0;
if (result != 0 && pDexFile != NULL) {
dexFileFree(pDexFile);
pDexFile = NULL;
return pDexF
* Free up the DexFile and any associated data structures.
* Note we may be called with a partially-initialized DexFile.
void dexFileFree(DexFile* pDexFile)
if (pDexFile == NULL)
free(pDexFile);
* Look up a class definition entry by descriptor.
* &descriptor& should look like &Landroid/debug/S&.
const DexClassDef* dexFindClass(const DexFile* pDexFile,
const char* descriptor)
const DexClassLookup* pLookup = pDexFile-&pClassL
hash = classDescriptorHash(descriptor);
mask = pLookup-&numEntries - 1;
idx = hash &
* Search until we find a matching entry or an empty slot.
while (true) {
offset = pLookup-&table[idx].classDescriptorO
if (offset == 0)
return NULL;
if (pLookup-&table[idx].classDescriptorHash == hash) {
const char*
str = (const char*) (pDexFile-&baseAddr + offset);
if (strcmp(str, descriptor) == 0) {
return (const DexClassDef*)
(pDexFile-&baseAddr + pLookup-&table[idx].classDefOffset);
idx = (idx + 1) &
* Compute the DEX file checksum for a memory-mapped DEX file.
u4 dexComputeChecksum(const DexHeader* pHeader)
const u1* start = (const u1*) pH
uLong adler = adler32(0L, Z_NULL, 0);
const int nonSum = sizeof(pHeader-&magic) + sizeof(pHeader-&checksum);
return (u4) adler32(adler, start + nonSum, pHeader-&fileSize - nonSum);
* Compute the size, in bytes, of a DexCode.
size_t dexGetDexCodeSize(const DexCode* pCode)
* The catch handler data is the last entry.
It has a variable number
* of variable-size pieces, so we need to create an iterator.
u4 handlersS
if (pCode-&triesSize != 0) {
handlersSize = dexGetHandlersSize(pCode);
offset = dexGetFirstHandlerOffset(pCode);
handlersSize = 0;
offset = 0;
for (ui = 0; ui & handlersS ui++) {
dexCatchIteratorInit(&iterator, pCode, offset);
offset = dexCatchIteratorGetEndOffset(&iterator, pCode);
const u1* handlerData = dexGetCatchHandlerData(pCode);
//ALOGD(&+++ pCode=%p handlerData=%p last offset=%d&,
pCode, handlerData, offset);
/* return the size of the catch handler + everything before it */
return (handlerData - (u1*) pCode) +
* Round up to the next highest power of 2.
* Found on http://graphics.stanford.edu/~seander/bithacks.html.
u4 dexRoundUpPower2(u4 val)
val |= val && 1;
val |= val && 2;
val |= val && 4;
val |= val && 8;
val |= val && 16;
DexHacker.h
Created by BunnyBlue on 6/23/15.
#ifndef ____DexHacker__
#define ____DexHacker__
#include &iostream&
#include&string.h&
#include&stdio.h&
#include &base64.h&
#include &sys/types.h&
#include &unistd.h&
#include &stdio.h&
#include &fcntl.h&
#define BUFLEN 1024
class DexHacker{
writeDex2Encoded(unsigned char * data,size_t length);
writeEncodedDex2Dex(const char *dexPath);
char * getProcessName(char * buffer);
#endif /* defined(____DexHacker__) */
* \file base64.h
* \brief RFC 1521 base64 encoding/decoding
Copyright (C) , Brainspark B.V.
This file is part of PolarSSL (http://www.polarssl.org)
Lead Maintainer: Paul Bakker &polarssl_maintainer at polarssl.org&
All rights reserved.
This prog you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software F either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
* if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA
POLARSSL_BASE64_C
#define POLARSSL_SELF_TEST
#ifndef POLARSSL_BASE64_H
#define POLARSSL_BASE64_H
#include &string.h&
#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL
/**& Output buffer too small. */
#define POLARSSL_ERR_BASE64_INVALID_CHARACTER
/**& Invalid character in input. */
#ifdef __cplusplus
extern &C& {
Encode a buffer into base64 format
* \param dst
destination buffer
* \param dlen
size of the buffer
* \param src
source buffer
* \param slen
amount of data to be encoded
0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
*dlen is always updated to reflect the amount
of data that has (or would have) been written.
Call this function with *dlen = 0 to obtain the
required buffer size in *dlen
int base64_encode( unsigned char *dst, size_t *dlen,
const unsigned char *src, size_t slen );
Decode a base64-formatted buffer
* \param dst
destination buffer
* \param dlen
size of the buffer
* \param src
source buffer
* \param slen
amount of data to be decoded
0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
POLARSSL_ERR_BASE64_INVALID_CHARACTER if the input data is
not correct. *dlen is always updated to reflect the amount
of data that has (or would have) been written.
Call this function with *dlen = 0 to obtain the
required buffer size in *dlen
int base64_decode( unsigned char *dst, size_t *dlen,
const unsigned char *src, size_t slen );
int base64_self_test( int verbose );
#ifdef __cplusplus
#endif /* base64.h */
RFC 1521 base64 encoding/decoding
Copyright (C) , Brainspark B.V.
This file is part of PolarSSL (http://www.polarssl.org)
Lead Maintainer: Paul Bakker &polarssl_maintainer at polarssl.org&
All rights reserved.
This prog you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software F either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
* if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA
#define POLARSSL_BASE64_C
#define POLARSSL_SELF_TEST
#if defined(POLARSSL_BASE64_C)
#include &base64.h&
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include &basetsd.h&
typedef UINT32 uint32_t;
#include &inttypes.h&
static const unsigned char base64_enc_map[64] =
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '+', '/'
static const unsigned char base64_dec_map[128] =
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127,
62, 127, 127, 127,
61, 127, 127,
64, 127, 127, 127,
25, 127, 127, 127, 127, 127, 127,
51, 127, 127, 127, 127, 127
* Encode a buffer into base64 format
int base64_encode( unsigned char *dst, size_t *dlen,
const unsigned char *src, size_t slen )
int C1, C2, C3;
unsigned char *p;
if( slen == 0 )
return( 0 );
n = (slen && 3) / 6;
switch( (slen && 3) - (n * 6) )
2: n += 3;
4: n += 2;
if( *dlen & n + 1 )
*dlen = n + 1;
return( POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL );
n = (slen / 3) * 3;
for( i = 0, p = i & i += 3 )
C1 = *src++;
C2 = *src++;
C3 = *src++;
*p++ = base64_enc_map[(C1 && 2) & 0x3F];
*p++ = base64_enc_map[(((C1 &
3) && 4) + (C2 && 4)) & 0x3F];
*p++ = base64_enc_map[(((C2 & 15) && 2) + (C3 && 6)) & 0x3F];
*p++ = base64_enc_map[C3 & 0x3F];
if( i & slen )
C1 = *src++;
C2 = ((i + 1) & slen) ? *src++ : 0;
*p++ = base64_enc_map[(C1 && 2) & 0x3F];
*p++ = base64_enc_map[(((C1 & 3) && 4) + (C2 && 4)) & 0x3F];
if( (i + 1) & slen )
*p++ = base64_enc_map[((C2 & 15) && 2) & 0x3F];
else *p++ = '=';
*p++ = '=';
*dlen = p -
return( 0 );
* Decode a base64-formatted buffer
int base64_decode( unsigned char *dst, size_t *dlen,
const unsigned char *src, size_t slen )
uint32_t j,
unsigned char *p;
for( i = n = j = 0; i & i++ )
if( ( slen - i ) &= 2 &&
src[i] == '\r' && src[i + 1] == '\n' )
if( src[i] == '\n' )
if( src[i] == '=' && ++j & 2 )
return( POLARSSL_ERR_BASE64_INVALID_CHARACTER );
if( src[i] & 127 || base64_dec_map[src[i]] == 127 )
return( POLARSSL_ERR_BASE64_INVALID_CHARACTER );
if( base64_dec_map[src[i]] & 64 && j != 0 )
return( POLARSSL_ERR_BASE64_INVALID_CHARACTER );
if( n == 0 )
return( 0 );
n = ((n * 6) + 7) && 3;
if( dst == NULL || *dlen & n )
return( POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL );
for( j = 3, n = x = 0, p = i & 0; i--, src++ )
if( *src == '\r' || *src == '\n' )
j -= ( base64_dec_map[*src] == 64 );
= (x && 6) | ( base64_dec_map[*src] & 0x3F );
if( ++n == 4 )
if( j & 0 ) *p++ = (unsigned char)( x && 16 );
if( j & 1 ) *p++ = (unsigned char)( x &&
if( j & 2 ) *p++ = (unsigned char)( x
*dlen = p -
return( 0 );
#if defined(POLARSSL_SELF_TEST)
#include &string.h&
#include &stdio.h&
static const unsigned char base64_test_dec[64] =
0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01,
0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09,
0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13,
0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31,
0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38,
0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B,
0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97
static const unsigned char base64_test_enc[] =
&JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK&
&swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw==&;
* Checkup routine
int base64_self_test( int verbose )
const unsigned char *
unsigned char buffer[128];
if( verbose != 0 )
Base64 encoding test: & );
len = sizeof( buffer );
src = base64_test_
if( base64_encode( buffer, &len, src, 64 ) != 0 ||
memcmp( base64_test_enc, buffer, 88 ) != 0 )
if( verbose != 0 )
printf( &failed\n& );
return( 1 );
if( verbose != 0 )
printf( &passed\n
Base64 decoding test: & );
len = sizeof( buffer );
src = base64_test_
if( base64_decode( buffer, &len, src, 88 ) != 0 ||
memcmp( base64_test_dec, buffer, 64 ) != 0 )
if( verbose != 0 )
printf( &failed\n& );
return( 1 );
if( verbose != 0 )
printf( &passed\n\n& );
return( 0 );
# Copyright (C) 2008 The Android Open Source Project
# Licensed under the Apache License, Version 2.0 (the &License&);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an &AS IS& BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
LOCAL_PATH:= $(call my-dir)
dex_src_files := \
CmdUtils.cpp \
DexCatch.cpp \
DexClass.cpp \
DexDataMap.cpp \
DexDebugInfo.cpp \
DexFile.cpp \
DexInlines.cpp \
DexOptData.cpp \
DexOpcodes.cpp \
DexProto.cpp \
DexSwapVerify.cpp \
DexUtf.cpp \
InstrUtils.cpp \
Leb128.cpp \
OptInvocation.cpp \
sha1.cpp \
SysUtil.cpp \
ZipArchive.cpp\
dex_include_files := \
external/zlib \
external/safe-iop/include
## Build the device version of libdex
ifneq ($(SDK_ONLY),true)
# SDK_only doesn't need device version
include $(CLEAR_VARS)
LOCAL_CFLAGS += -DCODE_DVM -fpermissive
LOCAL_CXXFLAGS += -DCODE_DVM -fpermissive
LOCAL_CPPFLAGS += -DCODE_DVM -fpermissive
#LOCAL_CFLAGS += -UNDEBUG -DDEBUG=1
LOCAL_SRC_FILES := $(dex_src_files)
LOCAL_C_INCLUDES += $(dex_include_files)
LOCAL_STATIC_LIBRARIES := liblog
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libdex
include $(BUILD_STATIC_LIBRARY)
endif # !SDK_ONLY
## Build the host version of libdex
include $(CLEAR_VARS)
LOCAL_CFLAGS += -DCODE_DVM
LOCAL_CXXFLAGS += -DCODE_DVM -fpermissive
LOCAL_CPPFLAGS += -DCODE_DVM -fpermissive
LOCAL_SRC_FILES := $(dex_src_files)
LOCAL_C_INCLUDES += $(dex_include_files)
LOCAL_STATIC_LIBRARIES := liblog
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libdex
include $(BUILD_HOST_STATIC_LIBRARY)
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:311062次
积分:4611
积分:4611
排名:第7178名
原创:130篇
转载:23篇
评论:195条
文章:13篇
阅读:30874
文章:52篇
阅读:133579
阅读:11526
文章:16篇
阅读:30865
文章:10篇
阅读:13795
(2)(2)(3)(5)(5)(2)(12)(8)(8)(6)(14)(7)(3)(4)(1)(3)(3)(2)(17)(16)(3)(7)(6)(1)(10)(4)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'

我要回帖

更多关于 tmpfile.tmp 的文章

 

随机推荐