Symbian 计算 MD5
2010-03-26 04:22:00 来源:WEB开发网从MD5 HexDigest for Symbian看到的代码
LOCAL_C HBufC8* Md5HexDigestLC(const TDes8& aString)
{
CMD5* md5 = CMD5::NewL();
CleanupStack::PushL(md5);
TPtrC8 hashedSig(md5->Hash(aString));
HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
TPtr8 bufPtr = buf->Des();
for(TInt i=0; i< hashedSig.Length(); i++)
{
bufPtr.AppendFormat(_L8(“%+02x”),hashedSig[i]);
}
CleanupStack::PopAndDestroy(md5);
CleanupStack::PushL(buf);
return buf;
}
改成更简单的
LOCAL_C HBufC8* DoMD5(const TDes8& aString)
{
CMD5* MD5 = CMD5::NewL();
CleanupStack::PushL(MD5);
HBufC8 *HashSigned=(MD5->Hash(aFileName)).AllocL();
//TPtrC8 bytes = md5->Hash(aSource);
CleanupStack::PopAndDestroy(MD5);
return HashSigned;
}
注意:
CMD5包含头文件hash.h,并需要链接hash.lib
LOCAL_C void Md5HexDigestLC(const TDes8& aString)
{
CMD5* md5 = CMD5::NewL();
CleanupStack::PushL(md5);
TPtrC8 hashedSig = md5->Hash(aString);
CleanupStack::PopAndDestroy(md5);
}
我们看看IDA反汇编出来的结果
PUSH {R4,R5,LR}
SUB SP, SP, #0xC
MOVS R5, R0
BLX _ZN4CMD54NewLEv ; CMD5::NewL(void)
MOVS R4, R0
BLX _ZN12CleanupStack5PushLEP5CBase ; CleanupStack::PushL(CBase *)
LDR R3, [R4]
MOV R0, SP
MOVS R2, R5
LDR R3, [R3,#0x10]
MOVS R1, R4
BLX R3 ;这里就是调用 md5->Hash()
BLX _ZN12CleanupStack13PopAndDestroyEv ; CleanupStack::PopAndDestroy(void)
ADD SP, SP, #0xC
POP {R4,R5,PC}
类似地, 下面的这段代码,是从某个实际的应用程序中提取到的
LDR R12, [R7,#4] ; 载入md5对象
MOV R0, R8
MOV R2, R4
MOV R1, R12
LDR R3, [R12] ; 读取虚函数表指针
MOV LR, PC ; 保存返回地址
LDR PC, [R3,#0x10] ; 调用hash的虚函数
更多精彩
赞助商链接