Posted December 8, 20177 yr Hi guys and gals. I wanna execute an exe inside same process with Java code. Hopefully someone will give some advices , I am not familiarly not even with executing exes from native code. So first I have to use LoadLibrary of the exe, then what? From what I've read on https://stackoverflow.com/questions/44912/java-delegates I'm fornicated since there are no delegates on Java!
December 8, 20177 yr Author Solved a part of problems, I've used com.sun.jna.win32-x86 and the fallowing code: Path path = Paths.get(jTextField1.getText()); byte[] data = Files.readAllBytes(path); int EPrva = GetEntryPointRva(data); HANDLE handle = ClassReaderWriter.mainprogram.Kernel32.INSTANCE.LoadLibraryA(jTextField1.getText()); Pointer pointer = new Pointer(handle.getPointer().peer+EPrva); Function func = new Function(pointer, 0); func.invokeVoid(new Object[]{}); It throws and exception but only because imports are not fixed and dwords are not re-based. A lot of work to do. Does anyone know a good import table parser/fixer on C++ so I would convert it to Java?
December 9, 20177 yr Author Finded a good solution for preserving default ImageBase: public static boolean WasPersevedSpace = false; public static void ExecuteItself() { ClassReaderWriter.mainprogram.Kernel32.MemoryBasicInformation mb = new ClassReaderWriter.mainprogram.Kernel32.MemoryBasicInformation(); Pointer ba_pointer = new Pointer(0x0400000); // standard image base ClassReaderWriter.mainprogram.Kernel32.INSTANCE.VirtualQuery( ba_pointer, mb, mb.size()); if (mb.RegionSize.longValue()>10*1024*1024) // if we have at last 10 MB { WasPersevedSpace = true; return; } ProcessInformation processInformation = new ProcessInformation(); StartupInfoA startupInfo = new StartupInfoA(); // startupInfo.dwFlags = CREATE_SUSPENDED; //startupInfo.wShowWindow = SW_HIDE; boolean ok = Kernel32.INSTANCE.CreateProcessA("D:\\HonorableNetPatcher.exe", null , null , null , true , CREATE_SUSPENDED , null , "C:\\Windows\\System32\\" , startupInfo , processInformation); Pointer global_alloc = ClassReaderWriter.mainprogram.Kernel32.INSTANCE.VirtualAllocEx( processInformation.hProcess, ba_pointer, 15*1024*1024, // 15 MB reserved ClassReaderWriter.mainprogram.Kernel32.MEM_RESERVE, ClassReaderWriter.mainprogram.Kernel32.PAGE_EXECUTE_READWRITE); ClassReaderWriter.mainprogram.Kernel32.INSTANCE.ResumeThread(processInformation.hThread); } So in this way we reserve 15 MB of space at default ImageBase: 0400000 I've found an article: https://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/comment-page-1/ But how do we get current process name and current process parameters??? A proper import table fixer in C++ still to be found, the one from article I've posted is silly! Edited December 9, 20177 yr by CodeCracker
Create an account or sign in to comment