private static void ResetExprentTypes(DirectGraph graph) { graph.IterateExprents((Exprent exprent) => { List <Exprent> lst = exprent.GetAllExprents(true); lst.Add(exprent); foreach (Exprent expr in lst) { if (expr.type == Exprent.Exprent_Var) { ((VarExprent)expr).SetVarType(VarType.Vartype_Unknown); } else if (expr.type == Exprent.Exprent_Const) { ConstExprent constExpr = (ConstExprent)expr; if (constExpr.GetConstType().typeFamily == ICodeConstants.Type_Family_Integer) { constExpr.SetConstType(new ConstExprent(constExpr.GetIntValue(), constExpr.IsBoolPermitted (), null).GetConstType()); } } } return(0); } ); }
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 UpdateVersions(DirectGraph graph, Dictionary <VarVersionPair, int> versions) { graph.IterateExprents((Exprent exprent) => { List <Exprent> lst = exprent.GetAllExprents(true); lst.Add(exprent); foreach (Exprent expr in lst) { if (expr.type == Exprent.Exprent_Var) { VarExprent var = (VarExprent)expr; int?version = versions.GetOrNullable(new VarVersionPair(var)); if (version != null) { var.SetVersion(version.Value); } } } return(0); } ); }
private void SetNewVarIndices(VarTypeProcessor typeProcessor, DirectGraph graph, VarVersionsProcessor previousVersionsProcessor) { Dictionary <VarVersionPair, VarType> mapExprentMaxTypes = typeProcessor.GetMapExprentMaxTypes (); Dictionary <VarVersionPair, VarType> mapExprentMinTypes = typeProcessor.GetMapExprentMinTypes (); Dictionary <VarVersionPair, int> mapFinalVars = typeProcessor.GetMapFinalVars(); CounterContainer counters = DecompilerContext.GetCounterContainer(); Dictionary <VarVersionPair, int> mapVarPaar = new Dictionary <VarVersionPair, int> (); Dictionary <int, int> mapOriginalVarIndices = new Dictionary <int, int>(); // map var-version pairs on new var indexes foreach (VarVersionPair pair in new List <VarVersionPair>(mapExprentMinTypes.Keys)) { if (pair.version >= 0) { int newIndex = pair.version == 1 ? pair.var : counters.GetCounterAndIncrement(CounterContainer .Var_Counter); VarVersionPair newVar = new VarVersionPair(newIndex, 0); Sharpen.Collections.Put(mapExprentMinTypes, newVar, mapExprentMinTypes.GetOrNull( pair)); Sharpen.Collections.Put(mapExprentMaxTypes, newVar, mapExprentMaxTypes.GetOrNull( pair)); if (mapFinalVars.ContainsKey(pair)) { Sharpen.Collections.Put(mapFinalVars, newVar, Sharpen.Collections.Remove(mapFinalVars , pair)); } Sharpen.Collections.Put(mapVarPaar, pair, newIndex); Sharpen.Collections.Put(mapOriginalVarIndices, newIndex, pair.var); } } // set new vars graph.IterateExprents((Exprent exprent) => { List <Exprent> lst = exprent.GetAllExprents(true); lst.Add(exprent); foreach (Exprent expr in lst) { if (expr.type == Exprent.Exprent_Var) { VarExprent newVar = (VarExprent)expr; int?newVarIndex = mapVarPaar.GetOrNullable(new VarVersionPair(newVar)); if (newVarIndex != null) { newVar.SetIndex(newVarIndex.Value); newVar.SetVersion(0); } } else if (expr.type == Exprent.Exprent_Const) { VarType maxType = mapExprentMaxTypes.GetOrNull(new VarVersionPair(expr.id, -1)); if (maxType != null && maxType.Equals(VarType.Vartype_Char)) { ((ConstExprent)expr).SetConstType(maxType); } } } return(0); } ); if (previousVersionsProcessor != null) { Dictionary <int, int> oldIndices = previousVersionsProcessor.GetMapOriginalVarIndices (); this.mapOriginalVarIndices = new Dictionary <int, int>(mapOriginalVarIndices.Count ); foreach (KeyValuePair <int, int> entry in mapOriginalVarIndices) { int value = entry.Value; int?oldValue = oldIndices.GetOrNullable(value); value = oldValue != null ? oldValue.Value : value; Sharpen.Collections.Put(this.mapOriginalVarIndices, entry.Key, value); } } else { this.mapOriginalVarIndices = mapOriginalVarIndices; } }
private bool ProcessVarTypes(DirectGraph graph) { return(graph.IterateExprents((Exprent exprent) => CheckTypeExprent(exprent) ? 0 : 1)); }