CryptCreateHash + CALG_MD5
发布日期:2021-06-30 22:10:27
浏览次数:2
分类:技术文章
本文共 5043 字,大约阅读时间需要 16 分钟。
前言
看见反汇编中有一段算md5的代码,记录一下。
记录
// testCase1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include#include #include #include BOOL __cdecl fnMd5(const BYTE* pbData, DWORD dwDataLen, BYTE* pucAryHash);int main(int argc, char* argv[]){ int i = 0; BYTE cBuf[MAXBYTE] = { '\0'}; ///< 全0的buffer BYTE ucRc[16] = { '\0'}; if (fnMd5(cBuf, MAXBYTE, ucRc)) { for (i = 0; i < sizeof(ucRc); i++) { printf("%.2X ", ucRc[i]); } printf("\r\n"); } /** run result 6D F9 01 2B 2B 7C B3 C5 59 63 49 9A 26 30 9B BA */ printf("END\n"); return 0;}BOOL __cdecl fnMd5(const BYTE* pbData, DWORD dwDataLen, BYTE* pucAryHash){ BOOL bRc = FALSE; // 这里直接假设算出的hash值为16字节 // msdn上的说法是要先算一下hash值占用的空间, CryptGetHashParam(hHash, HP_HASHSIZE DWORD dwOutPutBufferSize = 16; HCRYPTPROV hProv = NULL; HCRYPTHASH hHash = NULL; if (!CryptAcquireContextA(&hProv, 0, 0, PROV_RSA_FULL/*1u*/, CRYPT_VERIFYCONTEXT/*0xF0000000u*/)) { return 0; } if (CryptCreateHash(hProv, CALG_MD5/*0x8003u*/, 0, 0, &hHash)) { if (!CryptHashData(hHash, pbData, dwDataLen, 0)) { CryptReleaseContext(hProv, 0); CryptDestroyHash(hHash); return 0; } if (CryptGetHashParam(hHash, HP_HASHVAL/*2u*/, pucAryHash, &dwOutPutBufferSize, 0)) { bRc = TRUE; } CryptDestroyHash(hHash); } CryptReleaseContext(hProv, 0); return bRc;}
反汇编代码
; =============== S U B R O U T I N E =======================================; Attributes: bp-based frame; int __cdecl fnMd5(BYTE *pbData, DWORD dwDataLen, int)fnMd5 proc near ; CODE XREF: fnMd51+68p fnMd52+18p ...pdwDataLen = dword ptr -0ChhProv = dword ptr -8hHash = dword ptr -4pbData = dword ptr 8dwDataLen = dword ptr 0Charg_8 = dword ptr 10h push ebp mov ebp, esp sub esp, 0Ch push esi push edi xor esi, esi push 0F0000000h ; dwFlags push 1 ; dwProvType push esi ; szProvider lea eax, [ebp+hProv] push esi ; szContainer push eax ; phProv xor edi, edi mov [ebp+hProv], esi mov [ebp+hHash], esi mov [ebp+pdwDataLen], esi call CryptAcquireContextA test eax, eax jz short loc_10004896 lea eax, [ebp+hHash] push eax ; phHash push esi ; dwFlags push esi ; hKey push 8003h ; Algid push [ebp+hProv] ; hProv call CryptCreateHash test eax, eax jz short loc_100048C4 push esi ; dwFlags push [ebp+dwDataLen] ; dwDataLen push [ebp+pbData] ; pbData push [ebp+hHash] ; hHash call CryptHashData test eax, eax jnz short loc_1000489A push esi ; dwFlags push [ebp+hProv] ; hProv call CryptReleaseContext push [ebp+hHash] ; hHash call CryptDestroyHashloc_10004896: ; CODE XREF: fnMd5+2Aj xor eax, eax jmp short loc_100048D0; ---------------------------------------------------------------------------loc_1000489A: ; CODE XREF: fnMd5+56j lea eax, [ebp+pdwDataLen] push esi ; dwFlags push eax ; pdwDataLen mov [ebp+pdwDataLen], 10h push [ebp+arg_8] ; pbData push 2 ; dwParam push [ebp+hHash] ; hHash call CryptGetHashParam test eax, eax jz short loc_100048BB push 1 pop ediloc_100048BB: ; CODE XREF: fnMd5+8Bj push [ebp+hHash] ; hHash call CryptDestroyHashloc_100048C4: ; CODE XREF: fnMd5+42j push esi ; dwFlags push [ebp+hProv] ; hProv call CryptReleaseContext mov eax, ediloc_100048D0: ; CODE XREF: fnMd5+6Dj pop edi pop esi leave retnfnMd5 endp; =============== S U B R O U T I N E =======================================
转载地址:https://lostspeed.blog.csdn.net/article/details/52585050 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2024年04月29日 20时41分15秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
leetcode 1143. 最长公共子序列
2019-04-30
leetcode 83. 删除排序链表中的重复元素
2019-04-30
Python 之 histogram直方图
2019-04-30
Python实现决策树 Desision Tree & 可视化
2019-04-30
决策树 Decision tree
2019-04-30
nominal和ordinal & 数据处理中四种基本数据类型
2019-04-30
Grid SearchCV(网格搜索)& Python实现
2019-04-30
单目深度估计 monodepth2模型 代码
2019-04-30
位图索引Bitmap indexes
2019-04-30
YOLO算法(二)—— Yolov2 & yolo9000
2019-04-30
Python的__future__模块
2019-04-30
计算机视觉中的cost-volume的概念具体指什么(代价体积)
2019-04-30
启发函数heuristic 与 A*
2019-04-30
Image Pyramid(图像金字塔)
2019-04-30