Added support for writing parameter registers with the p<n> syntax

git-svn-id: https://smali.googlecode.com/svn/trunk@376 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-08-08 23:44:28 +00:00
parent b7399b7fb3
commit 3c23129eec
34 changed files with 402 additions and 250 deletions

View File

@ -28,19 +28,17 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.ArrayDataPseudoInstruction;
import org.jf.dexlib.Util.ByteArray;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.ArrayDataPseudoInstruction;
import org.jf.dexlib.CodeItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.Arrays;
public class ArrayDataMethodItem extends InstructionFormatMethodItem<ArrayDataPseudoInstruction> {
public ArrayDataMethodItem(int offset, StringTemplateGroup stg, ArrayDataPseudoInstruction instruction) {
super(offset, stg, instruction);
public ArrayDataMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
ArrayDataPseudoInstruction instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
@ -53,10 +51,10 @@ public class ArrayDataMethodItem extends InstructionFormatMethodItem<ArrayDataPs
while (iterator.hasNext()) {
ArrayDataPseudoInstruction.ArrayElement element = iterator.next();
StringTemplate template = parentTemplate.getGroup().getInstanceOf("ArrayElement");
StringTemplate template = parentTemplate.getGroup().getInstanceOf("ArrayElement");
for (int i=element.bufferIndex; i<element.bufferIndex + element.elementWidth; i++) {
template.setAttribute("Bytes", element.buffer[i]);
for (int i = element.bufferIndex; i < element.bufferIndex + element.elementWidth; i++) {
template.setAttribute("Bytes", (Byte)element.buffer[i]);
}
parentTemplate.setAttribute("Values", template);

View File

@ -28,13 +28,15 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction10t;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction10t;
import org.jf.dexlib.CodeItem;
public class Instruction10tMethodItem extends InstructionFormatMethodItem<Instruction10t> {
public Instruction10tMethodItem(int offset, StringTemplateGroup stg, Instruction10t instruction) {
super(offset, stg, instruction);
public Instruction10tMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction10t instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {

View File

@ -28,13 +28,14 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction10x;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction10x;
import org.jf.dexlib.CodeItem;
public class Instruction10xMethodItem extends InstructionFormatMethodItem<Instruction10x> {
public Instruction10xMethodItem(int offset, StringTemplateGroup stg, Instruction10x instruction) {
super(offset, stg, instruction);
public Instruction10xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, Instruction10x instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction11n;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction11n;
import org.jf.dexlib.CodeItem;
public class Instruction11nMethodItem extends InstructionFormatMethodItem<Instruction11n> {
public Instruction11nMethodItem(int offset, StringTemplateGroup stg, Instruction11n instruction) {
super(offset, stg, instruction);
public Instruction11nMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction11n instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
template.setAttribute("Literal", instruction.getLiteral());
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction11x;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction11x;
import org.jf.dexlib.CodeItem;
public class Instruction11xMethodItem extends InstructionFormatMethodItem<Instruction11x> {
public Instruction11xMethodItem(int offset, StringTemplateGroup stg, Instruction11x instruction) {
super(offset, stg, instruction);
public Instruction11xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction11x instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction12x;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction12x;
import org.jf.dexlib.CodeItem;
public class Instruction12xMethodItem extends InstructionFormatMethodItem<Instruction12x> {
public Instruction12xMethodItem(int offset, StringTemplateGroup stg, Instruction12x instruction) {
super(offset, stg, instruction);
public Instruction12xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction12x instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("RegisterA", instruction.getRegisterA());
template.setAttribute("RegisterB", instruction.getRegisterB());
template.setAttribute("RegisterA", formatRegister(instruction.getRegisterA()));
template.setAttribute("RegisterB", formatRegister(instruction.getRegisterB()));
}
}

View File

@ -28,15 +28,17 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction20t;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction20t;
import org.jf.dexlib.CodeItem;
public class Instruction20tMethodItem extends InstructionFormatMethodItem<Instruction20t> {
public Instruction20tMethodItem(int offset, StringTemplateGroup stg, Instruction20t instruction) {
super(offset, stg, instruction);
public Instruction20tMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction20t instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Target", Integer.toHexString(getOffset() + instruction.getOffset()));
}

View File

@ -28,19 +28,21 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction21c;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.jf.dexlib.Code.Format.Instruction21c;
import org.jf.dexlib.CodeItem;
public class Instruction21cMethodItem extends InstructionFormatMethodItem<Instruction21c> {
public Instruction21cMethodItem(int offset, StringTemplateGroup stg, Instruction21c instruction) {
super(offset, stg, instruction);
public Instruction21cMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction21c instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Reference", Reference.makeReference(template.getGroup(),
instruction.getReferencedItem()));
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction21h;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction21h;
import org.jf.dexlib.CodeItem;
public class Instruction21hMethodItem extends InstructionFormatMethodItem<Instruction21h> {
public Instruction21hMethodItem(int offset, StringTemplateGroup stg, Instruction21h instruction) {
super(offset, stg, instruction);
public Instruction21hMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction21h instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
template.setAttribute("Literal", instruction.getLiteral());
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction21s;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction21s;
import org.jf.dexlib.CodeItem;
public class Instruction21sMethodItem extends InstructionFormatMethodItem<Instruction21s> {
public Instruction21sMethodItem(int offset, StringTemplateGroup stg, Instruction21s instruction) {
super(offset, stg, instruction);
public Instruction21sMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction21s instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
template.setAttribute("Literal", instruction.getLiteral());
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction21t;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction21t;
import org.jf.dexlib.CodeItem;
public class Instruction21tMethodItem extends InstructionFormatMethodItem<Instruction21t> {
public Instruction21tMethodItem(int offset, StringTemplateGroup stg, Instruction21t instruction) {
super(offset, stg,instruction);
public Instruction21tMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction21t instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
template.setAttribute("Target", Integer.toHexString(getOffset() + instruction.getOffset()));
}
}

View File

@ -28,18 +28,20 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction22b;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction22b;
import org.jf.dexlib.CodeItem;
public class Instruction22bMethodItem extends InstructionFormatMethodItem<Instruction22b> {
public Instruction22bMethodItem(int offset, StringTemplateGroup stg, Instruction22b instruction) {
super(offset, stg, instruction);
public Instruction22bMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction22b instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("RegisterA", instruction.getRegisterA());
template.setAttribute("RegisterB", instruction.getRegisterB());
template.setAttribute("RegisterA", formatRegister(instruction.getRegisterA()));
template.setAttribute("RegisterB", formatRegister(instruction.getRegisterB()));
template.setAttribute("Literal", instruction.getLiteral());
}
}

View File

@ -28,20 +28,22 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction22c;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.jf.dexlib.Code.Format.Instruction22c;
import org.jf.dexlib.CodeItem;
public class Instruction22cMethodItem extends InstructionFormatMethodItem<Instruction22c> {
public Instruction22cMethodItem(int offset, StringTemplateGroup stg, Instruction22c instruction) {
super(offset, stg, instruction);
public Instruction22cMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction22c instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Reference", Reference.makeReference(template.getGroup(),
instruction.getReferencedItem()));
template.setAttribute("RegisterA", instruction.getRegisterA());
template.setAttribute("RegisterB", instruction.getRegisterB());
template.setAttribute("RegisterA", formatRegister(instruction.getRegisterA()));
template.setAttribute("RegisterB", formatRegister(instruction.getRegisterB()));
}
}

View File

@ -28,18 +28,20 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction22s;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction22s;
import org.jf.dexlib.CodeItem;
public class Instruction22sMethodItem extends InstructionFormatMethodItem<Instruction22s> {
public Instruction22sMethodItem(int offset, StringTemplateGroup stg, Instruction22s instruction) {
super(offset, stg, instruction);
public Instruction22sMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction22s instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("RegisterA", instruction.getRegisterA());
template.setAttribute("RegisterB", instruction.getRegisterB());
template.setAttribute("RegisterA", formatRegister(instruction.getRegisterA()));
template.setAttribute("RegisterB", formatRegister(instruction.getRegisterB()));
template.setAttribute("Literal", instruction.getLiteral());
}
}

View File

@ -28,18 +28,20 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction22t;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction22t;
import org.jf.dexlib.CodeItem;
public class Instruction22tMethodItem extends InstructionFormatMethodItem<Instruction22t> {
public Instruction22tMethodItem(int offset, StringTemplateGroup stg, Instruction22t instruction) {
super(offset, stg, instruction);
public Instruction22tMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction22t instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("RegisterA", instruction.getRegisterA());
template.setAttribute("RegisterB", instruction.getRegisterB());
template.setAttribute("RegisterA", formatRegister(instruction.getRegisterA()));
template.setAttribute("RegisterB", formatRegister(instruction.getRegisterB()));
template.setAttribute("Target", Integer.toHexString(getOffset() + instruction.getOffset()));
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction22x;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction22x;
import org.jf.dexlib.CodeItem;
public class Instruction22xMethodItem extends InstructionFormatMethodItem<Instruction22x> {
public Instruction22xMethodItem(int offset, StringTemplateGroup stg, Instruction22x instruction) {
super(offset, stg, instruction);
public Instruction22xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction22x instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("RegisterA", instruction.getRegisterA());
template.setAttribute("RegisterB", instruction.getRegisterB());
template.setAttribute("RegisterA", formatRegister(instruction.getRegisterA()));
template.setAttribute("RegisterB", formatRegister(instruction.getRegisterB()));
}
}

View File

@ -28,18 +28,20 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction23x;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction23x;
import org.jf.dexlib.CodeItem;
public class Instruction23xMethodItem extends InstructionFormatMethodItem<Instruction23x> {
public Instruction23xMethodItem(int offset, StringTemplateGroup stg, Instruction23x instruction) {
super(offset, stg, instruction);
public Instruction23xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction23x instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("RegisterA", instruction.getRegisterA());
template.setAttribute("RegisterB", instruction.getRegisterB());
template.setAttribute("RegisterC", instruction.getRegisterC());
template.setAttribute("RegisterA", formatRegister(instruction.getRegisterA()));
template.setAttribute("RegisterB", formatRegister(instruction.getRegisterB()));
template.setAttribute("RegisterC", formatRegister(instruction.getRegisterC()));
}
}

View File

@ -28,13 +28,15 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction30t;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction30t;
import org.jf.dexlib.CodeItem;
public class Instruction30tMethodItem extends InstructionFormatMethodItem<Instruction30t> {
public Instruction30tMethodItem(int offset, StringTemplateGroup stg, Instruction30t instruction) {
super(offset, stg, instruction);
public Instruction30tMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction30t instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {

View File

@ -28,19 +28,21 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction31c;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.jf.dexlib.Code.Format.Instruction31c;
import org.jf.dexlib.CodeItem;
public class Instruction31cMethodItem extends InstructionFormatMethodItem<Instruction31c> {
public Instruction31cMethodItem(int offset, StringTemplateGroup stg, Instruction31c instruction) {
super(offset, stg, instruction);
public Instruction31cMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction31c instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Reference", Reference.makeReference(template.getGroup(),
instruction.getReferencedItem()));
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction31i;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction31i;
import org.jf.dexlib.CodeItem;
public class Instruction31iMethodItem extends InstructionFormatMethodItem<Instruction31i> {
public Instruction31iMethodItem(int offset, StringTemplateGroup stg, Instruction31i instruction) {
super(offset, stg, instruction);
public Instruction31iMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction31i instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
template.setAttribute("Literal", instruction.getLiteral());
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction31t;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction31t;
import org.jf.dexlib.CodeItem;
public class Instruction31tMethodItem extends InstructionFormatMethodItem<Instruction31t> {
public Instruction31tMethodItem(int offset, StringTemplateGroup stg, Instruction31t instruction) {
super(offset, stg, instruction);
public Instruction31tMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction31t instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
template.setAttribute("Target", Integer.toHexString(getOffset() + instruction.getOffset()));
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction32x;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction32x;
import org.jf.dexlib.CodeItem;
public class Instruction32xMethodItem extends InstructionFormatMethodItem<Instruction32x> {
public Instruction32xMethodItem(int offset, StringTemplateGroup stg, Instruction32x instruction) {
super(offset, stg, instruction);
public Instruction32xMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction32x instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("RegisterA", instruction.getRegisterA());
template.setAttribute("RegisterB", instruction.getRegisterB());
template.setAttribute("RegisterA", formatRegister(instruction.getRegisterA()));
template.setAttribute("RegisterB", formatRegister(instruction.getRegisterB()));
}
}

View File

@ -28,16 +28,16 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction35c;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import java.util.Arrays;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.jf.dexlib.Code.Format.Instruction35c;
import org.jf.dexlib.CodeItem;
public class Instruction35cMethodItem extends InstructionFormatMethodItem<Instruction35c> {
public Instruction35cMethodItem(int offset, StringTemplateGroup stg, Instruction35c instruction) {
super(offset, stg, instruction);
public Instruction35cMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction35c instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
@ -49,29 +49,29 @@ public class Instruction35cMethodItem extends InstructionFormatMethodItem<Instru
private void setRegistersAttribute(StringTemplate template) {
switch (instruction.getRegCount()) {
case 1:
template.setAttribute("Registers", (int)instruction.getRegisterD());
template.setAttribute("Registers", formatRegister(instruction.getRegisterD()));
return;
case 2:
template.setAttribute("Registers", (int)instruction.getRegisterD());
template.setAttribute("Registers", (int)instruction.getRegisterE());
template.setAttribute("Registers", formatRegister(instruction.getRegisterD()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterE()));
return;
case 3:
template.setAttribute("Registers", (int)instruction.getRegisterD());
template.setAttribute("Registers", (int)instruction.getRegisterE());
template.setAttribute("Registers", (int)instruction.getRegisterF());
template.setAttribute("Registers", formatRegister(instruction.getRegisterD()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterE()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterF()));
return;
case 4:
template.setAttribute("Registers", (int)instruction.getRegisterD());
template.setAttribute("Registers", (int)instruction.getRegisterE());
template.setAttribute("Registers", (int)instruction.getRegisterF());
template.setAttribute("Registers", (int)instruction.getRegisterG());
template.setAttribute("Registers", formatRegister(instruction.getRegisterD()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterE()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterF()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterG()));
return;
case 5:
template.setAttribute("Registers", (int)instruction.getRegisterD());
template.setAttribute("Registers", (int)instruction.getRegisterE());
template.setAttribute("Registers", (int)instruction.getRegisterF());
template.setAttribute("Registers", (int)instruction.getRegisterG());
template.setAttribute("Registers", (int)instruction.getRegisterA());
template.setAttribute("Registers", formatRegister(instruction.getRegisterD()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterE()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterF()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterG()));
template.setAttribute("Registers", formatRegister(instruction.getRegisterA()));
}
}
}

View File

@ -28,20 +28,26 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction3rc;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.jf.baksmali.Adaptors.RegisterFormatter;
import org.jf.dexlib.Code.Format.Instruction3rc;
import org.jf.dexlib.CodeItem;
public class Instruction3rcMethodItem extends InstructionFormatMethodItem<Instruction3rc> {
public Instruction3rcMethodItem(int offset, StringTemplateGroup stg, Instruction3rc instruction) {
super(offset, stg, instruction);
public Instruction3rcMethodItem(int offset, StringTemplateGroup stg, Instruction3rc instruction, CodeItem codeItem) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Reference", Reference.makeReference(template.getGroup(),
instruction.getReferencedItem()));
template.setAttribute("StartRegister", instruction.getStartRegister());
template.setAttribute("LastRegister", instruction.getStartRegister() + instruction.getRegCount() - 1);
String[] registers = RegisterFormatter.formatFormat3rcRegisters(codeItem, instruction.getStartRegister(),
instruction.getStartRegister() + instruction.getRegCount() - 1);
template.setAttribute("StartRegister", registers[0]);
template.setAttribute("LastRegister", registers[1]);
}
}

View File

@ -28,17 +28,19 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.Instruction51l;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.Instruction51l;
import org.jf.dexlib.CodeItem;
public class Instruction51lMethodItem extends InstructionFormatMethodItem<Instruction51l> {
public Instruction51lMethodItem(int offset, StringTemplateGroup stg, Instruction51l instruction) {
super(offset, stg, instruction);
public Instruction51lMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
Instruction51l instruction) {
super(codeItem, offset, stg, instruction);
}
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", instruction.getRegister());
template.setAttribute("Register", formatRegister(instruction.getRegister()));
template.setAttribute("Literal", instruction.getLiteral());
}
}

View File

@ -28,18 +28,22 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.baksmali.Adaptors.MethodItem;
import org.jf.baksmali.Adaptors.Reference.Reference;
import org.jf.dexlib.Code.Instruction;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.baksmali.Adaptors.MethodItem;
import org.jf.baksmali.Adaptors.RegisterFormatter;
import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.CodeItem;
public abstract class InstructionFormatMethodItem<T extends Instruction> extends MethodItem {
protected final CodeItem codeItem;
private final StringTemplateGroup stg;
protected final T instruction;
public InstructionFormatMethodItem(int offset, StringTemplateGroup stg, T instruction) {
public InstructionFormatMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, T instruction) {
super(offset);
this.codeItem = codeItem;
this.stg = stg;
this.instruction = instruction;
}
@ -57,6 +61,10 @@ public abstract class InstructionFormatMethodItem<T extends Instruction> extends
return instruction.getFormat().name();
}
protected String formatRegister(int register) {
return RegisterFormatter.formatRegister(codeItem, register);
}
@Override
public String toString() {
StringTemplate template = stg.getInstanceOf(instruction.getFormat().name());

View File

@ -28,21 +28,21 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.PackedSwitchDataPseudoInstruction;
import org.jf.dexlib.Code.Format.SparseSwitchDataPseudoInstruction;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.PackedSwitchDataPseudoInstruction;
import org.jf.dexlib.CodeItem;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
public class PackedSwitchMethodItem extends InstructionFormatMethodItem<PackedSwitchDataPseudoInstruction> {
private int baseAddress;
public PackedSwitchMethodItem(int offset, StringTemplateGroup stg, PackedSwitchDataPseudoInstruction instruction,
int baseAddress) {
super(offset, stg, instruction);
public PackedSwitchMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
PackedSwitchDataPseudoInstruction instruction, int baseAddress) {
super(codeItem, offset, stg, instruction);
this.baseAddress = baseAddress;
}

View File

@ -28,20 +28,21 @@
package org.jf.baksmali.Adaptors.Format;
import org.jf.dexlib.Code.Format.SparseSwitchDataPseudoInstruction;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.jf.dexlib.Code.Format.SparseSwitchDataPseudoInstruction;
import org.jf.dexlib.CodeItem;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
public class SparseSwitchMethodItem extends InstructionFormatMethodItem<SparseSwitchDataPseudoInstruction> {
private int baseAddress;
public SparseSwitchMethodItem(int offset, StringTemplateGroup stg, SparseSwitchDataPseudoInstruction instruction,
int baseAddress) {
super(offset, stg, instruction);
public SparseSwitchMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg,
SparseSwitchDataPseudoInstruction instruction, int baseAddress) {
super(codeItem, offset, stg, instruction);
this.baseAddress = baseAddress;
}

View File

@ -30,19 +30,21 @@ package org.jf.baksmali.Adaptors;
import org.jf.dexlib.TypeIdItem;
import org.jf.dexlib.StringIdItem;
import org.jf.dexlib.CodeItem;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplate;
public class LocalDebugMethodItem extends DebugMethodItem {
private final int register;
private final String register;
private final String name;
private final String type;
private final String signature;
public LocalDebugMethodItem(int offset, StringTemplateGroup stg, String templateName, int sortOrder, int register,
StringIdItem name, TypeIdItem type, StringIdItem signature) {
public LocalDebugMethodItem(CodeItem codeItem, int offset, StringTemplateGroup stg, String templateName,
int sortOrder, int register, StringIdItem name, TypeIdItem type,
StringIdItem signature) {
super(offset, stg, templateName, sortOrder);
this.register = register;
this.register = RegisterFormatter.formatRegister(codeItem, register);
this.name = name==null?null:name.getStringValue();
this.type = type==null?null:type.getTypeDescriptor();
this.signature = signature==null?null:signature.getStringValue();
@ -50,7 +52,7 @@ public class LocalDebugMethodItem extends DebugMethodItem {
@Override
protected void setAttributes(StringTemplate template) {
template.setAttribute("Register", Integer.toString(register));
template.setAttribute("Register", register);
template.setAttribute("Name", name);
template.setAttribute("Type", type);
template.setAttribute("Signature", signature);

View File

@ -227,69 +227,69 @@ public class MethodDefinition {
private void addMethodItemsForInstruction(int offset, Instruction instruction) {
switch (instruction.getFormat()) {
case Format10t:
instructions.add(new Instruction10tMethodItem(offset, stg,(Instruction10t)instruction));
instructions.add(new Instruction10tMethodItem(codeItem, offset, stg,(Instruction10t)instruction));
labels.add(new LabelMethodItem(offset + ((Instruction10t)instruction).getOffset(), stg, "goto_"));
return;
case Format10x:
instructions.add(new Instruction10xMethodItem(offset, stg, (Instruction10x)instruction));
instructions.add(new Instruction10xMethodItem(codeItem, offset, stg, (Instruction10x)instruction));
return;
case Format11n:
instructions.add(new Instruction11nMethodItem(offset, stg, (Instruction11n)instruction));
instructions.add(new Instruction11nMethodItem(codeItem, offset, stg, (Instruction11n)instruction));
return;
case Format11x:
instructions.add(new Instruction11xMethodItem(offset, stg, (Instruction11x)instruction));
instructions.add(new Instruction11xMethodItem(codeItem, offset, stg, (Instruction11x)instruction));
return;
case Format12x:
instructions.add(new Instruction12xMethodItem(offset, stg, (Instruction12x)instruction));
instructions.add(new Instruction12xMethodItem(codeItem, offset, stg, (Instruction12x)instruction));
return;
case Format20t:
instructions.add(new Instruction20tMethodItem(offset, stg, (Instruction20t)instruction));
instructions.add(new Instruction20tMethodItem(codeItem, offset, stg, (Instruction20t)instruction));
labels.add(new LabelMethodItem(offset + ((Instruction20t)instruction).getOffset(), stg, "goto_"));
return;
case Format21c:
instructions.add(new Instruction21cMethodItem(offset, stg, (Instruction21c)instruction));
instructions.add(new Instruction21cMethodItem(codeItem, offset, stg, (Instruction21c)instruction));
return;
case Format21h:
instructions.add(new Instruction21hMethodItem(offset, stg, (Instruction21h)instruction));
instructions.add(new Instruction21hMethodItem(codeItem, offset, stg, (Instruction21h)instruction));
return;
case Format21s:
instructions.add(new Instruction21sMethodItem(offset, stg, (Instruction21s)instruction));
instructions.add(new Instruction21sMethodItem(codeItem, offset, stg, (Instruction21s)instruction));
return;
case Format21t:
instructions.add(new Instruction21tMethodItem(offset, stg, (Instruction21t)instruction));
instructions.add(new Instruction21tMethodItem(codeItem, offset, stg, (Instruction21t)instruction));
labels.add(new LabelMethodItem(offset + ((Instruction21t)instruction).getOffset(), stg, "cond_"));
return;
case Format22b:
instructions.add(new Instruction22bMethodItem(offset, stg, (Instruction22b)instruction));
instructions.add(new Instruction22bMethodItem(codeItem, offset, stg, (Instruction22b)instruction));
return;
case Format22c:
instructions.add(new Instruction22cMethodItem(offset, stg, (Instruction22c)instruction));
instructions.add(new Instruction22cMethodItem(codeItem, offset, stg, (Instruction22c)instruction));
return;
case Format22s:
instructions.add(new Instruction22sMethodItem(offset, stg, (Instruction22s)instruction));
instructions.add(new Instruction22sMethodItem(codeItem, offset, stg, (Instruction22s)instruction));
return;
case Format22t:
instructions.add(new Instruction22tMethodItem(offset, stg, (Instruction22t)instruction));
instructions.add(new Instruction22tMethodItem(codeItem, offset, stg, (Instruction22t)instruction));
labels.add(new LabelMethodItem(offset + ((Instruction22t)instruction).getOffset(), stg, "cond_"));
return;
case Format22x:
instructions.add(new Instruction22xMethodItem(offset, stg, (Instruction22x)instruction));
instructions.add(new Instruction22xMethodItem(codeItem, offset, stg, (Instruction22x)instruction));
return;
case Format23x:
instructions.add(new Instruction23xMethodItem(offset, stg, (Instruction23x)instruction));
instructions.add(new Instruction23xMethodItem(codeItem, offset, stg, (Instruction23x)instruction));
return;
case Format30t:
instructions.add(new Instruction30tMethodItem(offset, stg, (Instruction30t)instruction));
instructions.add(new Instruction30tMethodItem(codeItem, offset, stg, (Instruction30t)instruction));
labels.add(new LabelMethodItem(offset + ((Instruction30t)instruction).getOffset(), stg, "goto_"));
return;
case Format31c:
instructions.add(new Instruction31cMethodItem(offset, stg, (Instruction31c)instruction));
instructions.add(new Instruction31cMethodItem(codeItem, offset, stg, (Instruction31c)instruction));
return;
case Format31i:
instructions.add(new Instruction31iMethodItem(offset, stg, (Instruction31i)instruction));
instructions.add(new Instruction31iMethodItem(codeItem, offset, stg, (Instruction31i)instruction));
return;
case Format31t:
instructions.add(new Instruction31tMethodItem(offset, stg, (Instruction31t)instruction));
instructions.add(new Instruction31tMethodItem(codeItem, offset, stg, (Instruction31t)instruction));
if (instruction.opcode == Opcode.FILL_ARRAY_DATA) {
labels.add(new LabelMethodItem(offset + ((Instruction31t)instruction).getOffset(), stg,
"array_"));
@ -302,19 +302,19 @@ public class MethodDefinition {
}
return;
case Format32x:
instructions.add(new Instruction32xMethodItem(offset, stg, (Instruction32x)instruction));
instructions.add(new Instruction32xMethodItem(codeItem, offset, stg, (Instruction32x)instruction));
return;
case Format35c:
instructions.add(new Instruction35cMethodItem(offset, stg, (Instruction35c)instruction));
instructions.add(new Instruction35cMethodItem(codeItem, offset, stg, (Instruction35c)instruction));
return;
case Format3rc:
instructions.add(new Instruction3rcMethodItem(offset, stg, (Instruction3rc)instruction));
instructions.add(new Instruction3rcMethodItem(offset, stg, (Instruction3rc)instruction, codeItem));
return;
case Format51l:
instructions.add(new Instruction51lMethodItem(offset, stg, (Instruction51l)instruction));
instructions.add(new Instruction51lMethodItem(codeItem, offset, stg, (Instruction51l)instruction));
return;
case ArrayData:
instructions.add(new ArrayDataMethodItem(offset, stg, (ArrayDataPseudoInstruction)instruction));
instructions.add(new ArrayDataMethodItem(codeItem, offset, stg, (ArrayDataPseudoInstruction)instruction));
return;
case PackedSwitchData:
{
@ -324,7 +324,7 @@ public class MethodDefinition {
PackedSwitchDataPseudoInstruction packedSwitchInstruction =
(PackedSwitchDataPseudoInstruction)instruction;
instructions.add(new PackedSwitchMethodItem(offset, stg,
instructions.add(new PackedSwitchMethodItem(codeItem, offset, stg,
packedSwitchInstruction, baseAddress));
Iterator<PackedSwitchDataPseudoInstruction.PackedSwitchTarget> iterator =
@ -344,7 +344,7 @@ public class MethodDefinition {
SparseSwitchDataPseudoInstruction sparseSwitchInstruction =
(SparseSwitchDataPseudoInstruction)instruction;
instructions.add(new SparseSwitchMethodItem(offset, stg,
instructions.add(new SparseSwitchMethodItem(codeItem, offset, stg,
sparseSwitchInstruction, baseAddress));
Iterator<SparseSwitchDataPseudoInstruction.SparseSwitchTarget> iterator =
@ -442,30 +442,30 @@ public class MethodDefinition {
@Override
public void ProcessStartLocal(int codeAddress, int length, int registerNum, StringIdItem name,
TypeIdItem type) {
debugItems.add(new LocalDebugMethodItem(codeAddress, stg, "StartLocal", -1, registerNum,
name, type, null));
debugItems.add(new LocalDebugMethodItem(codeItem, codeAddress, stg, "StartLocal", -1,
registerNum, name, type, null));
}
@Override
public void ProcessStartLocalExtended(int codeAddress, int length, int registerNum,
StringIdItem name, TypeIdItem type,
StringIdItem signature) {
debugItems.add(new LocalDebugMethodItem(codeAddress, stg, "StartLocal", -1, registerNum,
name, type, signature));
debugItems.add(new LocalDebugMethodItem(codeItem, codeAddress, stg, "StartLocal", -1,
registerNum, name, type, signature));
}
@Override
public void ProcessEndLocal(int codeAddress, int length, int registerNum, StringIdItem name,
TypeIdItem type, StringIdItem signature) {
debugItems.add(new LocalDebugMethodItem(codeAddress, stg, "EndLocal", -1, registerNum, name,
type, signature));
debugItems.add(new LocalDebugMethodItem(codeItem, codeAddress, stg, "EndLocal", -1,
registerNum, name, type, signature));
}
@Override
public void ProcessRestartLocal(int codeAddress, int length, int registerNum, StringIdItem name,
TypeIdItem type, StringIdItem signature) {
debugItems.add(new LocalDebugMethodItem(codeAddress, stg, "RestartLocal", -1, registerNum,
name, type, signature));
debugItems.add(new LocalDebugMethodItem(codeItem, codeAddress, stg, "RestartLocal", -1,
registerNum, name, type, signature));
}
@Override

View File

@ -0,0 +1,85 @@
/*
* [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.Adaptors;
import org.jf.dexlib.CodeItem;
import org.jf.baksmali.baksmali;
/**
* This class contains the logic used for formatting registers
*/
public class RegisterFormatter {
/**
* This method is used (only) by format 3rc (the format that uses a range of regsiters like {v1 .. v10}) to format
* it's registers. If both registers are parameter registers, they will be formatted as such, otherwise they will
* both be formatted as normal registers
* @param codeItem
* @param startRegister
* @param lastRegister
* @return an array of 2 strings containing the formatted registers
*/
public static String[] formatFormat3rcRegisters(CodeItem codeItem, int startRegister, int lastRegister) {
if (!baksmali.noParameterRegisters) {
int parameterRegisterCount = codeItem.getParent().method.getPrototype().getParameterRegisterCount()
+ (codeItem.getParent().isDirect()?0:1);
int registerCount = codeItem.getRegisterCount();
assert startRegister <= lastRegister;
if (startRegister >= registerCount - parameterRegisterCount) {
return new String[] {"p" + (startRegister - (registerCount - parameterRegisterCount)),
"p" + (lastRegister - (registerCount - parameterRegisterCount))};
}
}
return new String[] {"v" + startRegister,
"v" + lastRegister};
}
/**
* Formats a register with the appropriate format - with either the normal v<n> format or the p<n> parameter format.
*
* It uses the register and parameter information from the give <code>CodeItem</code> to determine if the given
* register is a normal or parameter register.
* @param codeItem
* @param register
* @return The formatted register
*/
public static String formatRegister(CodeItem codeItem, int register) {
if (!baksmali.noParameterRegisters) {
int parameterRegisterCount = codeItem.getParent().method.getPrototype().getParameterRegisterCount()
+ (codeItem.getParent().isDirect()?0:1);
int registerCount = codeItem.getRegisterCount();
if (register >= registerCount - parameterRegisterCount) {
return "p" + (register - (registerCount - parameterRegisterCount));
}
}
return "v" + register;
}
}

View File

@ -39,8 +39,12 @@ import org.jf.dexlib.StringIdItem;
import java.io.*;
public class baksmali {
public static void disassembleDexFile(DexFile dexFile, String outputDirectory)
public static boolean noParameterRegisters = false;
public static void disassembleDexFile(DexFile dexFile, String outputDirectory, boolean noParameterRegisters)
{
baksmali.noParameterRegisters = noParameterRegisters;
File outputDirectoryFile = new File(outputDirectory);
if (!outputDirectoryFile.exists()) {
if (!outputDirectoryFile.mkdirs()) {

View File

@ -74,6 +74,7 @@ public class main {
boolean sort = false;
boolean fixRegisters = false;
boolean readOnly = false;
boolean noParameterRegisters = false;
String outputDirectory = "out";
String dumpFileName = null;
@ -131,6 +132,10 @@ public class main {
fixRegisters = true;
}
if (commandLine.hasOption("p")) {
noParameterRegisters = true;
}
try {
File dexFileFile = new File(inputDexFileName);
if (!dexFileFile.exists()) {
@ -146,7 +151,7 @@ public class main {
}
if (disassemble) {
baksmali.disassembleDexFile(dexFile, outputDirectory);
baksmali.disassembleDexFile(dexFile, outputDirectory, noParameterRegisters);
}
if (doDump || write) {
@ -230,9 +235,15 @@ public class main {
.create("s");
Option fixSignedRegisterOption = OptionBuilder.withLongOpt("fix-signed-registers")
.withDescription("when dumping or rewriting, fix any registers in the debug info that are encoded as a signed value")
.withDescription("when dumping or rewriting, fix any registers in the debug info that are encoded as" +
" a signed value")
.create("f");
Option noParameterRegistersOption = OptionBuilder.withLongOpt("no-parameter-registers")
.withDescription("use the v<n> syntax instead of the p<n> syntax for registers mapped to method" +
" parameters")
.create("p");
OptionGroup dumpCommand = new OptionGroup();
dumpCommand.addOption(dumpOption);
dumpCommand.addOption(dumpOnlyOption);
@ -245,5 +256,6 @@ public class main {
options.addOption(outputDirOption);
options.addOption(sortOption);
options.addOption(fixSignedRegisterOption);
options.addOption(noParameterRegistersOption);
}
}

View File

@ -128,13 +128,6 @@ Format31tLabelMap ::= [
]
Register(num) ::=
<<
v<num; format="decimal">
>>
Format10t(Opcode, Target) ::=
<<
<Opcode> goto_<Target>:
@ -147,17 +140,17 @@ Format10x(Opcode) ::=
Format11n(Opcode, Register, Literal) ::=
<<
<Opcode> <Register(Register)>, <Literal>
<Opcode> <Register>, <Literal>
>>
Format11x(Opcode, Register) ::=
<<
<Opcode> <Register(Register)>
<Opcode> <Register>
>>
Format12x(Opcode, RegisterA, RegisterB) ::=
<<
<Opcode> <Register(RegisterA)>, <Register(RegisterB)>
<Opcode> <RegisterA>, <RegisterB>
>>
Format20t(Opcode, Target) ::=
@ -167,52 +160,52 @@ Format20t(Opcode, Target) ::=
Format21c(Opcode, Register, Reference) ::=
<<
<Opcode> <Register(Register)>, <Reference>
<Opcode> <Register>, <Reference>
>>
Format21h(Opcode, Register, Literal) ::=
<<
<Opcode> <Register(Register)>, <Literal>
<Opcode> <Register>, <Literal>
>>
Format21s(Opcode, Register, Literal) ::=
<<
<Opcode> <Register(Register)>, <Literal>
<Opcode> <Register>, <Literal>
>>
Format21t(Opcode, Register, Target) ::=
<<
<Opcode> <Register(Register)>, cond_<Target>:
<Opcode> <Register>, cond_<Target>:
>>
Format22b(Opcode, RegisterA, RegisterB, Literal) ::=
<<
<Opcode> <Register(RegisterA)>, <Register(RegisterB)>, <Literal>
<Opcode> <RegisterA>, <RegisterB>, <Literal>
>>
Format22c(Opcode, RegisterA, RegisterB, Reference) ::=
<<
<Opcode> <Register(RegisterA)>, <Register(RegisterB)>, <Reference>
<Opcode> <RegisterA>, <RegisterB>, <Reference>
>>
Format22s(Opcode, RegisterA, RegisterB, Literal) ::=
<<
<Opcode> <Register(RegisterA)>, <Register(RegisterB)>, <Literal>
<Opcode> <RegisterA>, <RegisterB>, <Literal>
>>
Format22t(Opcode, RegisterA, RegisterB, Target) ::=
<<
<Opcode> <Register(RegisterA)>, <Register(RegisterB)>, cond_<Target>:
<Opcode> <RegisterA>, <RegisterB>, cond_<Target>:
>>
Format22x(Opcode, RegisterA, RegisterB) ::=
<<
<Opcode> <Register(RegisterA)>, <Register(RegisterB)>
<Opcode> <RegisterA>, <RegisterB>
>>
Format23x(Opcode, RegisterA, RegisterB, RegisterC) ::=
<<
<Opcode> <Register(RegisterA)>, <Register(RegisterB)>, <Register(RegisterC)>
<Opcode> <RegisterA>, <RegisterB>, <RegisterC>
>>
Format30t(Opcode, Target) ::=
@ -222,37 +215,37 @@ Format30t(Opcode, Target) ::=
Format31c(Opcode, Register, Reference) ::=
<<
<Opcode> <Register(Register)>, <Reference>
<Opcode> <Register>, <Reference>
>>
Format31i(Opcode, Register, Literal) ::=
<<
<Opcode> <Register(Register)>, <Literal>
<Opcode> <Register>, <Literal>
>>
Format31t(Opcode, Register, Target) ::=
<<
<Opcode> <Register(Register)>, <Format31tLabelMap.(Opcode)><Target>:
<Opcode> <Register>, <Format31tLabelMap.(Opcode)><Target>:
>>
Format32x(Opcode, RegisterA, RegisterB) ::=
<<
<Opcode> <Register(RegisterA)>, <Register(RegisterB)>
<Opcode> <RegisterA>, <RegisterB>
>>
Format35c(Opcode, Registers, Reference) ::=
<<
<Opcode> {<Registers: Register(it); separator=", ">}, <Reference>
<Opcode> {<Registers; separator=", ">}, <Reference>
>>
Format3rc(Opcode, StartRegister, LastRegister, Reference) ::=
<<
<Opcode> {<Register(StartRegister)> .. <Register(LastRegister)>}, <Reference>
<Opcode> {<StartRegister> .. <LastRegister>}, <Reference>
>>
Format51l(Opcode, Register, Literal) ::=
<<
<Opcode> <Register(Register)>, <Literal>
<Opcode> <Register>, <Literal>
>>
ArrayData(Opcode, ElementWidth, Values) ::=
@ -304,17 +297,17 @@ StartEpilogue(Epilogue) ::=
StartLocal(Register, Name, Type, Signature) ::=
<<
.local <Register(Register)>, <Name>:<Type><if(Signature)>,"<Signature>"<endif>
.local <Register>, <Name>:<Type><if(Signature)>,"<Signature>"<endif>
>>
EndLocal(Register, Name, Type, Signature) ::=
<<
.end local <Register(Register)> <if(Name)>#<Name>:<Type>,<if(Signature)>, "<Signature>"<endif><endif>
.end local <Register> <if(Name)>#<Name>:<Type>,<if(Signature)>, "<Signature>"<endif><endif>
>>
RestartLocal(Register, Name, Type, Signature) ::=
<<
.restart local <Register(Register)> <if(Name)>#<Name>:<Type>,<if(Signature)>, "<Signature>"<endif><endif>
.restart local <Register> <if(Name)>#<Name>:<Type>,<if(Signature)>, "<Signature>"<endif><endif>
>>
SetFile(FileName) ::=