Example #1
0
        private LispList <Pair <EdgeTag, Subroutine> > InsertInvariant(CFGBlock from, LispList <Pair <EdgeTag, Subroutine> > list,
                                                                       Method calledMethod, ref TypeNode type,
                                                                       LispList <Edge <CFGBlock, EdgeTag> > context)
        {
            IMetaDataProvider metadataDecoder = this.SubroutineFacade.MetaDataProvider;

            Property property;

            if (metadataDecoder.IsPropertySetter(calledMethod, out property) &&
                (metadataDecoder.IsAutoPropertyMember(calledMethod) || WithinConstructor(from, context)))
            {
                return(list);
            }

            if (metadataDecoder.IsConstructor(calledMethod))
            {
                type = metadataDecoder.DeclaringType(calledMethod);
            }

            Subroutine invariant = this.SubroutineFacade.GetInvariant(type);

            if (invariant != null)
            {
                var methodCallBlock = from as MethodCallBlock <Label>;
                if (methodCallBlock != null)
                {
                    EdgeTag first = methodCallBlock.IsNewObj ? EdgeTag.AfterNewObj : EdgeTag.AfterCall;
                    return(list.Cons(new Pair <EdgeTag, Subroutine> (first, invariant)));
                }
            }

            return(list);
        }
Example #2
0
        private static void GetILOffsets(APC pc, Method method, out int primaryILOffset, out int methodILOffset)
        {
            primaryILOffset = pc.ILOffset;
            if (pc.Block.Subroutine.IsMethod)
            {
                methodILOffset = 0;
                return;
            }
            // look through context
            FList <STuple <CFGBlock, CFGBlock, string> > context = pc.SubroutineContext;

            while (context != null)
            {
                if (context.Head.One.Subroutine.IsMethod)
                {
                    string topLabel = context.Head.Three;
                    if (topLabel == "exit" || topLabel == "entry" || topLabel.StartsWith("after"))
                    {
                        CFGBlock fromBlock = context.Head.One;
                        methodILOffset = fromBlock.ILOffset(fromBlock.PriorLast);
                    }
                    else
                    {
                        CFGBlock toBlock = context.Head.Two;
                        methodILOffset = toBlock.ILOffset(toBlock.First);
                    }
                    return;
                }
                context = context.Tail;
            }
            methodILOffset = primaryILOffset;
        }
Example #3
0
		private void WriteBlock(StringBuilder sb, CFGBlock block, int level, bool noCasing = false)
		{
			if (!noCasing) {
				if (block.HasValue)
					sb.AppendLine(String.Format("{0}{1} {2}", GetTabSpacing(level), block.Name, GetValue(block.Value)));
				else
					sb.AppendLine(String.Format("{0}{1}", new String('\t', level), block.Name));

				sb.AppendLine(String.Format("{0}{{", GetTabSpacing(level)));
			}

			int newLevel = level;
			if (!noCasing)
				newLevel++;

			foreach (CFGBlock b in block.Blocks) {
				WriteBlock(sb, b, newLevel);
				sb.AppendLine();
			}

			foreach (CFGProperty property in block)
				WriteProperty(sb, property, newLevel);

			if (!noCasing) {
				sb.AppendLine(String.Format("{0}}}", GetTabSpacing(level)));
			}
		}
 public void Initialize(CFGBlock cfgBlock)
 {
     foreach (var cfgAnalysis in _analyses)
     {
         cfgAnalysis.Value.Initialize(cfgBlock);
     }
 }
Example #5
0
 public EquationBlock(CFGBlock ID)
 {
     this.id = ID;
     this.formalParameters = new List <string>();
     this.bodies           = new List <EquationBody>();
     this.condition        = null;
 }
Example #6
0
 public EquationBlock(CFGBlock ID)
 {
     id = ID;
     formalParameters = new List <string>();
     bodies           = new List <EquationBody>();
     condition        = null;
 }
Example #7
0
        private void ElseIfStatementsEnter(XmlNode node)
        {
            var conditionNode = new CFGBlock {
                AstEntryNode = node
            };
            var trueNode = new CFGBlock();

            var currentScope = scopeHandler.GetIfStmt();
            TaggedEdge <CFGBlock, EdgeTag> toCurrentConditionNode;

            if (currentScope.ElseifBlock != null)
            {
                toCurrentConditionNode = new TaggedEdge <CFGBlock, EdgeTag>(currentScope.ElseifBlock, conditionNode, new EdgeTag(EdgeType.False));
            }
            else
            {
                toCurrentConditionNode = new TaggedEdge <CFGBlock, EdgeTag>(currentScope.EntryBlock, conditionNode, new EdgeTag(EdgeType.False));
            }

            var toTrueNodeEdge = new TaggedEdge <CFGBlock, EdgeTag>(conditionNode, trueNode, new EdgeTag(EdgeType.True));

            Graph.AddVerticesAndEdge(toCurrentConditionNode);
            currentScope.ElseifBlock = conditionNode;

            Graph.AddVerticesAndEdge(toTrueNodeEdge);

            DoNotVisitChildren(Conditional.GetCondNode(node));
            CurrentBlock = trueNode;
        }
Example #8
0
        private void DoStatementEnter(XmlNode node)
        {
            var loopEntryBlock = new CFGBlock();

            if (!CurrentBlock.BreaksOutOfScope)
            {
                loopEntryBlock = ConnectNewBlockTo(CurrentBlock, EdgeType.Normal);
            }
            Graph.AddVertex(loopEntryBlock);
            CurrentBlock = loopEntryBlock;

            CFGBlock conditionBlock = new CFGBlock {
                AstEntryNode = node
            };
            CFGBlock loopDoneBlock = ConnectNewBlockTo(conditionBlock, EdgeType.False);

            ConnectBlocks(conditionBlock, loopEntryBlock, EdgeType.True);

            var loopScope = new LoopScope(loopEntryBlock)
            {
                LoopBodyStartBlock  = loopEntryBlock,
                LoopConditionBlock  = conditionBlock,
                ContinueDestination = conditionBlock,
                EndBlock            = loopDoneBlock,
            };

            scopeHandler.EnterLoop(loopScope);
            DoNotVisitChildren(Conditional.GetCondNode(node));
        }
Example #9
0
        private void IfStatementEnter(XmlNode node)
        {
            if (CurrentBlock.BreaksOutOfScope)
            {
                CurrentBlock = new CFGBlock();
                Graph.AddVertex(CurrentBlock);
            }
            CFGBlock conditionBlock = ConnectNewBlockTo(CurrentBlock, EdgeType.Normal);

            CurrentBlock = conditionBlock;

            CFGBlock trueBlock = ConnectNewBlockTo(CurrentBlock, EdgeType.True);

            CurrentBlock = trueBlock;

            conditionBlock.AstEntryNode = node;

            var ifScope = new IfScope(conditionBlock, trueBlock)
            {
                EndBlock = new CFGBlock()
            };

            Graph.AddVertex(ifScope.EndBlock);

            DoNotVisitChildren(Conditional.GetCondNode(node));
            scopeHandler.PushIfStmt(ifScope);
        }
Example #10
0
        private LispList <Handler> ProtectingHandlerList(CFGBlock block)
        {
            LispList <Handler> list;

            this.ProtectingHandlers.TryGetValue(block, out list);
            return(list);
        }
Example #11
0
        private int PatchPriorBeginOld(CFGBlock endBlock, int endOldIndex, out CFGBlock beginBlock)
        {
            for (int i = this == endBlock ? endOldIndex - 2 : Count - 1; i >= 0; i--)
            {
                int endOldI;
                if (IsBeginOld(i, out endOldI))
                {
                    this.overridingLabels [i] = BeginOldMask | (uint)endOldIndex;
                    beginBlock = this;
                    Subroutine.AddInferredOldMap(this.Index, i, endBlock, default(TypeNode));
                    return(i);
                }
            }

            IEnumerator <CFGBlock> enumerator = Subroutine.PredecessorBlocks(this).GetEnumerator();

            if (!enumerator.MoveNext())
            {
                throw new InvalidOperationException("missing begin_old");
            }
            int result = PatchPriorBeginOld(endBlock, endOldIndex, enumerator.Current, out beginBlock);

            enumerator.MoveNext();
            return(result);
        }
Example #12
0
        public override Result ForwardDecode <Data, Result, Visitor> (APC pc, Visitor visitor, Data data)
        {
            Label label;

            if (TryGetLabel(pc.Index, out label))
            {
                return(base.ForwardDecode <Data, Result, Visitor> (pc, visitor, data));
            }

            int endOldIndex;

            if (IsBeginOld(pc.Index, out endOldIndex))
            {
                CFGBlock block = Subroutine.InferredBeginEndBijection(pc);
                return(visitor.BeginOld(pc, new APC(block, endOldIndex, pc.SubroutineContext), data));
            }

            int beginOldIndex;

            if (IsEndOld(pc.Index, out beginOldIndex))
            {
                TypeNode endOldType;
                CFGBlock block = Subroutine.InferredBeginEndBijection(pc, out endOldType);
                return(visitor.EndOld(pc, new APC(block, beginOldIndex, pc.SubroutineContext), endOldType, Dummy.Value, Dummy.Value, data));
            }

            return(visitor.Nop(pc, data));
        }
Example #13
0
 private void AddBaseRequires(CFGBlock targetOfEntry, IImmutableSet <Subroutine> inherited)
 {
     foreach (var subroutine in inherited.Elements)
     {
         this.AddEdgeSubroutine(this.Entry, targetOfEntry, subroutine, EdgeTag.Inherited);
     }
 }
Example #14
0
 private StackInfo ComputeBlockStartDepth(CFGBlock block)
 {
     if (block.Subroutine.IsCatchFilterHeader(block))
     {
         return(new StackInfo(1, 2));
     }
     return(new StackInfo(0, 4));
 }
Example #15
0
        private Edge <CFGBlock> ConnectBlocks(CFGBlock source, CFGBlock target, EdgeType edgeType)
        {
            var edge = new TaggedEdge <CFGBlock, EdgeTag>(source, target, new EdgeTag(edgeType));

            Graph.AddEdge(edge);

            return(edge);
        }
Example #16
0
        public void SetStartState(CFGBlock succ)
        {
            ScanState sstate;

            if (!this.block_start_state.TryGetValue(succ, out sstate))
            {
                this.block_start_state.Add(succ, this.state);
            }
        }
Example #17
0
        private CFGBlock ConnectNewBlockTo(CFGBlock block, EdgeType edgeType)
        {
            var newBlock = new CFGBlock();
            var edge     = new TaggedEdge <CFGBlock, EdgeTag>(block, newBlock, new EdgeTag(edgeType));

            Graph.AddVerticesAndEdge(edge);

            return(newBlock);
        }
Example #18
0
        public override bool IsSplitPoint(CFGBlock block)
        {
            if (IsSubroutineStart(block) || IsSubroutineEnd(block))
            {
                return(true);
            }

            return(SuccessorEdges [block].Count > 1);
        }
Example #19
0
        public override bool IsJoinPoint(CFGBlock block)
        {
            if (IsCatchFilterHeader(block) || IsSubroutineStart(block) || IsSubroutineEnd(block))
            {
                return(true);
            }

            return(PredecessorEdges [block].Count > 1);
        }
Example #20
0
 public IEnumerable <SubroutineContext> CachedContexts(CFGBlock block)
 {
     foreach (KeyValuePair <APC, AState> kv in this.JoinStates())
     {
         if (kv.Key.Index == 0 && kv.Key.Block == block)
         {
             yield return(kv.Key.SubroutineContext);
         }
     }
 }
Example #21
0
        private void AddStartDepth(Dictionary <int, StackInfo> dict, CFGBlock block, StackInfo stackDepth)
        {
            StackInfo stackInfo;

            if (dict.TryGetValue(block.Index, out stackInfo))
            {
                return;
            }
            dict.Add(block.Index, stackDepth.Clone());
        }
Example #22
0
        public override IEnumerable <CFGBlock> ExceptionHandlers <Data, TType> (CFGBlock block, Subroutine innerSubroutine,
                                                                                Data data, IHandlerFilter <Data> handlerPredicate)
        {
            IHandlerFilter <Data> handleFilter       = handlerPredicate;
            LispList <Handler>    protectingHandlers = ProtectingHandlerList(block);

            if (innerSubroutine != null && innerSubroutine.IsFaultFinally)
            {
                for (; protectingHandlers != null; protectingHandlers = protectingHandlers.Tail)
                {
                    if (IsFaultOrFinally(protectingHandlers.Head) && this.FaultFinallySubroutines [protectingHandlers.Head] == innerSubroutine)
                    {
                        protectingHandlers = protectingHandlers.Tail;
                        break;
                    }
                }
            }

            for (; protectingHandlers != null; protectingHandlers = protectingHandlers.Tail)
            {
                Handler handler = protectingHandlers.Head;
                if (!IsFaultOrFinally(handler))
                {
                    if (handleFilter != null)
                    {
                        bool stopPropagation;
                        if (CodeProvider.IsCatchHandler(handler))
                        {
                            if (handleFilter.Catch(data, CodeProvider.CatchType(handler), out stopPropagation))
                            {
                                yield return(this.CatchFilterHeaders [handler]);
                            }
                        }
                        else if (handleFilter.Filter(data, new APC(this.FilterCodeBlocks [handler], 0, null), out stopPropagation))
                        {
                            yield return(this.CatchFilterHeaders [handler]);
                        }
                        if (stopPropagation)
                        {
                            yield break;
                        }
                    }
                    else
                    {
                        yield return(this.CatchFilterHeaders [handler]);
                    }

                    if (CodeProvider.IsCatchAllHandler(handler))
                    {
                        yield break;
                    }
                }
            }
            yield return(ExceptionExit);
        }
Example #23
0
        public bool IsSink(CFGBlock target)
        {
            Preconditions.NotNull(target, "target");

            if (target.AstEntryNode == null)
            {
                return(false);
            }

            return(this.sinks.Contains(target.AstEntryNode.LocalName));
        }
Example #24
0
        private object GetProperty(CFGBlock block, string name, object defaultVar)
        {
            CFGProperty property = block.GetFirstProperty(name);

            if (property == null)
            {
                return(defaultVar);
            }

            return(property.Values[0]);
        }
Example #25
0
 private void AddBaseEnsures(CFGBlock from, CFGBlock to, IImmutableSet <Subroutine> inherited)
 {
     if (inherited == null)
     {
         return;
     }
     foreach (Subroutine subroutine in inherited.Elements)
     {
         AddEdgeSubroutine(from, to, subroutine, EdgeTag.Inherited);
     }
 }
Example #26
0
        public override bool HasSinglePredecessor(APC point, out APC ifFound)
        {
            if (point.Index > 0)
            {
                ifFound = new APC(point.Block, point.Index - 1, point.SubroutineContext);
                return(true);
            }

            if (IsSubroutineStart(point.Block))
            {
                if (point.SubroutineContext == null)
                {
                    ifFound = APC.Dummy;
                    return(false);
                }

                bool hasSinglePredecessor;
                ifFound = ComputeSubroutinePreContinuation(point, out hasSinglePredecessor);
                return(hasSinglePredecessor);
            }


            CFGBlock onlyOne = null;

            foreach (CFGBlock predecessor in point.Block.Subroutine.PredecessorBlocks(point.Block))
            {
                if (onlyOne != null)
                {
                    ifFound = APC.Dummy;
                    return(false);
                }
                onlyOne = predecessor;
            }
            if (onlyOne == null)
            {
                ifFound = APC.Dummy;
                return(false);
            }

            LispList <Pair <EdgeTag, Subroutine> > list = EdgeSubroutinesOuterToInner(onlyOne, point.Block, point.SubroutineContext);

            if (list.IsEmpty())
            {
                ifFound = APC.ForEnd(onlyOne, point.SubroutineContext);
                return(true);
            }

            var        edge = new Edge <CFGBlock, EdgeTag> (onlyOne, point.Block, list.Head.Key);
            Subroutine sub  = list.Head.Value;

            ifFound = APC.ForEnd(sub.Exit, point.SubroutineContext.Cons(edge));
            return(true);
        }
Example #27
0
        public virtual IEnumerable <Pair <Dummy, CFGBlock> > Successors(CFGBlock node)
        {
            foreach (var pair in this.successor_edges[node])
            {
                yield return(new Pair <Dummy, CFGBlock> (Dummy.Value, pair.Value));
            }

            if (node != this.exception_exit)
            {
                yield return(new Pair <Dummy, CFGBlock> (Dummy.Value, this.exception_exit));
            }
        }
Example #28
0
 private void AnalyzeEcho(CFGBlock block, CFGTaintInfo taintInfo)
 {
     //var xssTaintedVars = taintInfo.In.Where(info => info.Value.XssTaint.TaintTags.Contains(XSSTaint.XSS_ALL))
     //                                 .Select(info => info.Key);
     //foreach (var taintedVar in xssTaintedVars)
     //{
     //    if (block.AstEntryNode.InnerText.Contains(taintedVar))
     //    {
     //        vulnerabilityReporter.ReportVulnerability(block, "XSS");
     //    }
     //}
 }
Example #29
0
        private static List<CFGBlock> MaterializeContainingLoop(Dictionary<CFGBlock, List<CFGBlock>> map, CFGBlock block)
        {
            Contract.Requires(map != null);// F: Added as of Clousot suggestion

            List<CFGBlock> result;
            if (!map.TryGetValue(block, out result))
            {
                result = new List<CFGBlock>();
                map.Add(block, result);
            }
            return result;
        }
Example #30
0
        public void Initialize(CFGBlock cfgBlock)
        {
            var taintInfo = CFGTaintInfo.Default;

            if (cfgBlock.IsRoot)
            {
                var varStorage = ImmutableDictionary <EdgeType, ImmutableVariableStorage> .Empty.Add(EdgeType.Normal, initialTaint);

                taintInfo = new CFGTaintInfo(initialTaint, varStorage);
            }
            _taints.Add(cfgBlock, taintInfo);
        }
Example #31
0
        public int GlobalStackDepth(APC pc)
        {
            int num = LocalStackDepth(pc);

            if (pc.SubroutineContext == null || !pc.Block.Subroutine.HasContextDependentStackDepth)
            {
                return(num);
            }

            CFGBlock block = pc.SubroutineContext.Head.From;

            return(num + GlobalStackDepth(APC.ForEnd(block, pc.SubroutineContext.Tail)));
        }
Example #32
0
        public override APC ComputeTargetFinallyContext(APC pc, CFGBlock succ)
        {
            LispList <Pair <EdgeTag, Subroutine> > list = EdgeSubroutinesOuterToInner(pc.Block, succ, pc.SubroutineContext);

            if (list.IsEmpty())
            {
                return(new APC(succ, 0, pc.SubroutineContext));
            }

            Pair <EdgeTag, Subroutine> last = list.Last();

            return(new APC(last.Value.Entry, 0, pc.SubroutineContext.Cons(new Edge <CFGBlock, EdgeTag> (pc.Block, succ, last.Key))));
        }
Example #33
0
 bool IsSplitPoint (CFGBlock block)
 {
         return block.Subroutine.IsSplitPoint (block);
 }
Example #34
0
		public Challenge(CFGBlock block)
			: this()
		{
			mName = block.Value;

			mID = Convert.ToInt32(GetProperty(block, "Id", mID));

			mSmallDesc = (string)GetProperty(block, "SmallDesc", String.Empty);
			mDesc = (string)GetProperty(block, "Desc", String.Empty);

			mReqOrangePegs = Convert.ToInt32(GetProperty(block, "NumOrange", 0));
			mReqScore = Convert.ToInt32(GetProperty(block, "ScoreReq", 0));
			mReqStyleScore = Convert.ToInt32(GetProperty(block, "StyleScoreReq", 0));
			mReqUniqueStyleShots = Convert.ToInt32(GetProperty(block, "UniqueStyleShotsReq", 0));
			mReqClearLevel = ((string)GetProperty(block, "ClearLevel", "false") == "true");

			mCharacter = (string)GetProperty(block, "Characters", String.Empty);
			mBalls = Convert.ToInt32(GetProperty(block, "Balls", 0));

			//Powerups
			CFGProperty[] cfgps = block.GetProperties("Powerups");
			string[] ppsv = new string[0];

			if (cfgps.Length > 0)
				ppsv = cfgps[0].Values.ToArray();
			
			foreach (string p in ppsv) {
				string pv = p.Replace(" ", "");
				pv = p.Replace("\t", "");
				string[] args = pv.Split('=');
				if (args.Length != 2)
					continue;

				string powerupName = args[0];
				int powerupCount = Convert.ToInt32(args[1]);

				SetPowerup(powerupName, powerupCount);
			}


			mScoreReset = ((string)GetProperty(block, "ScoreReset", "false") == "true");
			mNoFreeballs = ((string)GetProperty(block, "NoFreeballs", "false") == "true");
			mNoGreenPegs = ((string)GetProperty(block, "NoGreens", "false") == "true");
			mNoForceWin = ((string)GetProperty(block, "NoForceWin", "false") == "true");
			mFreeballBucketCovered = ((string)GetProperty(block, "FreeballCovered", "false") == "true");
			mNoEndOnWin = ((string)GetProperty(block, "NoEndOnWin", "false") == "true");

			mGravityMod = Convert.ToSingle(GetProperty(block, "GravityMod", 0.0f));
			mProjectileSpeedMod = Convert.ToSingle(GetProperty(block, "ProjSpeedMod", 0.0f));


			CFGProperty plevels = block.GetFirstProperty("Levels");
			foreach (string v in plevels.Values) {
				ChallengeLevel level = new ChallengeLevel();
				level.Level = v;
				mLevels.Add(level);
			}
		}
Example #35
0
		public CFGBlock GetCFGBlock()
		{
			CFGBlock block = new CFGBlock();
			block.Name = "Trophy";
			block.Value = mName;

			if (mID != 0)
				block.Properties.Add(new CFGProperty("Id", mID.ToString()));

			if (!String.IsNullOrEmpty(mSmallDesc))
				block.Properties.Add(new CFGProperty("SmallDesc", mSmallDesc));
			if (!String.IsNullOrEmpty(mDesc))
				block.Properties.Add(new CFGProperty("Desc", mDesc));
			if (mReqOrangePegs != 0)
				block.Properties.Add(new CFGProperty("NumOrange", mReqOrangePegs.ToString()));
			if (mReqScore != 0)
				block.Properties.Add(new CFGProperty("ScoreReq", mReqScore.ToString()));
			if (mReqStyleScore != 0)
				block.Properties.Add(new CFGProperty("StyleScoreReq", mReqStyleScore.ToString()));
			if (mReqUniqueStyleShots != 0)
				block.Properties.Add(new CFGProperty("UniqueStyleShotsReq", mReqUniqueStyleShots.ToString()));

			if (mReqClearLevel)
				block.Properties.Add(new CFGProperty("ClearLevel", "true"));

			if (!String.IsNullOrEmpty(mCharacter))
				block.Properties.Add(new CFGProperty("Characters", mCharacter));
			if (mBalls != 0)
				block.Properties.Add(new CFGProperty("Balls", mBalls.ToString()));

			//Levels
			List<string> levelNames = new List<string>();
			foreach (ChallengeLevel level in mLevels) {
				levelNames.Add(level.Level);
			}
			if (levelNames.Count != 0)
				block.Properties.Add(new CFGProperty("Levels", levelNames.ToArray()));

			if (mAgainstOpponents) {
				//Opponents
				List<string> opponents = new List<string>();
				foreach (ChallengeLevel level in mLevels) {
					opponents.Add(level.Opponent);
				}
				if (opponents.Count != 0)
					block.Properties.Add(new CFGProperty("Opponents", opponents.ToArray()));

				//Opponent difficulties
				List<string> opponentDifficulties = new List<string>();
				foreach (ChallengeLevel level in mLevels) {
					opponentDifficulties.Add(level.OpponentDifficulty.ToString());
				}
				if (opponentDifficulties.Count != 0)
					block.Properties.Add(new CFGProperty("OpponentDifficulty", opponentDifficulties.ToArray()));
			}


			//Powerups
			List<string> pvalues = new List<string>();

			PropertyInfo[] pi_array = GetType().GetProperties();
			foreach (PropertyInfo pi in pi_array) {
				if (pi.Name.StartsWith("Powerup")) {
					string name = pi.Name.Substring("Powerup".Length, pi.Name.Length - ("Powerup".Length));
					int value = (int)pi.GetValue(this, null);

					if (value == 0)
						continue;

					pvalues.Add(String.Format("{0}={1}", name, value));
				}
			}

			if (pvalues.Count != 0)
				block.Properties.Add(new CFGProperty("Powerups", pvalues.ToArray()));
			

			if (mScoreReset)
				block.Properties.Add(new CFGProperty("ScoreReset", "true"));
			if (mNoFreeballs)
				block.Properties.Add(new CFGProperty("NoFreeballs", "true"));
			if (mNoGreenPegs)
				block.Properties.Add(new CFGProperty("NoGreens", "true"));
			if (mNoForceWin)
				block.Properties.Add(new CFGProperty("NoForceWin", "true"));
			if (mFreeballBucketCovered)
				block.Properties.Add(new CFGProperty("FreeballCovered", "true"));
			if (mNoEndOnWin)
				block.Properties.Add(new CFGProperty("NoEndOnWin", "true"));

			if (mGravityMod != 0.0f)
				block.Properties.Add(new CFGProperty("GravityMod", mGravityMod.ToString()));
			if (mProjectileSpeedMod != 0.0f)
				block.Properties.Add(new CFGProperty("ProjSpeedMod", mProjectileSpeedMod.ToString()));

			return block;
		}
Example #36
0
 bool IsJoinPoint (CFGBlock block)
 {
         return block.Subroutine.IsJoinPoint (block);
 }
Example #37
0
		private object GetProperty(CFGBlock block, string name, object defaultVar)
		{
			CFGProperty property = block.GetFirstProperty(name);
			if (property == null)
				return defaultVar;

			return property.Values[0];
		}
Example #38
0
		private string WriteCFG()
		{
			CFGDocument document = new CFGDocument();
			CFGBlock docblock = new CFGBlock();

			//Number of stages needed
			int numStages = (int)Math.Ceiling((float)mLevels.Count / 5.0f);
			for (int i = 0; i < numStages; i++) {
				CFGBlock block = new CFGBlock();
				block.Name = "Stage";

				block.Properties.Add(new CFGProperty("Name", mName));
				block.Properties.Add(new CFGProperty("Desc", mDescription));

				for (int j = i * 5; j < Math.Min(mLevels.Count, (i + 1) * 5); j++) {
				    Level lvl = mLevels[j];
				    block.Properties.Add(new CFGProperty("Level", lvl.Info.Filename, lvl.Info.Name, lvl.Info.AceScore.ToString(), lvl.Info.MinStage.ToString()));
				}

				docblock.Blocks.Add(block);
			}

			//Challenges
			foreach (ChallengePage page in mChallengePages) {
				docblock.Blocks.Add(page.GetCFGBlock());
			}

			document.Blocks.Add(docblock);

			CFGWriter writer = new CFGWriter(document);
			return writer.GetText();
		}
Example #39
0
		public CFGReader(string inputText)
			: this()
		{
			//try {
				Stack<CFGBlock> blockStack = new Stack<CFGBlock>();
				blockStack.Push(new CFGBlock());

				StringReader reader = new StringReader(inputText);
				for (; ; ) {
					string line = reader.ReadLine();

					if (line == null)
						break;

					line = ParseLine(line);

					if (line.Length == 0)
						continue;

					int colonIndex = SpecialIndexOf(line, ':');
					if (colonIndex != -1) {
						//Its a property
						blockStack.Peek().Properties.Add(new CFGProperty(line));
					} else if (line.StartsWith("{")) {
						continue;
					} else if (line.StartsWith("}")) {
						CFGBlock block = blockStack.Pop();

						if (blockStack.Count > 0) {
							blockStack.Peek().Blocks.Add(block);
						} else {
							mDocument.Blocks.Add(block);
						}

					} else {
						//Block
						int space = SpecialIndexOf(line, ' ');
						int tab = SpecialIndexOf(line, '\t');

						int firstGap = space;
						if (tab != -1 && tab < space)
							firstGap = tab;

						if (firstGap != -1) {
							CFGBlock block = new CFGBlock();
							block.Name = line.Substring(0, firstGap);
							block.Value = Dequote(line.Substring(firstGap, line.Length - firstGap).Trim());

							blockStack.Push(block);
						} else {
							CFGBlock block = new CFGBlock();
							block.Name = line;

							blockStack.Push(block);
						}
					}
				}

				mDocument.Blocks.Add(blockStack.Pop());

			//} catch (Exception ex) {
			//    System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);

			//    MessageBox.Show(trace.GetFrame(0).GetMethod().Name);
			//    MessageBox.Show("Line: " + trace.GetFrame(0).GetFileLineNumber());
			//    MessageBox.Show("Column: " + trace.GetFrame(0).GetFileColumnNumber());
			//}
		}
Example #40
0
		LispList<Pair<EdgeTag, Subroutine>> IEdgeSubroutineAdaptor.GetOrdinaryEdgeSubroutinesInternal (CFGBlock @from, CFGBlock to,
		                                                                                               LispList<Edge<CFGBlock, EdgeTag>> context)
		{
			return DecoratorHelper.Inner<IEdgeSubroutineAdaptor> (this)
				.GetOrdinaryEdgeSubroutinesInternal (from, to, context).Where ((pair) => !pair.Value.IsContract && !pair.Value.IsOldValue);
		}
Example #41
0
 public IfScope(CFGBlock ifConditionNode, CFGBlock trueNode = null)
 {
     EntryBlock = ifConditionNode;
     this.TrueNode = trueNode;
 }