mirror of
https://github.com/revanced/smali.git
synced 2025-05-04 16:44:25 +02:00
refactor ClassDefinition to use template attributes instead of object parameters
git-svn-id: https://smali.googlecode.com/svn/trunk@371 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
fa7e91bff2
commit
7885a819a0
@ -52,6 +52,23 @@ public class ClassDefinition {
|
||||
buildAnnotationMaps();
|
||||
}
|
||||
|
||||
public StringTemplate makeTemplate() {
|
||||
StringTemplate template = stg.getInstanceOf("smaliFile");
|
||||
|
||||
template.setAttribute("AccessFlags", getAccessFlags());
|
||||
template.setAttribute("ClassType", classDefItem.getClassType().getTypeDescriptor());
|
||||
template.setAttribute("SuperType", getSuperType());
|
||||
template.setAttribute("SourceFile", getSourceFile());
|
||||
template.setAttribute("Interfaces", getInterfaces());
|
||||
template.setAttribute("Annotations", getAnnotations());
|
||||
template.setAttribute("StaticFields", getStaticFields());
|
||||
template.setAttribute("InstanceFields", getInstanceFields());
|
||||
template.setAttribute("DirectMethods", getDirectMethods());
|
||||
template.setAttribute("VirtualMethods", getVirtualMethods());
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
private void buildAnnotationMaps() {
|
||||
AnnotationDirectoryItem annotationDirectory = classDefItem.getAnnotations();
|
||||
if (annotationDirectory == null) {
|
||||
@ -78,7 +95,7 @@ public class ClassDefinition {
|
||||
});
|
||||
}
|
||||
|
||||
public List<String> getAccessFlags() {
|
||||
private List<String> getAccessFlags() {
|
||||
List<String> accessFlags = new ArrayList<String>();
|
||||
|
||||
for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForClass(classDefItem.getAccessFlags())) {
|
||||
@ -88,11 +105,8 @@ public class ClassDefinition {
|
||||
return accessFlags;
|
||||
}
|
||||
|
||||
public String getClassType() {
|
||||
return classDefItem.getClassType().getTypeDescriptor();
|
||||
}
|
||||
|
||||
public String getSuperType() {
|
||||
private String getSuperType() {
|
||||
TypeIdItem superClass = classDefItem.getSuperclass();
|
||||
if (superClass != null) {
|
||||
return superClass.getTypeDescriptor();
|
||||
@ -100,7 +114,7 @@ public class ClassDefinition {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSourceFile() {
|
||||
private String getSourceFile() {
|
||||
StringIdItem sourceFile = classDefItem.getSourceFile();
|
||||
|
||||
if (sourceFile == null) {
|
||||
@ -109,7 +123,7 @@ public class ClassDefinition {
|
||||
return classDefItem.getSourceFile().getStringValue();
|
||||
}
|
||||
|
||||
public List<String> getInterfaces() {
|
||||
private List<String> getInterfaces() {
|
||||
List<String> interfaces = new ArrayList<String>();
|
||||
|
||||
TypeListItem interfaceList = classDefItem.getInterfaces();
|
||||
@ -123,17 +137,26 @@ public class ClassDefinition {
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
public String getHasStaticFields() {
|
||||
if (classDataItem != null) {
|
||||
ClassDataItem.EncodedField fields[] = classDataItem.getStaticFields();
|
||||
if (fields != null && fields.length > 0) {
|
||||
return "true";
|
||||
}
|
||||
private List<StringTemplate> getAnnotations() {
|
||||
AnnotationDirectoryItem annotationDirectory = classDefItem.getAnnotations();
|
||||
if (annotationDirectory == null) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
AnnotationSetItem annotationSet = annotationDirectory.getClassAnnotations();
|
||||
if (annotationSet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<StringTemplate> annotations = new ArrayList<StringTemplate>();
|
||||
|
||||
for (AnnotationItem annotationItem: annotationSet.getAnnotations()) {
|
||||
annotations.add(AnnotationAdaptor.makeTemplate(stg, annotationItem));
|
||||
}
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public List<StringTemplate> getStaticFields() {
|
||||
private List<StringTemplate> getStaticFields() {
|
||||
List<StringTemplate> staticFields = new ArrayList<StringTemplate>();
|
||||
|
||||
if (classDataItem != null) {
|
||||
@ -161,17 +184,7 @@ public class ClassDefinition {
|
||||
return staticFields;
|
||||
}
|
||||
|
||||
public String getHasInstanceFields() {
|
||||
if (classDataItem != null) {
|
||||
ClassDataItem.EncodedField fields[] = classDataItem.getInstanceFields();
|
||||
if (fields != null && fields.length > 0) {
|
||||
return "true";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<StringTemplate> getInstanceFields() {
|
||||
private List<StringTemplate> getInstanceFields() {
|
||||
List<StringTemplate> instanceFields = new ArrayList<StringTemplate>();
|
||||
|
||||
if (classDataItem != null) {
|
||||
@ -184,17 +197,7 @@ public class ClassDefinition {
|
||||
return instanceFields;
|
||||
}
|
||||
|
||||
public String getHasDirectMethods() {
|
||||
if (classDataItem != null) {
|
||||
ClassDataItem.EncodedMethod[] methods = classDataItem.getDirectMethods();
|
||||
if (methods != null && methods.length > 0) {
|
||||
return "true";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<StringTemplate> getDirectMethods() {
|
||||
private List<StringTemplate> getDirectMethods() {
|
||||
List<StringTemplate> directMethods = new ArrayList<StringTemplate>();
|
||||
|
||||
if (classDataItem != null) {
|
||||
@ -208,17 +211,7 @@ public class ClassDefinition {
|
||||
return directMethods;
|
||||
}
|
||||
|
||||
public String getHasVirtualMethods() {
|
||||
if (classDataItem != null) {
|
||||
ClassDataItem.EncodedMethod[] methods = classDataItem.getVirtualMethods();
|
||||
if (methods != null && methods.length > 0) {
|
||||
return "true";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<StringTemplate> getVirtualMethods() {
|
||||
private List<StringTemplate> getVirtualMethods() {
|
||||
List<StringTemplate> virtualMethods = new ArrayList<StringTemplate>();
|
||||
|
||||
if (classDataItem != null) {
|
||||
@ -231,23 +224,4 @@ public class ClassDefinition {
|
||||
|
||||
return virtualMethods;
|
||||
}
|
||||
|
||||
public List<StringTemplate> getAnnotations() {
|
||||
AnnotationDirectoryItem annotationDirectory = classDefItem.getAnnotations();
|
||||
if (annotationDirectory == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AnnotationSetItem annotationSet = annotationDirectory.getClassAnnotations();
|
||||
if (annotationSet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<StringTemplate> annotations = new ArrayList<StringTemplate>();
|
||||
|
||||
for (AnnotationItem annotationItem: annotationSet.getAnnotations()) {
|
||||
annotations.add(AnnotationAdaptor.makeTemplate(stg, annotationItem));
|
||||
}
|
||||
return annotations;
|
||||
}
|
||||
}
|
||||
|
@ -96,8 +96,9 @@ public class baksmali {
|
||||
File smaliFile = new File(smaliPath.toString());
|
||||
|
||||
//create and initialize the top level string template
|
||||
StringTemplate smaliFileST = templates.getInstanceOf("smaliFile");
|
||||
smaliFileST.setAttribute("classDef", new ClassDefinition(templates, classDefItem));
|
||||
ClassDefinition classDefinition = new ClassDefinition(templates, classDefItem);
|
||||
|
||||
StringTemplate smaliFileST = classDefinition.makeTemplate();
|
||||
|
||||
//generate the disassembly
|
||||
String output = smaliFileST.toString();
|
||||
@ -126,7 +127,6 @@ public class baksmali {
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("\n\nError occured while disassembling class " + classDescriptor.replace('/', '.') + " - skipping class");
|
||||
ex.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -136,7 +136,7 @@ public class baksmali {
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("\n\nError occured while closing file " + smaliFile.toString());
|
||||
ex.printStackTrace();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,57 @@
|
||||
group baksmali;
|
||||
|
||||
smaliFile(classDef) ::=
|
||||
smaliFile(AccessFlags, ClassType, SuperType, SourceFile, Interfaces, Annotations, StaticFields,
|
||||
InstanceFields, DirectMethods, VirtualMethods) ::=
|
||||
<<
|
||||
.class <classDef.AccessFlags: {<it> }><classDef.ClassType>
|
||||
<if(classDef.SuperType)>
|
||||
.super <classDef.SuperType>
|
||||
.class <AccessFlags: {<it> }><ClassType>
|
||||
<if(SuperType)>
|
||||
.super <SuperType>
|
||||
<endif>
|
||||
<if(classDef.SourceFile)>
|
||||
<if(SourceFile)>
|
||||
|
||||
.source "<classDef.SourceFile>"
|
||||
.source "<SourceFile>"
|
||||
|
||||
|
||||
<endif>
|
||||
<if(classDef.Interfaces)>
|
||||
<if(Interfaces)>
|
||||
|
||||
# interfaces
|
||||
<classDef.Interfaces: implement(it); separator="\n">
|
||||
<Interfaces: implement(it); separator="\n">
|
||||
|
||||
<endif>
|
||||
<if(classDef.Annotations)>
|
||||
<if(Annotations)>
|
||||
|
||||
|
||||
# annotations
|
||||
<classDef.Annotations; separator="\n\n">
|
||||
<Annotations; separator="\n\n">
|
||||
|
||||
<endif>
|
||||
<if(classDef.HasStaticFields)>
|
||||
<if(StaticFields)>
|
||||
|
||||
|
||||
# static fields
|
||||
<classDef.StaticFields; separator="\n">
|
||||
<StaticFields; separator="\n">
|
||||
|
||||
<endif>
|
||||
<if(classDef.HasInstanceFields)>
|
||||
<if(InstanceFields)>
|
||||
|
||||
|
||||
# instance fields
|
||||
<classDef.InstanceFields; separator="\n">
|
||||
<InstanceFields; separator="\n">
|
||||
|
||||
<endif>
|
||||
<if(classDef.HasDirectMethods)>
|
||||
<if(DirectMethods)>
|
||||
|
||||
|
||||
# direct methods
|
||||
<classDef.DirectMethods; separator="\n\n">
|
||||
<DirectMethods; separator="\n\n">
|
||||
|
||||
<endif>
|
||||
<if(classDef.HasVirtualMethods)>
|
||||
<if(VirtualMethods)>
|
||||
|
||||
|
||||
# virtual methods
|
||||
<classDef.VirtualMethods; separator="\n\n">
|
||||
<VirtualMethods; separator="\n\n">
|
||||
|
||||
<endif>
|
||||
>>
|
||||
|
Loading…
x
Reference in New Issue
Block a user