From 69c3abb483d8a6329f38fb3c30afa3d138d3adc0 Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Thu, 25 Jun 2009 04:38:00 +0000 Subject: [PATCH] - fixed an issue where java.lang.Object from core.jar couldn't be re-assembled, because it has no superclass git-svn-id: https://smali.googlecode.com/svn/trunk@221 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../java/org/jf/baksmali/Adaptors/ClassDefinition.java | 6 +++++- baksmali/src/main/resources/templates/baksmali.stg | 4 +++- smali/src/main/antlr3/org/jf/smali/smaliParser.g | 10 ++++++---- smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java index f5ae880c..fa21db4e 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/ClassDefinition.java @@ -92,7 +92,11 @@ public class ClassDefinition { } public String getSuperType() { - return classDefItem.getSuperclass().getTypeDescriptor(); + TypeIdItem superClass = classDefItem.getSuperclass(); + if (superClass != null) { + return superClass.getTypeDescriptor(); + } + return null; } public String getSourceFile() { diff --git a/baksmali/src/main/resources/templates/baksmali.stg b/baksmali/src/main/resources/templates/baksmali.stg index 8f3c3eb5..f9878cd9 100644 --- a/baksmali/src/main/resources/templates/baksmali.stg +++ b/baksmali/src/main/resources/templates/baksmali.stg @@ -3,8 +3,10 @@ group baksmali; smaliFile(classDef) ::= << .class }> + .super - + + .source "" diff --git a/smali/src/main/antlr3/org/jf/smali/smaliParser.g b/smali/src/main/antlr3/org/jf/smali/smaliParser.g index 6417f401..9b2b4e4f 100644 --- a/smali/src/main/antlr3/org/jf/smali/smaliParser.g +++ b/smali/src/main/antlr3/org/jf/smali/smaliParser.g @@ -191,18 +191,20 @@ smali_file } if (!$smali_file::hasSuperSpec) { - throw new SemanticException(input, "The file must contain a .super directive"); + if (!$class_spec.className.equals("Ljava/lang/Object;")) { + throw new SemanticException(input, "The file must contain a .super directive"); + } } } -> ^(I_CLASS_DEF class_spec - super_spec + super_spec? implements_spec* source_spec? ^(I_METHODS method*) ^(I_FIELDS field*) ^(I_ANNOTATIONS annotation*)); -class_spec - : CLASS_DIRECTIVE access_list CLASS_DESCRIPTOR -> CLASS_DESCRIPTOR access_list; +class_spec returns[String className] + : CLASS_DIRECTIVE access_list CLASS_DESCRIPTOR {$className = $CLASS_DESCRIPTOR.text;} -> CLASS_DESCRIPTOR access_list; super_spec : SUPER_DIRECTIVE CLASS_DESCRIPTOR -> ^(I_SUPER[$start, "I_SUPER"] CLASS_DESCRIPTOR); diff --git a/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g b/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g index f0d8aa3d..ce415192 100644 --- a/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g +++ b/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g @@ -142,7 +142,7 @@ smali_file header returns[TypeIdItem classType, int accessFlags, TypeIdItem superType, TypeListItem implementsList, StringIdItem sourceSpec] -: class_spec super_spec implements_list source_spec +: class_spec super_spec? implements_list source_spec { classDataItem = new ClassDataItem(dexFile, 0); classDefItem = new ClassDefItem(dexFile, $class_spec.type, $class_spec.accessFlags,