一共两个文件 APIAdress.asm和mecp.asm
APIAdress.asm中代码如下
_call MACRO procedure, parameters:VARARG
LOCAL param, reversed
reversed TEXTEQU <>
% for param, <parameters>
reversed CATSTR <param>, <!,>, reversed
endm
% for param, <reversed>
push param
endm
call procedure
ENDM
Attachment proto
AttachWindowProc proto :DWORD,:DWORD,:DWORD,:DWORD
init_crc32table proto
arraycrc32 proto
.const
hWndAttachExStyle equ 0
hWndAttachStyle equ WS_MINIMIZEBOX or WS_SYSMENU or WS_CAPTION or WS_OVERLAPPED or WS_THICKFRAME
dwWndAttachWidth equ 320
dwWndAttachHeight equ 120
IDC_BUTTON_OK equ 3001
IDM_ATTACH_MENU_ABOUT equ 3002
.code
attach_start equ $
attach_data_start equ $
hLibUser32 dd ?
hLibGDI32 dd ?
crc32tbl dd 256 dup(?)
_GetProcAddress dd 0
_LoadLibrary dd 0
_FreeLibrary dd 0
_ExitProcess dd 0
_GetModuleHandle dd 0
_GetMessage dd 0
_TranslateMessage dd 0
_DispatchMessage dd 0
_GetSystemMetrics dd 0
_PostMessage dd 0
_SendMessage dd 0
_ShowWindow dd 0
_UpdateWindow dd 0
_LoadCursor dd 0
_PostQuitMessage dd 0
_MessageBox dd 0
_RegisterClassEx dd 0
_CreateWindowEx dd 0
_DefWindowProc dd 0
_SetFocus dd 0
_GetWindowLong dd 0
_SetWindowLong dd 0
_GetDlgItemText dd 0
_GetSystemMenu dd 0
_AppendMenu dd 0
_CreateFontIndirect dd 0
_DeleteObject dd 0
_IsDialogMessage dd 0
_GetDlgItem dd 0
_hWndAttach HWND 0
_wsprintfA dd 0
_SetWindowTextA dd 0
szLibUser32 db "user32", 0
szLibGDI32 db "gdi32", 0
szProcLoadLibrary db "LoadLibraryA", 0
szProcFreeLibrary db "FreeLibrary", 0
szProcExitProcess db "ExitProcess", 0
szProcGetModuleHandle db "GetModuleHandleA", 0
szProcGetMessage db "GetMessageA", 0
szProcTranslateMessage db "TranslateMessage", 0
szProcDispatchMessage db "DispatchMessageA", 0
szProcGetSystemMetrics db "GetSystemMetrics", 0
szProcPostMessage db "PostMessageA", 0
szProcSendMessage db "SendMessageA", 0
szProcShowWindow db "ShowWindow", 0
szProcUpdateWindow db "UpdateWindow", 0
szProcLoadCursor db "LoadCursorA", 0
szProcPostQuitMessage db "PostQuitMessage", 0
szProcMessageBox db "MessageBoxA", 0
szProcRegisterClassEx db "RegisterClassExA", 0
szProcCreateWindowEx db "CreateWindowExA", 0
szProcDefWindowProc db "DefWindowProcA", 0
szProcSetFocus db "SetFocus", 0
szProcGetWindowLong db "GetWindowLongA", 0
szProcSetWindowLong db "SetWindowLongA", 0
szProcGetDlgItemText db "GetDlgItemTextA", 0
szProcGetSystemMenu db "GetSystemMenu", 0
szProcAppendMenu db "AppendMenuA", 0
szIsDialogMessage db "IsDialogMessage", 0
szGetDlgItem db "GetDlgItem", 0
szwsprintfA db "wsprintfA", 0
szSetWindowTextA db "SetWindowTextA", 0
szProcCreateFontIndirect db "CreateFontIndirectA", 0
szProcDeleteObject db "DeleteObject", 0
_fnt LOGFONT <13, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH or FF_DONTCARE, "宋体">
_szAppClass db "MokeCrypty32", 0
_szAppTitle db "MokeMars Crypty :: v1.0 by 摩科", 0
_szMenuAbout db "&About MokeMars Crypty", 0
_szMsgAbout db "★摩科的加密软件V1.0★", 13, 10
db "Version: 1.0", 13, 10, 13, 10
db "作者:摩科", 13, 10
db "E-Mail: [email protected]", 13, 10, 13, 10
db "摩科的博客", 13, 10
db "http://www.csdn.net/blog/mokemars", 0
_szClassEdit db "Edit", 0
_szClassStatic db "Static", 0
_szClassButton db "Button", 0
_szTitlePassword db "请输入密码:", 0
_szOK db "确定(&O)", 0
_szWrongPassword db "密码不正确,请重新输入!", 0
_szTemplate db "--= 您还剩下 %d 次机会 =--", 0
_szRealPassword db 16 dup (?)
_szPassword db 16 dup (?)
_szChanceCount db 255 dup(?)
_hFont dd 0
_bCorrect db 0
_hWndChanceCount HWND 0
_wc WNDCLASSEX <0>
_msg MSG <0>
_nCount dd 3
attach_code_start equ $
Attachment proc
mov eax, [esp]
and eax, 0FFFF0000h
@@chk:
cmp dword ptr [eax], 00905A4Dh
je @@fnd
sub eax, 1000h
jmp @@chk
@@fnd:
push ebp
push ebx
push esi
push edi
mov ebp, eax
add eax, [eax][IMAGE_DOS_HEADER.e_lfanew]
mov edi, [eax][IMAGE_NT_HEADERS.OptionalHeader.DataDirectory]
add edi, ebp
mov esi, [edi][IMAGE_EXPORT_DIRECTORY.AddressOfNames]
add esi, ebp
xor edx, edx
@@name:
mov eax, [esi]
add eax, ebp
@@chgp: ; GetProcAddress()
cmp dword ptr [eax+00h], "PteG"
jne @@next
cmp dword ptr [eax+04h], "Acor"
jne @@next
cmp dword ptr [eax+08h], "erdd"
jne @@next
cmp word ptr [eax+0Ch], "ss"
jne @@next
mov eax, [edi][IMAGE_EXPORT_DIRECTORY.AddressOfNameOrdinals]
add eax, ebp
movzx ebx, word ptr [edx*2+eax]
mov eax, [edi][IMAGE_EXPORT_DIRECTORY.AddressOfFunctions]
add eax, ebp
mov eax, [ebx*4+eax]
add eax, ebp
mov [_GetProcAddress], eax
@@next:
add esi, 4
inc edx
cmp edx, [edi][IMAGE_EXPORT_DIRECTORY.NumberOfNames]
jne @@name
_call [_GetProcAddress], ebp, offset szProcFreeLibrary
mov [_FreeLibrary], eax
_call [_GetProcAddress], ebp, offset szProcGetModuleHandle
mov [_GetModuleHandle], eax
_call [_GetProcAddress], ebp, offset szProcExitProcess
mov [_ExitProcess], eax
_call [_GetProcAddress], ebp, offset szProcLoadLibrary
mov [_LoadLibrary], eax
_call eax, offset szLibUser32
mov [hLibUser32], eax
_call [_GetProcAddress], eax, offset szProcGetMessage
mov [_GetMessage], eax
_call [_GetProcAddress], [hLibUser32], offset szProcTranslateMessage
mov [_TranslateMessage], eax
_call [_GetProcAddress], [hLibUser32], offset szProcDispatchMessage
mov [_DispatchMessage], eax
_call [_GetProcAddress], [hLibUser32], offset szProcGetSystemMetrics
mov [_GetSystemMetrics], eax
_call [_GetProcAddress], [hLibUser32], offset szProcPostMessage
mov [_PostMessage], eax
_call [_GetProcAddress], [hLibUser32], offset szProcSendMessage
mov [_SendMessage], eax
_call [_GetProcAddress], [hLibUser32], offset szProcShowWindow
mov [_ShowWindow], eax
_call [_GetProcAddress], [hLibUser32], offset szProcUpdateWindow
mov [_UpdateWindow], eax
_call [_GetProcAddress], [hLibUser32], offset szProcLoadCursor
mov [_LoadCursor], eax
_call [_GetProcAddress], [hLibUser32], offset szProcPostQuitMessage
mov [_PostQuitMessage], eax
_call [_GetProcAddress], [hLibUser32], offset szProcMessageBox
mov [_MessageBox], eax
_call [_GetProcAddress], [hLibUser32], offset szProcRegisterClassEx
mov [_RegisterClassEx], eax
_call [_GetProcAddress], [hLibUser32], offset szProcCreateWindowEx
mov [_CreateWindowEx], eax
_call [_GetProcAddress], [hLibUser32], offset szProcDefWindowProc
mov [_DefWindowProc], eax
_call [_GetProcAddress], [hLibUser32], offset szProcSetFocus
mov [_SetFocus], eax
_call [_GetProcAddress], [hLibUser32], offset szProcGetWindowLong
mov [_GetWindowLong], eax
_call [_GetProcAddress], [hLibUser32], offset szProcSetWindowLong
mov [_SetWindowLong], eax
_call [_GetProcAddress], [hLibUser32], offset szProcGetDlgItemText
mov [_GetDlgItemText], eax
_call [_GetProcAddress], [hLibUser32], offset szProcGetSystemMenu
mov [_GetSystemMenu], eax
_call [_GetProcAddress], [hLibUser32], offset szProcAppendMenu
mov [_AppendMenu], eax
_call [_GetProcAddress], [hLibUser32], offset szIsDialogMessage
mov [_IsDialogMessage], eax
_call [_GetProcAddress], [hLibUser32], offset szGetDlgItem
mov [_GetDlgItem], eax
_call [_GetProcAddress], [hLibUser32], offset szwsprintfA
mov [_wsprintfA], eax
_call [_GetProcAddress], [hLibUser32], offset szSetWindowTextA
mov [_SetWindowTextA], eax
_call [_LoadLibrary], offset szLibGDI32
mov [hLibGDI32], eax
_call [_GetProcAddress], eax, offset szProcCreateFontIndirect
mov [_CreateFontIndirect], eax
_call [_GetProcAddress], [hLibGDI32], offset szProcDeleteObject
mov [_DeleteObject], eax
pop edi
pop esi
pop ebx
pop ebp
_call [_GetModuleHandle], 0
mov [_wc.hInstance], eax
or [_wc.cbSize], sizeof _wc
or [_wc.style], CS_HREDRAW or CS_VREDRAW
or [_wc.lpfnWndProc], offset AttachWindowProc
or [_wc.hbrBackground], COLOR_BTNFACE+1
or [_wc.lpszClassName], offset _szAppClass
_call [_LoadCursor], 0, IDC_ARROW
mov [_wc.hCursor], eax
_call [_RegisterClassEx], offset _wc
_call [_GetSystemMetrics], SM_CYSCREEN
sar eax, 1
sub eax, dwWndAttachHeight shr 1
push eax
_call [_GetSystemMetrics], SM_CXSCREEN
sar eax, 1
sub eax, dwWndAttachWidth shr 1
pop ecx
_call [_CreateWindowEx], hWndAttachExStyle, offset _szAppClass, offset _szAppTitle, hWndAttachStyle, eax, ecx, dwWndAttachWidth, dwWndAttachHeight, 0, 0, [_wc.hInstance], 0
mov [_hWndAttach], eax
push eax
_call [_ShowWindow], eax, SW_SHOW
_call [_UpdateWindow]
@@ml00:
xor eax, eax
_call [_GetMessage], offset _msg, eax, eax, eax
test eax, eax
jz @@ml01
mov eax, offset _msg
push eax
_call [_IsDialogMessage], [_hWndAttach], eax
.if eax == FALSE
mov eax, offset _msg
push eax
_call [_TranslateMessage], eax
_call [_DispatchMessage]
.endif
jmp @@ml00
@@ml01:
_call [_FreeLibrary], [hLibGDI32]
_call [_FreeLibrary], [hLibUser32]
.if [_bCorrect]
@@oep equ $ - attach_start + 1
mov eax, 00000000h
jmp eax
.endif
_call [_ExitProcess], 0
Attachment endp
AttachWindowProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
.if [uMsg] == WM_CREATE
_call [_GetSystemMenu], [hWnd], 0
push offset _szMenuAbout
push IDM_ATTACH_MENU_ABOUT
push MFT_STRING
push eax
_call [_AppendMenu], eax, MFT_SEPARATOR, 0, 0
_call [_AppendMenu]
_call [_CreateFontIndirect], offset _fnt
mov [_hFont], eax
push ebp
mov ebp, esp
sub esp, 12
_call [_wsprintfA], offset _szChanceCount, offset _szTemplate, _nCount
add esp, 12
mov esp, ebp
pop ebp
_call [_CreateWindowEx], 0, offset _szClassStatic, offset _szChanceCount, SS_CENTER or SS_CENTERIMAGE or WS_VISIBLE or WS_CHILD, 10, 32, 300, 22, [hWnd], 0, [_wc.hInstance], 0
mov [_hWndChanceCount], eax
_call [_SendMessage], eax, WM_SETFONT, [_hFont], 0
_call [_CreateWindowEx], 0, offset _szClassStatic, offset _szTitlePassword, SS_RIGHT or SS_CENTERIMAGE or WS_VISIBLE or WS_CHILD, 10, 10, 80, 22, [hWnd], 0, [_wc.hInstance], 0
_call [_SendMessage], eax, WM_SETFONT, [_hFont], 0
_call [_CreateWindowEx], WS_EX_STATICEDGE, offset _szClassEdit, 0, ES_AUTOHSCROLL or ES_PASSWORD or WS_VISIBLE or WS_TABSTOP or WS_CHILD, 95, 12, 205, 15, [hWnd], 0, [_wc.hInstance], 0
push eax ; SetFocus()
push 0 ; SendMessage()
push sizeof _szPassword
push EM_SETLIMITTEXT
push eax
push IDC_PASSWORD1 ; SetWindowLong()
push GWL_ID
push eax
_call [_SendMessage], eax, WM_SETFONT, [_hFont], 0
_call [_SetWindowLong]
_call [_SendMessage]
_call [_SetFocus]
_call [_CreateWindowEx], 0, offset _szClassButton, offset _szOK, BS_FLAT or BS_DEFPUSHBUTTON or WS_VISIBLE or WS_TABSTOP or WS_CHILD, 120, 60, 80, 20, [hWnd], 0, [_wc.hInstance], 0
push IDC_BUTTON_OK ; SetWindowLong()
push GWL_ID
push eax
_call [_SendMessage], eax, WM_SETFONT, [_hFont], 0
_call [_SetWindowLong]
.elseif [uMsg] == WM_COMMAND
mov eax, [wParam]
.if ax == IDC_BUTTON_OK || ax == IDOK
mov edi, offset _szPassword
mov ecx, sizeof _szPassword shr 2
xor eax, eax
rep stosd
_call [_GetDlgItemText], [hWnd], IDC_PASSWORD1, offset _szPassword, sizeof _szPassword
invoke init_crc32table
lea ebx, _szPassword
invoke arraycrc32
cmp dword ptr [_szRealPassword], eax
sete [_bCorrect]
.if zero? || _nCount == 1
_call [_PostMessage], [hWnd], WM_CLOSE, 0, 0
.else
_call [_MessageBox], [hWnd], offset _szWrongPassword, offset _szAppTitle, MB_OK or MB_ICONASTERISK or MB_APPLMODAL
_call [_GetDlgItem], [hWnd], IDC_PASSWORD1
_call [_SetFocus], eax
_call [_SendMessage], eax, EM_SETSEL, 0, -1
dec _nCount
push ebp
mov ebp, esp
sub esp, 12
_call [_wsprintfA], offset _szChanceCount, offset _szTemplate, _nCount
add esp, 12
mov esp, ebp
pop ebp
_call [_SetWindowTextA], [_hWndChanceCount], offset _szChanceCount
.endif
.endif
.elseif [uMsg] == WM_SYSCOMMAND && [wParam] == IDM_ATTACH_MENU_ABOUT
_call [_MessageBox], [hWnd], offset _szMsgAbout, offset _szAppTitle, MB_OK or MB_ICONASTERISK or MB_APPLMODAL
.elseif [uMsg] == WM_CLOSE
_call [_DeleteObject], [_hFont]
.elseif [uMsg]==WM_DESTROY
_call [_PostQuitMessage], 0
xor eax, eax
ret
.endif
pop ebp
jmp [_DefWindowProc]
AttachWindowProc endp
init_crc32table proc
mov ecx, 256
mov edx, 0EDB88320h
$BigLoop:
lea eax, [ecx-1]
push ecx
mov ecx, 8
$SmallLoop:
shr eax, 1
jnc @F
xor eax, edx
@@:
dec ecx
jne $SmallLoop
pop ecx
mov [crc32tbl+ecx*4-4], eax
dec ecx
jne $BigLoop
ret
init_crc32table endp
arraycrc32 proc
mov eax, -1
or ebx, ebx
jz $Done
@@:
mov dl, [ebx]
or dl, dl
je $Done
xor dl, al
movzx edx, dl
shr eax, 8
xor eax, [crc32tbl+edx*4]
inc ebx
jmp @B
$Done:
not eax
ret
arraycrc32 endp
attach_size equ $ - offset attach_start
mecp.asm中代码如下
.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/shell32.inc
include /masm32/include/comdlg32.inc
include /masm32/bin/APIAdress.asm
includelib /masm32/lib/kernel32.lib
includelib /masm32/lib/user32.lib
includelib /masm32/lib/shell32.lib
includelib /masm32/lib/comdlg32.lib
CTEXT MACRO y:VARARG
LOCAL sym
CONST segment
ifidni <y>,<>
sym db 0
else
sym db y,0
endif
CONST ends
exitm <offset sym>
ENDM
m2m MACRO M1, M2
push M2
pop M1
ENDM
AboutProc proto :DWORD,:DWORD,:DWORD,:DWORD
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD
Encode proto
Decode proto
ErrorHandler proto C :DWORD,:DWORD,:DWORD,:DWORD
ExceptionFilter proto :DWORD
init_crc32table_m proto
arraycrc32_m proto
.const
DLG_MAIN equ 100
DLG_ABOUT equ 101
IDI_MOUSE equ 102
IDC_CHECK_OK equ 1000
IDC_HOMEPAGE equ 1001
IDC_GB equ 1005
IDC_FILENAME equ 1006
IDC_OK equ 1007
IDC_PSWD1 equ 1008
IDC_PASSWORD1 equ 1009
IDC_PASSWORD2 equ 1010
IDC_PSWD2 equ 1011
IDC_JIAMI equ 1012
IDC_JIEMI equ 1014
IDC_ABOUT equ 1015
IDM_MENU_ABOUT equ 1016
.data
szMenuAbout db "About MokeMars Crypt Software", 0
szCaption db "MokeMars Crypt :: v1.0 by MokeMars", 0
szFileFilter db "All File", 0, "*.*", 0, 0
szError db "Error", 0
szErrorThread db "Error at %08Xh", 13, 10, "Registers:", 13, 10, "eax = %08Xh ebx = %08Xh ecx = %08Xh", 13, 10, "edx = %08Xh esp = %08Xh ebp = %08Xh", 13, 10, "esi = %08Xh edi = %08Xh", 13, 10, 13, 10, "Recovering...", 0
szErrorFinal db "Error at %08Xh", 13, 10, "Quitting...", 0
.data?
hFile dd ?
szMessage db 256 dup (?)
SEH dd 6 dup (?)
data_start equ $
szFileName db MAX_PATH dup (?)
img_dos_hdr IMAGE_DOS_HEADER <>
img_nt_hdrs IMAGE_NT_HEADERS <>
img_sect_hdr IMAGE_SECTION_HEADER <>
szBuffer db 256 dup (?)
szPassword1 db 16 dup (?)
szPassword2 db 16 dup (?)
data_size equ $ - data_start
ofn OPENFILENAME <>
hInstance dd ?
bNew db attach_size dup (?)
crc32tble dd 256 dup(?)
hMapFile dd ?
pMemory dd ?
SizeWritten DWORD ?
hWindow dd ?
.code
start:
invoke SetUnhandledExceptionFilter, addr ExceptionFilter
push edi
xor eax,eax
mov ecx,data_size shr 2
mov edi,data_start
rep stosd
.if data_size and 3
mov edi, data_start
mov ecx, data_size and 3
rep stosb
.endif
pop edi
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset DlgProc,0
invoke ExitProcess,NULL
DlgProc proc hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
mov eax,uMsg
.if eax==WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax==WM_INITDIALOG
invoke LoadIcon, hInstance, IDI_MOUSE
invoke SendMessage, hWnd, WM_SETICON, ICON_SMALL, eax
mov eax, hWnd
mov hWindow,eax
invoke GetSystemMenu,eax,0
push offset szMenuAbout
push IDM_MENU_ABOUT
push MFT_STRING
push eax
invoke AppendMenu, eax, MFT_SEPARATOR, 0, 0
call AppendMenu
invoke SendDlgItemMessage, hWnd, IDC_FILENAME,EM_SETLIMITTEXT,sizeof szFileName, 0
invoke SendDlgItemMessage, hWnd, IDC_PASSWORD1,EM_SETLIMITTEXT,sizeof szPassword1, 0
invoke SendDlgItemMessage, hWnd, IDC_PASSWORD2,EM_SETLIMITTEXT,sizeof szPassword2, 0
.elseif uMsg == WM_SYSCOMMAND
.if wParam == IDM_MENU_ABOUT
invoke DialogBoxParam, hInstance,DLG_ABOUT, hWnd, offset AboutProc, 0
.endif
.elseif uMsg == WM_COMMAND
mov eax, wParam
.if ax ==IDC_OK
mov ofn.lStructSize, sizeof ofn
mov ofn.lpstrFilter, offset szFileFilter
mov ofn.lpstrFile, offset szFileName
mov ofn.nMaxFile, sizeof szFileName
invoke GetOpenFileName, addr ofn
test eax, eax
.if !zero?
invoke SetDlgItemText, hWnd, IDC_FILENAME, addr szFileName
.endif
.elseif ax ==IDC_JIAMI
invoke Encode
.elseif ax==IDC_JIEMI
invoke Decode
.elseif ax ==IDC_ABOUT
invoke DialogBoxParam, hInstance, DLG_ABOUT, hWnd, offset AboutProc, 0
.endif
.else
mov eax, FALSE
ret
.endif
xor eax,eax
ret
DlgProc endp
AboutProc proc uses edx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg == WM_CLOSE
invoke EndDialog, hWnd, 0
.elseif uMsg == WM_INITDIALOG
invoke LoadIcon, hInstance, IDI_MOUSE
invoke SendMessage, hWnd, WM_SETICON, ICON_SMALL, eax
.elseif uMsg == WM_COMMAND
mov eax, wParam
mov edx, eax
shr edx, 16
movzx eax, ax
.if edx == BN_CLICKED
.if eax ==IDC_CHECK_OK
invoke EndDialog, hWnd, NULL
.elseif eax == IDC_HOMEPAGE
invoke ShellExecute, hWnd, CTEXT("open"), CTEXT("http://www.csdn.net/blog/mokemars"), NULL, NULL, SW_SHOWNORMAL
.endif
.endif
.else
mov eax, FALSE
ret
.endif
mov eax, TRUE
ret
AboutProc endp
Encode proc uses ebx edi esi ecx edx
LOCAL OK: BOOL
LOCAL dwFileSize:DWORD
LOCAL dwPassWordLen:DWORD
mov OK, TRUE
assume fs:nothing
push offset ErrorHandler
push fs:[0]
mov [SEH],esp
mov [SEH+4],ebp
mov [SEH+8],ebx
mov [SEH+12],esi
mov [SEH+16],edi
mov [SEH+20],offset @safe
mov fs:[0],esp
invoke GetDlgItemText, hWindow, IDC_FILENAME, addr szFileName, sizeof szFileName
invoke GetDlgItemText, hWindow, IDC_PASSWORD1, addr szPassword1, sizeof szPassword1
invoke GetDlgItemText, hWindow, IDC_PASSWORD2, addr szPassword2, sizeof szPassword2
invoke CreateFile, addr szFileName, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
.if eax == INVALID_HANDLE_VALUE
invoke MessageBox, hWindow, CTEXT("打开文件失败!"), addr szCaption, MB_OK or MB_ICONHAND
invoke GetDlgItem, hWindow, IDC_FILENAME
invoke SetFocus, eax
invoke SendMessage,eax,EM_SETSEL,0,-1
mov OK, FALSE
jmp Error_Exit
.endif
mov hFile, eax
invoke lstrlen, addr szPassword1
.if eax == 0
invoke MessageBox,hWindow, CTEXT("请先输入密码!"), addr szCaption, MB_OK or MB_ICONHAND
invoke GetDlgItem,hWindow, IDC_PASSWORD1
invoke SetFocus, eax
mov OK,FALSE
jmp @safe
.endif
mov dwPassWordLen,eax
invoke lstrcmp ,addr szPassword1,addr szPassword2
.if eax!=0
invoke MessageBox,hWindow,CTEXT("两次密码输入不相同!"), addr szCaption, MB_OK or MB_ICONHAND
mov OK, FALSE
jmp @safe
.endif
invoke ReadFile,hFile,addr img_dos_hdr,sizeof img_dos_hdr,esp, 0
cmp [img_dos_hdr.e_magic], "ZM"
.if !zero?
invoke GetFileSize,hFile,0
.if eax == 0
invoke MessageBox,hWindow, CTEXT("文件长度为0!"),addr szCaption, MB_OK or MB_ICONHAND
invoke GetDlgItem, hWindow, IDC_FILENAME
invoke SetFocus, eax
invoke SendMessage,eax,EM_SETSEL,0,-1
mov OK,FALSE
jmp @safe
.endif
mov dwFileSize,eax
invoke CreateFileMapping,hFile,NULL,PAGE_READWRITE,0,0,NULL
mov hMapFile,eax
invoke MapViewOfFile,hMapFile,FILE_MAP_WRITE or FILE_MAP_READ,0,0,0
mov pMemory,eax
mov esi,pMemory
xor ecx,ecx
xor edx,edx
mov edi,offset szPassword1
@@1:
mov al,[esi+ecx]
mov ah,[edi+edx]
xor al,ah
rol al,3
mov [esi+ecx],al
inc ecx
inc edx
.if edx>dwPassWordLen
xor edx,edx
.endif
cmp ecx,dwFileSize
jbe @@1
invoke SetFilePointer,hFile,0,0,FILE_BEGIN
invoke WriteFile,hFile,pMemory,dwFileSize,ADDR SizeWritten,NULL
invoke UnmapViewOfFile,pMemory
invoke CloseHandle,hMapFile
mov hMapFile,0
jmp @safe
.endif
invoke SetFilePointer,hFile,img_dos_hdr.e_lfanew,0,FILE_BEGIN
invoke ReadFile,hFile,addr img_nt_hdrs, sizeof img_nt_hdrs,esp,0
cmp [img_nt_hdrs.Signature],"EP"
.if !zero?
invoke GetFileSize,hFile,0
.if eax == 0
invoke MessageBox,hWindow, CTEXT("文件长度为0!"),addr szCaption, MB_OK or MB_ICONHAND
invoke GetDlgItem, hWindow, IDC_FILENAME
invoke SetFocus, eax
invoke SendMessage,eax,EM_SETSEL,0,-1
mov OK,FALSE
jmp @safe
.endif
invoke CreateFileMapping,hFile,NULL,PAGE_READWRITE,0,0,NULL
mov hMapFile,eax
invoke MapViewOfFile,hMapFile,FILE_MAP_WRITE or FILE_MAP_READ,0,0,0
mov pMemory,eax
mov esi,pMemory
xor ecx,ecx
xor edx,edx
mov edi,offset szPassword1
@@2:
mov al,[esi+ecx]
mov ah,[edi+edx]
xor al,ah
rol al,3
mov [esi+ecx],al
inc ecx
inc edx
.if edx>dwPassWordLen
xor edx,edx
.endif
cmp ecx,dwFileSize
jbe @@2
invoke SetFilePointer,hFile,0,0,FILE_BEGIN
invoke WriteFile,hFile,pMemory,dwFileSize,ADDR SizeWritten,NULL
invoke UnmapViewOfFile,pMemory
invoke CloseHandle,hMapFile
mov hMapFile,0
jmp @safe
.endif
xor eax, eax
xor edx, edx
movzx ecx,[img_nt_hdrs.FileHeader.NumberOfSections]
@start0:
push ecx
push eax
push edx
invoke ReadFile,hFile,addr img_sect_hdr,sizeof img_sect_hdr,esp, 0
invoke lstrcmp, CTEXT("MK"),addr [img_sect_hdr.Name1]
.if eax == 0
invoke MessageBox, hWindow, CTEXT("您忘记了?文件已被加密过啦!"),addr szCaption,MB_OK or MB_ICONHAND
mov OK, FALSE
jmp @safe
.endif
pop edx
mov eax,img_sect_hdr.PointerToRawData
add eax,img_sect_hdr.SizeOfRawData
cmp eax,edx
jbe @start1
mov edx,eax
@start1:
pop eax
mov ecx,[img_sect_hdr.VirtualAddress]
add ecx,[img_sect_hdr.Misc.VirtualSize]
cmp eax,ecx
jae @start2
mov eax,ecx
@start2:
pop ecx
loopd @start0
mov dword ptr [img_sect_hdr.Name1+00h], "KM"
mov [img_sect_hdr.Misc.VirtualSize], attach_size
mov [img_sect_hdr.VirtualAddress], eax
mov [img_sect_hdr.SizeOfRawData], attach_size
mov [img_sect_hdr.PointerToRawData], edx
mov [img_sect_hdr.PointerToRelocations], ecx
mov [img_sect_hdr.PointerToLinenumbers], ecx
mov dword ptr [img_sect_hdr.NumberOfRelocations], ecx
mov edx, 00000FFFh
test [img_sect_hdr.VirtualAddress], edx
.if !zero?
and edx,[img_sect_hdr.VirtualAddress]
sub edx,1000h
neg edx
add [img_sect_hdr.VirtualAddress], edx
.endif
xor edx, edx
mov eax,[img_sect_hdr.PointerToRawData]
mov ecx,200h
div ecx
test edx,edx
.if !zero?
sub edx,200h
neg edx
add [img_sect_hdr.PointerToRawData],edx
.endif
mov [img_sect_hdr.Characteristics],0E00000E0h
invoke WriteFile,[hFile],addr img_sect_hdr,sizeof img_sect_hdr,esp, 0
invoke SetFilePointer,[hFile],[img_sect_hdr.PointerToRawData],0,FILE_BEGIN
push esi
push edi
mov esi,attach_start
mov edi,offset bNew
mov ecx,attach_size shr 2
rep movsd
mov ecx, attach_size and 3
rep movsb
mov esi,offset bNew
mov ecx,attach_size
@copy:
mov eax,[esi]
and eax,NOT 00000FFFh
cmp eax, attach_data_start
.if zero?
mov eax,[esi]
sub eax,attach_start
add eax,[img_nt_hdrs.OptionalHeader.ImageBase]
add eax,[img_sect_hdr.VirtualAddress]
mov [esi], eax
.endif
inc esi
loopd @copy
mov eax, [img_nt_hdrs.OptionalHeader.AddressOfEntryPoint]
add eax, [img_nt_hdrs.OptionalHeader.ImageBase]
mov dword ptr [bNew + @@oep], eax
invoke init_crc32table_m
lea ebx, szPassword1
invoke arraycrc32_m
mov dword ptr [esi],eax
mov edi, offset bNew + (offset _szRealPassword - attach_start)
mov ecx, 4
rep movsd
pop edi
pop esi
invoke WriteFile, [hFile], addr bNew, attach_size, esp, 0
invoke SetFilePointer, [hFile], [img_dos_hdr.e_lfanew], 0, FILE_BEGIN
mov eax,[img_sect_hdr.VirtualAddress]
add eax, attach_code_start - attach_start
inc [img_nt_hdrs.FileHeader.NumberOfSections]
mov [img_nt_hdrs.OptionalHeader.AddressOfEntryPoint],eax
add [img_nt_hdrs.OptionalHeader.SizeOfImage],attach_size
push 0
pop [img_nt_hdrs.OptionalHeader.DataDirectory(88).VirtualAddress]
invoke WriteFile,[hFile],addr img_nt_hdrs,sizeof img_nt_hdrs,esp, 0
@safe:
invoke CloseHandle, [hFile]
Error_Exit:
.if OK == TRUE
invoke MessageBox,hWindow, CTEXT("加密成功完成!请记住您的密码!"), addr szCaption, MB_OK or MB_ICONINFORMATION
.endif
pop fs:[0]
add esp,4
ret
Encode endp
ErrorHandler proc C lpExcept:DWORD, lpFrame:DWORD, lpContext:DWORD, lpDispatch:DWORD
mov eax,[lpExcept]
mov ecx,[lpContext]
invoke wsprintf,addr szMessage,addr szErrorThread,[eax][EXCEPTION_RECORD.ExceptionAddress],[ecx][CONTEXT.regEax], [ecx][CONTEXT.regEbx], [ecx][CONTEXT.regEcx], [ecx][CONTEXT.regEdx], [ecx][CONTEXT.regEsp], [ecx][CONTEXT.regEbp], [ecx][CONTEXT.regEsi], [ecx][CONTEXT.regEdi]
invoke MessageBox,hWindow,addr szMessage,addr szError,MB_OK OR MB_ICONHAND OR MB_APPLMODAL
mov eax,[lpContext]
m2m [eax][CONTEXT.regEsp],[SEH]
m2m [eax][CONTEXT.regEbp],[SEH+4]
m2m [eax][CONTEXT.regEbx],[SEH+8]
m2m [eax][CONTEXT.regEsi],[SEH+12]
m2m [eax][CONTEXT.regEdi],[SEH+16]
m2m [eax][CONTEXT.regEip],[SEH+20]
xor eax,eax
ret
ErrorHandler endp
ExceptionFilter proc lpExcept:DWORD
mov eax, [lpExcept]
invoke wsprintf, addr szMessage, addr szErrorFinal, [eax][EXCEPTION_RECORD.ExceptionAddress]
invoke MessageBox, hWindow, addr szMessage, addr szError, MB_OK OR MB_ICONHAND OR MB_APPLMODAL
invoke EndDialog, hWindow, eax
invoke ExitProcess, 0
xor eax,eax
inc eax
ret
ExceptionFilter endp
init_crc32table_m proc
mov ecx,256
mov edx,0EDB88320h
@OUT:
lea eax,[ecx-1]
push ecx
mov ecx, 8
@IN:
shr eax, 1
jnc @F
xor eax,edx
@@:
dec ecx
jne @IN
pop ecx
mov [crc32tble+ecx*4-4],eax
dec ecx
jne @OUT
ret
init_crc32table_m endp
arraycrc32_m proc
mov eax,-1
or ebx,ebx
jz @OK
@@:
mov dl,[ebx]
or dl,dl
je @OK
xor dl,al
movzx edx,dl
shr eax,8
xor eax,[crc32tble+edx*4]
inc ebx
jmp @B
@OK:
not eax
ret
arraycrc32_m endp
Decode proc
LOCAL dwFileSize:DWORD
LOCAL dwPassWordLen:DWORD
invoke GetDlgItemText, hWindow, IDC_FILENAME, addr szFileName, sizeof szFileName
invoke GetDlgItemText, hWindow, IDC_PASSWORD1, addr szPassword1, sizeof szPassword1
invoke GetDlgItemText, hWindow, IDC_PASSWORD2, addr szPassword2, sizeof szPassword2
invoke CreateFile, addr szFileName, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
.if eax == INVALID_HANDLE_VALUE
invoke MessageBox, hWindow, CTEXT("打开文件失败!"), addr szCaption, MB_OK or MB_ICONHAND
invoke GetDlgItem, hWindow, IDC_FILENAME
invoke SetFocus, eax
invoke SendMessage,eax,EM_SETSEL,0,-1
jmp DError_Exit
.endif
mov hFile, eax
invoke lstrlen, addr szPassword1
.if eax == 0
invoke MessageBox,hWindow, CTEXT("请先输入密码!"), addr szCaption, MB_OK or MB_ICONHAND
invoke GetDlgItem,hWindow, IDC_PASSWORD1
invoke SetFocus, eax
jmp @SafeOut
.endif
mov dwPassWordLen,eax
invoke lstrcmp ,addr szPassword1,addr szPassword2
.if eax!=0
invoke MessageBox,hWindow,CTEXT("两次密码输入不相同!"), addr szCaption, MB_OK or MB_ICONHAND
jmp @SafeOut
.endif
invoke ReadFile,hFile,addr img_dos_hdr,sizeof img_dos_hdr,esp, 0
cmp [img_dos_hdr.e_magic], "ZM"
.if zero?
invoke MessageBox,hWindow,CTEXT("PE文件不能被解密!"),addr szCaption, MB_OK or MB_ICONHAND
jmp @SafeOut
.endif
invoke SetFilePointer,hFile,img_dos_hdr.e_lfanew,0,FILE_BEGIN
invoke ReadFile,hFile,addr img_nt_hdrs, sizeof img_nt_hdrs,esp,0
cmp [img_nt_hdrs.Signature],"EP"
.if zero?
invoke MessageBox,hWindow,CTEXT("PE文件不能被解密!"),addr szCaption, MB_OK or MB_ICONHAND
jmp @SafeOut
.endif
invoke GetFileSize,hFile,0
.if eax == 0
invoke MessageBox,hWindow, CTEXT("文件长度为0!"),addr szCaption, MB_OK or MB_ICONHAND
invoke GetDlgItem, hWindow, IDC_FILENAME
invoke SetFocus, eax
invoke SendMessage,eax,EM_SETSEL,0,-1
jmp @SafeOut
.endif
mov dwFileSize,eax
invoke CreateFileMapping,hFile,NULL,PAGE_READWRITE,0,0,NULL
mov hMapFile,eax
invoke MapViewOfFile,hMapFile,FILE_MAP_WRITE or FILE_MAP_READ,0,0,0
mov pMemory,eax
mov esi,pMemory
xor ecx,ecx
xor edx,edx
mov edi,offset szPassword1
@@3:
mov al,[esi+ecx]
mov ah,[edi+edx]
ror al,3
xor al,ah
mov [esi+ecx],al
inc ecx
inc edx
.if edx>dwPassWordLen
xor edx,edx
.endif
cmp ecx,dwFileSize
jbe @@3
invoke SetFilePointer,hFile,0,0,FILE_BEGIN
invoke WriteFile,hFile,esi,dwFileSize,ADDR SizeWritten,NULL
invoke UnmapViewOfFile,pMemory
invoke CloseHandle,hMapFile
mov hMapFile,0
invoke MessageBox,hWindow, CTEXT("解密成功,请保护好的的资料!"), addr szCaption, MB_OK or MB_ICONINFORMATION
@SafeOut:
invoke CloseHandle, [hFile]
DError_Exit:
xor eax,eax
ret
Decode endp
end start