.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 IDD_Main equ 1000 IDC_FilePath equ 1002 IDC_Open equ 1003 IDC_VarName equ 1007 IDC_OutputName equ 1008 IDC_Save equ 1009 IDC_asm equ 1010 IDC_vc equ 1011 ico equ 2001 IDC_Start equ 1013 IDC_vb equ 1014 IDC_delphi equ 1015 IDM_About equ 10002 IDM_Exit equ 10003 IDM_Context equ 10004
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD AllocEx proto :DWORD,:DWORD Concat proto :DWORD,:DWORD Buf STRUCT p dd ? l dd ? Buf ENDS 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 dword ptr M1 ENDM return MACRO Arg mov eax,Arg ret ENDM
.data ofn OPENFILENAME <> n db 0 style db 0 szTagetName db 40 dup(0) VarName db 40 dup(0)
.data? ProgPath db 256 dup(?) AppPath db 1024 dup (?) BufSrc Buf <> BufTgt Buf <> hFile dd ? hTgt dd ? hInstance dd ? hDlg dd ? hMenu dd ? hSubMenu1 dd ? hSubMenu2 dd ? hSubMenu3 dd ? nRead 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 invoke CheckDlgButton,hWnd,IDC_asm,BST_CHECKED invoke GetDlgItemText,hWnd,IDC_VarName,addr VarName,sizeof VarName .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("-数据格式转换工具 V0.1- ",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 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_VarName,addr VarName,sizeof VarName .if eax==0 invoke MessageBox,hDlg,CTEXT("还未设置变量名称!"),CTEXT("提示"),MB_OK ret .endif invoke GetDlgItemText,hDlg,IDC_OutputName,addr szTagetName,sizeof szTagetName .if eax==0 invoke MessageBox,hDlg,CTEXT("请设置输出的文件名!"),CTEXT("提示"),MB_OK ret .endif invoke IsDlgButtonChecked,hDlg,IDC_asm .if eax == BST_CHECKED mov style,0 jmp @f .endif invoke IsDlgButtonChecked,hDlg,IDC_vc .if eax == BST_CHECKED mov style,1 jmp @f .endif invoke IsDlgButtonChecked,hDlg,IDC_vb .if eax == BST_CHECKED mov style,2 jmp @f .endif invoke IsDlgButtonChecked,hDlg,IDC_delphi .if eax == BST_CHECKED mov style,3 jmp @f .endif
@@: mov eax,offset VarName @@lp: inc eax cmp byte ptr [eax],0 jne @@lp sub eax,offset VarName push 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 BufSrc.l,eax invoke AllocEx,ADDR BufSrc,CTEXT("源文件") mov ecx,eax and ecx,0fh ;剩余部分 cmp ecx,0 je @@skip lea ecx,[ecx*4+ecx+3] @@skip: shr eax,4 ;栏目数 imul eax,84 add eax,ecx pop ecx ;变量名长度 inc ecx add eax,ecx ;总长度 mov BufTgt.l,eax invoke AllocEx,ADDR BufSrc,CTEXT("源文件") invoke ReadFile,hFile,BufSrc.p,BufSrc.l,ADDR nRead,0 .if eax==INVALID_HANDLE_VALUE invoke MessageBox,hDlg,CTEXT("读取文件错误!"),CTEXT("提示"),MB_OK ret .endif 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 hTgt,eax ;processing the file push edi mov edx,BufTgt.p mov ebx,offset VarName movzx edi,style nextvarch: mov al,byte ptr [ebx] cmp al,0 je vartab mov byte ptr [edx],al inc edx inc ebx jmp nextvarch vartab: mov byte ptr [edx],20h mov ecx,nRead mov ebx,BufSrc.p ;读出的内容 inc edx NextLine:: mov word ptr [edx],"bd" ;db inc edx inc edx mov byte ptr [edx],9 inc edx NextByte: movzx ax,byte ptr [ebx] ;逐个取字符串 inc ebx ;取下一位 ror ax,4 ror ah,4 add ax,"00" cmp al,":" jb DontAdjAL add al,7 DontAdjAL: cmp ah,":" jb DontAdjAH add ah,7 DontAdjAH: cmp edi,0 je asm cmp edi,1 je vc cmp edi,2 je vb cmp edi,3 je delphi vc: mov word ptr [edx],"x0" jmp do vb: mov word ptr [edx],"H&" jmp do do: inc edx inc edx jmp X1 delphi: mov word ptr [edx],"$" inc edx jmp X1 asm: mov byte ptr [edx],"0" inc edx X1: mov word ptr [edx],ax inc edx inc edx cmp edi,0 jne X2 mov byte ptr [edx],"h" inc edx X2: inc n cmp n,16 je newline mov byte ptr [edx],"," inc edx loop NextByte dec edx jmp Done newline: mov n,0 mov word ptr [edx],0A0Dh ; inc edx inc edx loop Line Line :: jmp NextLine dec edx dec edx Done: sub edx,BufTgt.p pop edi ;writing the file invoke WriteFile,hTgt,BufTgt.p,edx,ADDR nRead,0 .if eax==INVALID_HANDLE_VALUE invoke MessageBox,hDlg,CTEXT("写入错误!"),CTEXT("提示"),MB_OK ret .endif invoke CloseHandle,hTgt Exit: ret Covert 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("文本文件 (*.txt)",0,'*.txt',0) mov @stOF.lpstrFile,offset szTagetName mov @stOF.nMaxFile,MAX_PATH mov @stOF.Flags,OFN_PATHMUSTEXIST mov @stOF.lpstrDefExt,CTEXT('txt',0) mov @stOF.lpstrTitle,CTEXT("保存为文本文件") invoke GetSaveFileName,addr @stOF .if eax invoke SetDlgItemText,hDlg,IDC_OutputName,addr szTagetName ret .else invoke MessageBox,NULL,CTEXT("设置路径错误!!!"),CTEXT("提示"),MB_OK .endif mov eax,FALSE ret
SaveAs endp Concat proc dest,src pushfd push ecx push esi push edi ;looking for 0 xor eax,eax xor ecx,ecx mov edi,dest mov esi,src cld repne scasb ;storing src @@: lodsb stosb cmp al,0 jne @b mov eax,edi dec eax pop edi pop esi pop ecx popfd ret Concat endp AllocEx proc pBuf,pMsg push eax push ecx mov eax,pBuf push eax add eax,4 mov eax,[eax] ;size member of Buf structure invoke VirtualAlloc,0,eax,MEM_RESERVE or MEM_COMMIT,PAGE_READWRITE pop ecx .if eax==0 invoke MessageBox,NULL,CTEXT("不能分配内存"),CTEXT("提示"),MB_OK ret .endif mov [ecx],eax ;ptr member is set pop ecx pop eax ret AllocEx endp end Start
|