[smali] update to 2.0 final

This commit is contained in:
Connor Tumbleson
2013-10-11 11:43:59 -05:00
parent 5fa3c2d297
commit 03fc77cca8
168 changed files with 69 additions and 28897 deletions

View File

@ -33,14 +33,12 @@ package org.jf.dexlib2.builder;
import org.jf.dexlib2.iface.debug.DebugItem;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class BuilderDebugItem implements DebugItem {
@Nullable MethodLocation location;
public BuilderDebugItem(@Nonnull MethodLocation location) {
this.location = location;
public BuilderDebugItem() {
}
@Override public int getCodeAddress() {

View File

@ -183,31 +183,31 @@ public class MethodLocation {
}
public void addLineNumber(int lineNumber) {
debugItems.add(new BuilderLineNumber(this, lineNumber));
getDebugItems().add(new BuilderLineNumber(lineNumber));
}
public void addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type,
@Nullable StringReference signature) {
debugItems.add(new BuilderStartLocal(this, registerNumber, name, type, signature));
getDebugItems().add(new BuilderStartLocal(registerNumber, name, type, signature));
}
public void addEndLocal(int registerNumber) {
debugItems.add(new BuilderEndLocal(this, registerNumber));
getDebugItems().add(new BuilderEndLocal(registerNumber));
}
public void addRestartLocal(int registerNumber) {
debugItems.add(new BuilderRestartLocal(this, registerNumber));
getDebugItems().add(new BuilderRestartLocal(registerNumber));
}
public void addPrologue() {
debugItems.add(new BuilderPrologueEnd(this));
getDebugItems().add(new BuilderPrologueEnd());
}
public void addEpilogue() {
debugItems.add(new BuilderEpilogueBegin(this));
getDebugItems().add(new BuilderEpilogueBegin());
}
public void addSetSourceFile(@Nullable BuilderStringReference sourceFile) {
debugItems.add(new BuilderSetSourceFile(this, sourceFile));
getDebugItems().add(new BuilderSetSourceFile(sourceFile));
}
}

View File

@ -106,7 +106,7 @@ public class MutableMethodImplementation implements MethodImplementation {
int debugCodeAddress = debugItem.getCodeAddress();
int locationIndex = mapCodeAddressToIndex(codeAddressToIndex, debugCodeAddress);
MethodLocation debugLocation = instructionList.get(locationIndex);
BuilderDebugItem builderDebugItem = convertDebugItem(debugLocation, debugItem);
BuilderDebugItem builderDebugItem = convertDebugItem(debugItem);
debugLocation.getDebugItems().add(builderDebugItem);
builderDebugItem.location = debugLocation;
}
@ -909,32 +909,32 @@ public class MutableMethodImplementation implements MethodImplementation {
}
@Nonnull
private BuilderDebugItem convertDebugItem(@Nonnull MethodLocation location, @Nonnull DebugItem debugItem) {
private BuilderDebugItem convertDebugItem(@Nonnull DebugItem debugItem) {
switch (debugItem.getDebugItemType()) {
case DebugItemType.START_LOCAL: {
StartLocal startLocal = (StartLocal)debugItem;
return new BuilderStartLocal(location, startLocal.getRegister(), startLocal.getNameReference(),
return new BuilderStartLocal(startLocal.getRegister(), startLocal.getNameReference(),
startLocal.getTypeReference(), startLocal.getSignatureReference());
}
case DebugItemType.END_LOCAL: {
EndLocal endLocal = (EndLocal)debugItem;
return new BuilderEndLocal(location, endLocal.getRegister());
return new BuilderEndLocal(endLocal.getRegister());
}
case DebugItemType.RESTART_LOCAL: {
RestartLocal restartLocal = (RestartLocal)debugItem;
return new BuilderRestartLocal(location, restartLocal.getRegister());
return new BuilderRestartLocal(restartLocal.getRegister());
}
case DebugItemType.PROLOGUE_END:
return new BuilderPrologueEnd(location);
return new BuilderPrologueEnd();
case DebugItemType.EPILOGUE_BEGIN:
return new BuilderEpilogueBegin(location);
return new BuilderEpilogueBegin();
case DebugItemType.LINE_NUMBER: {
LineNumber lineNumber = (LineNumber)debugItem;
return new BuilderLineNumber(location, lineNumber.getLineNumber());
return new BuilderLineNumber(lineNumber.getLineNumber());
}
case DebugItemType.SET_SOURCE_FILE: {
SetSourceFile setSourceFile = (SetSourceFile)debugItem;
return new BuilderSetSourceFile(location, setSourceFile.getSourceFileReference());
return new BuilderSetSourceFile(setSourceFile.getSourceFileReference());
}
default:
throw new ExceptionWithContext("Invalid debug item type: " + debugItem.getDebugItemType());

View File

@ -33,18 +33,14 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.EndLocal;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BuilderEndLocal extends BuilderDebugItem implements EndLocal {
private final int register;
public BuilderEndLocal(@Nonnull MethodLocation location,
int register) {
super(location);
public BuilderEndLocal(int register) {
this.register = register;
}

View File

@ -33,14 +33,10 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.EpilogueBegin;
import javax.annotation.Nonnull;
public class BuilderEpilogueBegin extends BuilderDebugItem implements EpilogueBegin {
public BuilderEpilogueBegin(@Nonnull MethodLocation location) {
super(location);
public BuilderEpilogueBegin() {
}
@Override public int getDebugItemType() { return DebugItemType.EPILOGUE_BEGIN; }

View File

@ -33,17 +33,12 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.LineNumber;
import javax.annotation.Nonnull;
public class BuilderLineNumber extends BuilderDebugItem implements LineNumber {
private final int lineNumber;
public BuilderLineNumber(@Nonnull MethodLocation location,
int lineNumber) {
super(location);
public BuilderLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}

View File

@ -33,14 +33,10 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.PrologueEnd;
import javax.annotation.Nonnull;
public class BuilderPrologueEnd extends BuilderDebugItem implements PrologueEnd {
public BuilderPrologueEnd(@Nonnull MethodLocation location) {
super(location);
public BuilderPrologueEnd() {
}
@Override public int getDebugItemType() { return DebugItemType.PROLOGUE_END; }

View File

@ -33,18 +33,14 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.RestartLocal;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BuilderRestartLocal extends BuilderDebugItem implements RestartLocal {
private final int register;
public BuilderRestartLocal(@Nonnull MethodLocation location,
int register) {
super(location);
public BuilderRestartLocal(int register) {
this.register = register;
}

View File

@ -33,20 +33,16 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.SetSourceFile;
import org.jf.dexlib2.iface.reference.StringReference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BuilderSetSourceFile extends BuilderDebugItem implements SetSourceFile {
@Nullable
private final StringReference sourceFile;
public BuilderSetSourceFile(@Nonnull MethodLocation location,
@Nullable StringReference sourceFile) {
super(location);
public BuilderSetSourceFile(@Nullable StringReference sourceFile) {
this.sourceFile = sourceFile;
}

View File

@ -33,12 +33,10 @@ package org.jf.dexlib2.builder.debug;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.builder.BuilderDebugItem;
import org.jf.dexlib2.builder.MethodLocation;
import org.jf.dexlib2.iface.debug.StartLocal;
import org.jf.dexlib2.iface.reference.StringReference;
import org.jf.dexlib2.iface.reference.TypeReference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BuilderStartLocal extends BuilderDebugItem implements StartLocal {
@ -47,12 +45,10 @@ public class BuilderStartLocal extends BuilderDebugItem implements StartLocal {
@Nullable private final TypeReference type;
@Nullable private final StringReference signature;
public BuilderStartLocal(@Nonnull MethodLocation location,
int register,
public BuilderStartLocal(int register,
@Nullable StringReference name,
@Nullable TypeReference type,
@Nullable StringReference signature) {
super(location);
this.register = register;
this.name = name;
this.type = type;

View File

@ -31,10 +31,7 @@
package org.jf.dexlib2.immutable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.*;
import org.jf.dexlib2.base.reference.BaseTypeReference;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.ClassDef;
@ -71,6 +68,13 @@ public class ImmutableClassDef extends BaseTypeReference implements ClassDef {
@Nullable Collection<? extends Annotation> annotations,
@Nullable Iterable<? extends Field> fields,
@Nullable Iterable<? extends Method> methods) {
if (fields == null) {
fields = ImmutableList.of();
}
if (methods == null) {
methods = ImmutableList.of();
}
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;

View File

@ -31,10 +31,7 @@
package org.jf.dexlib2.writer;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import com.google.common.collect.*;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.ReferenceType;
@ -80,7 +77,6 @@ public abstract class DexWriter<
StringKey extends CharSequence, StringRef extends StringReference, TypeKey extends CharSequence,
TypeRef extends TypeReference, ProtoKey extends Comparable<ProtoKey>,
FieldRefKey extends FieldReference, MethodRefKey extends MethodReference,
BaseReference extends Reference,
ClassKey extends Comparable<? super ClassKey>,
AnnotationKey extends Annotation, AnnotationSetKey,
TypeListKey,
@ -117,8 +113,6 @@ public abstract class DexWriter<
protected int numCodeItemItems = 0;
protected int numClassDataItems = 0;
protected final InstructionFactory<BaseReference> instructionFactory;
protected final StringSection<StringKey, StringRef> stringSection;
protected final TypeSection<StringKey, TypeKey, TypeRef> typeSection;
protected final ProtoSection<StringKey, TypeKey, ProtoKey, TypeListKey> protoSection;
@ -132,7 +126,6 @@ public abstract class DexWriter<
protected final AnnotationSetSection<AnnotationKey, AnnotationSetKey> annotationSetSection;
protected DexWriter(int api,
InstructionFactory<BaseReference> instructionFactory,
StringSection<StringKey, StringRef> stringSection,
TypeSection<StringKey, TypeKey, TypeRef> typeSection,
ProtoSection<StringKey, TypeKey, ProtoKey, TypeListKey> protoSection,
@ -145,7 +138,6 @@ public abstract class DexWriter<
EncodedValue> annotationSection,
AnnotationSetSection<AnnotationKey, AnnotationSetKey> annotationSetSection) {
this.api = api;
this.instructionFactory = instructionFactory;
this.stringSection = stringSection;
this.typeSection = typeSection;
this.protoSection = protoSection;
@ -816,7 +808,8 @@ public abstract class DexWriter<
}
}
if (debugItems == null && parameterCount == 0) {
if (parameterCount == 0 && (debugItems == null || Iterables.isEmpty(debugItems))) {
return NO_OFFSET;
}
@ -1179,11 +1172,8 @@ public abstract class DexWriter<
}
private void writeHeader(@Nonnull DexDataWriter writer, int dataOffset, int fileSize) throws IOException {
if (api < 14) {
writer.write(HeaderItem.MAGIC_VALUES[0]);
} else {
writer.write(HeaderItem.MAGIC_VALUES[1]);
}
// always write the 035 version, there's no reason to use the 036 version for now
writer.write(HeaderItem.MAGIC_VALUES[0]);
// checksum placeholder
writer.writeInt(0);

View File

@ -67,26 +67,23 @@ public class BuilderClassDef extends BaseTypeReference implements ClassDef {
@Nonnull BuilderAnnotationSet annotations,
@Nullable Iterable<? extends BuilderField> fields,
@Nullable Iterable<? extends BuilderMethod> methods) {
if (fields == null) {
fields = ImmutableList.of();
}
if (methods == null) {
methods = ImmutableList.of();
}
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;
this.interfaces = interfaces;
this.sourceFile = sourceFile;
this.annotations = annotations;
if (fields == null) {
this.staticFields = ImmutableSortedSet.of();
this.instanceFields = ImmutableSortedSet.of();
} else {
this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
}
if (methods == null) {
this.directMethods = ImmutableSortedSet.of();
this.virtualMethods = ImmutableSortedSet.of();
} else {
this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
@Nonnull @Override public String getType() { return type.getType(); }

View File

@ -1,426 +0,0 @@
/*
* Copyright 2013, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.writer.builder;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.Instruction;
import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.dexlib2.iface.instruction.formats.*;
import org.jf.dexlib2.immutable.instruction.*;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public interface BuilderInstruction extends Instruction {
static abstract class BaseBuilderInstruction implements BuilderInstruction {
@Nonnull protected final Opcode opcode;
public BaseBuilderInstruction(@Nonnull Opcode opcode) {
Preconditions.checkFormat(opcode, getFormat());
this.opcode = opcode;
}
@Nonnull public abstract Format getFormat();
@Nonnull @Override public Opcode getOpcode() {
return opcode;
}
@Override public int getCodeUnits() {
return getFormat().size/2;
}
}
public static class BuilderInstruction10t extends ImmutableInstruction10t implements BuilderInstruction {
public BuilderInstruction10t(@Nonnull Opcode opcode, int codeOffset) {
super(opcode, codeOffset);
}
}
public static class BuilderInstruction10x extends ImmutableInstruction10x implements BuilderInstruction {
public BuilderInstruction10x(@Nonnull Opcode opcode) {
super(opcode);
}
}
public static class BuilderInstruction11n extends ImmutableInstruction11n implements BuilderInstruction {
public BuilderInstruction11n(@Nonnull Opcode opcode, int registerA, int literal) {
super(opcode, registerA, literal);
}
}
public static class BuilderInstruction11x extends ImmutableInstruction11x implements BuilderInstruction {
public BuilderInstruction11x(@Nonnull Opcode opcode, int registerA) {
super(opcode, registerA);
}
}
public static class BuilderInstruction12x extends ImmutableInstruction12x implements BuilderInstruction {
public BuilderInstruction12x(@Nonnull Opcode opcode, int registerA, int registerB) {
super(opcode, registerA, registerB);
}
}
public static class BuilderInstruction20bc extends BaseBuilderInstruction implements Instruction20bc {
public static final Format FORMAT = Format.Format20bc;
protected final int verificationError;
@Nonnull protected final BuilderReference reference;
public BuilderInstruction20bc(@Nonnull Opcode opcode,
int verificationError,
@Nonnull BuilderReference reference) {
super(opcode);
this.verificationError = Preconditions.checkVerificationError(verificationError);
this.reference = Preconditions.checkReference(opcode.referenceType, reference);
}
@Override public int getVerificationError() { return verificationError; }
@Nonnull @Override public BuilderReference getReference() { return reference; }
@Nonnull @Override public Format getFormat() { return FORMAT; }
}
public static class BuilderInstruction20t extends ImmutableInstruction20t implements BuilderInstruction {
public BuilderInstruction20t(@Nonnull Opcode opcode, int codeOffset) {
super(opcode, codeOffset);
}
}
public static class BuilderInstruction21c extends BaseBuilderInstruction implements Instruction21c {
public static final Format FORMAT = Format.Format21c;
protected final int registerA;
@Nonnull protected final BuilderReference reference;
public BuilderInstruction21c(@Nonnull Opcode opcode,
int registerA,
@Nonnull BuilderReference reference) {
super(opcode);
this.registerA = Preconditions.checkByteRegister(registerA);
this.reference = Preconditions.checkReference(opcode.referenceType, reference);
}
@Override public int getRegisterA() { return registerA; }
@Nonnull @Override public BuilderReference getReference() { return reference; }
@Nonnull @Override public Format getFormat() { return FORMAT; }
}
public static class BuilderInstruction21ih extends ImmutableInstruction21ih implements BuilderInstruction {
public BuilderInstruction21ih(@Nonnull Opcode opcode, int registerA, int literal) {
super(opcode, registerA, literal);
}
}
public static class BuilderInstruction21lh extends ImmutableInstruction21lh implements BuilderInstruction {
public BuilderInstruction21lh(@Nonnull Opcode opcode, int registerA, long literal) {
super(opcode, registerA, literal);
}
}
public static class BuilderInstruction21s extends ImmutableInstruction21s implements BuilderInstruction {
public BuilderInstruction21s(@Nonnull Opcode opcode, int registerA, int literal) {
super(opcode, registerA, literal);
}
}
public static class BuilderInstruction21t extends ImmutableInstruction21t implements BuilderInstruction {
public BuilderInstruction21t(@Nonnull Opcode opcode, int registerA, int codeOffset) {
super(opcode, registerA, codeOffset);
}
}
public static class BuilderInstruction22b extends ImmutableInstruction22b implements BuilderInstruction {
public BuilderInstruction22b(@Nonnull Opcode opcode, int registerA, int registerB, int literal) {
super(opcode, registerA, registerB, literal);
}
}
public static class BuilderInstruction22c extends BaseBuilderInstruction implements Instruction22c {
public static final Format FORMAT = Format.Format22c;
protected final int registerA;
protected final int registerB;
@Nonnull protected final BuilderReference reference;
public BuilderInstruction22c(@Nonnull Opcode opcode,
int registerA,
int registerB,
@Nonnull BuilderReference reference) {
super(opcode);
this.registerA = Preconditions.checkNibbleRegister(registerA);
this.registerB = Preconditions.checkNibbleRegister(registerB);
this.reference = Preconditions.checkReference(opcode.referenceType, reference);
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Nonnull @Override public BuilderReference getReference() { return reference; }
@Nonnull @Override public Format getFormat() { return FORMAT; }
}
public static class BuilderInstruction22s extends ImmutableInstruction22s implements BuilderInstruction {
public BuilderInstruction22s(@Nonnull Opcode opcode, int registerA, int registerB, int literal) {
super(opcode, registerA, registerB, literal);
}
}
public static class BuilderInstruction22t extends ImmutableInstruction22t implements BuilderInstruction {
public BuilderInstruction22t(@Nonnull Opcode opcode, int registerA, int registerB, int codeOffset) {
super(opcode, registerA, registerB, codeOffset);
}
}
public static class BuilderInstruction22x extends ImmutableInstruction22x implements BuilderInstruction {
public BuilderInstruction22x(@Nonnull Opcode opcode, int registerA, int registerB) {
super(opcode, registerA, registerB);
}
}
public static class BuilderInstruction23x extends ImmutableInstruction23x implements BuilderInstruction {
public BuilderInstruction23x(@Nonnull Opcode opcode, int registerA, int registerB, int registerC) {
super(opcode, registerA, registerB, registerC);
}
}
public static class BuilderInstruction30t extends ImmutableInstruction30t implements BuilderInstruction {
public BuilderInstruction30t(@Nonnull Opcode opcode, int codeOffset) {
super(opcode, codeOffset);
}
}
public static class BuilderInstruction31c extends BaseBuilderInstruction implements Instruction31c {
public static final Format FORMAT = Format.Format31c;
protected final int registerA;
@Nonnull protected final BuilderReference reference;
public BuilderInstruction31c(@Nonnull Opcode opcode,
int registerA,
@Nonnull BuilderReference reference) {
super(opcode);
this.registerA = Preconditions.checkByteRegister(registerA);
this.reference = Preconditions.checkReference(opcode.referenceType, reference);
}
@Override public int getRegisterA() { return registerA; }
@Nonnull @Override public BuilderReference getReference() { return reference; }
@Nonnull @Override public Format getFormat() { return FORMAT; }
}
public static class BuilderInstruction31i extends ImmutableInstruction31i implements BuilderInstruction {
public BuilderInstruction31i(@Nonnull Opcode opcode, int registerA, int literal) {
super(opcode, registerA, literal);
}
}
public static class BuilderInstruction31t extends ImmutableInstruction31t implements BuilderInstruction {
public BuilderInstruction31t(@Nonnull Opcode opcode, int registerA, int codeOffset) {
super(opcode, registerA, codeOffset);
}
}
public static class BuilderInstruction32x extends ImmutableInstruction32x implements BuilderInstruction {
public BuilderInstruction32x(@Nonnull Opcode opcode, int registerA, int registerB) {
super(opcode, registerA, registerB);
}
}
public static class BuilderInstruction35c extends BaseBuilderInstruction implements Instruction35c {
public static final Format FORMAT = Format.Format35c;
protected final int registerCount;
protected final int registerC;
protected final int registerD;
protected final int registerE;
protected final int registerF;
protected final int registerG;
@Nonnull protected final BuilderReference reference;
public BuilderInstruction35c(@Nonnull Opcode opcode,
int registerCount,
int registerC,
int registerD,
int registerE,
int registerF,
int registerG,
@Nonnull BuilderReference reference) {
super(opcode);
this.registerCount = Preconditions.check35cRegisterCount(registerCount);
this.registerC = (registerCount>0) ? Preconditions.checkNibbleRegister(registerC) : 0;
this.registerD = (registerCount>1) ? Preconditions.checkNibbleRegister(registerD) : 0;
this.registerE = (registerCount>2) ? Preconditions.checkNibbleRegister(registerE) : 0;
this.registerF = (registerCount>3) ? Preconditions.checkNibbleRegister(registerF) : 0;
this.registerG = (registerCount>4) ? Preconditions.checkNibbleRegister(registerG) : 0;
this.reference = Preconditions.checkReference(opcode.referenceType, reference);
}
@Override public int getRegisterCount() { return registerCount; }
@Override public int getRegisterC() { return registerC; }
@Override public int getRegisterD() { return registerD; }
@Override public int getRegisterE() { return registerE; }
@Override public int getRegisterF() { return registerF; }
@Override public int getRegisterG() { return registerG; }
@Nonnull @Override public BuilderReference getReference() { return reference; }
@Nonnull @Override public Format getFormat() { return FORMAT; }
}
public static class BuilderInstruction3rc extends BaseBuilderInstruction implements Instruction3rc {
public static final Format FORMAT = Format.Format3rc;
private final int startRegister;
private final int registerCount;
@Nonnull protected final BuilderReference reference;
public BuilderInstruction3rc(@Nonnull Opcode opcode,
int startRegister,
int registerCount,
@Nonnull BuilderReference reference) {
super(opcode);
this.startRegister = Preconditions.checkShortRegister(startRegister);
this.registerCount = Preconditions.checkRegisterRangeCount(registerCount);
this.reference = Preconditions.checkReference(opcode.referenceType, reference);
}
@Nonnull @Override public BuilderReference getReference() {
return reference;
}
@Override public int getStartRegister() {
return startRegister;
}
@Override public int getRegisterCount() {
return registerCount;
}
@Nonnull @Override public Format getFormat() {
return FORMAT;
}
}
public static class BuilderInstruction51l extends ImmutableInstruction51l implements BuilderInstruction {
public BuilderInstruction51l(@Nonnull Opcode opcode, int registerA, long literal) {
super(opcode, registerA, literal);
}
}
public static class BuilderArrayPayload extends BaseBuilderInstruction implements ArrayPayload {
public static final Format FORMAT = Format.ArrayPayload;
private final int elementWidth;
@Nonnull private final List<Number> arrayElements;
public BuilderArrayPayload(int elementWidth, @Nullable List<Number> arrayElements) {
super(Opcode.ARRAY_PAYLOAD);
this.elementWidth = elementWidth;
if (arrayElements == null) {
arrayElements = ImmutableList.of();
}
this.arrayElements = arrayElements;
}
@Override public int getElementWidth() {
return elementWidth;
}
@Nonnull @Override public List<Number> getArrayElements() {
return arrayElements;
}
@Nonnull @Override public Format getFormat() {
return FORMAT;
}
@Override public int getCodeUnits() {
return 4 + (elementWidth * arrayElements.size() + 1) / 2;
}
}
public static class BuilderPackedSwitchPayload extends BaseBuilderInstruction implements PackedSwitchPayload {
public static final Format FORMAT = Format.PackedSwitchPayload;
@Nonnull private final List<? extends SwitchElement> elements;
public BuilderPackedSwitchPayload(@Nullable List<? extends SwitchElement> switchElements) {
super(Opcode.PACKED_SWITCH_PAYLOAD);
if (switchElements == null) {
switchElements = ImmutableList.of();
}
this.elements = switchElements;
}
@Nonnull @Override public List<? extends SwitchElement> getSwitchElements() {
return elements;
}
@Nonnull @Override public Format getFormat() {
return FORMAT;
}
@Override public int getCodeUnits() {
return 4 + elements.size() * 2;
}
}
public static class BuilderSparseSwitchPayload extends BaseBuilderInstruction implements SparseSwitchPayload {
public static final Format FORMAT = Format.SparseSwitchPayload;
@Nonnull private final List<? extends SwitchElement> elements;
public BuilderSparseSwitchPayload(@Nullable List<? extends SwitchElement> switchElements) {
super(Opcode.SPARSE_SWITCH_PAYLOAD);
if (switchElements == null) {
switchElements = ImmutableList.of();
}
this.elements = switchElements;
}
@Nonnull @Override public List<? extends SwitchElement> getSwitchElements() {
return elements;
}
@Nonnull @Override public Format getFormat() {
return FORMAT;
}
@Override public int getCodeUnits() {
return 2 + elements.size() * 4;
}
}
}

View File

@ -1,223 +0,0 @@
/*
* Copyright 2013, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.writer.builder;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.dexlib2.writer.InstructionFactory;
import org.jf.dexlib2.writer.builder.BuilderInstruction.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class BuilderInstructionFactory implements InstructionFactory<BuilderReference> {
public static final BuilderInstructionFactory INSTANCE = new BuilderInstructionFactory();
private BuilderInstructionFactory() {
}
public BuilderInstruction10t makeInstruction10t(@Nonnull Opcode opcode,
int codeOffset) {
return new BuilderInstruction10t(opcode, codeOffset);
}
public BuilderInstruction10x makeInstruction10x(@Nonnull Opcode opcode) {
return new BuilderInstruction10x(opcode);
}
public BuilderInstruction11n makeInstruction11n(@Nonnull Opcode opcode,
int registerA,
int literal) {
return new BuilderInstruction11n(opcode, registerA, literal);
}
public BuilderInstruction11x makeInstruction11x(@Nonnull Opcode opcode,
int registerA) {
return new BuilderInstruction11x(opcode, registerA);
}
public BuilderInstruction12x makeInstruction12x(@Nonnull Opcode opcode,
int registerA,
int registerB) {
return new BuilderInstruction12x(opcode, registerA, registerB);
}
public BuilderInstruction20bc makeInstruction20bc(@Nonnull Opcode opcode,
int verificationError,
@Nonnull BuilderReference reference) {
return new BuilderInstruction20bc(opcode, verificationError, reference);
}
public BuilderInstruction20t makeInstruction20t(@Nonnull Opcode opcode,
int codeOffset) {
return new BuilderInstruction20t(opcode, codeOffset);
}
public BuilderInstruction21c makeInstruction21c(@Nonnull Opcode opcode,
int registerA,
@Nonnull BuilderReference reference) {
return new BuilderInstruction21c(opcode, registerA, reference);
}
public BuilderInstruction21ih makeInstruction21ih(@Nonnull Opcode opcode,
int registerA,
int literal) {
return new BuilderInstruction21ih(opcode, registerA, literal);
}
public BuilderInstruction21lh makeInstruction21lh(@Nonnull Opcode opcode,
int registerA,
long literal) {
return new BuilderInstruction21lh(opcode, registerA, literal);
}
public BuilderInstruction21s makeInstruction21s(@Nonnull Opcode opcode,
int registerA,
int literal) {
return new BuilderInstruction21s(opcode, registerA, literal);
}
public BuilderInstruction21t makeInstruction21t(@Nonnull Opcode opcode,
int registerA,
int codeOffset) {
return new BuilderInstruction21t(opcode, registerA, codeOffset);
}
public BuilderInstruction22b makeInstruction22b(@Nonnull Opcode opcode,
int registerA,
int registerB,
int literal) {
return new BuilderInstruction22b(opcode, registerA, registerB, literal);
}
public BuilderInstruction22c makeInstruction22c(@Nonnull Opcode opcode,
int registerA,
int registerB,
@Nonnull BuilderReference reference) {
return new BuilderInstruction22c(opcode, registerA, registerB, reference);
}
public BuilderInstruction22s makeInstruction22s(@Nonnull Opcode opcode,
int registerA,
int registerB,
int literal) {
return new BuilderInstruction22s(opcode, registerA, registerB, literal);
}
public BuilderInstruction22t makeInstruction22t(@Nonnull Opcode opcode,
int registerA,
int registerB,
int codeOffset) {
return new BuilderInstruction22t(opcode, registerA, registerB, codeOffset);
}
public BuilderInstruction22x makeInstruction22x(@Nonnull Opcode opcode,
int registerA,
int registerB) {
return new BuilderInstruction22x(opcode, registerA, registerB);
}
public BuilderInstruction23x makeInstruction23x(@Nonnull Opcode opcode,
int registerA,
int registerB,
int registerC) {
return new BuilderInstruction23x(opcode, registerA, registerB, registerC);
}
public BuilderInstruction30t makeInstruction30t(@Nonnull Opcode opcode,
int codeOffset) {
return new BuilderInstruction30t(opcode, codeOffset);
}
public BuilderInstruction31c makeInstruction31c(@Nonnull Opcode opcode,
int registerA,
@Nonnull BuilderReference reference) {
return new BuilderInstruction31c(opcode, registerA, reference);
}
public BuilderInstruction31i makeInstruction31i(@Nonnull Opcode opcode,
int registerA,
int literal) {
return new BuilderInstruction31i(opcode, registerA, literal);
}
public BuilderInstruction31t makeInstruction31t(@Nonnull Opcode opcode,
int registerA,
int codeOffset) {
return new BuilderInstruction31t(opcode, registerA, codeOffset);
}
public BuilderInstruction32x makeInstruction32x(@Nonnull Opcode opcode,
int registerA,
int registerB) {
return new BuilderInstruction32x(opcode, registerA, registerB);
}
public BuilderInstruction35c makeInstruction35c(@Nonnull Opcode opcode,
int registerCount,
int registerC,
int registerD,
int registerE,
int registerF,
int registerG,
@Nonnull BuilderReference reference) {
return new BuilderInstruction35c(opcode, registerCount, registerC, registerD, registerE, registerF, registerG,
reference);
}
public BuilderInstruction3rc makeInstruction3rc(@Nonnull Opcode opcode,
int startRegister,
int registerCount,
@Nonnull BuilderReference reference) {
return new BuilderInstruction3rc(opcode, startRegister, registerCount, reference);
}
public BuilderInstruction51l makeInstruction51l(@Nonnull Opcode opcode,
int registerA,
long literal) {
return new BuilderInstruction51l(opcode, registerA, literal);
}
public BuilderSparseSwitchPayload makeSparseSwitchPayload(@Nullable List<? extends SwitchElement> switchElements) {
return new BuilderSparseSwitchPayload(switchElements);
}
public BuilderPackedSwitchPayload makePackedSwitchPayload(@Nullable List<? extends SwitchElement> switchElements) {
return new BuilderPackedSwitchPayload(switchElements);
}
public BuilderArrayPayload makeArrayPayload(int elementWidth,
@Nullable List<Number> arrayElements) {
return new BuilderArrayPayload(elementWidth, arrayElements);
}
}

View File

@ -54,7 +54,7 @@ import java.util.List;
import java.util.Set;
public class DexBuilder extends DexWriter<BuilderStringReference, BuilderStringReference, BuilderTypeReference,
BuilderTypeReference, BuilderProtoReference, BuilderFieldReference, BuilderMethodReference, BuilderReference,
BuilderTypeReference, BuilderProtoReference, BuilderFieldReference, BuilderMethodReference,
BuilderClassDef, BuilderAnnotation, BuilderAnnotationSet, BuilderTypeList, BuilderField, BuilderMethod,
BuilderEncodedValue, BuilderAnnotationElement> {
@ -71,7 +71,7 @@ public class DexBuilder extends DexWriter<BuilderStringReference, BuilderStringR
}
private DexBuilder(int api, @Nonnull BuilderContext context) {
super(api, BuilderInstructionFactory.INSTANCE, context.stringPool, context.typePool, context.protoPool,
super(api, context.stringPool, context.typePool, context.protoPool,
context.fieldPool, context.methodPool, context.classPool, context.typeListPool, context.annotationPool,
context.annotationSetPool);
this.context = context;

View File

@ -38,7 +38,6 @@ import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.reference.*;
import org.jf.dexlib2.iface.value.*;
import org.jf.dexlib2.immutable.instruction.ImmutableInstructionFactory;
import org.jf.dexlib2.writer.DexWriter;
import org.jf.dexlib2.writer.io.FileDataStore;
import org.jf.dexlib2.writer.pool.ProtoPool.Key;
@ -51,7 +50,7 @@ import java.util.Collection;
import java.util.Set;
public class DexPool extends DexWriter<CharSequence, StringReference, CharSequence, TypeReference, Key,
FieldReference, MethodReference, Reference, PoolClassDef,
FieldReference, MethodReference, PoolClassDef,
Annotation, Set<? extends Annotation>,
TypeListPool.Key<? extends Collection<? extends CharSequence>>, Field, PoolMethod,
EncodedValue, AnnotationElement> {
@ -79,7 +78,7 @@ public class DexPool extends DexWriter<CharSequence, StringReference, CharSequen
private DexPool(int api, StringPool stringPool, TypePool typePool, ProtoPool protoPool, FieldPool fieldPool,
MethodPool methodPool, ClassPool classPool, TypeListPool typeListPool,
AnnotationPool annotationPool, AnnotationSetPool annotationSetPool) {
super(api, ImmutableInstructionFactory.INSTANCE, stringPool, typePool, protoPool, fieldPool, methodPool,
super(api, stringPool, typePool, protoPool, fieldPool, methodPool,
classPool, typeListPool, annotationPool, annotationSetPool);
}