Skip to content

Commit 0d561db

Browse files
committed
Removed unused Native classes, added MODULEENTRY32W manually util JNA fixes their build >.>
1 parent 120e270 commit 0d561db

3 files changed

Lines changed: 110 additions & 134 deletions

File tree

src/main/java/com/beaudoin/jmm/natives/win32/Kernel32.java

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,137 @@
2828
import com.sun.jna.Native;
2929
import com.sun.jna.NativeLibrary;
3030
import com.sun.jna.Pointer;
31+
import com.sun.jna.Structure;
3132
import com.sun.jna.platform.win32.Tlhelp32;
3233
import com.sun.jna.platform.win32.WinDef;
33-
import com.sun.jna.ptr.IntByReference;
3434
import com.sun.jna.win32.W32APIOptions;
3535

36+
import java.util.Arrays;
37+
import java.util.List;
38+
3639
public final class Kernel32 {
3740

3841
static {
3942
Native.register(NativeLibrary.getInstance("Kernel32", W32APIOptions.UNICODE_OPTIONS));
4043
}
4144

42-
public static native Pointer CreateToolhelp32Snapshot(WinDef.DWORD dword, int junk);
45+
public static native Pointer CreateToolhelp32Snapshot(int flags, int pid);
4346

4447
public static native boolean CloseHandle(Pointer pointer);
4548

4649
public static native Pointer OpenProcess(int desired, boolean inherit, int pid);
4750

4851
public static native boolean Process32Next(Pointer pointer, Tlhelp32.PROCESSENTRY32 entry);
4952

53+
public static native boolean Module32NextW(Pointer pointer, Kernel32.MODULEENTRY32W entry);
54+
5055
public static native long ReadProcessMemory(Pointer process, Pointer address, MemoryBuffer memory, int size, int written);
5156

5257
public static native long WriteProcessMemory(Pointer process, Pointer address, MemoryBuffer memory, int size, int written);
5358

54-
public static native WinDef.HMODULE GetModuleHandle(String value);
59+
/**
60+
* Describes an entry from a list of the modules belonging to the specified
61+
* process.
62+
*
63+
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms684225(v=vs.85).aspx">MSDN</a>
64+
*/
65+
public static class MODULEENTRY32W extends Structure {
66+
67+
public static final int MAX_MODULE_NAME32 = 255;
68+
69+
/**
70+
* A representation of a MODULEENTRY32 structure as a reference
71+
*/
72+
public static class ByReference extends MODULEENTRY32W implements Structure.ByReference {
73+
public ByReference() {
74+
}
75+
76+
public ByReference(Pointer memory) {
77+
super(memory);
78+
}
79+
}
80+
81+
/**
82+
* The size of the structure, in bytes. Before calling the Module32First
83+
* function, set this member to sizeof(MODULEENTRY32). If you do not
84+
* initialize dwSize, Module32First fails.
85+
*/
86+
public WinDef.DWORD dwSize;
87+
88+
/**
89+
* This member is no longer used, and is always set to one.
90+
*/
91+
public WinDef.DWORD th32ModuleID;
92+
93+
/**
94+
* The identifier of the process whose modules are to be examined.
95+
*/
96+
public WinDef.DWORD th32ProcessID;
97+
98+
/**
99+
* The load count of the module, which is not generally meaningful, and
100+
* usually equal to 0xFFFF.
101+
*/
102+
public WinDef.DWORD GlblcntUsage;
103+
104+
/**
105+
* The load count of the module (same as GlblcntUsage), which is not
106+
* generally meaningful, and usually equal to 0xFFFF.
107+
*/
108+
public WinDef.DWORD ProccntUsage;
55109

56-
public static native boolean GetExitCodeProcess(Pointer hProcess, IntByReference lpExitCode);
110+
/**
111+
* The base address of the module in the context of the owning process.
112+
*/
113+
public Pointer modBaseAddr;
114+
115+
/**
116+
* The size of the module, in bytes.
117+
*/
118+
public WinDef.DWORD modBaseSize;
119+
120+
/**
121+
* A handle to the module in the context of the owning process.
122+
*/
123+
public WinDef.HMODULE hModule;
124+
125+
/**
126+
* The module name.
127+
*/
128+
public char[] szModule = new char[MAX_MODULE_NAME32 + 1];
129+
130+
/**
131+
* The module path.
132+
*/
133+
public char[] szExePath = new char[com.sun.jna.platform.win32.Kernel32.MAX_PATH];
134+
135+
public MODULEENTRY32W() {
136+
dwSize = new WinDef.DWORD(size());
137+
}
138+
139+
public MODULEENTRY32W(Pointer memory) {
140+
super(memory);
141+
read();
142+
}
143+
144+
/**
145+
* @return The module name.
146+
*/
147+
public String szModule() {
148+
return Native.toString(this.szModule);
149+
}
150+
151+
/**
152+
* @return The module path.
153+
*/
154+
public String szExePath() {
155+
return Native.toString(this.szExePath);
156+
}
157+
158+
@Override
159+
protected List<String> getFieldOrder() {
160+
return Arrays.asList("dwSize", "th32ModuleID", "th32ProcessID", "GlblcntUsage", "ProccntUsage", "modBaseAddr", "modBaseSize", "hModule", "szModule", "szExePath");
161+
}
162+
}
57163

58164
}

src/main/java/com/beaudoin/jmm/natives/win32/Psapi.java

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/main/java/com/beaudoin/jmm/natives/win32/User32.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)