示例#1
0
 public int getPositionInVirtualTable(
     Pointer<Pointer<?>> pVirtualTable, Method method, NativeLibrary library) {
   // Pointer<?> typeInfo = pVirtualTable.get(1);
   int methodsOffset = 0; // library.isMSVC() ? 0 : -2;///2;
   String className = getCPPClassName(method.getDeclaringClass());
   for (int iVirtual = 0; ; iVirtual++) {
     Pointer<?> pMethod = pVirtualTable.get(methodsOffset + iVirtual);
     String virtualMethodName = pMethod == null ? null : library.getSymbolName(pMethod.getPeer());
     // System.out.println("#\n# At index " + methodsOffset + " + " + iVirtual + " of vptr for
     // class " + className + ", found symbol " + Long.toHexString(pMethod.getPeer()) + " = '" +
     // virtualMethodName + "'\n#");
     if (virtualMethodName == null) {
       if (debug) info("\tVtable(" + className + ")[" + iVirtual + "] = null");
       return -1;
     }
     try {
       MemberRef mr = library.parseSymbol(virtualMethodName);
       if (debug)
         info("\tVtable(" + className + ")[" + iVirtual + "] = " + virtualMethodName + " = " + mr);
       if (mr != null && mr.matchesSignature(method)) return iVirtual;
       else if (library.isMSVC() && !mr.matchesEnclosingType(method))
         break; // no NULL terminator in MSVC++ vtables, so we have to guess when we've reached the
                // end
     } catch (Demangler.DemanglingException ex) {
       BridJ.warning(
           "Failed to demangle '"
               + virtualMethodName
               + "' during inspection of virtual table for '"
               + method.toGenericString()
               + "' : "
               + ex);
     }
   }
   return -1;
 }
  public static void reconstructHeaders(Iterable<NativeLibrary> libraries, PrintWriter out) {
    List<MemberRef> orphanMembers = new ArrayList<MemberRef>();
    Map<TypeRef, List<MemberRef>> membersByClass = new HashMap<TypeRef, List<MemberRef>>();
    for (NativeLibrary library : libraries) {
      for (Symbol symbol : library.getSymbols()) {
        MemberRef mr = symbol.getParsedRef();
        if (mr == null) continue;

        TypeRef et = mr.getEnclosingType();
        if (et == null) orphanMembers.add(mr);
        else {
          List<MemberRef> mrs = membersByClass.get(et);
          if (mrs == null) membersByClass.put(et, mrs = new ArrayList<MemberRef>());
          mrs.add(mr);
        }
      }
    }
    for (TypeRef tr : membersByClass.keySet()) out.println("class " + tr + ";");

    for (MemberRef mr : orphanMembers) out.println(mr + ";");

    for (Map.Entry<TypeRef, List<MemberRef>> e : membersByClass.entrySet()) {
      TypeRef tr = e.getKey();
      List<MemberRef> mrs = e.getValue();
      out.println("class " + tr + " \n{");
      for (MemberRef mr : mrs) {
        out.println("\t" + mr + ";");
      }
      out.println("}");
    }
  }
示例#3
0
    public MemoryOperators(NativeLibrary library) {
      for (Symbol sym : library.getSymbols()) {
        try {
          MemberRef parsedRef = sym.getParsedRef();
          IdentLike n = parsedRef.getMemberName();

          if (SpecialName.New.equals(n))
            newFct =
                pointerToAddress(sym.getAddress())
                    .asDynamicFunction(null, Pointer.class, SizeT.class);
          else if (SpecialName.NewArray.equals(n))
            newFct =
                pointerToAddress(sym.getAddress())
                    .asDynamicFunction(null, Pointer.class, SizeT.class);
          else if (SpecialName.Delete.equals(n))
            newFct =
                pointerToAddress(sym.getAddress())
                    .asDynamicFunction(null, Void.class, Pointer.class);
          else if (SpecialName.DeleteArray.equals(n))
            newFct =
                pointerToAddress(sym.getAddress())
                    .asDynamicFunction(null, Void.class, Pointer.class);

        } catch (Exception ex) {
        }
      }
    }