Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/JesusFreke/smali.git into…
Browse files Browse the repository at this point in the history
… smali
  • Loading branch information
testwhat committed Oct 3, 2016
2 parents aec3b46 + dcaf46c commit f1b7f86
Show file tree
Hide file tree
Showing 127 changed files with 6,866 additions and 2,816 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,6 +9,7 @@
/smaliex-bin/*
/util/build
/smalidea/build
/build
*.iml
*.ipr
*.iws
Expand Down
20 changes: 17 additions & 3 deletions baksmali/build.gradle
Expand Up @@ -41,8 +41,8 @@ buildscript {
dependencies {
compile project(':util')
compile project(':dexlib2')
compile depends.commons_cli
compile depends.guava
compile depends.jcommander

testCompile depends.junit
testCompile project(':smali')
Expand All @@ -59,7 +59,7 @@ task fatJar(type: Jar) {
classifier = 'fat'

manifest {
attributes('Main-Class': 'org.jf.baksmali.main')
attributes('Main-Class': 'org.jf.baksmali.Main')
}

doLast {
Expand Down Expand Up @@ -93,7 +93,7 @@ task proguard(type: proguard.gradle.ProGuardTask, dependsOn: fatJar) {
dontobfuscate
dontoptimize

keep 'public class org.jf.baksmali.main { public static void main(java.lang.String[]); }'
keep 'public class org.jf.baksmali.Main { public static void main(java.lang.String[]); }'
keepclassmembers 'enum * { public static **[] values(); public static ** valueOf(java.lang.String); }'

dontwarn 'com.google.common.**'
Expand All @@ -110,3 +110,17 @@ task dist(dependsOn: proguard) {
file(project.outFile).renameTo(dist)
}
}

task fastbuild(dependsOn: build) {
}

task fb(dependsOn: fastbuild) {
}

tasks.getByPath('javadoc').onlyIf({
!gradle.taskGraph.hasTask(fastbuild)
})

tasks.getByPath('test').onlyIf({
!gradle.taskGraph.hasTask(fastbuild)
})
Expand Up @@ -28,7 +28,7 @@

package org.jf.baksmali.Adaptors;

import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.util.IndentingWriter;

import javax.annotation.Nonnull;
Expand All @@ -42,7 +42,7 @@ public class CatchMethodItem extends MethodItem {
private final LabelMethodItem tryEndLabel;
private final LabelMethodItem handlerLabel;

public CatchMethodItem(@Nonnull baksmaliOptions options, @Nonnull MethodDefinition.LabelCache labelCache,
public CatchMethodItem(@Nonnull BaksmaliOptions options, @Nonnull MethodDefinition.LabelCache labelCache,
int codeAddress, @Nullable String exceptionType, int startAddress, int endAddress,
int handlerAddress) {
super(codeAddress);
Expand Down
Expand Up @@ -28,8 +28,7 @@

package org.jf.baksmali.Adaptors;

import com.google.common.collect.Lists;
import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.dexbacked.DexBackedClassDef;
import org.jf.dexlib2.dexbacked.DexBackedDexFile.InvalidItemIndex;
Expand All @@ -46,24 +45,24 @@
import java.util.*;

public class ClassDefinition {
@Nonnull public final baksmaliOptions options;
@Nonnull public final BaksmaliOptions options;
@Nonnull public final ClassDef classDef;
@Nonnull private final HashSet<String> fieldsSetInStaticConstructor;

protected boolean validationErrors;

public ClassDefinition(@Nonnull baksmaliOptions options, @Nonnull ClassDef classDef) {
public ClassDefinition(@Nonnull BaksmaliOptions options, @Nonnull ClassDef classDef) {
this.options = options;
this.classDef = classDef;
fieldsSetInStaticConstructor = findFieldsSetInStaticConstructor();
fieldsSetInStaticConstructor = findFieldsSetInStaticConstructor(classDef);
}

public boolean hadValidationErrors() {
return validationErrors;
}

@Nonnull
private HashSet<String> findFieldsSetInStaticConstructor() {
private static HashSet<String> findFieldsSetInStaticConstructor(@Nonnull ClassDef classDef) {
HashSet<String> fieldsSetInStaticConstructor = new HashSet<String>();

for (Method method: classDef.getDirectMethods()) {
Expand Down Expand Up @@ -166,7 +165,7 @@ private void writeAnnotations(IndentingWriter writer) throws IOException {
writer.write("# annotations\n");

String containingClass = null;
if (options.useImplicitReferences) {
if (options.implicitReferences) {
containingClass = classDef.getType();
}

Expand Down
Expand Up @@ -28,14 +28,14 @@

package org.jf.baksmali.Adaptors;

import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;

import javax.annotation.Nonnull;

public class EndTryLabelMethodItem extends LabelMethodItem {
private int endTryAddress;

public EndTryLabelMethodItem(@Nonnull baksmaliOptions options, int codeAddress, int endTryAddress) {
public EndTryLabelMethodItem(@Nonnull BaksmaliOptions options, int codeAddress, int endTryAddress) {
super(options, codeAddress, "try_end_");
this.endTryAddress = endTryAddress;
}
Expand Down
Expand Up @@ -29,7 +29,7 @@
package org.jf.baksmali.Adaptors;

import org.jf.baksmali.Adaptors.EncodedValue.EncodedValueAdaptor;
import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.Field;
Expand All @@ -41,7 +41,7 @@
import java.util.Collection;

public class FieldDefinition {
public static void writeTo(baksmaliOptions options, IndentingWriter writer, Field field,
public static void writeTo(BaksmaliOptions options, IndentingWriter writer, Field field,
boolean setInStaticConstructor) throws IOException {
EncodedValue initialValue = field.getInitialValue();
int accessFlags = field.getAccessFlags();
Expand All @@ -68,7 +68,7 @@ public static void writeTo(baksmaliOptions options, IndentingWriter writer, Fiel
writer.write(" = ");

String containingClass = null;
if (options.useImplicitReferences) {
if (options.implicitReferences) {
containingClass = field.getDefiningClass();
}

Expand All @@ -82,7 +82,7 @@ public static void writeTo(baksmaliOptions options, IndentingWriter writer, Fiel
writer.indent(4);

String containingClass = null;
if (options.useImplicitReferences) {
if (options.implicitReferences) {
containingClass = field.getDefiningClass();
}

Expand Down
Expand Up @@ -37,7 +37,7 @@
import org.jf.baksmali.Adaptors.MethodDefinition.InvalidSwitchPayload;
import org.jf.baksmali.Adaptors.MethodItem;
import org.jf.baksmali.Renderers.LongRenderer;
import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.ReferenceType;
import org.jf.dexlib2.VerificationError;
Expand Down Expand Up @@ -80,7 +80,7 @@ public double getSortOrder() {
}

private boolean isAllowedOdex(@Nonnull Opcode opcode) {
baksmaliOptions options = methodDef.classDef.options;
BaksmaliOptions options = methodDef.classDef.options;
if (options.allowOdex) {
return true;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ public boolean writeTo(IndentingWriter writer) throws IOException {
if (instruction instanceof ReferenceInstruction) {
ReferenceInstruction referenceInstruction = (ReferenceInstruction)instruction;
String classContext = null;
if (methodDef.classDef.options.useImplicitReferences) {
if (methodDef.classDef.options.implicitReferences) {
classContext = methodDef.method.getDefiningClass();
}

Expand Down
Expand Up @@ -30,7 +30,7 @@

import org.jf.baksmali.Adaptors.LabelMethodItem;
import org.jf.baksmali.Adaptors.MethodDefinition;
import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.OffsetInstruction;
import org.jf.util.IndentingWriter;
Expand All @@ -41,7 +41,7 @@
public class OffsetInstructionFormatMethodItem extends InstructionMethodItem<OffsetInstruction> {
protected LabelMethodItem label;

public OffsetInstructionFormatMethodItem(@Nonnull baksmaliOptions options, @Nonnull MethodDefinition methodDef,
public OffsetInstructionFormatMethodItem(@Nonnull BaksmaliOptions options, @Nonnull MethodDefinition methodDef,
int codeAddress, OffsetInstruction instruction) {
super(methodDef, codeAddress, instruction);

Expand Down
Expand Up @@ -28,18 +28,18 @@

package org.jf.baksmali.Adaptors;

import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.util.IndentingWriter;

import javax.annotation.Nonnull;
import java.io.IOException;

public class LabelMethodItem extends MethodItem {
private final baksmaliOptions options;
private final BaksmaliOptions options;
private final String labelPrefix;
private int labelSequence;

public LabelMethodItem(@Nonnull baksmaliOptions options, int codeAddress, @Nonnull String labelPrefix) {
public LabelMethodItem(@Nonnull BaksmaliOptions options, int codeAddress, @Nonnull String labelPrefix) {
super(codeAddress);
this.options = options;
this.labelPrefix = labelPrefix;
Expand Down Expand Up @@ -76,7 +76,7 @@ public boolean equals(Object o) {
public boolean writeTo(IndentingWriter writer) throws IOException {
writer.write(':');
writer.write(labelPrefix);
if (options.useSequentialLabels) {
if (options.sequentialLabels) {
writer.printUnsignedLongAsHex(labelSequence);
} else {
writer.printUnsignedLongAsHex(this.getLabelAddress());
Expand Down
Expand Up @@ -40,7 +40,7 @@

import org.jf.baksmali.Adaptors.Debug.DebugMethodItem;
import org.jf.baksmali.Adaptors.Format.InstructionMethodItemFactory;
import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
Expand Down Expand Up @@ -174,7 +174,7 @@ public MethodDefinition(@Nonnull ClassDefinition classDef, @Nonnull Method metho
}

public static void writeEmptyMethodTo(IndentingWriter writer, Method method,
baksmaliOptions options) throws IOException {
BaksmaliOptions options) throws IOException {
writer.write(".method ");
writeAccessFlags(writer, method.getAccessFlags());
writer.write(method.getName());
Expand All @@ -191,7 +191,7 @@ public static void writeEmptyMethodTo(IndentingWriter writer, Method method,
writeParameters(writer, method, methodParameters, options);

String containingClass = null;
if (options.useImplicitReferences) {
if (options.implicitReferences) {
containingClass = method.getDefiningClass();
}
AnnotationFormatter.writeTo(writer, method.getAnnotations(), containingClass);
Expand Down Expand Up @@ -223,7 +223,7 @@ public void writeTo(IndentingWriter writer) throws IOException {
writer.write('\n');

writer.indent(4);
if (classDef.options.useLocalsDirective) {
if (classDef.options.localsDirective) {
writer.write(".locals ");
writer.printSignedIntAsDec(methodImpl.getRegisterCount() - parameterRegisterCount);
} else {
Expand All @@ -239,7 +239,7 @@ public void writeTo(IndentingWriter writer) throws IOException {
}

String containingClass = null;
if (classDef.options.useImplicitReferences) {
if (classDef.options.implicitReferences) {
containingClass = method.getDefiningClass();
}
AnnotationFormatter.writeTo(writer, method.getAnnotations(), containingClass);
Expand Down Expand Up @@ -324,18 +324,18 @@ private static void writeAccessFlags(IndentingWriter writer, int accessFlags)

private static void writeParameters(IndentingWriter writer, Method method,
List<? extends MethodParameter> parameters,
baksmaliOptions options) throws IOException {
BaksmaliOptions options) throws IOException {
boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
int registerNumber = isStatic?0:1;
for (MethodParameter parameter: parameters) {
String parameterType = parameter.getType();
String parameterName = parameter.getName();
Collection<? extends Annotation> annotations = parameter.getAnnotations();
if ((options.outputDebugInfo && parameterName != null) || annotations.size() != 0) {
if ((options.debugInfo && parameterName != null) || annotations.size() != 0) {
writer.write(".param p");
writer.printSignedIntAsDec(registerNumber);

if (parameterName != null && options.outputDebugInfo) {
if (parameterName != null && options.debugInfo) {
writer.write(", ");
ReferenceFormatter.writeStringReference(writer, parameterName);
}
Expand All @@ -346,7 +346,7 @@ private static void writeParameters(IndentingWriter writer, Method method,
writer.indent(4);

String containingClass = null;
if (options.useImplicitReferences) {
if (options.implicitReferences) {
containingClass = method.getDefiningClass();
}
AnnotationFormatter.writeTo(writer, annotations, containingClass);
Expand Down Expand Up @@ -385,11 +385,11 @@ public List<MethodItem> getMethodItems() {
}

addTries(methodItems);
if (classDef.options.outputDebugInfo) {
if (classDef.options.debugInfo) {
addDebugInfo(methodItems);
}

if (classDef.options.useSequentialLabels) {
if (classDef.options.sequentialLabels) {
setLabelSequentialNumbers();
}

Expand Down Expand Up @@ -426,7 +426,7 @@ private void addInstructionMethodItems(List<MethodItem> methodItems) {
methodItems.add(new BlankMethodItem(currentCodeAddress));
}

if (classDef.options.addCodeOffsets) {
if (classDef.options.codeOffsets) {
methodItems.add(new MethodItem(currentCodeAddress) {

@Override
Expand All @@ -443,7 +443,7 @@ public boolean writeTo(IndentingWriter writer) throws IOException {
});
}

if (!classDef.options.noAccessorComments && (instruction instanceof ReferenceInstruction)) {
if (classDef.options.accessorComments && (instruction instanceof ReferenceInstruction)) {
Opcode opcode = instruction.getOpcode();

if (opcode.referenceType == ReferenceType.METHOD) {
Expand Down Expand Up @@ -504,7 +504,7 @@ private void addAnalyzedInstructionMethodItems(List<MethodItem> methodItems) {
methodItems.add(new BlankMethodItem(currentCodeAddress));
}

if (classDef.options.addCodeOffsets) {
if (classDef.options.codeOffsets) {
methodItems.add(new MethodItem(currentCodeAddress) {

@Override
Expand Down Expand Up @@ -608,7 +608,7 @@ private void setLabelSequentialNumbers() {

@Nullable
private String getContainingClassForImplicitReference() {
if (classDef.options.useImplicitReferences) {
if (classDef.options.implicitReferences) {
return classDef.classDef.getType();
}
return null;
Expand Down
Expand Up @@ -28,7 +28,7 @@

package org.jf.baksmali.Adaptors;

import org.jf.baksmali.baksmaliOptions;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.dexlib2.analysis.AnalyzedInstruction;
import org.jf.dexlib2.analysis.RegisterType;
import org.jf.util.IndentingWriter;
Expand Down Expand Up @@ -60,12 +60,12 @@ public boolean writeTo(IndentingWriter writer) throws IOException {
int registerCount = analyzedInstruction.getRegisterCount();
BitSet registers = new BitSet(registerCount);

if ((registerInfo & baksmaliOptions.ALL) != 0) {
if ((registerInfo & BaksmaliOptions.ALL) != 0) {
registers.set(0, registerCount);
} else {
if ((registerInfo & baksmaliOptions.ALLPOST) != 0) {
if ((registerInfo & BaksmaliOptions.ALLPOST) != 0) {
registers.set(0, registerCount);
} else if ((registerInfo & baksmaliOptions.DEST) != 0) {
} else if ((registerInfo & BaksmaliOptions.DEST) != 0) {
addDestRegs(registers, registerCount);
}
}
Expand Down

0 comments on commit f1b7f86

Please sign in to comment.