mirror of
https://github.com/revanced/smali.git
synced 2025-05-08 10:24:31 +02:00
- Added the plumbing to be able to handle the various types of "things" contained in a method (instructions, labels, debug info, etc.)
- Added wrappers for a few instruction formats - Added wrappers for item references git-svn-id: https://smali.googlecode.com/svn/trunk@148 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
119ddb0805
commit
ad1085e32a
@ -10,6 +10,52 @@
|
||||
<artifactId>smali-pom</artifactId>
|
||||
<version>0.91-SNAPSHOT</version>
|
||||
</parent>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jf</groupId>
|
||||
<artifactId>maven-smali-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>junit-tests</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>assemble</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirectory>src/test/smali</sourceDirectory>
|
||||
<outputFile>target/test/classes.dex</outputFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<workingDirectory>${basedir}</workingDirectory>
|
||||
<arguments>
|
||||
<argument>-classpath</argument>
|
||||
<classpath/>
|
||||
<argument>org.jf.baksmali.main</argument>
|
||||
<argument>--disassemble</argument>
|
||||
<argument>${project.build.directory}/test/classes.dex</argument>
|
||||
<argument>${project.build.directory}/test/out</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
|
@ -31,12 +31,18 @@ package org.jf.baksmali.wrappers;
|
||||
import org.jf.dexlib.ClassDataItem;
|
||||
import org.jf.dexlib.CodeItem;
|
||||
import org.jf.dexlib.MethodIdItem;
|
||||
import org.jf.dexlib.code.Instruction;
|
||||
import org.jf.dexlib.code.InstructionField;
|
||||
import org.jf.dexlib.code.Instruction;
|
||||
import org.jf.dexlib.code.Format.Instruction10x;
|
||||
import org.jf.dexlib.code.Format.Instruction35c;
|
||||
import org.jf.dexlib.code.Format.Instruction21c;
|
||||
import org.jf.dexlib.code.Format.Instruction11x;
|
||||
import org.jf.dexlib.util.AccessFlags;
|
||||
import org.jf.baksmali.wrappers.format.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class MethodDefinition {
|
||||
private ClassDataItem.EncodedMethod encodedMethod;
|
||||
@ -97,17 +103,50 @@ public class MethodDefinition {
|
||||
return registerCount;
|
||||
}
|
||||
|
||||
//TODO: how best to abstract this? I don't like exposing dexlib's "Instruction" directly
|
||||
private List<Instruction> instructions = null;
|
||||
public List<Instruction> getInstructions() {
|
||||
if (instructions == null) {
|
||||
instructions = new ArrayList<Instruction>();
|
||||
if (codeItem != null) {
|
||||
for (InstructionField instruction: codeItem.getInstructions()) {
|
||||
instructions.add(instruction.getInstruction());
|
||||
|
||||
private List<MethodItem> methodItems = null;
|
||||
public List<MethodItem> getMethodItems() {
|
||||
if (methodItems == null) {
|
||||
methodItems = generateMethodItemList();
|
||||
}
|
||||
return methodItems;
|
||||
}
|
||||
|
||||
|
||||
private List<MethodItem> generateMethodItemList() {
|
||||
if (codeItem == null) {
|
||||
return new ArrayList<MethodItem>();
|
||||
}
|
||||
|
||||
List<MethodItem> methodItems = new ArrayList<MethodItem>();
|
||||
|
||||
|
||||
int offset = 0;
|
||||
for (InstructionField instructionField: codeItem.getInstructions()) {
|
||||
for (MethodItem methodItem: getMethodItemsForInstruction(offset, instructionField)) {
|
||||
methodItems.add(methodItem);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(methodItems);
|
||||
|
||||
return methodItems;
|
||||
}
|
||||
|
||||
private MethodItem[] getMethodItemsForInstruction(int offset, InstructionField instructionField) {
|
||||
Instruction instruction = instructionField.getInstruction();
|
||||
|
||||
switch (instruction.getFormat()) {
|
||||
case Format10x:
|
||||
return new MethodItem[] {new Instruction10xMethodItem(offset, (Instruction10x)instruction)};
|
||||
case Format11x:
|
||||
return new MethodItem[] {new Instruction11xMethodItem(offset, (Instruction11x)instruction)};
|
||||
case Format21c:
|
||||
return new MethodItem[] {new Instruction21cMethodItem(offset, (Instruction21c)instruction)};
|
||||
case Format35c:
|
||||
return new MethodItem[] {new Instruction35cMethodItem(offset, (Instruction35c)instruction)};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return instructions;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers;
|
||||
|
||||
public abstract class MethodItem implements Comparable<MethodItem> {
|
||||
private int offset;
|
||||
|
||||
protected MethodItem(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
//return the name of the template that should be used to render this item
|
||||
public abstract String getTemplate();
|
||||
//return an arbitrary integer that determines how this item will be sorted with
|
||||
//others at the same offset
|
||||
public abstract int getSortOrder();
|
||||
|
||||
public int compareTo(MethodItem methodItem) {
|
||||
int result = ((Integer)offset).compareTo(methodItem.offset);
|
||||
|
||||
if (result == 0){
|
||||
return ((Integer)getSortOrder()).compareTo(methodItem.getSortOrder());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.format;
|
||||
|
||||
import org.jf.dexlib.code.Instruction;
|
||||
import org.jf.dexlib.code.Format.Instruction10x;
|
||||
|
||||
public class Instruction10xMethodItem extends InstructionFormatMethodItem<Instruction10x> {
|
||||
public Instruction10xMethodItem(int offset, Instruction10x instruction) {
|
||||
super(offset, instruction);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.format;
|
||||
|
||||
import org.jf.dexlib.code.Instruction;
|
||||
import org.jf.dexlib.code.Format.Instruction11x;
|
||||
|
||||
public class Instruction11xMethodItem extends InstructionFormatMethodItem<Instruction11x> {
|
||||
public Instruction11xMethodItem(int offset, Instruction11x instruction) {
|
||||
super(offset, instruction);
|
||||
}
|
||||
|
||||
public int getRegister() {
|
||||
return instruction.getRegister();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.format;
|
||||
|
||||
import org.jf.dexlib.code.Instruction;
|
||||
import org.jf.dexlib.code.Format.Instruction21c;
|
||||
|
||||
public class Instruction21cMethodItem extends InstructionFormatMethodItem<Instruction21c> {
|
||||
public Instruction21cMethodItem(int offset, Instruction21c instruction) {
|
||||
super(offset, instruction);
|
||||
}
|
||||
|
||||
public int getRegister() {
|
||||
return instruction.getRegister();
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.format;
|
||||
|
||||
import org.jf.dexlib.code.Instruction;
|
||||
import org.jf.dexlib.code.Format.Instruction35c;
|
||||
|
||||
public class Instruction35cMethodItem extends InstructionFormatMethodItem<Instruction35c> {
|
||||
public Instruction35cMethodItem(int offset, Instruction35c instruction) {
|
||||
super(offset, instruction);
|
||||
}
|
||||
|
||||
public int[] getRegisters() {
|
||||
switch (instruction.getRegCount()) {
|
||||
case 1:
|
||||
return new int[] {instruction.getRegisterD()};
|
||||
case 2:
|
||||
return new int[] {instruction.getRegisterD(), instruction.getRegisterE()};
|
||||
case 3:
|
||||
return new int[] {instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF()};
|
||||
case 4:
|
||||
return new int[] {instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(),
|
||||
instruction.getRegisterG()};
|
||||
case 5:
|
||||
return new int[] {instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(),
|
||||
instruction.getRegisterG(), instruction.getRegisterA()};
|
||||
default:
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.format;
|
||||
|
||||
import org.jf.baksmali.wrappers.MethodItem;
|
||||
import org.jf.baksmali.wrappers.reference.Reference;
|
||||
import org.jf.dexlib.code.Instruction;
|
||||
import org.jf.dexlib.code.Format.Format;
|
||||
|
||||
public abstract class InstructionFormatMethodItem<T extends Instruction> extends MethodItem {
|
||||
protected T instruction;
|
||||
|
||||
public InstructionFormatMethodItem(int offset, T instruction) {
|
||||
super(offset);
|
||||
this.instruction = instruction;
|
||||
}
|
||||
|
||||
public int getSortOrder() {
|
||||
//instructions should appear after everything except an "end try" label
|
||||
return 100;
|
||||
}
|
||||
|
||||
public String getOpcode() {
|
||||
return instruction.getOpcode().name;
|
||||
}
|
||||
|
||||
public String getTemplate() {
|
||||
return instruction.getFormat().name();
|
||||
}
|
||||
|
||||
public Reference getReference() {
|
||||
return Reference.makeReference(instruction.getReferencedItem());
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.reference;
|
||||
|
||||
import org.jf.dexlib.FieldIdItem;
|
||||
|
||||
public class FieldReference extends Reference<FieldIdItem> {
|
||||
public FieldReference(FieldIdItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
private String containingClass = null;
|
||||
public String getContainingClass() {
|
||||
if (containingClass == null) {
|
||||
containingClass = item.getContainingClass().getTypeDescriptor();
|
||||
}
|
||||
return containingClass;
|
||||
}
|
||||
|
||||
private String fieldName = null;
|
||||
public String getFieldName() {
|
||||
if (fieldName == null) {
|
||||
fieldName = item.getFieldName().getStringValue();
|
||||
}
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
private String fieldType = null;
|
||||
public String getFieldType() {
|
||||
if (fieldType == null) {
|
||||
fieldType = item.getFieldType().getTypeDescriptor();
|
||||
}
|
||||
return fieldType;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.reference;
|
||||
|
||||
import org.jf.dexlib.MethodIdItem;
|
||||
|
||||
public class MethodReference extends Reference<MethodIdItem> {
|
||||
public MethodReference(MethodIdItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
public String getContainingClass() {
|
||||
return item.getContainingClass().getTypeDescriptor();
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return item.getMethodName();
|
||||
}
|
||||
|
||||
public String getPrototype() {
|
||||
return item.getPrototype().getPrototypeString();
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.reference;
|
||||
|
||||
import org.jf.dexlib.*;
|
||||
|
||||
public abstract class Reference<T extends IndexedItem> {
|
||||
protected T item;
|
||||
|
||||
protected Reference(T item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public static Reference makeReference(IndexedItem item) {
|
||||
switch (item.getItemType()) {
|
||||
case TYPE_METHOD_ID_ITEM:
|
||||
return new MethodReference((MethodIdItem)item);
|
||||
case TYPE_FIELD_ID_ITEM:
|
||||
return new FieldReference((FieldIdItem)item);
|
||||
case TYPE_STRING_ID_ITEM:
|
||||
return new StringReference((StringIdItem)item);
|
||||
case TYPE_TYPE_ID_ITEM:
|
||||
return new TypeReference((TypeIdItem)item);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getTemplate() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.reference;
|
||||
|
||||
import org.jf.dexlib.StringIdItem;
|
||||
import org.jf.dexlib.util.Utf8Utils;
|
||||
|
||||
public class StringReference extends Reference<StringIdItem> {
|
||||
public StringReference(StringIdItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
public String getEscapedValue() {
|
||||
return Utf8Utils.escapeString(item.getStringValue());
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2009 Ben Gruver
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.wrappers.reference;
|
||||
|
||||
import org.jf.dexlib.TypeIdItem;
|
||||
|
||||
public class TypeReference extends Reference<TypeIdItem> {
|
||||
public TypeReference(TypeIdItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
public String getTypeDescriptor() {
|
||||
return item.getTypeDescriptor();
|
||||
}
|
||||
}
|
@ -69,37 +69,59 @@ method(methodDef) ::=
|
||||
<if(methodDef.hasCode)>
|
||||
.registers <methodDef.RegisterCount>
|
||||
|
||||
<methodDef.Instructions: Instruction(it); separator="\n">
|
||||
<methodDef.MethodItems: MethodItem(it); separator="\n">
|
||||
<endif>
|
||||
.end method
|
||||
>>
|
||||
|
||||
Instruction(Instruction) ::=
|
||||
MethodItem(MethodItem) ::=
|
||||
<<
|
||||
<Instruction: (Instruction.Format)()>
|
||||
<MethodItem: (MethodItem.Template)(MethodItem)>
|
||||
>>
|
||||
|
||||
Format10x() ::=
|
||||
|
||||
|
||||
|
||||
|
||||
Format10x(Instruction) ::=
|
||||
<<
|
||||
<it.Opcode.name>
|
||||
<Instruction.Opcode>
|
||||
>>
|
||||
|
||||
Format11x() ::=
|
||||
Format11x(Instruction) ::=
|
||||
<<
|
||||
<it.Opcode.name> v<it.Register>
|
||||
<Instruction.Opcode> v<Instruction.Register>
|
||||
>>
|
||||
|
||||
Format21c() ::=
|
||||
Format21c(Instruction) ::=
|
||||
<<
|
||||
<it.Opcode.name> v<it.Register>, <({Reference_<it.Opcode.referenceType>})(it.ReferencedItem)>
|
||||
<Instruction.Opcode> v<Instruction.Register>, <Reference(Instruction.Reference)>
|
||||
>>
|
||||
|
||||
Format35c() ::=
|
||||
Format35c(Instruction) ::=
|
||||
<<
|
||||
<it.Opcode.name>
|
||||
<Instruction.Opcode> {<Instruction.Registers: {v<it>}; separator=", ">}, <Reference(Instruction.Reference)>
|
||||
>>
|
||||
|
||||
Reference_string(StringItem) ::=
|
||||
|
||||
|
||||
|
||||
Reference(ReferencedItem) ::=
|
||||
<<
|
||||
"<StringItem.StringValue>"
|
||||
<(ReferencedItem.Template)(ReferencedItem)>
|
||||
>>
|
||||
|
||||
StringReference(StringReference) ::=
|
||||
<<
|
||||
"<StringReference.EscapedValue>"
|
||||
>>
|
||||
|
||||
FieldReference(FieldReference) ::=
|
||||
<<
|
||||
<FieldReference.ContainingClass>-><FieldReference.FieldName>:<FieldReference.FieldType>
|
||||
>>
|
||||
|
||||
MethodReference(MethodReference) ::=
|
||||
<<
|
||||
<MethodReference.ContainingClass>-><MethodReference.MethodName><MethodReference.Prototype>
|
||||
>>
|
24
baksmali/src/test/smali/baksmali_test_class.smali
Normal file
24
baksmali/src/test/smali/baksmali_test_class.smali
Normal file
@ -0,0 +1,24 @@
|
||||
.class public Lbaksmali/test/class;
|
||||
.super Ljava/lang/Object;
|
||||
|
||||
.implements Lsome/interface;
|
||||
.implements Lsome/other/interface;
|
||||
|
||||
.field public static staticField:I
|
||||
.field public instanceField:Ljava/lang/String;
|
||||
|
||||
.method public constructor <init>()V
|
||||
.registers 1
|
||||
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
|
||||
return-void
|
||||
.end method
|
||||
|
||||
.method public testMethod(ILjava/lang/String;)Ljava/lang/String;
|
||||
.registers 3
|
||||
const-string v0, "testing\n123"
|
||||
|
||||
sget v0, Lbaksmali/test/class;->staticField:I
|
||||
|
||||
return-object v0
|
||||
.end method
|
||||
|
Loading…
x
Reference in New Issue
Block a user