2013-04-30 3 views
0

system32CreateProcessW을 작성한 JNA 인터페이스에서 호출하려고합니다. 문제는 32 비트 JRE에서 소프트웨어를 실행할 때 제대로 작동하지만 64 비트 JRE로 이동하면 JVM이 손상된다는 것입니다. JNA 호출은 32 비트 JRE에서 작동하지만 64 비트 JRE에서는 작동하지 않습니다.

Kernel32 kernel = (Kernel32) Native.loadLibrary("kernel32", 
     Kernel32.class, new HashMap<String, Object>() { 
      private static final long serialVersionUID = 1L; 

      { 
       put(Library.OPTION_FUNCTION_MAPPER, 
         W32APIFunctionMapper.UNICODE); 
       put(Library.OPTION_TYPE_MAPPER, 
         W32APITypeMapper.UNICODE); 
      } 
     }); 

ProcessInformation processInformation = new ProcessInformation(); 
byte[] startupInfo = new byte[67]; 

int num2 = BitConverter.toInt32(bytes, 60); 
int num = BitConverter.toInt16(bytes, num2 + 6); 
IntByReference ptr4 = new IntByReference(BitConverter.toInt32(bytes, num2 + 0x54)); 
kernel.CreateProcessW(surrogateProcess, null, 0, 0, false, 4, 0, 
      null, startupInfo, processInformation); 

의 Kernal32 JNA 인터페이스 :

public interface Kernel32 extends StdCallLibrary { 

    boolean CreateProcessW(String appName, String commandLine, int procAttr, 
     int thrAttr, boolean inherit, int creation, int env, String curDir, 
     byte[] sInfo, ProcessInformation pInfo); 

} 

ProcessInformation JNA 구조 :

마지막으로
public final class ProcessInformation extends Structure implements ByReference { 

    public IntByReference hProcess; 
    public IntByReference hThread; 
    public int dwProcessId; 
    public int dwThreadId; 

    @Override 
    protected List<String> getFieldOrder() { 
     return Arrays 
       .asList("hProcess", "hThread", "dwProcessId", "dwThreadId"); 
    } 

} 

, 여기에 내가 64에서 실행할 때 발생하는 오류입니다 비트 JRE :

# 
# A fatal error has been detected by the Java Runtime Environment: 
# 
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000077a4e711, pid=1888, tid=8968 
# 
# JRE version: 6.0_43-b01 
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.14-b01 mixed mode windows-amd64 compressed oops) 
# Problematic frame: 
# C [ntdll.dll+0x4e711] 
# 
# An error report file with more information is saved as: 
# C:\Users\Thomas\workspace\trident\hs_err_pid1888.log 
# 
# If you would like to submit a bug report, please visit: 
# http://java.sun.com/webapps/bugreport/crash.jsp 
# The crash happened outside the Java Virtual Machine in native code. 
# See problematic frame for where to report the bug. 
# 

답변

2

귀하의 CreateProcess 매핑이 위조입니다. 포인터 값을 나타 내기 위해 Java int을 사용할 수있는 아이디어를 어디에서 얻었습니까? 오, 신경 쓰지 마라. win32 API가 그것을 가르쳐 주었음에 틀림 없다.

당신은 포인터를 나타 내기 위해 Pointer 또는 PointerType 또는 동등한를 사용해야합니다, 또는 정수 값을 사용하여에 붙어 정말이라면, 적어도 64 비트 플랫폼에서 long (64 비트)를 사용합니다.

BTW, JNA는 CreateProcess을 포함하여 커널 32 매핑을 포함하는 platform.jar을 포함합니다.