代码:
[注:转载请注明出处]
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\comctl32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\comctl32.lib
.const
IDD_DIALOG1 equ 1000
IDC_STR_EDIT equ 1001
IDC_CRC_EDIT equ 1002
IDC_OPEN_BUTTON equ 1003
MAXSIZE equ 512
WndProc proto :DWORD, :DWORD, :DWORD, :DWORD
MakeTable proto
GetCrc32 proto
.data
szTemplate db "%X", 0
Crc32Table dd 256 dup(0)
szStr db 255 dup(0)
.data?
hInt dd ?
szCRC32 dd 4 dup(?)
szText db 50 dup(?)
.code
start:
invoke InitCommonControls
invoke GetModuleHandle,NULL
mov hInt,eax
invoke DialogBoxParam,hInt,IDD_DIALOG1,NULL,offset WndProc,0
invoke ExitProcess,NULL
WndProc proc uses ebx ecx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
MOV eax,uMsg
.if eax == WM_CLOSE
invoke EndDialog, hWnd, 0
.elseif eax == WM_COMMAND
mov eax,wParam
.if eax==IDC_OPEN_BUTTON
invoke GetDlgItemText, hWnd, IDC_STR_EDIT, addr szStr, 255
invoke MakeTable
lea ebx, szStr
invoke GetCrc32
mov szCRC32, eax
invoke wsprintf, addr szText, addr szTemplate, szCRC32
invoke SetDlgItemText,hWnd,IDC_CRC_EDIT,ADDR szText
.endif
.else
mov eax, FALSE
ret
.endif
mov eax, TRUE
ret
WndProc endp
;动态生成码表
MakeTable proc
mov ecx, 256
mov edx, 0EDB88320h
$OneLoop:
lea eax, [ecx-1]
push ecx
mov ecx, 8
$TwoLoop:
shr eax, 1
jnc @F
xor eax, edx
@@:
dec ecx
jne $TwoLoop
pop ecx
mov [Crc32Table+ecx*4-4], eax
dec ecx
jne $OneLoop
ret
MakeTable endp
GetCrc32 proc
mov eax, -1
or ebx, ebx
jz $Exit
@@:
mov dl, [ebx]
or dl, dl
je $Exit
xor dl, al
movzx edx, dl
shr eax, 8
xor eax, [Crc32Table+edx*4]
inc ebx
jmp @B
$Exit:
not eax
ret
GetCrc32 endp
end start
资源文件:
#include "resource.h"
#define IDD_DIALOG1 1000
#define IDC_Str_EDIT 1001
#define IDC_CRC_EDIT 1002
#define IDC_OPEN_BUTTON 1003
IDD_DIALOG1 DIALOG DISCARDABLE -2, 0, 258, 67
STYLE DS_SYSMODAL |DS_FIXEDSYS |DS_SETFONT |DS_MODALFRAME |DS_CENTER |WS_POPUP |WS_CAPTION |WS_VISIBLE |WS_SYSMENU |WS_MINIMIZEBOX
CAPTION "获取字符串的Crc32校验值 By ksaiy"
FONT 9, "宋体"
BEGIN
CONTROL "",-1,"Static",SS_ETCHEDHORZ,5, 50, 248, 3
LTEXT "字符串:", IDC_STATIC,3, 3, 100, 12
EDITTEXT IDC_Str_EDIT,4, 13, 121, 12, ES_AUTOHSCROLL | ES_LEFT |WS_TABSTOP|WS_EX_STATICEDGE
PUSHBUTTON "获取字符串的CRC32值",IDC_OPEN_BUTTON,158, 30, 92, 14,BS_FLAT
LTEXT "By ksaiy 欢迎转载但请注明出处。", -1,121, 55, 128, 12, WS_DISABLED | WS_GROUP
LTEXT "字符串的CRC32校验值:", IDC_STATIC,135, 3, 100, 9
EDITTEXT IDC_CRC_EDIT,135, 13, 118, 12, ES_AUTOHSCROLL | ES_LEFT |WS_TABSTOP| ES_READONLY|WS_EX_STATICEDGE
END
[注:转载请注明出处]
本文地址:http://com.8s8s.com/it/it21802.htm