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 Project: Box   Author: lulululbj   File: Simulator.java    License: 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 Project: Box   Author: lulululbj   File: Main.java    License: 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 #3
Source Project: Box   Author: lulululbj   File: BaseDumper.java    License: 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 #4
Source Project: Box   Author: lulululbj   File: Simulator.java    License: 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 #5
Source Project: Box   Author: lulululbj   File: Main.java    License: 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 Project: Box   Author: lulululbj   File: BaseDumper.java    License: 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 #7
Source Project: buck   Author: facebook   File: Main.java    License: 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 #8
Source Project: J2ME-Loader   Author: nikita36078   File: Simulator.java    License: 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 #9
Source Project: J2ME-Loader   Author: nikita36078   File: Main.java    License: 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 Project: rhino-android   Author: F43nd1r   File: BaseAndroidClassLoader.java    License: 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 Project: Box   Author: lulululbj   File: Dops.java    License: 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 #12
Source Project: Box   Author: lulululbj   File: OutputFinisher.java    License: 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 #13
Source Project: Box   Author: lulululbj   File: CfTranslator.java    License: 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 #14
Source Project: Box   Author: lulululbj   File: Ropper.java    License: 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 #15
Source Project: Box   Author: lulululbj   File: Ropper.java    License: 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 #16
Source Project: Box   Author: lulululbj   File: FirstFitLocalCombiningAllocator.java    License: 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 #17
Source Project: Box   Author: lulululbj   File: DotDumper.java    License: 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 #18
Source Project: Box   Author: lulululbj   File: Dops.java    License: 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 #19
Source Project: Box   Author: lulululbj   File: OutputFinisher.java    License: 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 #20
Source Project: buck   Author: facebook   File: FirstFitLocalCombiningAllocator.java    License: 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 #21
Source Project: Box   Author: lulululbj   File: Ropper.java    License: 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 Project: Box   Author: lulululbj   File: Ropper.java    License: 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 Project: Box   Author: lulululbj   File: DotDumper.java    License: 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 #24
Source Project: lua-for-android   Author: qtiuto   File: DexMaker.java    License: 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 #25
Source Project: lua-for-android   Author: qtiuto   File: MainActivity.java    License: 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 #26
Source Project: J2ME-Loader   Author: nikita36078   File: Dops.java    License: 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 #27
Source Project: J2ME-Loader   Author: nikita36078   File: OutputFinisher.java    License: 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 #28
Source Project: J2ME-Loader   Author: nikita36078   File: CfTranslator.java    License: 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 #29
Source Project: J2ME-Loader   Author: nikita36078   File: Ropper.java    License: 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 #30
Source Project: J2ME-Loader   Author: nikita36078   File: Ropper.java    License: 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();
}