private static string IsClass14Invocation(Exprent exprent, ClassWrapper wrapper,
                                           MethodWrapper meth)
 {
     if (exprent.type == Exprent.Exprent_Function)
     {
         FunctionExprent fexpr = (FunctionExprent)exprent;
         if (fexpr.GetFuncType() == FunctionExprent.Function_Iif)
         {
             if (fexpr.GetLstOperands()[0].type == Exprent.Exprent_Function)
             {
                 FunctionExprent headexpr = (FunctionExprent)fexpr.GetLstOperands()[0];
                 if (headexpr.GetFuncType() == FunctionExprent.Function_Eq)
                 {
                     if (headexpr.GetLstOperands()[0].type == Exprent.Exprent_Field && headexpr.GetLstOperands
                             ()[1].type == Exprent.Exprent_Const && ((ConstExprent)headexpr.GetLstOperands()[
                                                                         1]).GetConstType().Equals(VarType.Vartype_Null))
                     {
                         FieldExprent field = (FieldExprent)headexpr.GetLstOperands()[0];
                         ClassesProcessor.ClassNode fieldnode = DecompilerContext.GetClassProcessor().GetMapRootClasses
                                                                    ().GetOrNull(field.GetClassname());
                         if (fieldnode != null && fieldnode.classStruct.qualifiedName.Equals(wrapper.GetClassStruct
                                                                                                 ().qualifiedName))
                         {
                             // source class
                             StructField fd = wrapper.GetClassStruct().GetField(field.GetName(), field.GetDescriptor
                                                                                    ().descriptorString);
                             // FIXME: can be null! why??
                             if (fd != null && fd.HasModifier(ICodeConstants.Acc_Static) && (fd.IsSynthetic() ||
                                                                                             DecompilerContext.GetOption(IFernflowerPreferences.Synthetic_Not_Set)))
                             {
                                 if (fexpr.GetLstOperands()[1].type == Exprent.Exprent_Assignment && fexpr.GetLstOperands
                                         ()[2].Equals(field))
                                 {
                                     AssignmentExprent asexpr = (AssignmentExprent)fexpr.GetLstOperands()[1];
                                     if (asexpr.GetLeft().Equals(field) && asexpr.GetRight().type == Exprent.Exprent_Invocation)
                                     {
                                         InvocationExprent invexpr = (InvocationExprent)asexpr.GetRight();
                                         if (invexpr.GetClassname().Equals(wrapper.GetClassStruct().qualifiedName) && invexpr
                                             .GetName().Equals(meth.methodStruct.GetName()) && invexpr.GetStringDescriptor().
                                             Equals(meth.methodStruct.GetDescriptor()))
                                         {
                                             if (invexpr.GetLstParameters()[0].type == Exprent.Exprent_Const)
                                             {
                                                 wrapper.GetHiddenMembers().Add(InterpreterUtil.MakeUniqueKey(fd.GetName(), fd.GetDescriptor
                                                                                                                  ()));
                                                 // hide synthetic field
                                                 return(((ConstExprent)invexpr.GetLstParameters()[0]).GetValue().ToString());
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        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 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);
            }
        }
示例#5
0
 public virtual string GetClassEntryName(StructClass cl, string entryName)
 {
     ClassesProcessor.ClassNode node = classProcessor.GetMapRootClasses().GetOrNull(cl
                                                                                    .qualifiedName);
     if (node.type != ClassesProcessor.ClassNode.Class_Root)
     {
         return(null);
     }
     else if (converter != null)
     {
         string simpleClassName = Sharpen.Runtime.Substring(cl.qualifiedName, cl.qualifiedName
                                                            .LastIndexOf('/') + 1);
         return(Sharpen.Runtime.Substring(entryName, 0, entryName.LastIndexOf('/') + 1) +
                simpleClassName + ".java");
     }
     else
     {
         return(Sharpen.Runtime.Substring(entryName, 0, entryName.LastIndexOf(".class")) +
                ".java");
     }
 }