Rename project directory cpp/mimis to cpp/jlibmimis

This commit is contained in:
2014-11-09 22:33:35 +00:00
parent bd1da16925
commit 10c8cc74f7
11 changed files with 0 additions and 18 deletions

View File

@@ -0,0 +1,89 @@
#include "mimis.h"
#include <windows.h>
#include <tlhelp32.h>
bool getProcessEntry32(const char *program, PROCESSENTRY32 *pe32) {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) {
return false;
}
bool bFound = false;
while (Process32Next(hSnapshot, pe32) != false) {
if (strcmp(program, pe32->szExeFile) == 0) {
bFound = true;
break;
}
}
CloseHandle(hSnapshot);
return bFound;
}
bool getProcess(const char *program, HANDLE *hProcess) {
PROCESSENTRY32 *pe32 = new PROCESSENTRY32;
bool bResult = false;
if (getProcessEntry32(program, pe32)) {
*hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pe32->th32ProcessID);
bResult = true;
}
delete pe32;
return bResult;
}
JNIEXPORT jint JNICALL Java_mimis_util_Native_getHandle(JNIEnv *env, jclass cls, jstring jwindow) {
const char *window = env->GetStringUTFChars(jwindow, 0);
return (int) FindWindow(window, NULL);
}
JNIEXPORT jint JNICALL Java_mimis_util_Native_sendMessage(JNIEnv *env, jclass cls, jint handle, jint message, jint wParam, jint lParam) {
return SendMessage((HWND) handle, message, wParam, lParam);
}
JNIEXPORT jint JNICALL Java_mimis_util_Native_postMessage(JNIEnv *env, jclass cls, jint handle, jint message, jint wParam, jint lParam) {
return PostMessage((HWND) handle, message, wParam, lParam);
}
JNIEXPORT jint JNICALL Java_mimis_util_Native_mapVirtualKey(JNIEnv *env, jclass cls, jint map, jint type) {
return MapVirtualKey(map, type);
}
JNIEXPORT jboolean JNICALL Java_mimis_util_Native_isRunning(JNIEnv *env, jclass cls, jstring jprogram) {
const char *program = env->GetStringUTFChars(jprogram, 0);
PROCESSENTRY32 *pe32 = new PROCESSENTRY32;
bool bRunning = getProcessEntry32(program, pe32);
delete pe32;
return bRunning;
}
JNIEXPORT jboolean JNICALL Java_mimis_util_Native_terminate(JNIEnv *env, jclass cls, jstring jprogram) {
const char *program = env->GetStringUTFChars(jprogram, 0);
HANDLE *hProcess = new HANDLE;
bool bResult = false;
if (getProcess(program, hProcess)) {
bResult = TerminateProcess(*hProcess, 0);
}
delete hProcess;
return bResult;
}
JNIEXPORT jstring JNICALL Java_mimis_util_Native_getValue(JNIEnv *env, jclass cls, jint registry, jstring jkey, jstring jname) {
const char *key = env->GetStringUTFChars(jkey, 0);
const char *name = env->GetStringUTFChars(jname, 0);
HKEY hKey;
char *value = NULL;
if (RegOpenKey((HKEY) registry, key, &hKey) == ERROR_SUCCESS) {
char nameBuffer[255];
byte valueBuffer[255];
DWORD dwNameSize = sizeof(nameBuffer);
DWORD dwValueSize = sizeof(valueBuffer);
int i = 0;
while (RegEnumValue(hKey, i++, nameBuffer, &dwNameSize, NULL, NULL, valueBuffer, &dwValueSize) == ERROR_SUCCESS) {
if (strcmp(name, nameBuffer) == 0) {
value = (char*) valueBuffer;
break;
}
dwNameSize = sizeof(nameBuffer);
}
}
RegCloseKey(hKey);
return env->NewStringUTF(value);
}

View File

@@ -0,0 +1,140 @@
/*
tlhelp32.h - Include file for Tool help functions.
Written by Mumit Khan <khan@nanotech.wisc.edu>
This file is part of a free library for the Win32 API.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef _TLHELP32_H
#define _TLHELP32_H
#if __GNUC__ >=3
#pragma GCC system_header
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define HF32_DEFAULT 1
#define HF32_SHARED 2
#define LF32_FIXED 0x1
#define LF32_FREE 0x2
#define LF32_MOVEABLE 0x4
#define MAX_MODULE_NAME32 255
#define TH32CS_SNAPHEAPLIST 0x1
#define TH32CS_SNAPPROCESS 0x2
#define TH32CS_SNAPTHREAD 0x4
#define TH32CS_SNAPMODULE 0x8
#define TH32CS_SNAPALL (TH32CS_SNAPHEAPLIST|TH32CS_SNAPPROCESS|TH32CS_SNAPTHREAD|TH32CS_SNAPMODULE)
#define TH32CS_INHERIT 0x80000000
typedef struct tagHEAPLIST32 {
DWORD dwSize;
DWORD th32ProcessID;
DWORD th32HeapID;
DWORD dwFlags;
} HEAPLIST32,*PHEAPLIST32,*LPHEAPLIST32;
typedef struct tagHEAPENTRY32 {
DWORD dwSize;
HANDLE hHandle;
DWORD dwAddress;
DWORD dwBlockSize;
DWORD dwFlags;
DWORD dwLockCount;
DWORD dwResvd;
DWORD th32ProcessID;
DWORD th32HeapID;
} HEAPENTRY32,*PHEAPENTRY32,*LPHEAPENTRY32;
typedef struct tagPROCESSENTRY32W {
DWORD dwSize;
DWORD cntUsage;
DWORD th32ProcessID;
DWORD th32DefaultHeapID;
DWORD th32ModuleID;
DWORD cntThreads;
DWORD th32ParentProcessID;
LONG pcPriClassBase;
DWORD dwFlags;
WCHAR szExeFile[MAX_PATH];
} PROCESSENTRY32W,*PPROCESSENTRY32W,*LPPROCESSENTRY32W;
typedef struct tagPROCESSENTRY32 {
DWORD dwSize;
DWORD cntUsage;
DWORD th32ProcessID;
DWORD th32DefaultHeapID;
DWORD th32ModuleID;
DWORD cntThreads;
DWORD th32ParentProcessID;
LONG pcPriClassBase;
DWORD dwFlags;
CHAR szExeFile[MAX_PATH];
} PROCESSENTRY32,*PPROCESSENTRY32,*LPPROCESSENTRY32;
typedef struct tagTHREADENTRY32 {
DWORD dwSize;
DWORD cntUsage;
DWORD th32ThreadID;
DWORD th32OwnerProcessID;
LONG tpBasePri;
LONG tpDeltaPri;
DWORD dwFlags;
} THREADENTRY32,*PTHREADENTRY32,*LPTHREADENTRY32;
typedef struct tagMODULEENTRY32W {
DWORD dwSize;
DWORD th32ModuleID;
DWORD th32ProcessID;
DWORD GlblcntUsage;
DWORD ProccntUsage;
BYTE *modBaseAddr;
DWORD modBaseSize;
HMODULE hModule;
WCHAR szModule[MAX_MODULE_NAME32 + 1];
WCHAR szExePath[MAX_PATH];
} MODULEENTRY32W,*PMODULEENTRY32W,*LPMODULEENTRY32W;
typedef struct tagMODULEENTRY32 {
DWORD dwSize;
DWORD th32ModuleID;
DWORD th32ProcessID;
DWORD GlblcntUsage;
DWORD ProccntUsage;
BYTE *modBaseAddr;
DWORD modBaseSize;
HMODULE hModule;
char szModule[MAX_MODULE_NAME32 + 1];
char szExePath[MAX_PATH];
} MODULEENTRY32,*PMODULEENTRY32,*LPMODULEENTRY32;
BOOL WINAPI Heap32First(LPHEAPENTRY32,DWORD,DWORD);
BOOL WINAPI Heap32ListFirst(HANDLE,LPHEAPLIST32);
BOOL WINAPI Heap32ListNext(HANDLE,LPHEAPLIST32);
BOOL WINAPI Heap32Next(LPHEAPENTRY32);
BOOL WINAPI Module32First(HANDLE,LPMODULEENTRY32);
BOOL WINAPI Module32FirstW(HANDLE,LPMODULEENTRY32W);
BOOL WINAPI Module32Next(HANDLE,LPMODULEENTRY32);
BOOL WINAPI Module32NextW(HANDLE,LPMODULEENTRY32W);
BOOL WINAPI Process32First(HANDLE,LPPROCESSENTRY32);
BOOL WINAPI Process32FirstW(HANDLE,LPPROCESSENTRY32W);
BOOL WINAPI Process32Next(HANDLE,LPPROCESSENTRY32);
BOOL WINAPI Process32NextW(HANDLE,LPPROCESSENTRY32W);
BOOL WINAPI Thread32First(HANDLE,LPTHREADENTRY32);
BOOL WINAPI Thread32Next(HANDLE,LPTHREADENTRY32);
BOOL WINAPI Toolhelp32ReadProcessMemory(DWORD,LPCVOID,LPVOID,DWORD,LPDWORD);
HANDLE WINAPI CreateToolhelp32Snapshot(DWORD,DWORD);
#ifdef UNICODE
#define LPMODULEENTRY32 LPMODULEENTRY32W
#define LPPROCESSENTRY32 LPPROCESSENTRY32W
#define MODULEENTRY32 MODULEENTRY32W
#define Module32First Module32FirstW
#define Module32Next Module32NextW
#define PMODULEENTRY32 PMODULEENTRY32W
#define PPROCESSENTRY32 PPROCESSENTRY32W
#define PROCESSENTRY32 PROCESSENTRY32W
#define Process32First Process32FirstW
#define Process32Next Process32NextW
#endif /* UNICODE */
#ifdef __cplusplus
}
#endif
#endif /* _TLHELP32_H */

View File

@@ -0,0 +1,44 @@
package mimis.util;
import mimis.value.Registry;
import mimis.value.Windows;
public class Native {
static {
net.rubygrapefruit.platform.Native.load("com.github.boukefalos.mimis", "mimis");
}
public native static int getHandle(String window);
public static int sendMessage(int handle, Windows windows, int wParam, int lParam) {
return sendMessage(handle, windows.getCode(), wParam, lParam);
}
public native static int sendMessage(int handle, int message, int wParam, int lParam);
public static int postMessage(int handle, Windows windows, int wParam, int lParam) {
return postMessage(handle, windows.getCode(), wParam, lParam);
}
public native static int postMessage(int handle, int message, int wParam, int lParam);
public static int mapVirtualKey(int code, Windows windows) {
return mapVirtualKey(code, windows.getCode());
}
public native static int mapVirtualKey(int code, int type);
public native static boolean isRunning(String program);
public native static boolean terminate(String program);
public static String getValue(Registry registry, String key) {
return getValue(registry, key, "");
}
public static String getValue(Registry registry, String key, String name) {
return getValue(registry.getCode(), key, name);
}
public native static String getValue(int registry, String key, String name);
}

View File

@@ -0,0 +1,21 @@
package mimis.value;
public enum Registry {
CLASSES_ROOT (0x80000000),
CURRENT_USER (0x80000001),
LOCAL_MACHINE (0x80000002),
USERS (0x80000003),
PERFORMANCE_DATA (0x80000004),
CURRENT_CONFIG (0x80000005),
DYN_DATA (0x80000006);
protected int code;
private Registry(int code) {
this.code = code;
}
public int getCode() {
return code;
}
}

View File

@@ -0,0 +1,20 @@
package mimis.value;
public enum Windows {
WM_CLOSE (0x0010),
WM_COMMAND (0x0111),
WM_SYSCOMMAND (0x0112),
WM_APPCOMMAND (0x0319),
WM_USER (0x0400),
MAPVK_VK_TO_VSC (0);
protected int code;
private Windows(int code) {
this.code = code;
}
public int getCode() {
return code;
}
}