标 题: 【原创】MD5算法程序
作 者: 非安全
时 间: 2007-11-15
链 接: http://bbs1.pediy.com/showthread.php?t=54926
一个还算完美的程序,主程序代码如下:
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Programmed by nohacks, nohacks@163.com
; Website: http://hi.baidu.com/nohacks
; Win32 ASM is Masm
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 版本信息
; WinMD5 for ASM V1.0 - 可以取得文本或文件的MD5值
;
; 2007年11月15日
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> .386
.model flat, stdcall
option casemap :none
include windows.inc
include user32.inc
include kernel32.inc
includelib user32.lib
includelib kernel32.lib
include comdlg32.inc
includelib comdlg32.lib
include debug.inc
include Stdlib.Inc
includelib Stdlib.lib
m2m Macro M1,M2
push M2
pop M1
endm
.const
ICO_ICO EQU 1
DLG_MAIN EQU 1000
IDC_EDT_IN EQU 1001
IDC_EDT_OUT EQU 1002
IDC_BTN_TXT EQU 1003
IDC_BTN_FILE EQU 1004
IDC_PGB EQU 1005
.data?
hWinMain dd ?
hInstance dd ?
hMenu HANDLE dword ?
TheThread DWORD ?
.data
FilterString BYTE "全部文件(*.*)",0,"*.*",0,0
temp db '%s',0DH,0AH,0
szReceive db '文件名:%s',0dh,0ah
db 'MD5值 :%s',0dh,0ah,0
TEMP db '.',0
include md5.asm
_OpenFileDlg Proc _hWnd,_lpName,_nMax
LOCAL @OFN:OPENFILENAME ;设置打开文件对话框
invoke RtlZeroMemory,_lpName,_nMax ;数据清零
invoke RtlZeroMemory,addr @OFN,SizeOf @OFN ;同上
mov @OFN.lStructSize,SizeOf @OFN
mov @OFN.lpstrFilter,offset FilterString
m2m @OFN.hwndOwner,_hWnd
m2m @OFN.lpstrFile,_lpName
m2m @OFN.nMaxFile,_nMax
mov @OFN.Flags,OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
mov @OFN.lpstrInitialDir,offset TEMP
invoke GetOpenFileName,addr @OFN ;调用打开文件对话框
ret
_OpenFileDlg endp _SetWindowCenter proc _hWnd:DWORD
LOCAL swidth,sheight,dwidth,dheight
LOCAL rect:RECT
invoke GetSystemMetrics,SM_CXSCREEN
mov swidth,eax
invoke GetSystemMetrics,SM_CYSCREEN ;取屏幕分辨率
mov sheight,eax
invoke GetWindowRect,_hWnd,addr rect ;取本程序窗口尺寸
mov eax,rect.right ;下面几行计算并设置屏幕中心位置
sub eax,rect.left
mov dwidth,eax
sub swidth,eax
mov eax,rect.bottom
sub eax,rect.top
mov dheight,eax
sub sheight,eax
shr sheight,1
shr swidth,1
invoke SetWindowPos,_hWnd,HWND_NOTOPMOST,swidth,sheight,dwidth,dheight,SWP_SHOWWINDOW ;设置窗口位置
ret
_SetWindowCenter endp
;********************************************************************
CloseMapFile PROC hMapFile:DWORD,hFileRead:DWORD
invoke CloseHandle,hMapFile
; mov hMapFile,0
invoke CloseHandle,hFileRead
ret
CloseMapFile endp
GetMd5Thread PROC H:DWORD
LOCAL @Text[MAX_PATH]:BYTE
LOCAL @FileText[MAX_PATH]:BYTE
LOCAL @TEMP[MAX_PATH]:BYTE
LOCAL @hFileRead,@hMapFile,@pMemory
invoke _OpenFileDlg,hWinMain,addr @Text,MAX_PATH ;调用打开文件对话框
.if eax==0
ret
.endif
invoke SetDlgItemText,hWinMain,IDC_EDT_IN,addr @Text ;输出文件路径到编辑框
invoke ExtractFileName,addr @Text,addr @FileText ;取短文件名
invoke CreateFile,ADDR @Text,\
GENERIC_READ ,\
0,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
.if eax==0
invoke MessageBox,0,CTEXT("打开文件失败!"),CTEXT("错误"),MB_OK
ret
.endif
mov @hFileRead,eax
invoke CreateFileMapping,@hFileRead,NULL,PAGE_READONLY,0,0,NULL ;创建映射文件
mov @hMapFile,eax
invoke MapViewOfFile,@hMapFile,FILE_MAP_READ,0,0,0 ;复制到本进程空间
mov @pMemory,eax
invoke SendDlgItemMessage,hWinMain,IDC_PGB,PBM_SETPOS,1,0 ;进度条开始
invoke GetFileSize,@hFileRead,0
invoke _MD5,@pMemory,eax
invoke wsprintf ,addr @TEMP,addr szReceive, addr @FileText,eax ;连接文本串
;invoke SendDlgItemMessage,hWinMain,IDC_EDT_OUT,EM_SETSEL,-1,0 ;选择文本
invoke SendDlgItemMessage,hWinMain,IDC_EDT_OUT,EM_REPLACESEL,0,addr @TEMP ;输出到编辑框
invoke SendDlgItemMessage,hWinMain,IDC_PGB,PBM_SETPOS,100,0 ;进度条结束
invoke UnmapViewOfFile,@pMemory ;关闭映射
invoke CloseMapFile,@hMapFile,@hFileRead ;关闭打开文件
ret
GetMd5Thread endp
_ProcDlgMain proc uses ebx edi esi, \
hWnd:DWORD,wMsg:DWORD,wParam:DWORD,lParam:DWORD
local @Text[MAX_PATH]:BYTE
local @Temp[MAX_PATH]:BYTE
LOCAL @hMem,@hFile,@Size,@Read
mov eax,wMsg
cmp eax,WM_COMMAND
je GetMd5
cmp eax,WM_INITDIALOG
je boxStart
cmp eax,WM_CLOSE
je boxClose
retFalse:
mov eax,FALSE
ret
boxClose:
invoke EndDialog,hWnd,NULL
jmp retTrue
boxStart:
push hWnd
pop hWinMain
invoke LoadIcon,hInstance,ICO_ICO
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax ;设置窗口图标
invoke SetWindowPos,hWnd,HWND_TOPMOST,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE ;窗口置顶
INVOKE _SetWindowCenter,hWinMain ;使窗体出现在屏幕中心
jmp retTrue
GetMd5:
mov eax,wParam
.if eax==IDC_BTN_TXT
invoke SendDlgItemMessage,hWinMain,IDC_PGB,PBM_SETPOS,1,0 ;进度条开始
invoke GetDlgItemText,hWnd, IDC_EDT_IN,addr @Text,MAX_PATH ;取用户输入
invoke _MD5,addr @Text,eax ;MD5转换
invoke wsprintf,addr @Temp,addr temp,eax ;连接文本开始
invoke SendDlgItemMessage,hWnd,IDC_EDT_OUT,EM_REPLACESEL,0,addr @Temp ;输出到编辑框
invoke SendDlgItemMessage,hWinMain,IDC_PGB,PBM_SETPOS,100,0 ;进度条结束
.elseif eax==IDC_BTN_FILE
invoke CreateThread,NULL,0,addr GetMd5Thread,0,0,0 ;创建线程
.endif
retTrue:
mov eax,TRUE
ret
_ProcDlgMain endp
Start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,_ProcDlgMain,0
invoke ExitProcess,NULL
End Start ==========================================
开发环境:MASM+RadASM
系统:Windows XP +SP2
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)
上传的附件: