안녕하세요 자바 전문가입니다! 일반적으로 나는 다음과 같은 질문을 스스로에게 던졌습니다: Java Memory Manipulation 라이브러리 덕분에 내가 작성한 프로세스 애플리케이션을 읽고 쓸 수 있습니까 ?이 질문을 한 것은 이번이 처음은 아니지만 이에 대한 정보가 거의 없습니다. 이 문제는 인터넷에서 발생합니다. 모든 사람이 Java에서는 이것이 불가능하다고 쓰기 때문입니다. 비록 이것이 실제라는 게시물을 본 적이 있기 때문입니다. 그래서 도움을 요청하고 싶은데, 이 제품을 어떻게 구현하면 되나요? :)
public static void main(String args[]) {
//Get ProcessID
long pid = findProcessId("nuclearthrone.exe");
if(pid == 0) {
System.err.println("ProcessId not found.");
System.exit(1);
}
System.out.println(pid);
Pointer readProcess = openProcess(readRight, pid);//opens process with read privileges
Pointer writeProcess = openProcess(writeRight, pid);
int size = 4;//we want to read 4 bytes
int adress = Integer.parseInt("036CB314", 16);
//ReadMemory
read = readMemory(readProcess, adress, size);
System.out.println(read.getInt(0));//value of memory read
//Write Memory
Cheater.writeMemory(4, 1079246848, writeProcess, adress);
}
static long findProcessId(String processName) {
//This Reference will contain the processInfo that will be parsed t recover the ProcessId
Tlhelp32.PROCESSENTRY32.ByReference processInfo = new Tlhelp32.PROCESSENTRY32.ByReference();
//this handle allows us to parse the process map
WinNT.HANDLE processesSnapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new DWORD(0L));
if(processesSnapshot == kernel32.INVALID_HANDLE_VALUE) {
if(DEBUG) System.err.println("INVALID_HANDLE_VALUE");
return 0L;
}
try {// This will parse all the processes to find the process id corresponding to the process name
kernel32.Process32First(processesSnapshot, processInfo);
if(processName.equals(Native.toString(processInfo.szExeFile))) {
if(DEBUG) if(DEBUG) System.out.println("Process " + processName + " found : " + processInfo.th32ProcessID.longValue());
return processInfo.th32ProcessID.longValue();
}
while(kernel32.Process32Next(processesSnapshot, processInfo)) {
if(processName.equals(Native.toString(processInfo.szExeFile)))
{
if(DEBUG) System.out.println("Process " + processName + " found : " + processInfo.th32ProcessID.longValue());
return processInfo.th32ProcessID.longValue();
}
}
if(DEBUG) System.out.println("Did not find requested Process: " + processName);
return 0L;
} finally {
kernel32.CloseHandle(processesSnapshot);
}
}//findProcessId
static Pointer openProcess( permissions, long pid) {
Pointer process = myKernel32.OpenProcess(permissions, true, (int)pid);
process;
}
static Memory readMemory( process, int adress, int readSize) {
output = new Memory(readSize);
if(!myKernel32.ReadProcessMemory(process, adress, output, readSize, new IntByReference(0))) {
int error =myKernel32.getLastError();
switch(error) {
default:
System.err.println("Failed to read the process: " + error);
break;
case 0x12B:
System.err.println("Failed to read the specified adress");
break;
}
System.exit(1);
}
return output;
}
static void writeMemory(int readSize, int newValue, Pointer process, long adress) {
IntByReference written = new IntByReference(0);
toWrite = new Memory(readSize);
toWrite.setInt(0, newValue);
if(!myKernel32.WriteProcessMemory(process, (int)adress toWrite, , written)) {
int error = myKernel32.getLastError();
switch(error)
{
default:
System.err.println("Failed to write in the process : " + error);
break;
}
System.exit(1);
}
System.out.println("Wrote " + written.getValue() + " times");
}
GO TO FULL VERSION