
Г-н Посол
   
Профиль
Группа: Экс. модератор
Сообщений: 3668
Регистрация: 13.7.2003
Где: 58°38' с.ш. 4 9°41' в.д.
Репутация: 2 Всего: 112
|
Вот, перевел, проверял - работает... | Код | procedure AsmProc; assembler; const API_size = 15; ButtonID = 1; EditID = 2; IDM_HELLO = 1; IDM_CLEAR = 2; IDM_GETTEXT = 3; IDM_EXIT = 4; SIZEOF_WNDCLASSEX = SizeOf(WNDCLASSEX);
asm pushad call @Delta @Delta: pop ebp sub ebp, offset @Delta
mov eax, [ebp + @CallAdr] mov [esp + 1ch], eax
xor edx, edx mov eax, fs:[edx] dec edx
@_SearchK32: cmp [eax], edx je @_CheckK32 mov eax, dword [eax] jmp @_SearchK32
@_CheckK32: mov eax, [eax+4] xor ax, ax
@_SearchMZ: cmp word ptr [eax],5A4Dh je @_CheckMZ sub eax,10000h jmp @_SearchMZ
@_CheckMZ: mov edx, [eax+3ch] add edx, eax cmp word ptr [edx],4550h jne @_Exit
//****************************************
mov edi, eax mov esi, edx
@Get_Api: mov [ebp + @hKernel], edi add esi, 78h mov ebx, [esi] add ebx, edi
mov esi, [ebx + 18h] mov [ebp + @NumberOfNames], esi mov edx, esi
mov esi, [ebx + 1ch] add esi, edi mov [ebp + @ExportAddressTable], esi
mov esi, [ebx + 20h] add esi, edi mov [ebp + @ExportNameTableP], esi
mov esi, [ebx + 24h] add esi, edi mov [ebp + @ExportOrdinalTable], esi
xor ebx, ebx mov esi, [ebp + @ExportNameTableP]
@Search_Api: mov [ebp + @Index], esi mov esi, [esi] add esi, [ebp + @hKernel] lea edi, [ebp + @strGetProcAddress] mov ecx, API_size repe cmpsb je @Get_Addr add dword ptr [ebp + @Index], 4 mov esi, [ebp + @Index] inc ebx cmp ebx, edx jge @_exit jmp @Search_Api
@Get_Addr: xchg eax, ebx mov ebx, 2 mul ebx mov esi, [ebp + @ExportOrdinalTable] add esi, eax
xor eax, eax mov ax, word ptr [esi] mov ecx, 4 mul ecx mov esi, [ebp + @ExportAddressTable] add esi, eax lodsd add eax, dword ptr [ebp + @hKernel] mov [ebp + @GPA], eax
//////////////////////////////////////////////////////////////////////////////// // Начало рабочего кода ////////////////////////////////////////////////////////////////////////////////
// Подключение "user32.dll" lea ecx, [ebp + @strUser32Dll] push ecx lea eax, [ebp + @strLoadLibrary] call @KernelDllProc mov [ebp + @hUser32], eax
push 0 lea eax, [ebp + @strGetModuleHandle] call @KernelDllProc mov [ebp + @hInstance], eax
@WinMain: lea eax, [ebp + @wc]///// mov [vvv], eax //////
// Заполнение структуры класса окна mov dword ptr [ebp + @wc + WNDCLASSEX.cbSize], SIZEOF_WNDCLASSEX mov dword ptr [ebp + @wc + WNDCLASSEX.Style], CS_HREDRAW or CS_VREDRAW lea eax, [ebp + @WndProc] mov dword ptr [ebp + @wc + WNDCLASSEX.lpfnWndProc], eax mov dword ptr [ebp + @wc + WNDCLASSEX.cbClsExtra], 0 mov dword ptr [ebp + @wc + WNDCLASSEX.cbWndExtra], 0 push dword ptr [ebp + @hInstance] pop dword ptr [ebp + @wc + WNDCLASSEX.hInstance] mov dword ptr [ebp + @wc + WNDCLASSEX.hbrBackground], COLOR_BTNFACE+1 lea eax, [ebp + @MenuName] mov dword ptr [ebp + @wc + WNDCLASSEX.lpszMenuName], 0//eax lea eax, [ebp + @ClassName] mov dword ptr [ebp + @wc + WNDCLASSEX.lpszClassName], eax
// Установка иконки push 32512 // IDI_APPLICATION push 0 lea eax, [ebp + @strLoadIcon] call @UserDllProc mov dword ptr [ebp + @wc + WNDCLASSEX.hIcon], eax mov dword ptr [ebp + @wc + WNDCLASSEX.hIconSm], 0//eax
// Установка курсора push 32512 // IDC_ARROW push 0 lea eax, [ebp + @strLoadCursor] call @UserDllProc mov dword ptr [ebp + @wc + WNDCLASSEX.hCursor], eax
// Регистрация класса окна lea eax, [ebp + @wc] push eax lea eax, [ebp + @strRegisterClassEx] call @UserDllProc
// Создание окна push 0 push dword ptr [ebp + @hInstance] push 0 push 0 push 200 push 300 push CW_USEDEFAULT push CW_USEDEFAULT push WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU//WS_OVERLAPPEDWINDOW lea eax, [ebp + @AppName] push eax lea eax, [ebp + @ClassName] push eax push WS_EX_CLIENTEDGE lea eax, [ebp + @strCreateWindowEx] call @UserDllProc mov [ebp + @hwnd], eax
// Показать окно push SW_SHOWNORMAL push dword ptr [ebp + @hwnd] lea eax, [ebp + @strShowWindow] call @UserDllProc
// Обновить содержимое окна push dword ptr [ebp + @hwnd] lea eax, [ebp + @strUpdateWindow] call @UserDllProc
// Цикл очереди сообщений @While1: push 0 push 0 push 0 lea eax, [ebp + @msg] push eax lea eax, [ebp + @strGetMessage] call @UserDllProc
test eax, eax jz @Break1
lea eax, [ebp + @msg] push eax lea eax, [ebp + @strTranslateMessage] call @UserDllProc
lea eax, [ebp + @msg] push eax lea eax, [ebp + @strDispatchMessage] call @UserDllProc
jmp @While1
@Break1: jmp @_Exit
// Оконная процедура // WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM @WndProc: push ebp
call @Delta2 @Delta2: pop ebp sub ebp, offset @Delta2
// Параметры, передаваемые функции mov eax, [esp + 14h] mov [ebp + @_lParam], eax mov eax, [esp + 10h] mov [ebp + @_wParam], eax mov eax, [esp + 0Ch] mov [ebp + @_uMsg], eax mov eax, [esp + 08h] mov [ebp + @_hWnd], eax
cmp dword ptr [ebp + @_uMsg], WM_DESTROY jnz @ELSEIF1
push 0 lea eax, [ebp + @strPostQuitMessage] call @UserDllProc jmp @ENDIF1
@ELSEIF1: cmp dword ptr [ebp + @_uMsg], WM_CREATE jnz @ELSEIF2
// Создание поля ввода push 0 push dword ptr [ebp + @hInstance] push EditID push dword ptr [ebp + @_hWnd] push 25 push 200 push 35 push 50 push WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL push 0 lea eax, [ebp + @EditClassName] push eax push WS_EX_CLIENTEDGE lea eax, [ebp + @strCreateWindowEx] call @UserDllProc mov [ebp + @hwndEdit], eax
// Установить фокус на поле ввода push dword ptr [ebp + @hwndEdit] lea eax, [ebp + @strSetFocus] call @UserDllProc
// Создание кнопки push 0 push dword ptr [ebp + @hInstance] push ButtonID push dword ptr [ebp + @_hWnd] push 25 push 140 push 70 push 75 push WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON lea eax, [ebp + @ButtonText] push eax lea eax, [ebp + @ButtonClassName] push eax push 0 lea eax, [ebp + @strCreateWindowEx] call @UserDllProc mov [ebp + @hwndButton], eax
jmp @ENDIF1
@ELSEIF2: cmp dword ptr [ebp + @_uMsg], WM_COMMAND jnz @ELSEIF3
mov eax, [ebp + @_wParam] cmp dword ptr [ebp + @_lParam], 0 jnz @ELSEIF2_1
// lParam == 0
cmp ax, IDM_HELLO jnz @ELSEIF2_1_1
lea eax, [ebp + @TestString] push eax push dword ptr [ebp + @hwndEdit] lea eax, [ebp + @strSetWindowText] call @UserDllProc jmp @ENDIF2_1
@ELSEIF2_1_1: cmp ax, IDM_CLEAR jnz @ELSEIF2_1_2
push 0 push dword ptr [ebp + @hwndEdit] lea eax, [ebp + @strSetWindowText] call @UserDllProc jmp @ENDIF2_1
@ELSEIF2_1_2: cmp ax, IDM_GETTEXT jnz @ELSEIF2_1_3
push 512 lea eax, [ebp + @buffer] push eax push dword ptr [ebp + @hwndEdit] lea eax, [ebp + @strGetWindowText] call @UserDllProc
push MB_OK lea eax, [ebp + @AppName] push eax lea eax, [ebp + @buffer] push eax push dword ptr [ebp + @hwndEdit] lea eax, [ebp + @strMessageBox] call @UserDllProc jmp @ENDIF2_1
@ELSEIF2_1_3: push dword ptr [@hWnd] lea eax, [ebp + @strDestroyWindow] call @UserDllProc jmp @ENDIF2_1
@ENDIF2_1: jmp @ENDIF1
// lParam <> 0 @ELSEIF2_1: cmp ax, ButtonID jnz @ELSEIF2_2
shr eax, 16 cmp eax, BN_CLICKED jnz @ENDIF2_2
push 0 push IDM_GETTEXT push WM_COMMAND push dword ptr [ebp + @_hWnd] lea eax, [ebp + @strSendMessage] call @UserDllProc
@ELSEIF2_2: @ENDIF2_2: jmp @ENDIF1
@ELSEIF3: push dword ptr [ebp + @_lParam] push dword ptr [ebp + @_wParam] push dword ptr [ebp + @_uMsg] push dword ptr [ebp + @_hWnd] lea eax, [ebp + @strDefWindowProc] call @UserDllProc jmp @_Exit2
@ENDIF1: xor eax, eax @_Exit2: pop ebp ret
@_Exit: popad jmp eax
@KernelDllProc: push eax mov eax, [ebp + @hKernel] push eax call [ebp + @GPA] jmp eax
@UserDllProc: push eax mov eax, [ebp + @hUser32] push eax call [ebp + @GPA] jmp eax
@NumberOfNames: dd 0 @ExportAddressTable: dd 0 @ExportNameTableP: dd 0 @ExportOrdinalTable: dd 0 @Index: dd 0 @strGetProcAddress: db 'GetProcAddress', 0 // API_Size = 15 @GPA: dd 0
@strLoadLibrary: db 'LoadLibraryA', 0 @strUser32Dll: db 'user32.dll', 0 @strMessageBox: db 'MessageBoxA', 0 @strGetModuleHandle: db 'GetModuleHandleA', 0 @strGetCommandLine: db 'GetCommandLineA', 0 @strLoadIcon: db 'LoadIconA', 0 @strLoadCursor: db 'LoadCursorA', 0 @strRegisterClassEx: db 'RegisterClassExA', 0 @strCreateWindowEx: db 'CreateWindowExA', 0 @strShowWindow: db 'ShowWindow', 0 @strUpdateWindow: db 'UpdateWindow', 0 @strGetMessage: db 'GetMessageA', 0 @strTranslateMessage: db 'TranslateMessage', 0 @strDispatchMessage: db 'DispatchMessageA', 0 @strPostQuitMessage: db 'PostQuitMessage', 0 @strSetFocus: db 'SetFocus', 0 @strSetWindowText: db 'SetWindowTextA', 0 @strGetWindowText: db 'GetWindowTextA', 0 @strDestroyWindow: db 'DestroyWindow', 0 @strDefWindowProc: db 'DefWindowProcA', 0 @strSendMessage: db 'SendMessageA', 0 @strGetLastError: db 'GetLastError', 0
@hKernel: dd 0 @hUser32: dd 0 @hInstance: dd 0
@wc: dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 @msg: dd 0, 0, 0, 0, 0, 0, 0 @hwnd: dd 0
@_hWnd: dd 0 @_uMsg: dd 0 @_wParam: dd 0 @_lParam: dd 0
@ClassName: db 'SimpleWndClass', 0 @AppName: db 'Our First Window', 0 @MenuName: db 'FirstMenu', 0 @ButtonClassName: db 'button', 0 @ButtonText: db 'My First Button', 0 @EditClassName: db 'edit', 0 @TestString: db 'Wow! Im in an edit box now', 0
@CommandLine: dd 0 @hwndButton: dd 0 @hwndEdit: dd 0 @buffer: dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@CallAdr: dd EndOfProcID end; |
--------------------
С уважением, г-н Посол.
|