com.android.dx.dex.DexOptions Java Examples

The following examples show how to use com.android.dx.dex.DexOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Simulator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param machine {@code non-null;} machine to use when simulating
 * @param method {@code non-null;} method data to use
 * @param dexOptions {@code non-null;} options for dex output
 */
public Simulator(Machine machine, ConcreteMethod method, DexOptions dexOptions) {
    if (machine == null) {
        throw new NullPointerException("machine == null");
    }

    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (dexOptions == null) {
        throw new NullPointerException("dexOptions == null");
    }

    this.machine = machine;
    this.code = method.getCode();
    this.method = method;
    this.localVariables = method.getLocalVariables();
    this.visitor = new SimVisitor();
    this.dexOptions = dexOptions;

    // This check assumes class is initialized (accesses dexOptions).
    if (method.isDefaultOrStaticInterfaceMethod()) {
        checkInterfaceMethodDeclaration(method);
    }
}
 
Example #2
Source File: Simulator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param machine {@code non-null;} machine to use when simulating
 * @param method {@code non-null;} method data to use
 * @param dexOptions {@code non-null;} options for dex output
 */
public Simulator(Machine machine, ConcreteMethod method, DexOptions dexOptions) {
    if (machine == null) {
        throw new NullPointerException("machine == null");
    }

    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (dexOptions == null) {
        throw new NullPointerException("dexOptions == null");
    }

    this.machine = machine;
    this.code = method.getCode();
    this.method = method;
    this.localVariables = method.getLocalVariables();
    this.visitor = new SimVisitor();
    this.dexOptions = dexOptions;

    // This check assumes class is initialized (accesses dexOptions).
    if (method.isDefaultOrStaticInterfaceMethod()) {
        checkInterfaceMethodDeclaration(method);
    }
}
 
Example #3
Source File: Simulator.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param machine {@code non-null;} machine to use when simulating
 * @param method {@code non-null;} method data to use
 * @param dexOptions {@code non-null;} options for dex output
 */
public Simulator(Machine machine, ConcreteMethod method, DexOptions dexOptions) {
    if (machine == null) {
        throw new NullPointerException("machine == null");
    }

    if (method == null) {
        throw new NullPointerException("method == null");
    }

    this.machine = machine;
    this.code = method.getCode();
    this.localVariables = method.getLocalVariables();
    this.visitor = new SimVisitor();
    this.dexOptions = dexOptions;
}
 
Example #4
Source File: BaseDumper.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param bytes {@code non-null;} bytes of the (alleged) class file
 * on the left)
 * @param out {@code non-null;} where to dump to
 * @param filePath the file path for the class, excluding any base
 * directory specification
 */
public BaseDumper(byte[] bytes, PrintStream out,
                  String filePath, Args args) {
    this.bytes = bytes;
    this.rawBytes = args.rawBytes;
    this.out = out;
    this.width = (args.width <= 0) ? 79 : args.width;
    this.filePath = filePath;
    this.strictParse = args.strictParse;
    this.indent = 0;
    this.separator = rawBytes ? "|" : "";
    this.readBytes = 0;
    this.args = args;

    this.dexOptions = new DexOptions();

    int hexCols = (((width - 5) / 15) + 1) & ~1;
    if (hexCols < 6) {
        hexCols = 6;
    } else if (hexCols > 10) {
        hexCols = 10;
    }
    this.hexCols = hexCols;
}
 
Example #5
Source File: Main.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Copies relevant arguments over into CfOptions and DexOptions instances.
 */
public void makeOptionsObjects() {
    cfOptions = new CfOptions();
    cfOptions.positionInfo = positionInfo;
    cfOptions.localInfo = localInfo;
    cfOptions.strictNameCheck = strictNameCheck;
    cfOptions.optimize = optimize;
    cfOptions.optimizeListFile = optimizeListFile;
    cfOptions.dontOptimizeListFile = dontOptimizeListFile;
    cfOptions.statistics = statistics;

    if (warnings) {
        cfOptions.warn = context.err;
    } else {
        cfOptions.warn = context.noop;
    }

    dexOptions = new DexOptions(context.err);
    dexOptions.minSdkVersion = minSdkVersion;
    dexOptions.forceJumbo = forceJumbo;
    dexOptions.allowAllInterfaceMethodInvokes = allowAllInterfaceMethodInvokes;
}
 
Example #6
Source File: Main.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Copies relevant arguments over into CfOptions and
 * DexOptions instances.
 */
public void makeOptionsObjects(DxContext context) {
    cfOptions = new CfOptions();
    cfOptions.positionInfo = positionInfo;
    cfOptions.localInfo = localInfo;
    cfOptions.strictNameCheck = strictNameCheck;
    cfOptions.optimize = optimize;
    cfOptions.optimizeListFile = optimizeListFile;
    cfOptions.dontOptimizeListFile = dontOptimizeListFile;
    cfOptions.statistics = statistics;

    if (warnings) {
        cfOptions.warn = context.err;
    } else {
        cfOptions.warn = context.noop;
    }

    dexOptions = new DexOptions();
    dexOptions.forceJumbo = forceJumbo;
}
 
Example #7
Source File: Main.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Copies relevant arguments over into CfOptions and DexOptions instances.
 */
public void makeOptionsObjects() {
    cfOptions = new CfOptions();
    cfOptions.positionInfo = positionInfo;
    cfOptions.localInfo = localInfo;
    cfOptions.strictNameCheck = strictNameCheck;
    cfOptions.optimize = optimize;
    cfOptions.optimizeListFile = optimizeListFile;
    cfOptions.dontOptimizeListFile = dontOptimizeListFile;
    cfOptions.statistics = statistics;

    if (warnings) {
        cfOptions.warn = context.err;
    } else {
        cfOptions.warn = context.noop;
    }

    dexOptions = new DexOptions(context.err);
    dexOptions.minSdkVersion = minSdkVersion;
    dexOptions.forceJumbo = forceJumbo;
    dexOptions.allowAllInterfaceMethodInvokes = allowAllInterfaceMethodInvokes;
}
 
Example #8
Source File: BaseDumper.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param bytes {@code non-null;} bytes of the (alleged) class file
 * on the left)
 * @param out {@code non-null;} where to dump to
 * @param filePath the file path for the class, excluding any base
 * directory specification
 */
public BaseDumper(byte[] bytes, PrintStream out,
                  String filePath, Args args) {
    this.bytes = bytes;
    this.rawBytes = args.rawBytes;
    this.out = out;
    this.width = (args.width <= 0) ? 79 : args.width;
    this.filePath = filePath;
    this.strictParse = args.strictParse;
    this.indent = 0;
    this.separator = rawBytes ? "|" : "";
    this.readBytes = 0;
    this.args = args;

    this.dexOptions = new DexOptions();

    int hexCols = (((width - 5) / 15) + 1) & ~1;
    if (hexCols < 6) {
        hexCols = 6;
    } else if (hexCols > 10) {
        hexCols = 10;
    }
    this.hexCols = hexCols;
}
 
Example #9
Source File: Main.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Copies relevant arguments over into CfOptions and DexOptions instances.
 */
public void makeOptionsObjects() {
    cfOptions = new CfOptions();
    cfOptions.positionInfo = positionInfo;
    cfOptions.localInfo = localInfo;
    cfOptions.strictNameCheck = strictNameCheck;
    cfOptions.optimize = optimize;
    cfOptions.optimizeListFile = optimizeListFile;
    cfOptions.dontOptimizeListFile = dontOptimizeListFile;
    cfOptions.statistics = statistics;

    if (warnings) {
        cfOptions.warn = context.err;
    } else {
        cfOptions.warn = context.noop;
    }

    dexOptions = new DexOptions();
    dexOptions.minSdkVersion = minSdkVersion;
    dexOptions.forceJumbo = forceJumbo;
}
 
Example #10
Source File: BaseAndroidClassLoader.java    From rhino-android with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Class<?> defineClass(String name, byte[] data) {
    try {
        DexOptions dexOptions = new DexOptions();
        DexFile dexFile = new DexFile(dexOptions);
        DirectClassFile classFile = new DirectClassFile(data, name.replace('.', '/') + ".class", true);
        classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        classFile.getMagic();
        DxContext context = new DxContext();
        dexFile.add(CfTranslator.translate(context, classFile, null, new CfOptions(), dexOptions, dexFile));
        Dex dex = new Dex(dexFile.toDex(null, false));
        Dex oldDex = getLastDex();
        if (oldDex != null) {
            dex = new DexMerger(new Dex[]{dex, oldDex}, CollisionPolicy.KEEP_FIRST, context).merge();
        }
        return loadClass(dex, name);
    } catch (IOException | ClassNotFoundException e) {
        throw new FatalLoadingException(e);
    }
}
 
Example #11
Source File: CfTranslator.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Helper that updates the dex statistics.
 */
private static void updateDexStatistics(DxContext context, CfOptions cfOptions, DexOptions dexOptions,
                                        RopMethod optRmeth, RopMethod nonOptRmeth,
                                        LocalVariableInfo locals, int paramSize, int originalByteCount) {
    /*
     * Run rop->dex again on optimized vs. non-optimized method to
     * collect statistics. We have to totally convert both ways,
     * since converting the "real" method getting added to the
     * file would corrupt it (by messing with its constant pool
     * indices).
     */

    DalvCode optCode = RopTranslator.translate(optRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);
    DalvCode nonOptCode = RopTranslator.translate(nonOptRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);

    /*
     * Fake out the indices, so code.getInsns() can work well enough
     * for the current purpose.
     */

    DalvCode.AssignIndicesCallback callback =
        new DalvCode.AssignIndicesCallback() {
            public int getIndex(Constant cst) {
                // Everything is at index 0!
                return 0;
            }
        };

    optCode.assignIndices(callback);
    nonOptCode.assignIndices(callback);

    context.codeStatistics.updateDexStatistics(nonOptCode, optCode);
    context.codeStatistics.updateOriginalByteCount(originalByteCount);
}
 
Example #12
Source File: Dops.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the next {@link Dop} in the instruction fitting chain after the
 * given instance, if any.
 *
 * @param opcode {@code non-null;} the opcode
 * @param options {@code non-null;} options, used to determine
 * which opcodes are potentially off-limits
 * @return {@code null-ok;} the next opcode in the same family, in the
 * chain of opcodes to try, or {@code null} if the given opcode is
 * the last in its chain
 */
public static Dop getNextOrNull(Dop opcode, DexOptions options) {
  int nextOpcode = opcode.getNextOpcode();

  if (nextOpcode == Opcodes.NO_NEXT) {
    return null;
  }

  opcode = get(nextOpcode);

  return opcode;
}
 
Example #13
Source File: Dops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the next {@link Dop} in the instruction fitting chain after the
 * given instance, if any.
 *
 * @param opcode {@code non-null;} the opcode
 * @param options {@code non-null;} options, used to determine
 * which opcodes are potentially off-limits
 * @return {@code null-ok;} the next opcode in the same family, in the
 * chain of opcodes to try, or {@code null} if the given opcode is
 * the last in its chain
 */
public static Dop getNextOrNull(Dop opcode, DexOptions options) {
  int nextOpcode = opcode.getNextOpcode();

  if (nextOpcode == Opcodes.NO_NEXT) {
    return null;
  }

  opcode = get(nextOpcode);

  return opcode;
}
 
Example #14
Source File: OutputFinisher.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. It initially contains no instructions.
 *
 * @param dexOptions {@code non-null;} options for dex output
 * @param initialCapacity {@code >= 0;} initial capacity of the
 * instructions list
 * @param regCount {@code >= 0;} register count for the method
 * @param paramSize size, in register units, of all the parameters for this method
 */
public OutputFinisher(DexOptions dexOptions, int initialCapacity, int regCount, int paramSize) {
    this.dexOptions = dexOptions;
    this.unreservedRegCount = regCount;
    this.insns = new ArrayList<DalvInsn>(initialCapacity);
    this.reservedCount = -1;
    this.hasAnyPositionInfo = false;
    this.hasAnyLocalInfo = false;
    this.paramSize = paramSize;
}
 
Example #15
Source File: FirstFitLocalCombiningAllocator.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Return the register alignment constraint to have 64-bits registers that will be align on even
 * dalvik registers after that parameter registers are move up to the top of the frame to match
 * the calling convention.
 *
 * @param regCategory category of the register that will be aligned.
 * @return the register alignment constraint.
 */
private Alignment getAlignment(int regCategory) {
  Alignment alignment = Alignment.UNSPECIFIED;

  if (DexOptions.ALIGN_64BIT_REGS_SUPPORT && regCategory == 2) {
    if (isEven(paramRangeEnd)) {
      alignment = Alignment.EVEN;
    } else {
      alignment = Alignment.ODD;
    }
  }

  return alignment;
}
 
Example #16
Source File: CfTranslator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Helper that updates the dex statistics.
 */
private static void updateDexStatistics(DxContext context, CfOptions cfOptions, DexOptions dexOptions,
        RopMethod optRmeth, RopMethod nonOptRmeth,
        LocalVariableInfo locals, int paramSize, int originalByteCount) {
    /*
     * Run rop->dex again on optimized vs. non-optimized method to
     * collect statistics. We have to totally convert both ways,
     * since converting the "real" method getting added to the
     * file would corrupt it (by messing with its constant pool
     * indices).
     */

    DalvCode optCode = RopTranslator.translate(optRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);
    DalvCode nonOptCode = RopTranslator.translate(nonOptRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);

    /*
     * Fake out the indices, so code.getInsns() can work well enough
     * for the current purpose.
     */

    DalvCode.AssignIndicesCallback callback =
        new DalvCode.AssignIndicesCallback() {
            @Override
public int getIndex(Constant cst) {
                // Everything is at index 0!
                return 0;
            }
        };

    optCode.assignIndices(callback);
    nonOptCode.assignIndices(callback);

    context.codeStatistics.updateDexStatistics(nonOptCode, optCode);
    context.codeStatistics.updateOriginalByteCount(originalByteCount);
}
 
Example #17
Source File: CfTranslator.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper that updates the dex statistics.
 */
private static void updateDexStatistics(DxContext context, CfOptions cfOptions, DexOptions dexOptions,
        RopMethod optRmeth, RopMethod nonOptRmeth,
        LocalVariableInfo locals, int paramSize, int originalByteCount) {
    /*
     * Run rop->dex again on optimized vs. non-optimized method to
     * collect statistics. We have to totally convert both ways,
     * since converting the "real" method getting added to the
     * file would corrupt it (by messing with its constant pool
     * indices).
     */

    DalvCode optCode = RopTranslator.translate(optRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);
    DalvCode nonOptCode = RopTranslator.translate(nonOptRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);

    /*
     * Fake out the indices, so code.getInsns() can work well enough
     * for the current purpose.
     */

    DalvCode.AssignIndicesCallback callback =
        new DalvCode.AssignIndicesCallback() {
            @Override
            public int getIndex(Constant cst) {
                // Everything is at index 0!
                return 0;
            }
        };

    optCode.assignIndices(callback);
    nonOptCode.assignIndices(callback);

    context.codeStatistics.updateDexStatistics(nonOptCode, optCode);
    context.codeStatistics.updateOriginalByteCount(originalByteCount);
}
 
Example #18
Source File: DexLimitTrackerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static DexFile convertClass(Class<?> clazz) throws IOException {
  String path = clazz.getName().replace('.', '/') + ".class";
  try (InputStream in =
      Thread.currentThread().getContextClassLoader().getResourceAsStream(path)) {
    return new DexConverter(new Dexing(new DxContext(), new DexOptions(), new CfOptions()))
        .toDexFile(ByteStreams.toByteArray(in), path);
  }
}
 
Example #19
Source File: Ropper.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. This class is not publicly instantiable; use
 * {@link #convert}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @param dexOptions {@code non-null;} options for dex output
 */
private Ropper(ConcreteMethod method, TranslationAdvice advice, MethodList methods,
        DexOptions dexOptions) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.method = method;
    this.blocks = BasicBlocker.identifyBlocks(method);
    this.maxLabel = blocks.getMaxLabel();
    this.maxLocals = method.getMaxLocals();
    this.machine = new RopperMachine(this, method, advice, methods);
    this.sim = new Simulator(machine, method, dexOptions);
    this.startFrames = new Frame[maxLabel];
    this.subroutines = new Subroutine[maxLabel];

    /*
     * The "* 2 + 10" below is to conservatively believe that every
     * block is an exception handler target and should also
     * take care of enough other possible extra overhead such that
     * the underlying array is unlikely to need resizing.
     */
    this.result = new ArrayList<BasicBlock>(blocks.size() * 2 + 10);
    this.resultSubroutines =
        new ArrayList<IntList>(blocks.size() * 2 + 10);

    this.catchInfos = new CatchInfo[maxLabel];
    this.synchNeedsExceptionHandler = false;

    /*
     * Set up the first stack frame with the right limits, but leave it
     * empty here (to be filled in outside of the constructor).
     */
    startFrames[0] = new Frame(maxLocals, method.getMaxStack());
    exceptionSetupLabelAllocator = new ExceptionSetupLabelAllocator();
}
 
Example #20
Source File: Dops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the next {@link Dop} in the instruction fitting chain after the
 * given instance, if any.
 *
 * @param opcode {@code non-null;} the opcode
 * @param options {@code non-null;} options, used to determine
 * which opcodes are potentially off-limits
 * @return {@code null-ok;} the next opcode in the same family, in the
 * chain of opcodes to try, or {@code null} if the given opcode is
 * the last in its chain
 */
public static Dop getNextOrNull(Dop opcode, DexOptions options) {
  int nextOpcode = opcode.getNextOpcode();

  if (nextOpcode == Opcodes.NO_NEXT) {
    return null;
  }

  opcode = get(nextOpcode);

  return opcode;
}
 
Example #21
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link ConcreteMethod} to a {@link RopMethod}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @return {@code non-null;} the converted instance
 */
public static RopMethod convert(ConcreteMethod method,
        TranslationAdvice advice, MethodList methods, DexOptions dexOptions) {
    try {
        Ropper r = new Ropper(method, advice, methods, dexOptions);
        r.doit();
        return r.getRopMethod();
    } catch (SimException ex) {
        ex.addContext("...while working on method " +
                      method.getNat().toHuman());
        throw ex;
    }
}
 
Example #22
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. This class is not publicly instantiable; use
 * {@link #convert}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @param dexOptions {@code non-null;} options for dex output
 */
private Ropper(ConcreteMethod method, TranslationAdvice advice, MethodList methods,
        DexOptions dexOptions) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.method = method;
    this.blocks = BasicBlocker.identifyBlocks(method);
    this.maxLabel = blocks.getMaxLabel();
    this.maxLocals = method.getMaxLocals();
    this.machine = new RopperMachine(this, method, advice, methods);
    this.sim = new Simulator(machine, method, dexOptions);
    this.startFrames = new Frame[maxLabel];
    this.subroutines = new Subroutine[maxLabel];

    /*
     * The "* 2 + 10" below is to conservatively believe that every
     * block is an exception handler target and should also
     * take care of enough other possible extra overhead such that
     * the underlying array is unlikely to need resizing.
     */
    this.result = new ArrayList<BasicBlock>(blocks.size() * 2 + 10);
    this.resultSubroutines =
        new ArrayList<IntList>(blocks.size() * 2 + 10);

    this.catchInfos = new CatchInfo[maxLabel];
    this.synchNeedsExceptionHandler = false;

    /*
     * Set up the first stack frame with the right limits, but leave it
     * empty here (to be filled in outside of the constructor).
     */
    startFrames[0] = new Frame(maxLocals, method.getMaxStack());
    exceptionSetupLabelAllocator = new ExceptionSetupLabelAllocator();
}
 
Example #23
Source File: DexConversionEnqueuerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private void makeStuffer() {
  stuffer =
      new DexConversionEnqueuer(
          zip,
          newDirectExecutorService(),
          new DexConverter(new Dexing(new DxContext(), new DexOptions(), new CfOptions())),
          cache);
}
 
Example #24
Source File: DexFileAggregatorTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static DexFile convertClass(Class<?> clazz) throws IOException {
  String path = clazz.getName().replace('.', '/') + ".class";
  try (InputStream in =
      Thread.currentThread().getContextClassLoader().getResourceAsStream(path)) {
    return new DexConverter(new Dexing(new DxContext(), new DexOptions(), new CfOptions()))
        .toDexFile(ByteStreams.toByteArray(in), path);
  }
}
 
Example #25
Source File: DotDumper.java    From Box with Apache License 2.0 5 votes vote down vote up
DotDumper(byte[] bytes, String filePath, Args args) {
    this.bytes = bytes;
    this.filePath = filePath;
    this.strictParse = args.strictParse;
    this.optimize = args.optimize;
    this.args = args;
    this.dexOptions = new DexOptions();
}
 
Example #26
Source File: DexMaker.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
EncodedMethod toEncodedMethod(DexOptions dexOptions) {
    if (code != null) {
        RopMethod ropMethod = new RopMethod(code.toBasicBlocks(), 0);
        LocalVariableInfo locals = null;
        DalvCode dalvCode = RopTranslator.translate(
                ropMethod, PositionList.NONE, locals, code.paramSize(), dexOptions);
        return new EncodedMethod(method.constant, flags, dalvCode, StdTypeList.EMPTY);
    } else return new EncodedMethod(method.constant, flags, null, StdTypeList.EMPTY);

}
 
Example #27
Source File: MainActivity.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DexFile generateDexFile(List<byte[]> classByteCodes){
    DxContext dxContext=new DxContext();
    DexOptions dexOptions=new DexOptions();
    CfOptions cfOptions=new CfOptions();
    DexFile dexFile=new DexFile(dexOptions);
    for (byte[] cls:classByteCodes){
        DirectClassFile directClassFile=new DirectClassFile(cls,"",false);
        directClassFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        directClassFile.getMagic();
        dexFile.add(CfTranslator.translate(dxContext,directClassFile,cls,cfOptions,dexOptions,dexFile));
    }
    return dexFile;
}
 
Example #28
Source File: DexMaker.java    From dexmaker with Apache License 2.0 5 votes vote down vote up
EncodedMethod toEncodedMethod(DexOptions dexOptions) {
    if((flags & ABSTRACT) != 0 || (flags & NATIVE) != 0){
        return new EncodedMethod(method.constant, flags, null, StdTypeList.EMPTY);
    }

    RopMethod ropMethod = new RopMethod(code.toBasicBlocks(), 0);
    LocalVariableInfo locals = null;
    DalvCode dalvCode = RopTranslator.translate(
            ropMethod, PositionList.NONE, locals, code.paramSize(), dexOptions);
    return new EncodedMethod(method.constant, flags, dalvCode, StdTypeList.EMPTY);
}
 
Example #29
Source File: Dops.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the next {@link Dop} in the instruction fitting chain after the
 * given instance, if any.
 *
 * @param opcode {@code non-null;} the opcode
 * @param options {@code non-null;} options, used to determine
 * which opcodes are potentially off-limits
 * @return {@code null-ok;} the next opcode in the same family, in the
 * chain of opcodes to try, or {@code null} if the given opcode is
 * the last in its chain
 */
public static Dop getNextOrNull(Dop opcode, DexOptions options) {
  int nextOpcode = opcode.getNextOpcode();

  if (nextOpcode == Opcodes.NO_NEXT) {
    return null;
  }

  opcode = get(nextOpcode);

  return opcode;
}
 
Example #30
Source File: OutputFinisher.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. It initially contains no instructions.
 *
 * @param dexOptions {@code non-null;} options for dex output
 * @param initialCapacity {@code >= 0;} initial capacity of the
 * instructions list
 * @param regCount {@code >= 0;} register count for the method
 * @param paramSize size, in register units, of all the parameters for this method
 */
public OutputFinisher(DexOptions dexOptions, int initialCapacity, int regCount, int paramSize) {
    this.dexOptions = dexOptions;
    this.unreservedRegCount = regCount;
    this.insns = new ArrayList<DalvInsn>(initialCapacity);
    this.reservedCount = -1;
    this.hasAnyPositionInfo = false;
    this.hasAnyLocalInfo = false;
    this.paramSize = paramSize;
}