;//code by laomms 2007.6
.586 .model flat, stdcall option casemap :none
include windows.inc include user32.inc include kernel32.inc include masm32.inc include comdlg32.inc include shell32.inc include comctl32.inc
includelib user32.lib includelib kernel32.lib includelib masm32.lib includelib comdlg32.lib includelib shell32.lib includelib comctl32.lib include bin2coff.inc
IDR_MENU equ 10000 ico equ 2001 IDD_Main equ 1000 IDC_FilePath equ 1002 IDC_Open equ 1003 IDC_Label equ 1007 IDC_OutputName equ 1008 IDC_Save equ 1009 IDC_Start equ 1013 IDM_Context equ 10004 IDM_About equ 10002 IDM_Exit equ 10003
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD 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
.data ofn OPENFILENAME <> n db 0 style db 0 szTagetName db 40 dup(0) LabelName db 40 dup(0)
.data? ProgPath db 256 dup(?) AppPath db 1024 dup (?) BufTgt dd ? hTagetFile dd ? hInstance dd ? hDlg dd ? hMenu dd ? hSubMenu1 dd ? hSubMenu2 dd ? hSubMenu3 dd ? nRead dd ? hFile dd ? hHeap dd ? NumberOfBytesRead dd ? nNumberOfBytesToRead dd ? nNumberOfBytesToWrite dd ? lpBuffer dd ? lpMem dd ?
.code start: invoke GetModuleHandle, NULL mov hInstance,eax invoke DialogBoxParam, hInstance, IDD_Main, NULL, addr DlgProc, NULL invoke ExitProcess,eax DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM push hWnd pop hDlg .if uMsg == WM_INITDIALOG invoke GetWindowLong,hWnd,GWL_EXSTYLE or eax,WS_EX_LAYERED invoke LoadIcon,hInstance,ico invoke SendMessage,hWnd,WM_SETICON,1,eax invoke LoadMenu, hInstance, CTEXT("MyMenu") mov hMenu , eax invoke GetSubMenu, hMenu,0 mov hSubMenu1, eax invoke GetSubMenu, hMenu,1 mov hSubMenu2, eax invoke GetSubMenu, hMenu,2 mov hSubMenu3, eax .elseif uMsg==WM_COMMAND mov eax,wParam .if ax==IDC_Open call GetFilePath invoke SetDlgItemText,hWnd,IDC_FilePath,addr AppPath .elseif ax==IDC_Start call Covert .elseif ax==IDC_Save call SaveAs .elseif ax==IDM_Context invoke MessageBox,NULL,CTEXT("这个小工具可以将任何文件转成16进制数据格式以供调用。") ,CTEXT("说明"),MB_OK .elseif ax==IDM_About invoke MessageBox,NULL,CTEXT("-BIN2COFF- ",13,"-== laomms 2007.7 ==--") ,CTEXT("关于"),MB_OK .elseif ax==IDM_Exit invoke EndDialog,hWnd,0 .endif .elseif uMsg==WM_CONTEXTMENU mov eax, lParam and eax, 0ffffh mov ebx, lParam shr ebx, 16 invoke TrackPopupMenu, hSubMenu1, TPM_LEFTALIGN, eax, ebx, 0, hWnd, 0 invoke TrackPopupMenu, hSubMenu2, TPM_LEFTALIGN, eax, ebx, 0, hWnd, 0 invoke TrackPopupMenu, hSubMenu3, TPM_LEFTALIGN, eax, ebx, 0, hWnd, 0 .elseif uMsg== WM_CLOSE invoke EndDialog,hWnd,0 .endif xor eax,eax ret DlgProc endp GetFilePath proc mov ofn.lStructSize, sizeof ofn push hDlg pop ofn.hwndOwner push hInstance pop ofn.hInstance lea eax, offset AppPath mov ofn.lpstrFile, eax mov ofn.nMaxFile, offset AppPath mov ofn.Flags, OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST mov ofn.lpstrFilter, CTEXT("所有文件",0,"*.*",0 , 0) mov ofn.lpstrTitle, CTEXT("请打开一个PE可执行文件…") invoke GetOpenFileName, addr ofn .if !eax invoke MessageBox,hDlg,CTEXT("打开程序错误!"),CTEXT("提示"),MB_OK .endif ret GetFilePath endp SaveAs proc LOCAL @stOF:OPENFILENAME
invoke RtlZeroMemory,addr @stOF,sizeof @stOF mov @stOF.lStructSize,sizeof @stOF push hDlg pop @stOF.hwndOwner mov @stOF.lpstrFilter,CTEXT("MS COFF文件 (*.obj)",0,'*.obj',0) mov @stOF.lpstrFile,offset szTagetName mov @stOF.nMaxFile,MAX_PATH mov @stOF.Flags,OFN_PATHMUSTEXIST mov @stOF.lpstrDefExt,CTEXT('obj',0) mov @stOF.lpstrTitle,CTEXT("保存为文本文件") invoke GetSaveFileName,addr @stOF .if eax ;invoke CreateFile,addr szTagetName,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 ;.if eax==INVALID_HANDLE_VALUE ; invoke MessageBox,hDlg,CTEXT("创建错误"),CTEXT("提示"),MB_OK ; ret ;.endif ;mov hTagetFile,eax invoke SetDlgItemText,hDlg,IDC_OutputName,addr szTagetName .else invoke MessageBox,NULL,CTEXT("设置路径错误!!!"),CTEXT("提示"),MB_OK .endif mov eax,FALSE ret
SaveAs endp Covert proc invoke GetDlgItemText,hDlg,IDC_FilePath,addr AppPath,sizeof AppPath .if eax==0 invoke MessageBox,hDlg,CTEXT("请选择源文件!"),CTEXT("提示"),MB_OK ret .endif invoke GetDlgItemText,hDlg,IDC_Label,addr LabelName,sizeof LabelName .if eax==0 invoke MessageBox,hDlg,CTEXT("还未设置标签名称!"),CTEXT("提示"),MB_OK ret .endif push offset LabelName call GetLabel mov ebx, eax invoke CreateFile,addr AppPath,GENERIC_READ,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 .if eax==INVALID_HANDLE_VALUE invoke MessageBox,hDlg,CTEXT("打开错误!"),CTEXT("提示"),MB_OK ret .endif mov hFile,eax invoke GetFileSize,eax,0 .if eax==0 invoke MessageBox,hDlg,CTEXT("源文件内容为空!"),CTEXT("提示"),MB_OK ret .endif mov nNumberOfBytesToRead, eax lea ecx, [eax+3Ch] mov nNumberOfBytesToWrite, ecx lea ecx, [ecx+ebx+17h] push ecx ; dwBytes call GetProcessHeap
mov hHeap, eax push 8 ; dwFlags push eax ; hHeap call HeapAlloc .if eax==0 invoke MessageBox,hDlg,CTEXT("不能申请内存!"),CTEXT("提示"),MB_OK ret .endif mov edi, eax mov lpBuffer, eax mov lpMem, eax add eax, 3Ch invoke ReadFile,hFile,eax,nNumberOfBytesToRead,offset NumberOfBytesRead,0 .if eax==INVALID_HANDLE_VALUE invoke MessageBox,hDlg,CTEXT("读取文件错误!"),CTEXT("提示"),MB_OK ret .endif invoke CloseHandle,hFile invoke CreateFile,addr szTagetName,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 .if eax==INVALID_HANDLE_VALUE invoke MessageBox,hDlg,CTEXT("创建错误"),CTEXT("提示"),MB_OK ret .endif mov hTagetFile,eax mov word ptr [edi], 14Ch mov word ptr [edi+2], 1 mov dword ptr [edi+4], 0 mov eax, nNumberOfBytesToWrite mov [edi+8], eax mov dword ptr [edi+0Ch], 1 mov word ptr [edi+10h], 0 mov word ptr [edi+12h], 184h add edi, 14h mov dword ptr [edi], 7461642Eh mov dword ptr [edi+4], 61h mov dword ptr [edi+8], 0 mov dword ptr [edi+0Ch], 0 mov eax, nNumberOfBytesToRead mov [edi+10h], eax mov dword ptr [edi+14h], 3Ch mov dword ptr [edi+18h], 0 mov dword ptr [edi+1Ch], 0 mov word ptr [edi+20h], 0 mov word ptr [edi+22h], 0 mov dword ptr [edi+24h], 0C0300040h add edi, 28h invoke WriteFile,hTagetFile,lpBuffer,nNumberOfBytesToWrite,offset NumberOfBytesRead,0 .if eax==INVALID_HANDLE_VALUE invoke MessageBox,hDlg,CTEXT("写入错误!"),CTEXT("提示"),MB_OK ret .endif add edi, nNumberOfBytesToRead mov lpBuffer, edi cmp ebx, 8 jbe @1
mov dword ptr [edi], 0 mov dword ptr [edi+4], 4 jmp done
@1: push ebx push edi push offset LabelName call search
done: mov dword ptr [edi+8], 0 mov word ptr [edi+0Ch], 1 mov word ptr [edi+0Eh], 0 mov byte ptr [edi+10h], 2 mov byte ptr [edi+11h], 0 add edi, 12h mov eax, ebx cmp ebx, 8 jbe @2
add eax, 5 mov [edi], eax add edi, 4 push eax push ebx push edi push offset LabelName ; "_pEXE" call search pop eax jmp @WriteFile @2: mov eax, 4 mov [edi], eax @WriteFile: add eax, 12h invoke WriteFile,hTagetFile,lpBuffer,eax,offset NumberOfBytesRead,0 .if eax==INVALID_HANDLE_VALUE invoke MessageBox,hDlg,CTEXT("写入错误!"),CTEXT("提示"),MB_OK ret .endif invoke CloseHandle,hTagetFile invoke HeapFree,hHeap,0,lpMem ret Covert endp search proc near
arg_0 = dword ptr 8 arg_4 = dword ptr 0Ch arg_8 = dword ptr 10h
push ebp mov ebp, esp push esi push edi cld mov esi, [ebp+arg_0] mov edi, [ebp+arg_4] mov ecx, [ebp+arg_8] shr ecx, 2 rep movsd mov ecx, [ebp+arg_8] and ecx, 3 rep movsb pop edi pop esi leave retn 0Ch
search endp GetLabel proc near
arg_0 = dword ptr 4
mov eax, [esp+arg_0] lea esp, [esp+0] add eax, 0
@@1: mov edx, [eax] add eax, 4 test edx, 0FFh jz @@4
test edx, 0FF00h jz @@3
test edx, 0FF0000h jz @@2
test edx, 0FF000000h jnz @@1
sub eax, 1 sub eax, [esp+arg_0] retn 4
@@2: sub eax, 2 sub eax, [esp+arg_0] retn 4
@@3: sub eax, 3 sub eax, [esp+arg_0] retn 4
@@4: sub eax, 4 sub eax, [esp+arg_0] retn 4
GetLabel endp
end start
|