コード例 #1
0
ファイル: NativeLibrary.java プロジェクト: johangas/moped
 /**
  * Dynamically look up a native variable by name.
  *
  * <p>Look up the symbol in the default list of loaded libraries.
  *
  * @param varName
  * @param size the size of the variable in bytes
  * @return a Pointer that can be used to get/set the variable
  * @throws RuntimeException if there is no function by that name.
  */
 public VarPointer getGlobalVariableAddress(String varName, int size) {
   Address result = getSymbolAddress(varName);
   if (DEBUG) {
     VM.print("Var Lookup for ");
     VM.print(varName);
     VM.print(", size: ");
     VM.print(size);
     VM.print(" returned ");
     VM.printAddress(result);
     VM.println();
   }
   if (result.isZero()) {
     if (varName.charAt(0) != '_') {
       return getGlobalVariableAddress("_" + varName, size);
     }
     throw new RuntimeException(
         "Can't find native symbol " + varName + ". OS Error: " + errorStr());
   }
   return new VarPointer(varName, result, size);
 }
コード例 #2
0
ファイル: NativeLibrary.java プロジェクト: johangas/moped
 /**
  * Dynamically look up a native function address by name. Look up the symbol in the specified
  * library
  *
  * @param funcName
  * @return address of the function
  * @throws RuntimeException if there is no function by that name.
  */
 private Address getFunction0(String funcName) {
   Address result = getSymbolAddress(funcName);
   if (DEBUG) {
     VM.print("Function Lookup for ");
     VM.print(funcName);
     VM.print(" = ");
     VM.printAddress(result);
     VM.println();
   }
   if (result.isZero()) {
     if (Platform.getPlatform().isWindows()) {
       if (funcName.charAt(funcName.length() - 1) != 'A') {
         return getFunction0(funcName + 'A');
       }
     } else if (funcName.charAt(0) != '_') {
       return getFunction0("_" + funcName);
     }
     throw new RuntimeException(
         "Can't find native symbol " + funcName + ". OS Error: " + errorStr());
   }
   return result;
 }