Skip to content

Commit 39c15b7

Browse files
author
Jonathan Beaudoin
committed
Reformat
1 parent 8cfd5d6 commit 39c15b7

5 files changed

Lines changed: 43 additions & 25 deletions

File tree

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3-
xmlns="http://maven.apache.org/POM/4.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0">
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.jonathan.flaresoft</groupId>
77
<artifactId>Java-Memory-Manipulation</artifactId>
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
package com.beaudoin.jmm;
22

3-
import com.beaudoin.jmm.process.NativeProcess;
3+
import com.beaudoin.jmm.misc.Cacheable;
4+
import com.beaudoin.jmm.misc.MemoryBuffer;
5+
import com.beaudoin.jmm.natives.mac.mac;
6+
import com.sun.jna.Pointer;
7+
import com.sun.jna.ptr.IntByReference;
48

59
import java.io.IOException;
10+
import java.util.Arrays;
611

712
/**
813
* Created by Jonathan on 12/22/2015.
914
*/
1015
public final class Main {
1116

12-
public static void main(String[] args) throws IOException {
13-
System.out.println(NativeProcess.byName("csgo_linux").id());
14-
}
17+
public static void main(String[] args) throws IOException {
18+
// System.out.println(NativeProcess.byName("clion").id());
19+
20+
IntByReference out = new IntByReference();
21+
System.out.println(mac.getpid());
22+
System.out.println(mac.task_for_pid(mac.mach_task_self(), 3122, out) == 0);
23+
int taskId = out.getValue();
24+
25+
26+
IntByReference o = new IntByReference();
27+
MemoryBuffer buffer = Cacheable.buffer(4);
28+
29+
System.out.println(mac.vm_read(taskId, new Pointer(0x7fff53601b58L), 4, buffer, o));
30+
System.out.println(o.getValue());
31+
System.out.println(buffer.getInt());
32+
System.out.println(Arrays.toString(buffer.array()));
33+
}
1534

1635
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
*/
1010
public final class Utils {
1111

12-
public static int exec(String... command) {
13-
try {
14-
return Integer.parseInt(new Scanner(Runtime.getRuntime().exec(command).getInputStream()).next());
15-
} catch (IOException e) {
16-
throw new RuntimeException("Failed to read output from " + Arrays.toString(command));
17-
}
18-
}
12+
public static int exec(String... command) {
13+
try {
14+
return Integer.parseInt(new Scanner(Runtime.getRuntime().exec(command).getInputStream()).next());
15+
} catch (IOException e) {
16+
throw new RuntimeException("Failed to read output from " + Arrays.toString(command));
17+
}
18+
}
1919

2020
}

src/main/java/com/beaudoin/jmm/natives/mac/mac.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
*/
1313
public final class mac {
1414

15-
static {
16-
Native.register(NativeLibrary.getInstance("c"));
17-
}
15+
static {
16+
Native.register(NativeLibrary.getInstance("c"));
17+
}
1818

19-
public static native int task_for_pid(int taskid, int pid, IntByReference out);
19+
public static native int task_for_pid(int taskid, int pid, IntByReference out);
2020

21-
public static native int getpid();
21+
public static native int getpid();
2222

23-
public static native int mach_task_self();
23+
public static native int mach_task_self();
2424

25-
public static native int vm_write(int taskId, Pointer address, MemoryBuffer buffer, int size);
25+
public static native int vm_write(int taskId, Pointer address, MemoryBuffer buffer, int size);
2626

27-
public static native int vm_read(int taskId, Pointer address, int size, MemoryBuffer buffer, IntByReference ref);
27+
public static native int vm_read(int taskId, Pointer address, int size, MemoryBuffer buffer, IntByReference ref);
2828

29-
public static native String mach_error_string(int result) throws LastErrorException;
29+
public static native String mach_error_string(int result) throws LastErrorException;
3030

3131
}

src/main/java/com/beaudoin/jmm/process/impl/unix/UnixProcess.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
*/
1919
public final class UnixProcess implements NativeProcess {
2020

21+
private final int id;
2122
private uio.iovec local = new uio.iovec();
2223
private uio.iovec remote = new uio.iovec();
23-
24-
private final int id;
2524
private Map<String, Module> modules = new HashMap<>();
2625

2726
public UnixProcess(int id) {

0 commit comments

Comments
 (0)