.


:




:

































 

 

 

 


Win32




 

API .

Win32 API . API ( , ). kernel32.dll, user32.dll, gdi32.dll (3 ) . kernel32.dll , , user32.dll , gdi32.dll "" . , (kernel32.dll ).

4 , 2 . ( 2 ) : 2 kernel32.dll ntdll.dll ( Win NT) , . . , "exe" . , , , , . (, , mov eax, [value] eax , value, , ).

API , , , , . .

Call VirtualAalloc

VirtualAlloc . VirtualAlloc. Native API ntdll.dll. Native API sysenter ..

API .

VirtualAlloc , .

MS SDK

LPVOID VirtualAlloc(LPVOID lpAddress, // address of region to reserve or commit DWORD dwSize, // size of region DWORD flAllocationType, // type of allocation DWORD flProtect // type of access protection);
  • lpAddress -
  • dwSize -
  • flAllocationType - 3 :
    • MEM_COMMIT
    • MEM_RESERVE , .
    • MEM_TOP_DOWN , , , .
  • flProtect . .
    • PAGE_READONLY
    • PAGE_READWRITE
    • PAGE_EXECUTE .
    • PAGE_EXECUTE_READ
    • PAGE_EXECUTE_READWRITE
    • PAGE_NOACCESS

, MS SDK.

VirtualFree VirtualAlloc .

BOOL VirtualFree(LPVOID lpAddress, // DWORD dwSize, // DWORD dwFreeType // type of free operation);

dwFreeType :

MEM_RELEASE , MEM_DECOMMIT, , MEM_RELEASE, .

, .

VirtualProtect , .

BOOL VirtualProtect(LPVOID lpAddress, // DWORD dwSize, // DWORD flNewProtect, // PDWORD lpflOldProtect // );

.

VirtualLock , .

BOOL VirtualLock(LPVOID lpAddress, // DWORD dwSize // );

.

VirtualUnlock .

BOOL VirtualUnlock(LPVOID lpAddress, DWORD dwSize);

.

.

ASM + x64 + VS.NET 2005 = ERROR?!

: ACWares
3 2008

, ( ) . , , , " ". - " " Microsoft. Visual Studio.NET 64- . , , ? ( ) . , , , " ", .

, " - , - ". - , - . VS.NET 2005. , , 64- . , Windows XP x64-Edition Windows Server 2003.

: , () C++, (), (MASM) DLL-, 2 .

. DLL-. MASM-. VS.NET 2005, ::\Microsoft Visual Studio 8\VC\bin\amd64. Path (Control Panel a System a Advanced a Environment Variables a System Variables) . , (ML64, LINK ).

(kernel.asm):

.CODE DllMain PROC mov rax,1 retDllMain ENDP Sum PROC mov rax, rcx add rax, rdx retSum ENDP END

DLL DllMain, , (, C++ -). DLL- - - DEF-. (kernel.def):

LIBRARY kernelEXPORTS Sum @1

. ( COMPILE.BAT, ):

ml64 kernel.asm /link /OUT:"kernel.dll" /DLL/entry:DllMain /DEF:kernel.def /SUBSYSTEM:CONSOLE

ML64, kernel.asm. /link - : /OUT:kernel.dll - kernel.dll; /DLL - , DLL-, /entry:DllMain - - DllMain, /DEF - def- kernel.def.

. COMPILE.BAT. , . - kernel.dll.

. Visual C++, test_x64. kernel.dll . test_x64.cpp, :

#include "stdafx.h"#include <windows.h>#include <iostream>#include <conio.h> using namespace std; // Sum 2 , typedef __int64 (*pSum)(__int64, __int64); int _tmain(int argc, _TCHAR* argv[]){ // __int64 a, b, r = 0; // DLL- HMODULE hModule; // pSum Sum; // DLL hModule = LoadLibraryA("kernel.dll"); // Sum Sum = (pSum)GetProcAddress(hModule, "Sum"); cout << "A = "; cin >> a; cout << "B = "; cin >> b; // r = Sum(a, b); cout << "Result = " << r << endl; // DLL FreeLibrary(hModule); getch(); return 0;}

. . , 64- . . Solution Explorer a test_x64 a Properties. <Configuration Manager:>. <Action solution platform> <New:>. <x64>. ( , , VS.NET 64 ( , Visual C++) - ). OK. test_x64 Platform x64. Close, . : Configuration Properties a C/C++ a Preprocessor a Preprocessor Definitions _WIN32 _WIN64. , Configuration Properties a Linker a Advanced a Target Machine /MACHINE:X64. OK. , .

: , , - ( ) , . : SampleX64.zip. (, 64 ), - : rax, rdx, rcx? ? Sum ? , < >. .. , 64- . , , , ( ) .

( 1)





:


: 2015-10-01; !; : 607 |


:

:

.
==> ...

1567 - | 1437 -


© 2015-2024 lektsii.org - -

: 0.018 .