mirror of
https://github.com/revanced/smali.git
synced 2025-05-02 07:34:28 +02:00
Remove the now unused builder instructions and instruction factories
This commit is contained in:
parent
81648539c9
commit
edd961477e
@ -80,7 +80,6 @@ public abstract class DexWriter<
|
|||||||
StringKey extends CharSequence, StringRef extends StringReference, TypeKey extends CharSequence,
|
StringKey extends CharSequence, StringRef extends StringReference, TypeKey extends CharSequence,
|
||||||
TypeRef extends TypeReference, ProtoKey extends Comparable<ProtoKey>,
|
TypeRef extends TypeReference, ProtoKey extends Comparable<ProtoKey>,
|
||||||
FieldRefKey extends FieldReference, MethodRefKey extends MethodReference,
|
FieldRefKey extends FieldReference, MethodRefKey extends MethodReference,
|
||||||
BaseReference extends Reference,
|
|
||||||
ClassKey extends Comparable<? super ClassKey>,
|
ClassKey extends Comparable<? super ClassKey>,
|
||||||
AnnotationKey extends Annotation, AnnotationSetKey,
|
AnnotationKey extends Annotation, AnnotationSetKey,
|
||||||
TypeListKey,
|
TypeListKey,
|
||||||
@ -117,8 +116,6 @@ public abstract class DexWriter<
|
|||||||
protected int numCodeItemItems = 0;
|
protected int numCodeItemItems = 0;
|
||||||
protected int numClassDataItems = 0;
|
protected int numClassDataItems = 0;
|
||||||
|
|
||||||
protected final InstructionFactory<BaseReference> instructionFactory;
|
|
||||||
|
|
||||||
protected final StringSection<StringKey, StringRef> stringSection;
|
protected final StringSection<StringKey, StringRef> stringSection;
|
||||||
protected final TypeSection<StringKey, TypeKey, TypeRef> typeSection;
|
protected final TypeSection<StringKey, TypeKey, TypeRef> typeSection;
|
||||||
protected final ProtoSection<StringKey, TypeKey, ProtoKey, TypeListKey> protoSection;
|
protected final ProtoSection<StringKey, TypeKey, ProtoKey, TypeListKey> protoSection;
|
||||||
@ -132,7 +129,6 @@ public abstract class DexWriter<
|
|||||||
protected final AnnotationSetSection<AnnotationKey, AnnotationSetKey> annotationSetSection;
|
protected final AnnotationSetSection<AnnotationKey, AnnotationSetKey> annotationSetSection;
|
||||||
|
|
||||||
protected DexWriter(int api,
|
protected DexWriter(int api,
|
||||||
InstructionFactory<BaseReference> instructionFactory,
|
|
||||||
StringSection<StringKey, StringRef> stringSection,
|
StringSection<StringKey, StringRef> stringSection,
|
||||||
TypeSection<StringKey, TypeKey, TypeRef> typeSection,
|
TypeSection<StringKey, TypeKey, TypeRef> typeSection,
|
||||||
ProtoSection<StringKey, TypeKey, ProtoKey, TypeListKey> protoSection,
|
ProtoSection<StringKey, TypeKey, ProtoKey, TypeListKey> protoSection,
|
||||||
@ -145,7 +141,6 @@ public abstract class DexWriter<
|
|||||||
EncodedValue> annotationSection,
|
EncodedValue> annotationSection,
|
||||||
AnnotationSetSection<AnnotationKey, AnnotationSetKey> annotationSetSection) {
|
AnnotationSetSection<AnnotationKey, AnnotationSetKey> annotationSetSection) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.instructionFactory = instructionFactory;
|
|
||||||
this.stringSection = stringSection;
|
this.stringSection = stringSection;
|
||||||
this.typeSection = typeSection;
|
this.typeSection = typeSection;
|
||||||
this.protoSection = protoSection;
|
this.protoSection = protoSection;
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -54,7 +54,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DexBuilder extends DexWriter<BuilderStringReference, BuilderStringReference, BuilderTypeReference,
|
public class DexBuilder extends DexWriter<BuilderStringReference, BuilderStringReference, BuilderTypeReference,
|
||||||
BuilderTypeReference, BuilderProtoReference, BuilderFieldReference, BuilderMethodReference, BuilderReference,
|
BuilderTypeReference, BuilderProtoReference, BuilderFieldReference, BuilderMethodReference,
|
||||||
BuilderClassDef, BuilderAnnotation, BuilderAnnotationSet, BuilderTypeList, BuilderField, BuilderMethod,
|
BuilderClassDef, BuilderAnnotation, BuilderAnnotationSet, BuilderTypeList, BuilderField, BuilderMethod,
|
||||||
BuilderEncodedValue, BuilderAnnotationElement> {
|
BuilderEncodedValue, BuilderAnnotationElement> {
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ public class DexBuilder extends DexWriter<BuilderStringReference, BuilderStringR
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DexBuilder(int api, @Nonnull BuilderContext context) {
|
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.fieldPool, context.methodPool, context.classPool, context.typeListPool, context.annotationPool,
|
||||||
context.annotationSetPool);
|
context.annotationSetPool);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -38,7 +38,6 @@ import org.jf.dexlib2.iface.ClassDef;
|
|||||||
import org.jf.dexlib2.iface.Field;
|
import org.jf.dexlib2.iface.Field;
|
||||||
import org.jf.dexlib2.iface.reference.*;
|
import org.jf.dexlib2.iface.reference.*;
|
||||||
import org.jf.dexlib2.iface.value.*;
|
import org.jf.dexlib2.iface.value.*;
|
||||||
import org.jf.dexlib2.immutable.instruction.ImmutableInstructionFactory;
|
|
||||||
import org.jf.dexlib2.writer.DexWriter;
|
import org.jf.dexlib2.writer.DexWriter;
|
||||||
import org.jf.dexlib2.writer.io.FileDataStore;
|
import org.jf.dexlib2.writer.io.FileDataStore;
|
||||||
import org.jf.dexlib2.writer.pool.ProtoPool.Key;
|
import org.jf.dexlib2.writer.pool.ProtoPool.Key;
|
||||||
@ -51,7 +50,7 @@ import java.util.Collection;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DexPool extends DexWriter<CharSequence, StringReference, CharSequence, TypeReference, Key,
|
public class DexPool extends DexWriter<CharSequence, StringReference, CharSequence, TypeReference, Key,
|
||||||
FieldReference, MethodReference, Reference, PoolClassDef,
|
FieldReference, MethodReference, PoolClassDef,
|
||||||
Annotation, Set<? extends Annotation>,
|
Annotation, Set<? extends Annotation>,
|
||||||
TypeListPool.Key<? extends Collection<? extends CharSequence>>, Field, PoolMethod,
|
TypeListPool.Key<? extends Collection<? extends CharSequence>>, Field, PoolMethod,
|
||||||
EncodedValue, AnnotationElement> {
|
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,
|
private DexPool(int api, StringPool stringPool, TypePool typePool, ProtoPool protoPool, FieldPool fieldPool,
|
||||||
MethodPool methodPool, ClassPool classPool, TypeListPool typeListPool,
|
MethodPool methodPool, ClassPool classPool, TypeListPool typeListPool,
|
||||||
AnnotationPool annotationPool, AnnotationSetPool annotationSetPool) {
|
AnnotationPool annotationPool, AnnotationSetPool annotationSetPool) {
|
||||||
super(api, ImmutableInstructionFactory.INSTANCE, stringPool, typePool, protoPool, fieldPool, methodPool,
|
super(api, stringPool, typePool, protoPool, fieldPool, methodPool,
|
||||||
classPool, typeListPool, annotationPool, annotationSetPool);
|
classPool, typeListPool, annotationPool, annotationSetPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,8 +79,6 @@ import java.util.*;
|
|||||||
private int apiLevel = 15;
|
private int apiLevel = 15;
|
||||||
private Opcodes opcodes = new Opcodes(apiLevel);
|
private Opcodes opcodes = new Opcodes(apiLevel);
|
||||||
private DexBuilder dexBuilder;
|
private DexBuilder dexBuilder;
|
||||||
private InstructionFactory<BuilderReference> instructionFactory =
|
|
||||||
BuilderInstructionFactory.INSTANCE;
|
|
||||||
|
|
||||||
public void setDexBuilder(DexBuilder dexBuilder) {
|
public void setDexBuilder(DexBuilder dexBuilder) {
|
||||||
this.dexBuilder = dexBuilder;
|
this.dexBuilder = dexBuilder;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user