Skip to content

Commit ffd04aa

Browse files
author
Jonathan Beaudoin
committed
Added unix process module interfacing
1 parent 2416ebb commit ffd04aa

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

src/main/java/com/beaudoin/jmm/Main.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import com.beaudoin.jmm.process.NativeProcess;
44

5+
import java.io.IOException;
6+
57
/**
68
* Created by Jonathan on 12/22/2015.
79
*/
810
public final class Main {
911

10-
public static void main(String[] args) {
11-
NativeProcess process = NativeProcess.byId(57480);
12-
13-
System.out.println(process.readInt(0x7f0364049664L));
14-
}
12+
public static void main(String[] args) throws IOException {
13+
System.out.println(NativeProcess.byName("csgo_linux").id());
14+
}
1515

1616
}

src/main/java/com/beaudoin/jmm/natives/linux/uio.java renamed to src/main/java/com/beaudoin/jmm/natives/unix/uio.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.beaudoin.jmm.natives.linux;
1+
package com.beaudoin.jmm.natives.unix;
22

33
import com.sun.jna.*;
44

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public final class Module {
1313
private final Pointer pointer;
1414
private MemoryBuffer data;
1515

16-
public Module(NativeProcess process, String name, Pointer pointer, int size) {
16+
public Module(NativeProcess process, String name, Pointer pointer, long size) {
1717
this.process = process;
1818
this.name = name;
1919
this.address = Pointer.nativeValue(pointer);
20-
this.size = size;
20+
this.size = (int) size;
2121
this.pointer = pointer;
2222
}
2323

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import com.beaudoin.jmm.misc.Cacheable;
44
import com.beaudoin.jmm.misc.MemoryBuffer;
55
import com.beaudoin.jmm.misc.Strings;
6-
import com.beaudoin.jmm.natives.windows.Kernel32;
7-
import com.beaudoin.jmm.process.impl.LinuxProcess;
8-
import com.beaudoin.jmm.process.impl.WindowsProcess;
6+
import com.beaudoin.jmm.natives.win32.Kernel32;
7+
import com.beaudoin.jmm.process.impl.unix.UnixProcess;
8+
import com.beaudoin.jmm.process.impl.win32.Wind32Process;
99
import com.sun.jna.Native;
1010
import com.sun.jna.Platform;
1111
import com.sun.jna.Pointer;
1212
import com.sun.jna.platform.win32.Tlhelp32;
1313

14+
import java.io.IOException;
15+
import java.util.Scanner;
16+
1417
import static com.beaudoin.jmm.misc.Cacheable.buffer;
1518

1619
/**
@@ -36,8 +39,13 @@ static NativeProcess byName(String name) {
3639
throw new UnsupportedOperationException("Unknown mac system! (" + System.getProperty("os.name") + ")");
3740
//MAC
3841
} else if (Platform.isLinux()) {
39-
throw new UnsupportedOperationException("Unknown linux system! (" + System.getProperty("os.name") + ")");
40-
//Linux
42+
try {
43+
int processid = Integer.parseInt(new Scanner(Runtime.getRuntime().exec("ps -C "+name+" -o pid").getInputStream()).useDelimiter("\\A").next().replaceAll("[^0-9]",""));
44+
return byId(processid);
45+
} catch (Exception e) {
46+
e.printStackTrace();
47+
//throw new IllegalStateException("Process " + name + " was not found. Are you sure its running?");
48+
}
4149
} else {
4250
throw new UnsupportedOperationException("Unknown operating system! (" + System.getProperty("os.name") + ")");
4351
}
@@ -46,12 +54,12 @@ static NativeProcess byName(String name) {
4654

4755
static NativeProcess byId(int id) {
4856
if (Platform.isWindows()) {
49-
return new WindowsProcess(id, Kernel32.OpenProcess(0x438, true, id));
57+
return new Wind32Process(id, Kernel32.OpenProcess(0x438, true, id));
5058
} else if (Platform.isMac()) {
5159
throw new UnsupportedOperationException("Unknown mac system! (" + System.getProperty("os.name") + ")");
5260
//MAC
5361
} else if (Platform.isLinux()) {
54-
return new LinuxProcess(id, null);
62+
return new UnixProcess(id, null);
5563
} else {
5664
throw new IllegalStateException("Process " + id + " was not found. Are you sure its running?");
5765
}
@@ -61,6 +69,8 @@ static NativeProcess byId(int id) {
6169

6270
Pointer pointer();
6371

72+
void initModules();
73+
6474
Module findModule(String moduleName);
6575

6676
MemoryBuffer read(Pointer address, int size);

0 commit comments

Comments
 (0)