2016-07-21 6 views
4

私は教育用プロペラのためにJavaで(そしてJavaでのみ)dllインジェクタを作成したいと考えており、website especialized in online gameの基本的な例が見つかりました。JNA:いくつかの具体的なメソッドがありません

autorは、JNAインターフェイスを使用して作成されたとしか言いません。

NetBeans IDEとJNAを使用してこのコードをstudyngでコンパイルしようとしていますが、ここにあるJNAインターフェイス(4.2.2)にはコードの一部で使用されるすべてのメソッドと関数がありません著者によって残された

は、彼らは次のとおりです。

  1. のGetProcAddress
  2. VirtualAllocEx
  3. VirtualFreeEx

可能であれば試みは、これを解決するためにだから、私は、ここでいくつかの助けを望みますよJNAのメソッドの欠落の問題。

私はこれらのエラーを大きく修正しましたが、JNAのいくつかのメソッドがまだ不足しています。

任意の提案により、事前に
package inject; 

//////////////////// JNA-4.2.2 ///////////////////// 

import com.sun.jna.Memory; 
import com.sun.jna.Native; 
import com.sun.jna.Pointer; 
import com.sun.jna.platform.win32.Kernel32; 
import com.sun.jna.platform.win32.Tlhelp32; 
import com.sun.jna.platform.win32.WinDef; 
import com.sun.jna.platform.win32.WinDef.HMODULE; 
import com.sun.jna.platform.win32.WinNT; 
import com.sun.jna.platform.win32.WinNT.HANDLE; 
import com.sun.jna.ptr.IntByReference; 
import com.sun.jna.win32.W32APIOptions; 
import java.io.File; 

////////////////////////////////////////////////// 

// Extracted from: https://github.com/warmuuh/AndroidCtx/tree/master/HotContext/src/luz/winapi 

import inject.luz.winapi.constants.DwDesiredAccess; 
import inject.luz.winapi.tools.Advapi32Tools; 
import inject.luz.winapi.tools.Kernel32Tools; 
import luz.winapi.api.exception.Kernel32Exception; 

////////////////////////////////////////////////////////////////////////////////////////////// 

public class Inject { 

    private static int GetPid(String proc){ 

     int id = 0; 

     Kernel32 kernel32 = (Kernel32) Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS); 
     Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference();   

     WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0)); 
     try { 
      while (kernel32.Process32Next(snapshot, processEntry)) { 

       if (Native.toString(processEntry.szExeFile).equalsIgnoreCase(proc)) { 

        id = processEntry.th32ProcessID.intValue(); 

       } 
      } 
      } 
    finally { 
      kernel32.CloseHandle(snapshot); 
     } 

    return id; 
    } 

    private static String findProcessByPID(int pid){ 

     String name = ""; 

     Kernel32 kernel32 = (Kernel32) Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS); 
     Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference();   

     WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0)); 
     try { 
      while (kernel32.Process32Next(snapshot, processEntry)) { 

       if (pid == processEntry.th32ProcessID.intValue()) { 

        name = processEntry.szExeFile.toString(); 
       } 
      } 
      } 
    finally { 
      kernel32.CloseHandle(snapshot); 
     } 

    return name; 
    } 

    public static void inject(File dll, Integer pId) throws Kernel32Exception { 

    if(null == dll || !dll.exists() || !dll.isFile() || !dll.getName().endsWith(".dll")) 
      return; 

    String p = findProcessByPID(pId); 

    if(null == p) return; 

    Kernel32 kernel = Kernel32.INSTANCE; 

    HMODULE kernel32Pointer = kernel.GetModuleHandle("Kernel32"); 

             // Cannot find "GetProcAddress" 
     Pointer loadLibraryAddress = kernel.GetProcAddress(kernel32Pointer, "LoadLibraryA"); 

    HANDLE process = null; 

    DwDesiredAccess access = new DwDesiredAccess(); 
     access.setPROCESS_ALL_ACCESS(); 

     try { 
      Advapi32Tools.getInstance().enableDebugPrivilege(Kernel32Tools.getInstance().GetCurrentProcess()); 
     } catch (Exception e) { 
     } 

          // Incompatible types "Pointer" and "HANDLE" 
     process = Kernel32Tools.getInstance().OpenProcess(access, false, pId); 

     String path = dll.getPath() + '\0'; 
     byte[] bytes = path.getBytes(); 

     int pathLength = bytes.length; 

            // Cannot find "VirtualAllocEx" 
     Pointer memoryDllPath = kernel.VirtualAllocEx(process, null, pathLength, Kernel32Tools.MEM_COMMIT, Kernel32Tools.PAGE_READWRITE); 

     Memory dllPathContent = new Memory(pathLength); 

     for(int i=0;i<pathLength;i++) 
      dllPathContent.setByte(i, bytes[i]); 

     IntByReference writeResult = new IntByReference(); 

     boolean successWritting = kernel.WriteProcessMemory(process, memoryDllPath, dllPathContent, pathLength, writeResult); 

     if(!successWritting) { 

       kernel.CloseHandle(process); 

      return; 
     } 

     IntByReference threadId = new IntByReference();  

       // Pointer cannot be converted to "FOREIGN_THREAD_START_ROUTINE" 
     Pointer thread = kernel.CreateRemoteThread(process, null, 0, loadLibraryAddress, memoryDllPath, 0, threadId); 

     boolean res = false; 

         // Incompatible types "Pointer" and "HANDLE"    //Cannot find "WAIT_TIMEOUT" 
      res = kernel.WaitForSingleObject(thread, Integer.MAX_VALUE) != Kernel32Tools.WAIT_TIMEOUT; 

       // Cannot find "VirtualFreeEx" method     // Cannot find "MEM_RELEASE" 
     kernel.VirtualFreeEx(process, memoryDllPath, pathLength, Kernel32Tools.MEM_RELEASE); 

     kernel.CloseHandle(process); 

    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 

      System.out.println(GetPid("notepad.exe")); 


    } 
} 

感謝や

+1

これは、欠落している方法や問題の原因となっている方法をリストした場合、妥当な質問となります。具体的にする。皆さんがあなたのコードをコンパイルして、あなたが意味するものを見つけ出すことを期待しています。 –

+0

@Erwin Bolwidt、私は上記で編集しました。 –

答えて

0

JNA不足している方法:-)を助けますか? It ain't so!

は、あなただけの他の人が恩恵を受けることができるように理想的に、また、JNAライブラリに戻って「行方不明」メソッドに貢献ライブラリを拡張し、独自の(とを追加する必要があります。誰かがGetProcAddressがマッピングされたかの

Here is an example

Someone has mapped VirtualAllocEx here(それらが適切にKERNEL32を拡張しているのではなく、完全にそれをコピーした部分を編集しなければならないが)

私は他の人に見られるのと同じ15秒以内にVirtualFreeExの例を見つけることができませんでした...ありませんそれが外に出ていないことを意味するそこに他の人を書いた後でも、それを書いても大した問題はありません。

関連する問題