Skip to content

Commit fa0dddf

Browse files
committed
Code cleanup and updated version
1 parent 9684541 commit fa0dddf

6 files changed

Lines changed: 12 additions & 11 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'java'
22
apply plugin: 'maven'
33

44
group = 'com.beaudoin.jmm'
5-
version = '1.5'
5+
version = '1.6'
66

77
repositories {
88
mavenCentral()

src/main/java/com/beaudoin/jmm/misc/Cacheable.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package com.beaudoin.jmm.misc;
2626

2727
import com.sun.jna.Pointer;
28+
import com.sun.jna.platform.win32.WinDef;
2829
import com.sun.jna.ptr.IntByReference;
2930

3031
import java.util.HashMap;
@@ -34,16 +35,17 @@
3435
public final class Cacheable {
3536

3637
private static final Map<Integer, MemoryBuffer> bufferCache = new HashMap<>();
37-
private static final Function<Integer, MemoryBuffer> butterCreate = MemoryBuffer::new;
38+
private static final Function<Integer, MemoryBuffer> bufferCreate = MemoryBuffer::new;
3839

3940
private static final Map<Integer, byte[]> arrayCache = new HashMap<>();
4041
private static final Function<Integer, byte[]> arrayCreate = byte[]::new;
4142

4243
private static final Pointer cachedPointer = new Pointer(0);
4344
public static final IntByReference INT_BY_REF = new IntByReference();
45+
public static final WinDef.DWORD DWORD_ZERO = new WinDef.DWORD();
4446

4547
public static MemoryBuffer buffer(int size) {
46-
return bufferCache.computeIfAbsent(size, butterCreate);
48+
return bufferCache.computeIfAbsent(size, bufferCreate);
4749
}
4850

4951
public static byte[] array(int size) {

src/main/java/com/beaudoin/jmm/misc/Strings.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@
3434
*/
3535
public final class Strings {
3636

37-
private static Map<Long, String> map = new HashMap<>(16_982);
37+
private static Map<Long, String> stringCache = new HashMap<>(16_982);
3838

3939
public static String transform(byte[] bytes) {
4040
long hash = LongHashFunction.xx_r39().hashBytes(bytes);
41-
if (map.containsKey(hash)) {
42-
return map.get(hash);
41+
if (stringCache.containsKey(hash)) {
42+
return stringCache.get(hash);
4343
}
4444
for (int i = 0; i < bytes.length; i++) {
4545
if (bytes[i] == 0) {
4646
bytes[i] = 32;
4747
}
4848
}
4949
String string = new String(bytes).split(" ")[0].trim().intern();
50-
map.put(hash, string);
50+
stringCache.put(hash, string);
5151
return string;
5252
}
5353

src/main/java/com/beaudoin/jmm/process/AbstractProcess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public int id() {
2323

2424
@Override
2525
public Module findModule(String moduleName) {
26-
Module module = modules.get(moduleName);
26+
Module module = modules.isEmpty() ? null : modules.get(moduleName);
2727
if (module == null) {
2828
initModules();
2929
}

src/main/java/com/beaudoin/jmm/process/DataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ default double readDouble(long address) {
5151
}
5252

5353
default String readString(long address, int length) {
54-
byte[] bytes = Cacheable.array(length);
54+
byte[] bytes = new byte[length];
5555
read(address, bytes.length).get(bytes);
5656
return Strings.transform(bytes);
5757
}

src/main/java/com/beaudoin/jmm/process/impl/win32/Win32Process.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public final class Win32Process extends AbstractProcess {
4545
public Win32Process(int id, Pointer handle) {
4646
super(id);
4747
this.handle = handle;
48-
initModules();
4948
}
5049

5150
public Pointer pointer() {
@@ -59,7 +58,7 @@ public void initModules() {
5958
try {
6059
while (Kernel32.Module32NextW(snapshot, entry)) {
6160
String name = entry.szModule();
62-
modules.putIfAbsent(name, new Module(this, name, entry.getPointer(), entry.modBaseSize.intValue()));
61+
modules.putIfAbsent(name, new Module(this, name, entry.hModule.getPointer(), entry.modBaseSize.intValue()));
6362
}
6463
} finally {
6564
Kernel32.CloseHandle(snapshot);

0 commit comments

Comments
 (0)