📄 kernel32.java
字号:
*
* SEC_RESERVE Reserves all pages of a section without allocating physical storage.
*
* The reserved range of pages cannot be used by any other allocation operations until the range of pages is released.
*
* Reserved pages can be identified in subsequent calls to the VirtualAlloc function. This attribute is valid only if the hFile parameter is INVALID_HANDLE_VALUE; that is, a file mapping object that the operating system paging file backs.
* dwMaximumSizeHigh
* [in] The high-order DWORD of the maximum size of a file mapping object.
* dwMaximumSizeLow
* [in] The low-order DWORD of the maximum size of a file mapping object.
*
* If this parameter and dwMaximumSizeHigh are 0 (zero), the maximum size of the file mapping object is equal to the current size of the file that hFile identifies.
*
* An attempt to map a file with a length of 0 (zero) fails with an error code of ERROR_FILE_INVALID. Applications should test for files with a length of 0 (zero) and reject those files.
* lpName
* [in] A pointer to a null-terminated string that specifies the name of a mapping object.
*
* If this parameter matches the name of an existing mapping object that is named, the function requests access to the mapping object with the protection that flProtect specifies.
*
* If this parameter is NULL, the mapping object is created without a name.
*
* If lpName matches the name of an existing event, semaphore, mutex, waitable timer, or job object, the function fails, and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same namespace.
*
* Terminal Services: The name can have a "Global\" or "Local\" prefix to explicitly create the object in the global or session namespace. The remainder of the name can contain any character except the backslash character (\). Creating a file-mapping object in the global namespace requires the SeCreateGlobalPrivilege privilege. For more information, see Kernel Object Namespaces.
*
* Windows XP: Fast user switching is implemented by using Terminal Services sessions. The first user to log on uses session 0 (zero), the next user to log on uses session 1 (one), and so on. Kernel object names must follow the guidelines that are outlined for Terminal Services so that applications can support multiple users.
*
* Windows 2000: If Terminal Services is not running, the "Global\" and "Local\" prefixes are ignored. The remainder of the name can contain any character except the backslash character.
*
* Windows NT: The name can contain any character except the backslash character.
*
* Windows Me/98/95: The name can contain any character except the backslash character. An empty string ("") is a valid object name.
*
* Return Values
*
* If the function succeeds, the return value is a handle to the file mapping object.
*
* If the object exists before the function call, the function returns a handle to the existing object (with its current size, not the specified size), and GetLastError returns ERROR_ALREADY_EXISTS.
*
* If the function fails, the return value is NULL. To get extended error information, call GetLastError.
*
* </pre>
*
* @throws IllegalAccessException
* @throws NativeException
*/
public static HANDLE CreateFileMapping(HANDLE hFile,
SecurityAttributes lpAttributes, PageAccess flProtect,
DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow, String lpName)
throws NativeException, IllegalAccessException {
if (nCreateFileMapping == null) {
nCreateFileMapping = new JNative(DLL_NAME, "CreateFileMappingA");
nCreateFileMapping.setRetVal(Type.INT);
}
nCreateFileMapping.setParameter(0, hFile.getValue());
nCreateFileMapping.setParameter(1,
lpAttributes == null ? NullPointer.NULL : lpAttributes
.getPointer());
nCreateFileMapping.setParameter(2, flProtect.getValue());
nCreateFileMapping.setParameter(3, dwMaximumSizeHigh.getValue());
nCreateFileMapping.setParameter(4, dwMaximumSizeLow.getValue());
nCreateFileMapping.setParameter(5, lpName);
nCreateFileMapping.invoke();
return new HANDLE(Integer.parseInt(nCreateFileMapping.getRetVal()));
}
/**
* <pre>
* MapViewOfFileEx
*
* Maps a view of a file mapping into the address space of a calling process. A caller can optionally specify a suggested memory address for the view.
*
* To specify the NUMA node for the physical memory, see MapViewOfFileExNuma.
*
* LPVOID MapViewOfFileEx(
* HANDLE hFileMappingObject,
* DWORD dwDesiredAccess,
* DWORD dwFileOffsetHigh,
* DWORD dwFileOffsetLow,
* SIZE_T dwNumberOfBytesToMap,
* LPVOID lpBaseAddress
* );
*
* Parameters
*
* hFileMappingObject
* [in] A handle to an open handle to a file mapping object. The CreateFileMapping and OpenFileMapping functions return this handle.
* dwDesiredAccess
* [in] The type of access to a file mapping object, which ensures the page protection of the pages. This parameter can be one of the following values.
* Value Meaning
* FILE_MAP_WRITE Read-and-write access. The mapping object must be created with PAGE_READWRITE protection. A read/write view of the file is mapped.
* FILE_MAP_READ Read-only access. The mapping object must be created with PAGE_READWRITE or PAGE_READONLY protection. A read-only view of the file is mapped.
* FILE_MAP_COPY Copy-on-write access. The mapping object must be created with PAGE_WRITECOPY protection.
*
* The system commits physical storage from the paging file at the time MapViewOfFileEx is called. The actual physical storage is not used until a thread in the process writes to an address in the view. At that point, the system copies the original page to a new page backed by the paging file, maps the page into the process address space, and changes the page protection to PAGE_READWRITE. The threads in the process can access only this local copy of the data, not the original data. If this page is trimmed from the working set of the process, it can be written to the paging file storage that is committed when MapViewOfFileEx is called.
*
* This process only allocates physical memory when a virtual address is actually written to. Changes are never written back to the original file, and are freed when the thread in the process unmaps the view.
*
* Paging file space for the entire view is committed when copy-on-write access is specified, because the thread in the process can write to every single page. Therefore, enough physical storage space must be obtained at the time MapViewOfFileEx is called.
* FILE_MAP_EXECUTE Execute access. Code can be run from the mapped memory. The mapping object must be created with PAGE_EXECUTE_READWRITE or PAGE_EXECUTE_READ access.
*
* Windows Server 2003 and Windows XP: This feature is not available until Windows XP SP2 and Windows Server 2003 SP1.
*
* dwFileOffsetHigh
* [in] The high-order DWORD of the file offset where the view is to begin.
* dwFileOffsetLow
* [in] The low-order DWORD of the file offset where the view is to begin. The combination of the high and low offsets must specify an offset within the file that matches the memory allocation granularity of the system, or the function fails. That is, the offset must be a multiple of the allocation granularity. To obtain the memory allocation granularity of the system, use the GetSystemInfo function, which fills in the members of a SYSTEM_INFO structure.
* dwNumberOfBytesToMap
* [in] The number of bytes of a file mapping to map to a view. If this parameter is 0 (zero), the mapping extends from the specified offset to the end of the section.
* lpBaseAddress
* [in] A pointer to the memory address in the calling process address space where mapping begins. This must be a multiple of the system's memory allocation granularity, or the function fails. To determine the memory allocation granularity of the system, use the GetSystemInfo function. If there is not enough address space at the specified address, the function fails.
*
* If lpBaseAddress is NULL, the operating system chooses the mapping address. In this scenario, the function is equivalent to the MapViewOfFile function.
*
* While it is possible to specify an address that is safe now (not used by the operating system), there is no guarantee that the address will remain safe over time. Therefore, it is better to let the operating system choose the address. In this case, you would not store pointers in the memory mapped file, you would store offsets from the base of the file mapping so that the mapping can be used at any address.
*
* Return Values
*
* If the function succeeds, the return value is the starting address of the mapped view.
*
* If the function fails, the return value is NULL. To get extended error information, call GetLastError.
*
* </pre>
* @throws IllegalAccessException
* @throws NativeException
*/
public static LONG MapViewOfFileEx(HANDLE hFileMappingObject,
FileMap dwDesiredAccess, DWORD dwFileOffsetHigh,
DWORD dwFileOffsetLow, DWORD dwNumberOfBytesToMap, LONG lpBaseAddress) throws IllegalAccessException, NativeException {
if (nMapViewOfFileEx == null) {
nMapViewOfFileEx = new JNative(DLL_NAME, "MapViewOfFileEx");
nMapViewOfFileEx.setRetVal(Type.INT);
}
nMapViewOfFileEx.setParameter(0, hFileMappingObject.getValue());
nMapViewOfFileEx.setParameter(1, dwDesiredAccess.getValue());
nMapViewOfFileEx.setParameter(2, dwFileOffsetHigh.getValue());
nMapViewOfFileEx.setParameter(3, dwFileOffsetLow.getValue());
nMapViewOfFileEx.setParameter(4, dwNumberOfBytesToMap.getValue());
nMapViewOfFileEx.setParameter(5, lpBaseAddress.getValue());
nMapViewOfFileEx.invoke();
return new HANDLE(Integer.parseInt(nMapViewOfFileEx.getRetVal()));
}
/**
*
* <b>IsBadReadPtr</b>
* <pre>
* Verifies that the calling process has read access to the specified range of memory.
*
* BOOL IsBadReadPtr(
* const VOID* lp,
* UINT_PTR ucb
* );
*
* Parameters
*
* lp
* [in] A pointer to the first byte of the memory block.
* ucb
* [in] The size of the memory block, in bytes. If this parameter is zero, the return value is zero.
*
* Return Values
*
* If the calling process has read access to all bytes in the specified memory range, the return value is zero.
*
* If the calling process does not have read access to all bytes in the specified memory range, the return value is nonzero.
*
* If the application is compiled as a debugging version, and the process does not have read access to all bytes in the specified memory range, the function causes an assertion and breaks into the debugger. Leaving the debugger, the function continues as usual, and returns a nonzero value. This behavior is by design, as a debugging aid.
* </pre>
* @throws IllegalAccessException
* @throws NativeException */
public static boolean IsBadReadPtr(Pointer pointer) throws NativeException, IllegalAccessException {
JNative nIsBadReadPtr = new JNative(DLL_NAME, "IsBadReadPtr");
nIsBadReadPtr.setRetVal(Type.INT);
nIsBadReadPtr.setParameter(0, pointer.getPointer());
nIsBadReadPtr.setParameter(1, pointer.getSize());
nIsBadReadPtr.invoke();
return "0".equals(nIsBadReadPtr.getRetVal());
}
/**
* <b>UnmapViewOfFile</b>
* <pre>
*
*
* Unmaps a mapped view of a file from the calling process's address space.
*
* BOOL UnmapViewOfFile(
* LPCVOID lpBaseAddress
* );
*
* Parameters
*
* lpBaseAddress
* [in] A pointer to the base address of the mapped view of a file that is to be unmapped. This value must be identical to the value returned by a previous call to the MapViewOfFile or MapViewOfFileEx function.
*
* Return Values
*
* If the function succeeds, the return value is nonzero, and all dirty pages within the specified range are written "lazily" to disk.
*
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
* </pre>
* @throws IllegalAccessException
* @throws NativeException
*/
public static boolean UnmapViewOfFile(LONG lpBaseAddress) throws NativeException, IllegalAccessException {
JNative nUnmapViewOfFile = new JNative(DLL_NAME, "UnmapViewOfFile");
nUnmapViewOfFile.setRetVal(Type.INT);
nUnmapViewOfFile.setParameter(0, lpBaseAddress.getValue());
nUnmapViewOfFile.invoke();
return !"0".equals(nUnmapViewOfFile.getRetVal());
}
/**
* <pre>
* SetConsoleCtrlHandler
*
* Adds or removes an application-defined HandlerRoutine function from the list of handler functions for the calling process.
*
* If no handler function is specified, the function sets an inheritable attribute that determines whether the calling process ignores CTRL+C signals.
*
* BOOL WINAPI SetConsoleCtrlHandler(
* PHANDLER_ROUTINE HandlerRoutine,
* BOOL Add
* );
*
* Parameters
*
* HandlerRoutine
* [in] Pointer to the application-defined HandlerRoutine function to add or remove. This parameter can be NULL.
*
* Windows Me/98/95: This parameter cannot be NULL.
*
* Add
* [in] If this parameter is TRUE, the handler is added; if it is FALSE, the handler is removed.
*
* If the HandlerRoutine parameter is NULL, a TRUE value causes the calling process to ignore CTRL+C input, and a FALSE value restores normal processing of CTRL+C input. This attribute of ignoring or processing CTRL+C is inherited by child processes.
*
* Return Value
*
* If the function succeeds, the return value is nonzero.
*
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
* </pre>
* @throws IllegalAccessException
* @throws NativeException */
public static boolean SetConsoleCtrlHandler(Callback callback, boolean Add) throws NativeException, IllegalAccessException {
JNative SetConsoleCtrlHandler = new JNative(DLL_NAME, "SetConsoleCtrlHandler");
SetConsoleCtrlHandler.setRetVal(Type.INT);
SetConsoleCtrlHandler.setParameter(0, callback.getCallbackAddress());
SetConsoleCtrlHandler.setParameter(1, Add ? "1" :"0");
SetConsoleCtrlHandler.invoke();
return SetConsoleCtrlHandler.getRetValAsInt() != 0;
}
/**
*
* <h3>FindFirstChangeNotification</h3>
* <pre>
*
*
* The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. The function does not report changes to the specified directory itself.
*
* This function does not indicate the change that satisfied the wait condition. To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -