Ejemplo n.º 1
0
        private static Exprent IsSimpleConstructorInvocation(Exprent exprent)
        {
            List <Exprent> lst = exprent.GetAllExprents();

            foreach (Exprent expr in lst)
            {
                Exprent ret = IsSimpleConstructorInvocation(expr);
                if (ret != null)
                {
                    exprent.ReplaceExprent(expr, ret);
                }
            }
            if (exprent.type == Exprent.Exprent_Invocation)
            {
                InvocationExprent @in = (InvocationExprent)exprent;
                if (@in.GetFunctype() == InvocationExprent.Typ_Init && @in.GetInstance().type ==
                    Exprent.Exprent_New)
                {
                    NewExprent newExpr = (NewExprent)@in.GetInstance();
                    newExpr.SetConstructor(@in);
                    @in.SetInstance(null);
                    return(newExpr);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        private static Exprent IsLambda(Exprent exprent, StructClass cl)
        {
            List <Exprent> lst = exprent.GetAllExprents();

            foreach (Exprent expr in lst)
            {
                Exprent ret = IsLambda(expr, cl);
                if (ret != null)
                {
                    exprent.ReplaceExprent(expr, ret);
                }
            }
            if (exprent.type == Exprent.Exprent_Invocation)
            {
                InvocationExprent @in = (InvocationExprent)exprent;
                if (@in.GetInvocationTyp() == InvocationExprent.Invoke_Dynamic)
                {
                    string lambda_class_name = cl.qualifiedName + @in.GetInvokeDynamicClassSuffix();
                    ClassesProcessor.ClassNode lambda_class = DecompilerContext.GetClassProcessor().GetMapRootClasses
                                                                  ().GetOrNull(lambda_class_name);
                    if (lambda_class != null)
                    {
                        // real lambda class found, replace invocation with an anonymous class
                        NewExprent newExpr = new NewExprent(new VarType(lambda_class_name, true), null, 0
                                                            , @in.bytecode);
                        newExpr.SetConstructor(@in);
                        // note: we don't set the instance to null with in.setInstance(null) like it is done for a common constructor invocation
                        // lambda can also be a reference to a virtual method (e.g. String x; ...(x::toString);)
                        // in this case instance will hold the corresponding object
                        return(newExpr);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        // propagate (var = new X) forward to the <init> invocation
        private static bool IsConstructorInvocationRemote(List <Exprent> list, int index)
        {
            Exprent current = list[index];

            if (current.type == Exprent.Exprent_Assignment)
            {
                AssignmentExprent @as = (AssignmentExprent)current;
                if (@as.GetLeft().type == Exprent.Exprent_Var && @as.GetRight().type == Exprent.Exprent_New)
                {
                    NewExprent     newExpr  = (NewExprent)@as.GetRight();
                    VarType        newType  = newExpr.GetNewType();
                    VarVersionPair leftPair = new VarVersionPair((VarExprent)@as.GetLeft());
                    if (newType.type == ICodeConstants.Type_Object && newType.arrayDim == 0 && newExpr
                        .GetConstructor() == null)
                    {
                        for (int i = index + 1; i < list.Count; i++)
                        {
                            Exprent remote = list[i];
                            // <init> invocation
                            if (remote.type == Exprent.Exprent_Invocation)
                            {
                                InvocationExprent @in = (InvocationExprent)remote;
                                if (@in.GetFunctype() == InvocationExprent.Typ_Init && @in.GetInstance().type ==
                                    Exprent.Exprent_Var && @as.GetLeft().Equals(@in.GetInstance()))
                                {
                                    newExpr.SetConstructor(@in);
                                    @in.SetInstance(null);
                                    list[i] = @as.Copy();
                                    return(true);
                                }
                            }
                            // check for variable in use
                            HashSet <VarVersionPair> setVars = remote.GetAllVariables();
                            if (setVars.Contains(leftPair))
                            {
                                // variable used somewhere in between -> exit, need a better reduced code
                                return(false);
                            }
                        }
                    }
                }
            }
            return(false);
        }
        static ClassReference14Processor()
        {
            InvocationExprent invFor = new InvocationExprent();

            invFor.SetName("forName");
            invFor.SetClassname("java/lang/Class");
            invFor.SetStringDescriptor("(Ljava/lang/String;)Ljava/lang/Class;");
            invFor.SetDescriptor(MethodDescriptor.ParseDescriptor("(Ljava/lang/String;)Ljava/lang/Class;"
                                                                  ));
            invFor.SetStatic(true);
            invFor.SetLstParameters(new [] { new VarExprent(0, VarType
                                                            .Vartype_String, null) }.Cast <Exprent>().ToList());
            Body_Expr = new ExitExprent(ExitExprent.Exit_Return, invFor, VarType.Vartype_Class
                                        , null);
            InvocationExprent ctor = new InvocationExprent();

            ctor.SetName(ICodeConstants.Init_Name);
            ctor.SetClassname("java/lang/NoClassDefFoundError");
            ctor.SetStringDescriptor("()V");
            ctor.SetFunctype(InvocationExprent.Typ_Init);
            ctor.SetDescriptor(MethodDescriptor.ParseDescriptor("()V"));
            NewExprent newExpr = new NewExprent(new VarType(ICodeConstants.Type_Object, 0, "java/lang/NoClassDefFoundError"
                                                            ), new List <Exprent>(), null);

            newExpr.SetConstructor(ctor);
            InvocationExprent invCause = new InvocationExprent();

            invCause.SetName("initCause");
            invCause.SetClassname("java/lang/NoClassDefFoundError");
            invCause.SetStringDescriptor("(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
            invCause.SetDescriptor(MethodDescriptor.ParseDescriptor("(Ljava/lang/Throwable;)Ljava/lang/Throwable;"
                                                                    ));
            invCause.SetInstance(newExpr);
            invCause.SetLstParameters(new List <Exprent>(new [] { new VarExprent(2,
                                                                                 new VarType(ICodeConstants.Type_Object, 0, "java/lang/ClassNotFoundException"),
                                                                                 null) }.ToList()));
            Handler_Expr = new ExitExprent(ExitExprent.Exit_Throw, invCause, null, null);
        }