Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Execute an exe in same process Java

Featured Replies

Posted

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!
 

  • 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?
 

  • 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 by CodeCracker

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.