From cbd87b904e15c63d06f25b03b0eadf003780ec6c Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Fri, 2 Jan 2015 13:47:02 -0800 Subject: [PATCH] Create a psi-backed dexlib2 Method implementation --- .../jf/smalidea/dexlib/SmalideaMethod.java | 153 ++++++++++++ .../dexlib/SmalideaMethodParameter.java | 62 +++++ .../instruction/SmalideaArrayPayload.java | 55 +++++ .../instruction/SmalideaInstruction.java | 223 ++++++++++++++++++ .../instruction/SmalideaInstruction10t.java | 43 ++++ .../instruction/SmalideaInstruction10x.java | 43 ++++ .../instruction/SmalideaInstruction11n.java | 43 ++++ .../instruction/SmalideaInstruction11x.java | 43 ++++ .../instruction/SmalideaInstruction12x.java | 43 ++++ .../instruction/SmalideaInstruction20t.java | 43 ++++ .../instruction/SmalideaInstruction21c.java | 43 ++++ .../instruction/SmalideaInstruction21ih.java | 47 ++++ .../instruction/SmalideaInstruction21lh.java | 47 ++++ .../instruction/SmalideaInstruction21s.java | 43 ++++ .../instruction/SmalideaInstruction21t.java | 43 ++++ .../instruction/SmalideaInstruction22b.java | 43 ++++ .../instruction/SmalideaInstruction22c.java | 43 ++++ .../instruction/SmalideaInstruction22s.java | 43 ++++ .../instruction/SmalideaInstruction22t.java | 43 ++++ .../instruction/SmalideaInstruction22x.java | 43 ++++ .../instruction/SmalideaInstruction23x.java | 43 ++++ .../instruction/SmalideaInstruction30t.java | 43 ++++ .../instruction/SmalideaInstruction31c.java | 43 ++++ .../instruction/SmalideaInstruction31i.java | 43 ++++ .../instruction/SmalideaInstruction31t.java | 43 ++++ .../instruction/SmalideaInstruction32x.java | 43 ++++ .../instruction/SmalideaInstruction35c.java | 63 +++++ .../instruction/SmalideaInstruction3rc.java | 51 ++++ .../instruction/SmalideaInstruction51l.java | 43 ++++ .../SmalideaPackedSwitchPayload.java | 51 ++++ .../SmalideaSparseSwitchPayload.java | 51 ++++ .../smalidea/psi/impl/SmaliInstruction.java | 83 +++++++ .../org/jf/smalidea/psi/impl/SmaliLabel.java | 24 ++ .../org/jf/smalidea/psi/impl/SmaliMethod.java | 26 ++ 34 files changed, 1839 insertions(+) create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/SmalideaMethod.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/SmalideaMethodParameter.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaArrayPayload.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction10t.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction10x.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction11n.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction11x.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction12x.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction20t.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21c.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21ih.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21lh.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21s.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21t.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22b.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22c.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22s.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22t.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22x.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction23x.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction30t.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31c.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31i.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31t.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction32x.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction35c.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction3rc.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction51l.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaPackedSwitchPayload.java create mode 100644 smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaSparseSwitchPayload.java diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/SmalideaMethod.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/SmalideaMethod.java new file mode 100644 index 00000000..3533e346 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/SmalideaMethod.java @@ -0,0 +1,153 @@ +/* + * Copyright 2014, 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.smalidea.dexlib; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiParameter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jf.dexlib2.base.reference.BaseMethodReference; +import org.jf.dexlib2.iface.*; +import org.jf.dexlib2.iface.debug.DebugItem; +import org.jf.dexlib2.iface.instruction.Instruction; +import org.jf.smalidea.dexlib.instruction.SmalideaInstruction; +import org.jf.smalidea.psi.impl.SmaliInstruction; +import org.jf.smalidea.psi.impl.SmaliMethod; +import org.jf.smalidea.psi.impl.SmaliMethodParameter; +import org.jf.smalidea.util.NameUtils; + +import javax.annotation.Nonnull; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +public class SmalideaMethod extends BaseMethodReference implements Method { + private final SmaliMethod psiMethod; + + public SmalideaMethod(@NotNull SmaliMethod psiMethod) { + this.psiMethod = psiMethod; + } + + @Nonnull @Override public String getDefiningClass() { + PsiClass cls = psiMethod.getContainingClass(); + assert cls != null; + String qualifiedName = cls.getQualifiedName(); + assert qualifiedName != null; + return NameUtils.javaToSmaliType(qualifiedName); + } + + @Nonnull @Override public List getParameters() { + SmaliMethodParameter[] parameters = psiMethod.getParameterList().getParameters(); + + return Lists.transform(Arrays.asList(parameters), new Function() { + @Nullable @Override + public MethodParameter apply(@Nullable SmaliMethodParameter smaliParameter) { + if (smaliParameter == null) { + return null; + } + return new SmalideaMethodParameter(smaliParameter); + } + }); + } + + @Override public int getAccessFlags() { + return psiMethod.getModifierList().getAccessFlags(); + } + + @Nonnull @Override public Set getAnnotations() { + // TODO: implement this + return ImmutableSet.of(); + } + + @Nullable @Override public MethodImplementation getImplementation() { + List instructions = psiMethod.getInstructions(); + if (instructions.size() == 0) { + return null; + } + + // TODO: cache this? + return new MethodImplementation() { + @Override public int getRegisterCount() { + return psiMethod.getRegisterCount(); + } + + @Nonnull @Override public Iterable getInstructions() { + return Lists.transform(psiMethod.getInstructions(), + new Function() { + @javax.annotation.Nullable @Override + public Instruction apply(@javax.annotation.Nullable SmaliInstruction smaliInstruction) { + if (smaliInstruction == null) { + return null; + } + return SmalideaInstruction.of(smaliInstruction); + } + }); + } + + @Nonnull @Override public List> getTryBlocks() { + // TODO: implement this + return ImmutableList.of(); + } + + @Nonnull @Override public Iterable getDebugItems() { + // TODO: implement this + return ImmutableList.of(); + } + }; + } + + @Nonnull @Override public String getName() { + return psiMethod.getName(); + } + + @Nonnull @Override public List getParameterTypes() { + PsiParameter[] parameters = psiMethod.getParameterList().getParameters(); + + return Lists.transform(Arrays.asList(parameters), new Function() { + @Nullable @Override + public CharSequence apply(@Nullable PsiParameter psiParameter) { + if (psiParameter == null) { + return null; + } + return psiParameter.getText(); + } + }); + } + + @Nonnull @Override public String getReturnType() { + return psiMethod.getReturnTypeElement().getText(); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/SmalideaMethodParameter.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/SmalideaMethodParameter.java new file mode 100644 index 00000000..42eb9337 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/SmalideaMethodParameter.java @@ -0,0 +1,62 @@ +/* + * Copyright 2014, 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.smalidea.dexlib; + +import com.google.common.collect.ImmutableSet; +import org.jetbrains.annotations.Nullable; +import org.jf.dexlib2.base.BaseMethodParameter; +import org.jf.dexlib2.iface.Annotation; +import org.jf.smalidea.psi.impl.SmaliMethodParameter; + +import javax.annotation.Nonnull; +import java.util.Set; + +public class SmalideaMethodParameter extends BaseMethodParameter { + private final SmaliMethodParameter psiParameter; + + public SmalideaMethodParameter(SmaliMethodParameter psiParameter) { + this.psiParameter = psiParameter; + } + + @Nonnull @Override public Set getAnnotations() { + // TODO: implement this + return ImmutableSet.of(); + } + + @Nullable @Override public String getName() { + return psiParameter.getName(); + } + + @Nonnull @Override public String getType() { + return psiParameter.getTypeElement().getText(); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaArrayPayload.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaArrayPayload.java new file mode 100644 index 00000000..567803b2 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaArrayPayload.java @@ -0,0 +1,55 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import com.google.common.collect.ImmutableList; +import org.jf.dexlib2.iface.instruction.formats.ArrayPayload; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; +import java.util.List; + +public class SmalideaArrayPayload extends SmalideaInstruction implements ArrayPayload { + public SmalideaArrayPayload(@Nonnull SmaliInstruction instruction) { + super(instruction); + } + + @Override public int getElementWidth() { + // TODO: implement this + return 4; + } + + @Nonnull @Override public List getArrayElements() { + // TODO: implement this + return ImmutableList.of(); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction.java new file mode 100644 index 00000000..07cc4d1b --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction.java @@ -0,0 +1,223 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiType; +import org.jf.dexlib2.Opcode; +import org.jf.dexlib2.ReferenceType; +import org.jf.dexlib2.iface.instruction.Instruction; +import org.jf.dexlib2.iface.reference.Reference; +import org.jf.dexlib2.immutable.reference.ImmutableFieldReference; +import org.jf.dexlib2.immutable.reference.ImmutableMethodReference; +import org.jf.dexlib2.immutable.reference.ImmutableStringReference; +import org.jf.dexlib2.immutable.reference.ImmutableTypeReference; +import org.jf.smalidea.psi.SmaliElementTypes; +import org.jf.smalidea.psi.impl.*; +import org.jf.smalidea.util.NameUtils; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.List; + +public abstract class SmalideaInstruction implements Instruction { + @Nonnull protected final SmaliInstruction psiInstruction; + + protected SmalideaInstruction(@Nonnull SmaliInstruction instruction) { + this.psiInstruction = instruction; + } + + @Nonnull + public static SmalideaInstruction of(SmaliInstruction instruction) { + switch (instruction.getOpcode().format) { + case Format10t: + return new SmalideaInstruction10t(instruction); + case Format10x: + return new SmalideaInstruction10x(instruction); + case Format11n: + return new SmalideaInstruction11n(instruction); + case Format11x: + return new SmalideaInstruction11x(instruction); + case Format12x: + return new SmalideaInstruction12x(instruction); + case Format20t: + return new SmalideaInstruction20t(instruction); + case Format21c: + return new SmalideaInstruction21c(instruction); + case Format21ih: + return new SmalideaInstruction21ih(instruction); + case Format21lh: + return new SmalideaInstruction21lh(instruction); + case Format21s: + return new SmalideaInstruction21s(instruction); + case Format21t: + return new SmalideaInstruction21t(instruction); + case Format22b: + return new SmalideaInstruction22b(instruction); + case Format22c: + return new SmalideaInstruction22c(instruction); + case Format22s: + return new SmalideaInstruction22s(instruction); + case Format22t: + return new SmalideaInstruction22t(instruction); + case Format22x: + return new SmalideaInstruction22x(instruction); + case Format23x: + return new SmalideaInstruction23x(instruction); + case Format30t: + return new SmalideaInstruction30t(instruction); + case Format31c: + return new SmalideaInstruction31c(instruction); + case Format31i: + return new SmalideaInstruction31i(instruction); + case Format31t: + return new SmalideaInstruction31t(instruction); + case Format32x: + return new SmalideaInstruction32x(instruction); + case Format35c: + return new SmalideaInstruction35c(instruction); + case Format3rc: + return new SmalideaInstruction3rc(instruction); + case Format51l: + return new SmalideaInstruction51l(instruction); + case PackedSwitchPayload: + return new SmalideaPackedSwitchPayload(instruction); + case SparseSwitchPayload: + return new SmalideaSparseSwitchPayload(instruction); + case ArrayPayload: + return new SmalideaArrayPayload(instruction); + default: + throw new RuntimeException("Unexpected instruction type"); + } + } + + @Nonnull public Opcode getOpcode() { + return psiInstruction.getOpcode(); + } + + public int getCodeUnits() { + return getOpcode().format.size / 2; + } + + public int getCodeOffset() { + ASTNode labelNode = psiInstruction.getNode().findChildByType(SmaliElementTypes.LABEL_REFERENCE); + if (labelNode == null) { + return -1; + } + + SmaliLabelReference labelReference = (SmaliLabelReference)labelNode.getPsi(); + + SmaliLabel label = labelReference.resolve(); + if (label == null) { + return -1; + } + return (label.getOffset() - psiInstruction.getOffset())/2; + } + + public int getRegisterCount() { + return psiInstruction.getRegisterCount(); + } + + public int getRegisterA() { + return psiInstruction.getRegister(0); + } + + public int getRegisterB() { + return psiInstruction.getRegister(1); + } + + public int getRegisterC() { + return psiInstruction.getRegister(2); + } + + public int getNarrowLiteral() { + SmaliLiteral literal = psiInstruction.getLiteral(); + if (literal == null) { + return 0; + } + return (int)literal.getIntegralValue(); + } + + public long getWideLiteral() { + SmaliLiteral literal = psiInstruction.getLiteral(); + if (literal == null) { + return 0; + } + return literal.getIntegralValue(); + } + + @Nonnull public Reference getReference() { + switch (getReferenceType()) { + case ReferenceType.STRING: + // TODO: get the actual string value + return new ImmutableStringReference(""); + case ReferenceType.TYPE: + SmaliTypeElement typeReference = psiInstruction.getTypeReference(); + assert typeReference != null; + return new ImmutableTypeReference(typeReference.getText()); + case ReferenceType.METHOD: + SmaliMethodReference methodReference = psiInstruction.getMethodReference(); + assert methodReference != null; + String containingClass = NameUtils.javaToSmaliType(methodReference.getContainingClass().getQualifiedName()); + List paramTypes = + Lists.transform(methodReference.getParameterTypes(), new Function() { + @Nullable @Override public String apply(@Nullable PsiType psiType) { + if (psiType == null) { + return null; + } + return NameUtils.javaToSmaliType(psiType.getCanonicalText()); + } + }); + + return new ImmutableMethodReference(containingClass, + methodReference.getName(), + paramTypes, + methodReference.getReturnType().getText()); + case ReferenceType.FIELD: + SmaliFieldReference fieldReference = psiInstruction.getFieldReference(); + assert fieldReference != null; + containingClass = NameUtils.javaToSmaliType(fieldReference.getContainingClass().getQualifiedName()); + return new ImmutableFieldReference(containingClass, + fieldReference.getName(), + fieldReference.getFieldType().getText()); + } + assert false; + return null; + } + + public int getReferenceType() { + return psiInstruction.getOpcode().referenceType; + } + +} \ No newline at end of file diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction10t.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction10t.java new file mode 100644 index 00000000..80a4ba66 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction10t.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction10t; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction10t extends SmalideaInstruction implements Instruction10t { + public SmalideaInstruction10t(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction10x.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction10x.java new file mode 100644 index 00000000..04804514 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction10x.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction10x; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction10x extends SmalideaInstruction implements Instruction10x { + public SmalideaInstruction10x(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction11n.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction11n.java new file mode 100644 index 00000000..1b185dd8 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction11n.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction11n; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction11n extends SmalideaInstruction implements Instruction11n { + public SmalideaInstruction11n(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction11x.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction11x.java new file mode 100644 index 00000000..7e8fbf4d --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction11x.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction11x; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction11x extends SmalideaInstruction implements Instruction11x { + public SmalideaInstruction11x(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction12x.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction12x.java new file mode 100644 index 00000000..c6cba0a7 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction12x.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction12x; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction12x extends SmalideaInstruction implements Instruction12x { + public SmalideaInstruction12x(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction20t.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction20t.java new file mode 100644 index 00000000..1c0a9216 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction20t.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction20t; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction20t extends SmalideaInstruction implements Instruction20t { + public SmalideaInstruction20t(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21c.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21c.java new file mode 100644 index 00000000..f2ac6f1a --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21c.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction21c; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction21c extends SmalideaInstruction implements Instruction21c { + public SmalideaInstruction21c(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21ih.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21ih.java new file mode 100644 index 00000000..ce5f598f --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21ih.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction21ih; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction21ih extends SmalideaInstruction implements Instruction21ih { + public SmalideaInstruction21ih(@Nonnull SmaliInstruction instruction) { + super(instruction); + } + + @Override public short getHatLiteral() { + return (short)(getNarrowLiteral() >>> 16); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21lh.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21lh.java new file mode 100644 index 00000000..3ef08505 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21lh.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction21lh; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction21lh extends SmalideaInstruction implements Instruction21lh { + public SmalideaInstruction21lh(@Nonnull SmaliInstruction instruction) { + super(instruction); + } + + @Override public short getHatLiteral() { + return (short)(getWideLiteral() >>> 48); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21s.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21s.java new file mode 100644 index 00000000..5ae75060 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21s.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction21s; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction21s extends SmalideaInstruction implements Instruction21s { + public SmalideaInstruction21s(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21t.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21t.java new file mode 100644 index 00000000..11e17564 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction21t.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction21t; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction21t extends SmalideaInstruction implements Instruction21t { + public SmalideaInstruction21t(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22b.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22b.java new file mode 100644 index 00000000..f1360467 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22b.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction22b; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction22b extends SmalideaInstruction implements Instruction22b { + public SmalideaInstruction22b(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22c.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22c.java new file mode 100644 index 00000000..4d7dacbe --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22c.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction22c; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction22c extends SmalideaInstruction implements Instruction22c { + public SmalideaInstruction22c(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22s.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22s.java new file mode 100644 index 00000000..81897688 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22s.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction22s; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction22s extends SmalideaInstruction implements Instruction22s { + public SmalideaInstruction22s(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22t.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22t.java new file mode 100644 index 00000000..8f4811d9 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22t.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction22t; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction22t extends SmalideaInstruction implements Instruction22t { + public SmalideaInstruction22t(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22x.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22x.java new file mode 100644 index 00000000..5cc8b004 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction22x.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction22x; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction22x extends SmalideaInstruction implements Instruction22x { + public SmalideaInstruction22x(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction23x.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction23x.java new file mode 100644 index 00000000..3cc60d89 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction23x.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction23x; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction23x extends SmalideaInstruction implements Instruction23x { + public SmalideaInstruction23x(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction30t.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction30t.java new file mode 100644 index 00000000..324fc773 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction30t.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction30t; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction30t extends SmalideaInstruction implements Instruction30t { + public SmalideaInstruction30t(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31c.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31c.java new file mode 100644 index 00000000..ffea2175 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31c.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction31c; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction31c extends SmalideaInstruction implements Instruction31c { + public SmalideaInstruction31c(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31i.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31i.java new file mode 100644 index 00000000..0fef6674 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31i.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction31i; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction31i extends SmalideaInstruction implements Instruction31i { + public SmalideaInstruction31i(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31t.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31t.java new file mode 100644 index 00000000..142fd446 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction31t.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction31t; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction31t extends SmalideaInstruction implements Instruction31t { + public SmalideaInstruction31t(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction32x.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction32x.java new file mode 100644 index 00000000..1ac27deb --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction32x.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction32x; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction32x extends SmalideaInstruction implements Instruction32x { + public SmalideaInstruction32x(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction35c.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction35c.java new file mode 100644 index 00000000..a3ddcce0 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction35c.java @@ -0,0 +1,63 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction35c; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction35c extends SmalideaInstruction implements Instruction35c { + public SmalideaInstruction35c(@Nonnull SmaliInstruction instruction) { + super(instruction); + } + + @Override public int getRegisterC() { + return psiInstruction.getRegister(0); + } + + @Override public int getRegisterD() { + return psiInstruction.getRegister(1); + } + + @Override public int getRegisterE() { + return psiInstruction.getRegister(2); + } + + @Override public int getRegisterF() { + return psiInstruction.getRegister(3); + } + + @Override public int getRegisterG() { + return psiInstruction.getRegister(4); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction3rc.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction3rc.java new file mode 100644 index 00000000..509e6b75 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction3rc.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction3rc; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction3rc extends SmalideaInstruction implements Instruction3rc { + public SmalideaInstruction3rc(@Nonnull SmaliInstruction instruction) { + super(instruction); + } + + @Override public int getStartRegister() { + return psiInstruction.getRegister(0); + } + + @Override public int getRegisterCount() { + return psiInstruction.getRegister(1) - getStartRegister() + 1; + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction51l.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction51l.java new file mode 100644 index 00000000..3b58628b --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaInstruction51l.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import org.jf.dexlib2.iface.instruction.formats.Instruction51l; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; + +public class SmalideaInstruction51l extends SmalideaInstruction implements Instruction51l { + public SmalideaInstruction51l(@Nonnull SmaliInstruction instruction) { + super(instruction); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaPackedSwitchPayload.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaPackedSwitchPayload.java new file mode 100644 index 00000000..62a4ac0b --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaPackedSwitchPayload.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import com.google.common.collect.ImmutableList; +import org.jf.dexlib2.iface.instruction.SwitchElement; +import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; +import java.util.List; + +public class SmalideaPackedSwitchPayload extends SmalideaInstruction implements PackedSwitchPayload { + public SmalideaPackedSwitchPayload(@Nonnull SmaliInstruction instruction) { + super(instruction); + } + + @Nonnull @Override public List getSwitchElements() { + // TODO: implement this + return ImmutableList.of(); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaSparseSwitchPayload.java b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaSparseSwitchPayload.java new file mode 100644 index 00000000..f17dced0 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/dexlib/instruction/SmalideaSparseSwitchPayload.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014, 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.smalidea.dexlib.instruction; + +import com.google.common.collect.ImmutableList; +import org.jf.dexlib2.iface.instruction.SwitchElement; +import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload; +import org.jf.smalidea.psi.impl.SmaliInstruction; + +import javax.annotation.Nonnull; +import java.util.List; + +public class SmalideaSparseSwitchPayload extends SmalideaInstruction implements SparseSwitchPayload { + public SmalideaSparseSwitchPayload(@Nonnull SmaliInstruction instruction) { + super(instruction); + } + + @Nonnull @Override public List getSwitchElements() { + // TODO: implement this + return ImmutableList.of(); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliInstruction.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliInstruction.java index e11cb245..ed8df8ca 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliInstruction.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliInstruction.java @@ -31,15 +31,20 @@ package org.jf.smalidea.psi.impl; +import com.google.common.base.Preconditions; import com.intellij.lang.ASTNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jf.dexlib2.Opcode; import org.jf.dexlib2.Opcodes; +import org.jf.dexlib2.analysis.AnalyzedInstruction; +import org.jf.dexlib2.analysis.MethodAnalyzer; import org.jf.smalidea.SmaliTokens; import org.jf.smalidea.psi.SmaliCompositeElementFactory; import org.jf.smalidea.psi.SmaliElementTypes; +import java.util.List; + public class SmaliInstruction extends SmaliCompositeElement { private static final int NO_OFFSET = -1; @@ -56,6 +61,12 @@ public class SmaliInstruction extends SmaliCompositeElement { super(SmaliElementTypes.INSTRUCTION); } + @NotNull public SmaliMethod getParentMethod() { + SmaliMethod smaliMethod = findAncestorByClass(SmaliMethod.class); + assert smaliMethod != null; + return smaliMethod; + } + @NotNull public Opcode getOpcode() { if (opcode == null) { ASTNode instructionNode = findChildByType(SmaliTokens.INSTRUCTION_TOKENS); @@ -70,6 +81,7 @@ public class SmaliInstruction extends SmaliCompositeElement { } public int getOffset() { + // TODO: don't calculate this recursively. ugh! if (offset == NO_OFFSET) { SmaliInstruction previousInstruction = findPrevSiblingByClass(SmaliInstruction.class); if (previousInstruction == null) { @@ -81,4 +93,75 @@ public class SmaliInstruction extends SmaliCompositeElement { } return offset; } + + public int getRegister(int registerIndex) { + Preconditions.checkArgument(registerIndex >= 0); + + List registers = findChildrenByType(SmaliElementTypes.REGISTER_REFERENCE); + if (registerIndex >= registers.size()) { + return -1; + } + + SmaliRegisterReference registerReference = (SmaliRegisterReference)registers.get(registerIndex); + return registerReference.getRegisterNumber(); + } + + public int getRegisterCount() { + return findChildrenByType(SmaliElementTypes.REGISTER_REFERENCE).size(); + } + + @Nullable + public SmaliLiteral getLiteral() { + return findChildByClass(SmaliLiteral.class); + } + + @Nullable + public SmaliTypeElement getTypeReference() { + return findChildByClass(SmaliTypeElement.class); + } + + @Nullable + public SmaliFieldReference getFieldReference() { + return findChildByClass(SmaliFieldReference.class); + } + + @Nullable + public SmaliMethodReference getMethodReference() { + return findChildByClass(SmaliMethodReference.class); + } + + private AnalyzedInstruction analyzedInstruction = null; + + @NotNull + private AnalyzedInstruction getAnalyzedInstructionFromMethod() { + SmaliMethod method = getParentMethod(); + + MethodAnalyzer analyzer = method.getMethodAnalyzer(); + int thisOffset = this.getOffset() / 2; + int codeOffset = 0; + + for (AnalyzedInstruction instruction: analyzer.getAnalyzedInstructions()) { + if (codeOffset == thisOffset) { + return instruction; + } + assert codeOffset < thisOffset; + + codeOffset += instruction.getOriginalInstruction().getCodeUnits(); + } + assert false; + return null; + } + + @NotNull + public AnalyzedInstruction getAnalyzedInstruction() { + if (analyzedInstruction == null) { + analyzedInstruction = getAnalyzedInstructionFromMethod(); + } + return analyzedInstruction; + } + + @Override public void clearCaches() { + super.clearCaches(); + analyzedInstruction = null; + } } diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliLabel.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliLabel.java index d258075a..b07220dd 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliLabel.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliLabel.java @@ -31,6 +31,7 @@ package org.jf.smalidea.psi.impl; +import org.jetbrains.annotations.Nullable; import org.jf.smalidea.psi.SmaliCompositeElementFactory; import org.jf.smalidea.psi.SmaliElementTypes; @@ -48,4 +49,27 @@ public class SmaliLabel extends SmaliCompositeElement { @Override public String getName() { return getText().substring(1); } + + @Nullable + public SmaliInstruction getInstruction() { + return findNextSiblingByClass(SmaliInstruction.class); + } + + @Nullable + private SmaliInstruction getPreviousInstruction() { + return findPrevSiblingByClass(SmaliInstruction.class); + } + + public int getOffset() { + SmaliInstruction instruction = getInstruction(); + if (instruction == null) { + instruction = getPreviousInstruction(); + if (instruction == null) { + return 0; + } + // TODO: handle variable size instructions + return instruction.getOffset() + instruction.getOpcode().format.size; + } + return instruction.getOffset(); + } } diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethod.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethod.java index c6ab1452..ec6cf076 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethod.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethod.java @@ -48,10 +48,14 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jf.dexlib2.analysis.ClassPath; +import org.jf.dexlib2.analysis.MethodAnalyzer; +import org.jf.smalidea.dexlib.SmalideaMethod; import org.jf.smalidea.psi.SmaliElementTypes; import org.jf.smalidea.psi.iface.SmaliModifierListOwner; import org.jf.smalidea.psi.stub.SmaliMethodStub; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -286,4 +290,26 @@ public class SmaliMethod extends SmaliStubBasedPsiElement @Nullable public SmaliLabel getLabel(String name) { return labelMap.get().get(name); } + + private MethodAnalyzer methodAnalyzer = null; + + @NotNull + public MethodAnalyzer getMethodAnalyzer() { + if (methodAnalyzer == null) { + ClassPath classPath; + try { + classPath = new ClassPath(); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + + methodAnalyzer = new MethodAnalyzer(classPath, new SmalideaMethod(SmaliMethod.this), null); + } + return methodAnalyzer; + } + + @Override public void subtreeChanged() { + super.subtreeChanged(); + methodAnalyzer = null; + } }