How to find "for" loop?

Jun 11, 2012 at 8:50 PM

HI, how to find "for" loop in assembly? 

Coordinator
Jun 11, 2012 at 8:53 PM

Check out the decompiler in the cciast project.

Jun 12, 2012 at 9:18 PM

Thanks for help.

            using (var host = new PeReader.DefaultHost())
            {
                var assembly = host.LoadUnitFrom(@"path") as IAssembly;
                var mutableAssembly = Decompiler.GetCodeModelFromMetadataModel(host, assembly, null, DecompilerOptions.Loops);                

                foreach (INamedTypeDefinition type in mutableAssembly.AllTypes)
                {                    
                    foreach (IMethodDefinition methodDefinition in type.Methods)
                    {                        
                        ISourceMethodBody source = (ISourceMethodBody)methodDefinition.Body;

                        foreach (IStatement statement in source.Block.Statements)
                        {
                            if (statement as ForStatement != null)
                            {
                                ForStatement forStatement = (ForStatement)statement;                              
      
                                //Some action
                            }

                        }
                        
                    }
                }                
            }