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); }
private static void ExtractDynamicInitializers(ClassWrapper wrapper) { StructClass cl = wrapper.GetClassStruct(); bool isAnonymous = DecompilerContext.GetClassProcessor().GetMapRootClasses().GetOrNull (cl.qualifiedName).type == ClassesProcessor.ClassNode.Class_Anonymous; List <List <Exprent> > lstFirst = new List <List <Exprent> >(); List <MethodWrapper> lstMethodWrappers = new List <MethodWrapper>(); foreach (MethodWrapper method in wrapper.GetMethods()) { if (ICodeConstants.Init_Name.Equals(method.methodStruct.GetName()) && method.root != null) { // successfully decompiled constructor Statement firstData = Statements.FindFirstData(method.root); if (firstData == null || (firstData.GetExprents().Count == 0)) { return; } lstFirst.Add(firstData.GetExprents()); lstMethodWrappers.Add(method); Exprent exprent = firstData.GetExprents()[0]; if (!isAnonymous) { // FIXME: doesn't make sense if (exprent.type != Exprent.Exprent_Invocation || !Statements.IsInvocationInitConstructor ((InvocationExprent)exprent, method, wrapper, false)) { return; } } } } if ((lstFirst.Count == 0)) { return; } while (true) { string fieldWithDescr = null; Exprent value = null; for (int i = 0; i < lstFirst.Count; i++) { List <Exprent> lst = lstFirst[i]; if (lst.Count < (isAnonymous ? 1 : 2)) { return; } Exprent exprent = lst[isAnonymous ? 0 : 1]; bool found = false; if (exprent.type == Exprent.Exprent_Assignment) { AssignmentExprent assignExpr = (AssignmentExprent)exprent; if (assignExpr.GetLeft().type == Exprent.Exprent_Field) { FieldExprent fExpr = (FieldExprent)assignExpr.GetLeft(); if (!fExpr.IsStatic() && fExpr.GetClassname().Equals(cl.qualifiedName) && cl.HasField (fExpr.GetName(), fExpr.GetDescriptor().descriptorString)) { // check for the physical existence of the field. Could be defined in a superclass. if (IsExprentIndependent(assignExpr.GetRight(), lstMethodWrappers[i])) { string fieldKey = InterpreterUtil.MakeUniqueKey(fExpr.GetName(), fExpr.GetDescriptor ().descriptorString); if (fieldWithDescr == null) { fieldWithDescr = fieldKey; value = assignExpr.GetRight(); } else if (!fieldWithDescr.Equals(fieldKey) || !value.Equals(assignExpr.GetRight())) { return; } found = true; } } } } if (!found) { return; } } if (!wrapper.GetDynamicFieldInitializers().ContainsKey(fieldWithDescr)) { wrapper.GetDynamicFieldInitializers().AddWithKey(value, fieldWithDescr); foreach (List <Exprent> lst in lstFirst) { lst.RemoveAtReturningValue(isAnonymous ? 0 : 1); } } else { return; } } }