(int processID, String dllName)
| 32 | } |
| 33 | |
| 34 | public static boolean inject(int processID, String dllName) { |
| 35 | DWORD_PTR processAccess = new DWORD_PTR(0x43A); |
| 36 | |
| 37 | HANDLE hProcess = kernel32.OpenProcess(processAccess, new BOOL(false), new DWORD_PTR(processID)); |
| 38 | if(hProcess == null) { |
| 39 | System.out.println("Handle was NULL! Error: " + kernel32.GetLastError()); |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | DWORD_PTR loadLibraryAddress = kernel32.GetProcAddress(kernel32.GetModuleHandle("KERNEL32"), "LoadLibraryA"); |
| 44 | if(loadLibraryAddress.intValue() == 0) { |
| 45 | System.out.println("Could not find LoadLibrary! Error: " + kernel32.GetLastError()); |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | LPVOID dllNameAddress = kernel32.VirtualAllocEx(hProcess, null, (dllName.length() + 1), new DWORD_PTR(0x3000), new DWORD_PTR(0x4)); |
| 50 | if(dllNameAddress == null) { |
| 51 | System.out.println("dllNameAddress was NULL! Error: " + kernel32.GetLastError()); |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | Pointer m = new Memory(dllName.length() + 1); |
| 56 | m.setString(0, dllName); |
| 57 | |
| 58 | boolean wpmSuccess = kernel32.WriteProcessMemory(hProcess, dllNameAddress, m, dllName.length(), null).booleanValue(); |
| 59 | if(!wpmSuccess) { |
| 60 | System.out.println("WriteProcessMemory failed! Error: " + kernel32.GetLastError()); |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | DWORD_PTR threadHandle = kernel32.CreateRemoteThread(hProcess, 0, 0, loadLibraryAddress, dllNameAddress, 0, 0); |
| 65 | if(threadHandle.intValue() == 0) { |
| 66 | System.out.println("threadHandle was invalid! Error: " + kernel32.GetLastError()); |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | kernel32.CloseHandle(hProcess); |
| 71 | |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | } |
no test coverage detected