public static void BuildAssertions(ClassesProcessor.ClassNode node) { ClassWrapper wrapper = node.GetWrapper(); StructField field = FindAssertionField(node); if (field != null) { string key = InterpreterUtil.MakeUniqueKey(field.GetName(), field.GetDescriptor() ); bool res = false; foreach (MethodWrapper meth in wrapper.GetMethods()) { RootStatement root = meth.root; if (root != null) { res |= ReplaceAssertions(root, wrapper.GetClassStruct().qualifiedName, key); } } if (res) { // hide the helper field wrapper.GetHiddenMembers().Add(key); } } }
private static StructField FindAssertionField(ClassesProcessor.ClassNode node) { ClassWrapper wrapper = node.GetWrapper(); bool noSynthFlag = DecompilerContext.GetOption(IFernflowerPreferences.Synthetic_Not_Set ); foreach (StructField fd in wrapper.GetClassStruct().GetFields()) { string keyField = InterpreterUtil.MakeUniqueKey(fd.GetName(), fd.GetDescriptor()); // initializer exists if (wrapper.GetStaticFieldInitializers().ContainsKey(keyField)) { // access flags set if (fd.HasModifier(ICodeConstants.Acc_Static) && fd.HasModifier(ICodeConstants.Acc_Final ) && (noSynthFlag || fd.IsSynthetic())) { // field type boolean FieldDescriptor fdescr = FieldDescriptor.ParseDescriptor(fd.GetDescriptor()); if (VarType.Vartype_Boolean.Equals(fdescr.type)) { Exprent initializer = wrapper.GetStaticFieldInitializers().GetWithKey(keyField); if (initializer.type == Exprent.Exprent_Function) { FunctionExprent fexpr = (FunctionExprent)initializer; if (fexpr.GetFuncType() == FunctionExprent.Function_Bool_Not && fexpr.GetLstOperands ()[0].type == Exprent.Exprent_Invocation) { InvocationExprent invexpr = (InvocationExprent)fexpr.GetLstOperands()[0]; if (invexpr.GetInstance() != null && invexpr.GetInstance().type == Exprent.Exprent_Const && "desiredAssertionStatus".Equals(invexpr.GetName()) && "java/lang/Class".Equals (invexpr.GetClassname()) && (invexpr.GetLstParameters().Count == 0)) { ConstExprent cexpr = (ConstExprent)invexpr.GetInstance(); if (VarType.Vartype_Class.Equals(cexpr.GetConstType())) { ClassesProcessor.ClassNode nd = node; while (nd != null) { if (nd.GetWrapper().GetClassStruct().qualifiedName.Equals(cexpr.GetValue())) { break; } nd = nd.parent; } if (nd != null) { // found enclosing class with the same name return(fd); } } } } } } } } } return(null); }
private static void ProcessClassRec(ClassesProcessor.ClassNode node, IDictionary <ClassWrapper, MethodWrapper> mapClassMeths, HashSet <ClassWrapper> setFound) { ClassWrapper wrapper = node.GetWrapper(); // search code foreach (MethodWrapper meth in wrapper.GetMethods()) { RootStatement root = meth.root; if (root != null) { DirectGraph graph = meth.GetOrBuildGraph(); graph.IterateExprents((Exprent exprent) => { foreach (KeyValuePair <ClassWrapper, MethodWrapper> ent in mapClassMeths) { if (ReplaceInvocations(exprent, ent.Key, ent.Value)) { setFound.Add(ent.Key); } } return(0); } ); } } // search initializers for (int j = 0; j < 2; j++) { VBStyleCollection <Exprent, string> initializers = j == 0 ? wrapper.GetStaticFieldInitializers () : wrapper.GetDynamicFieldInitializers(); for (int i = 0; i < initializers.Count; i++) { foreach (KeyValuePair <ClassWrapper, MethodWrapper> ent in mapClassMeths) { Exprent exprent = initializers[i]; if (ReplaceInvocations(exprent, ent.Key, ent.Value)) { setFound.Add(ent.Key); } string cl = IsClass14Invocation(exprent, ent.Key, ent.Value); if (cl != null) { initializers[i] = new ConstExprent(VarType.Vartype_Class, cl.Replace('.', '/'), exprent .bytecode); setFound.Add(ent.Key); } } } } // iterate nested classes foreach (ClassesProcessor.ClassNode nd in node.nested) { ProcessClassRec(nd, mapClassMeths, setFound); } }
private static void MapClassMethods(ClassesProcessor.ClassNode node, Dictionary < ClassWrapper, MethodWrapper> map) { bool noSynthFlag = DecompilerContext.GetOption(IFernflowerPreferences.Synthetic_Not_Set ); ClassWrapper wrapper = node.GetWrapper(); foreach (MethodWrapper method in wrapper.GetMethods()) { StructMethod mt = method.methodStruct; if ((noSynthFlag || mt.IsSynthetic()) && mt.GetDescriptor().Equals("(Ljava/lang/String;)Ljava/lang/Class;" ) && mt.HasModifier(ICodeConstants.Acc_Static)) { RootStatement root = method.root; if (root != null && root.GetFirst().type == Statement.Type_Trycatch) { CatchStatement cst = (CatchStatement)root.GetFirst(); if (cst.GetStats().Count == 2 && cst.GetFirst().type == Statement.Type_Basicblock && cst.GetStats()[1].type == Statement.Type_Basicblock && cst.GetVars()[0].GetVarType ().Equals(new VarType(ICodeConstants.Type_Object, 0, "java/lang/ClassNotFoundException" ))) { BasicBlockStatement body = (BasicBlockStatement)cst.GetFirst(); BasicBlockStatement handler = (BasicBlockStatement)cst.GetStats()[1]; if (body.GetExprents().Count == 1 && handler.GetExprents().Count == 1) { if (Body_Expr.Equals(body.GetExprents()[0]) && Handler_Expr.Equals(handler.GetExprents ()[0])) { Sharpen.Collections.Put(map, wrapper, method); break; } } } } } } // iterate nested classes foreach (ClassesProcessor.ClassNode nd in node.nested) { MapClassMethods(nd, map); } }