package org.xvolks.jnative.util;
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.Type;
import org.xvolks.jnative.exceptions.NativeException;
import org.xvolks.jnative.logging.JNativeLogger.SEVERITY;
import org.xvolks.jnative.misc.FreeDiskSpace;
import org.xvolks.jnative.misc.MemoryStatusEx;
import org.xvolks.jnative.misc.SecurityAttributes;
import org.xvolks.jnative.misc.SystemInfo;
import org.xvolks.jnative.misc.basicStructures.AbstractBasicData;
import org.xvolks.jnative.misc.basicStructures.DWORD;
import org.xvolks.jnative.misc.basicStructures.HANDLE;
import org.xvolks.jnative.misc.basicStructures.INT64;
import org.xvolks.jnative.misc.basicStructures.LONG;
import org.xvolks.jnative.pointers.NullPointer;
import org.xvolks.jnative.pointers.Pointer;
import org.xvolks.jnative.pointers.memory.HeapMemoryBlock;
import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;
/**
* Kernel32 this is the class wrapper to Kernel32.dll.<br>
* When a developper needs a function of this DLL (s)he should add it here.
*
* $Id: Kernel32.java,v 1.23 2007/04/27 18:42:03 thubby Exp $;
*
* This software is released under the LGPL.
*
* @author Created by Marc DENTY - (c) 2006 JNative project
*/
public class Kernel32 {
public static final String DLL_NAME = "Kernel32.dll";
private static JNative nOpenProcess;
private static JNative nCloseHandle;
private static JNative nTerminateProcess;
private static JNative nSetLastError;
private static JNative nCreateFileMapping;
private static JNative nMapViewOfFileEx;
private static JNative nGetVersion;
private static JNative nWriteFile;
private static JNative nReadFile;
public static final DWORD IOCTL_STORAGE_EJECT_MEDIA = new DWORD(2967560);
/*
BOOL DeviceIoControl(
HANDLE hDevice,
DWORD dwIoControlCode,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped
);
*
*Example:
*
try {
HANDLE handle = Kernel32.CreateFile("\\\\.\\d:",
Kernel32.AccessMask.GENERIC_ALL,
Kernel32.ShareMode.FILE_SHARE_VALID_FLAGS,
new SecurityAttributes(),
Kernel32.CreationDisposition.OPEN_EXISTING,
Kernel32.FileAttribute.FILE_ATTRIBUTE_READONLY,0);
if(handle != null) {
Kernel32.DeviceIoControl(handle, Kernel32.IOCTL_STORAGE_EJECT_MEDIA, NullPointer.NULL, new DWORD(0), NullPointer.NULL, new DWORD(0), NullPointer.NULL, NullPointer.NULL);
Kernel32.CloseHandle(handle);
}
} catch(Exception e) {
e.printStackTrace();
}
*/
public static boolean DeviceIoControl(HANDLE hDevice,
DWORD dwIoControlCode,
Pointer lpInBuffer,
DWORD nInBufferSize,
Pointer lpOutBuffer,
DWORD nOutBufferSize,
Pointer lpBytesReturned,
Pointer lpOverlapped)
throws NativeException, IllegalAccessException {
JNative DeviceIoControl = new JNative(DLL_NAME, "DeviceIoControl");
DeviceIoControl.setRetVal(Type.INT);
int pos = 0;
Pointer p = null;
DeviceIoControl.setParameter(pos++, hDevice.getValue());
DeviceIoControl.setParameter(pos++, dwIoControlCode.getValue());
DeviceIoControl.setParameter(pos++, lpInBuffer);
DeviceIoControl.setParameter(pos++, nInBufferSize.getValue());
DeviceIoControl.setParameter(pos++, lpOutBuffer);
DeviceIoControl.setParameter(pos++, nOutBufferSize.getValue());
// if lpOverlapped is NullPointer, lpBytesReturned must not be NullPointer!
// TODO: Is it maybe better here to throw an Exception??
if(lpOverlapped instanceof NullPointer && lpBytesReturned instanceof NullPointer) {
JNative.getLogger().log(SEVERITY.WARN, "lpOverlapped is NullPointer, lpBytesReturned must not be NullPointer!");
p = new Pointer(MemoryBlockFactory.createMemoryBlock(16));
DeviceIoControl.setParameter(pos++, p);
} else
DeviceIoControl.setParameter(pos++, lpBytesReturned);
DeviceIoControl.setParameter(pos++, lpOverlapped);
DeviceIoControl.invoke();
pos = DeviceIoControl.getRetValAsInt();
DeviceIoControl.dispose();
if(p != null)
p.dispose();
return (pos != 0);
}
/*
ATOM GlobalDeleteAtom(
ATOM nAtom
);
*/
public static int GlobalDeleteAtom(int atom) throws NativeException, IllegalAccessException {
JNative GlobalDeleteAtom = new JNative(DLL_NAME, "GlobalDeleteAtom");
GlobalDeleteAtom.setRetVal(Type.INT);
int pos = 0;
GlobalDeleteAtom.setParameter(pos++, atom);
GlobalDeleteAtom.invoke();
pos = GlobalDeleteAtom.getRetValAsInt();
GlobalDeleteAtom.dispose();
return pos;
}
/*
ATOM GlobalAddAtom(
LPCTSTR lpString
);
*/
public static int GlobalAddAtom(String lpString) throws NativeException, IllegalAccessException {
JNative GlobalAddAtom = new JNative(DLL_NAME, "GlobalAddAtomA");
GlobalAddAtom.setRetVal(Type.INT);
int pos = 0;
GlobalAddAtom.setParameter(pos++, lpString);
GlobalAddAtom.invoke();
pos = GlobalAddAtom.getRetValAsInt();
GlobalAddAtom.dispose();
return pos;
}
/*
*returns some Information about the Windows Operating System.
*Look at class WindowsVersion for some convenience methodes
*/
public static DWORD GetVersion() throws NativeException, IllegalAccessException {
if (nGetVersion == null) {
nGetVersion = new JNative(DLL_NAME, "GetVersion");
nGetVersion.setRetVal(Type.INT);
}
nGetVersion.invoke();
return new DWORD(nGetVersion.getRetValAsInt());
}
/*
HANDLE hProcess,
LPCVOID lpBaseAddress,
LPVOID lpBuffer,
SIZE_T nSize,
SIZE_T* lpNumberOfBytesRead
*/
public static boolean ReadProcessMemory(HANDLE hProcess,
int lpBaseAddress,
Pointer lpBuffer,
int len)
throws NativeException, IllegalAccessException {
JNative gms = new JNative(DLL_NAME, "ReadProcessMemory");
gms.setRetVal(Type.INT);
int i = 0;
gms.setParameter(i++, hProcess.getValue());
gms.setParameter(i++, lpBaseAddress);
gms.setParameter(i++, lpBuffer);
gms.setParameter(i++, len);
gms.setParameter(i++, 0);
gms.invoke();
i = gms.getRetValAsInt();
gms.dispose();
return (i != 0);
}
/*
HANDLE hProcess,
LPVOID lpBaseAddress,
LPCVOID lpBuffer,
SIZE_T nSize,
SIZE_T* lpNumberOfBytesWritten
*/
public static boolean WriteProcessMemory(HANDLE hProcess,
int lpBaseAddress,
Pointer lpBuffer,
int len)
throws NativeException, IllegalAccessException {
JNative gms = new JNative(DLL_NAME, "WriteProcessMemory");
gms.setRetVal(Type.INT);
int i = 0;
gms.setParameter(i++, hProcess.getValue());
gms.setParameter(i++, lpBaseAddress);
gms.setParameter(i++, lpBuffer);
gms.setParameter(i++, len);
gms.setParameter(i++, 0);
gms.invoke();
i = gms.getRetValAsInt();
gms.dispose();
return (i != 0);
}
/**
* Method globalMemoryStatusEx
*
* <pre>
* BOOL GlobalMemoryStatusEx(
* LPMEMORYSTATUSEX lpBuffer
* );
*
* Parameters
*
* lpBuffer
* [in, out] Pointer to a MEMORYSTATUSEX structure that receives information about current memory availability.
*
* Return Values
*
没有合适的资源?快使用搜索试试~ 我知道了~
JNative(1.3.2) JNI工具包源码
共374个文件
class:109个
java:82个
entries:30个
需积分: 9 83 下载量 8 浏览量
2008-08-08
17:57:44
上传
评论
收藏 1.27MB ZIP 举报
温馨提示
JNative JNI工具包源码 ,非常适用的工具包
资源推荐
资源详情
资源评论
收起资源包目录
JNative(1.3.2) JNI工具包源码 (374个子文件)
jnative.a 78KB
createJavaDoc.bat 236B
jni_util.c 34KB
mem.c 402B
.cdtbuild 9KB
.cdtproject 951B
.cdtproject 88B
ChangeLog 579B
JNative.class 21KB
User32.class 18KB
Kernel32.class 18KB
Advapi32.class 14KB
WM.class 13KB
JNativeTester.class 12KB
SNDPTester.class 9KB
Win32SessionManager.class 7KB
Gdi32.class 7KB
Shell32.class 7KB
NOTIFYICONDATA.class 6KB
Pointer.class 6KB
WNDCLASS.class 5KB
ChooseColor.class 4KB
_1698452_mem_leak.class 4KB
PsAPI.class 4KB
StructConverter.class 4KB
ConsoleLogger.class 4KB
EnumCallback.class 3KB
Kernel32$AccessMask.class 3KB
Win32SessionManager$1.class 3KB
Win32SessionManager$1$1.class 3KB
ComDlg32.class 3KB
KillProcess.class 3KB
LinuxCallback.class 3KB
RegValueTypes.class 3KB
MemoryBlockFactory.class 3KB
WindowsVersion.class 3KB
HKEY.class 3KB
GlobalMemoryBlock.class 3KB
MemoryStatusEx.class 3KB
NullPointer.class 2KB
Kernel32$FileAttribute.class 2KB
TestCallback.class 2KB
MSG$WindowsConstants.class 2KB
UINT.class 2KB
Kernel32$SystemTime.class 2KB
AbstractBasicData.class 2KB
SimpleFileLogger.class 2KB
FILETIME.class 2KB
DOUBLE.class 2KB
FLOAT.class 2KB
LONG.class 2KB
FILEINFO.class 2KB
ICONINFO.class 2KB
BITMAP.class 2KB
MSG.class 2KB
TOKEN_PRIVILEGES.class 2KB
SystemInfo.class 2KB
BasicRegData.class 2KB
SecurityAttributes.class 2KB
JNativeTester$1Inline.class 2KB
RegValue.class 2KB
Kernel32$PageAccess.class 2KB
RegKey.class 2KB
Point.class 2KB
INT64.class 2KB
ITEMID.class 2KB
Win32SessionManager$CallBackWindowProc.class 2KB
JNativeLogger$SEVERITY.class 2KB
Kernel32$FileFlags.class 2KB
Type.class 2KB
HWND.class 2KB
NOTIFYICONDATA$ICON_TYPE.class 2KB
SimpleFileLogger$FileLogger.class 2KB
BITMAPINFOHEADER.class 2KB
Kernel32$CreationDisposition.class 2KB
Test.class 2KB
DbgHelp.class 2KB
Win32SessionManager$EndSessionListener$Origin.class 2KB
RegQueryKey.class 2KB
LinuxCallback$1.class 1KB
Convention.class 1KB
Kernel32$ShareMode.class 1KB
Win32SessionManager$3.class 1KB
Kernel32$FileMap.class 1KB
REGSAM.class 1KB
_1461912_mem_leak.class 1KB
Kernel32$MoveMode.class 1KB
FreeDiskSpace.class 1KB
Limits.class 1KB
RegData.class 1KB
TimedRegData.class 1KB
_1456493_npe.class 1KB
REGTYPE.class 1KB
HeapMemoryBlock.class 1KB
JNativeTester$2.class 985B
AbstractMemoryBlock.class 976B
AbstractLogger.class 899B
HANDLE.class 879B
JNativeTester$1.class 872B
JNative$LibDesc.class 834B
共 374 条
- 1
- 2
- 3
- 4
资源评论
lovingprince
- 粉丝: 906
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- OpenCv 使用fffffffff
- 正点原子开拓者FPGA多人表决器代码项目
- EOP-Last5Years.txt
- windows 32位、64位系统常见缺少的库
- 毕业设计基于springboot+vue实现的求职招聘类型网站源码+数据库(高分项目).zip
- 535springboot + vue 体质测试数据分析及可视化设计.zip(可运行源码+数据库文件+文档)
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统源码.zip
- 基于springboot+vue实现的求职招聘类型网站源代码+数据库(优质毕设项目).zip
- iOS APP提审checklist
- 第十四届中北大学ACM程序设计竞赛.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功