Ejemplo n.º 1
0
        private static SectionEntry CreateTestTree()
        {
            SectionEntry root = new SectionEntry("0");

            root.AddMany(new SectionEntry("1"), new SectionEntry("2"), new SectionEntry("9"), new SectionEntry("12"), new SectionEntry("13"));
            var n2 = (SectionEntry)root.Entries[1];

            n2.AddMany(new SectionEntry("3"), new ValueEntry("6"), new SectionEntry("7"));
            var n3 = (SectionEntry)n2.Entries[0];

            n3.AddMany(new ValueEntry("4"), new ValueEntry("5"));
            var n7 = (SectionEntry)n2.Entries[2];

            n7.AddMany(new ValueEntry("8"));
            var n9 = (SectionEntry)root.Entries[2];

            n9.AddMany(new ValueEntry("10"), new ValueEntry("11"));
            var n13 = (SectionEntry)root.Entries[4];

            n13.AddMany(new SectionEntry("14"), new ValueEntry("21"));
            var n14 = (SectionEntry)n13.Entries[0];

            n14.AddMany(new SectionEntry("15"), new SectionEntry("18"), new SectionEntry("19"));
            var n15 = (SectionEntry)n14.Entries[0];

            n15.AddMany(new ValueEntry("16"), new ValueEntry("17"));
            var n19 = (SectionEntry)n14.Entries[2];

            n19.AddMany(new ValueEntry("20"));
            return(root);
        }
Ejemplo n.º 2
0
        public void OnModifyEntry(Entry ent, TreeNodeAdv node)
        {
            ModifyEntryDialog diag = new ModifyEntryDialog();

            if (ent != null)
            {
                diag.Edited = ent.Clone();
            }
            diag.ShowDialog();

            if (diag.Confirmed)
            {
                TreePath     path   = node.Tree.GetPath(node);
                SectionEntry parent = (SectionEntry)node.Parent.Tag;

                int nodeIndex = node.Index;
                if (ent != null)
                {//if the entry is different, we need to remove the old one
                    parent.Entries.Remove(ent);
                    this.NodesRemoved(this, new TreeModelEventArgs(path.Up(), new int[] { node.Index }, new object[] { ent }));
                }
                if (diag.Edited != null)
                {//if the new entry exists (this was not just a deletion), we need to add it to the tree
                    parent.Entries.Insert(nodeIndex, diag.Edited);
                    diag.Edited.Parent = parent;
                    this.NodesInserted(this, new TreeModelEventArgs(path.Up(), new int[] { nodeIndex }, new object[] { diag.Edited }));
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a Import object from file and setup the import dir
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="header"></param>
        /// <param name="sections"></param>
        public Imports(Reader reader, Header header, Sections sections)
        {
            this.reader   = reader;
            this.header   = header;
            this.sections = sections;

            var importVirtualAddress = this.header.dataDirectoryHeader.importTableAddressDirectory.getVirtualAddress();

            // get the section that content the import address table
            SectionEntry importAddressTableSection = this.sections.getSectionFromVirtualAddress(importVirtualAddress);

            if (importAddressTableSection == null)
            {
                throw new Exception("The import address table is not in any sections");
            }

            // get the section that content the import directory
            SectionEntry importDirectorySection = this.sections.getSectionFromVirtualAddress(this.header.dataDirectoryHeader.importDirectory.getVirtualAddress());

            if (importDirectorySection == null)
            {
                throw new Exception("The import directory is not in any sections");
            }

            // check that the two data are in the same section
            if (importAddressTableSection.sectionId != importDirectorySection.sectionId)
            {
                throw new Exception("The import directory is not in the same section of import address table");
            }

            // set the section that content the imports data
            this.section = importAddressTableSection;
        }
Ejemplo n.º 4
0
 private void renderSectionHeaderDetail(SectionEntry header)
 {
     startDetailUpdate();
     addDetailLine(".nameoffs = 0x{0:x} ; \"{1}\"", header.nameoffs, header.Name);
     addDetailLine(".dataoffs = 0x{0:x}", header.dataoffs);
     addDetailLine(".size = {0} bytes", header.Size);
 }
Ejemplo n.º 5
0
 public void NestedReferenceTest()
 {
     SectionEntry root = GenerateTestTree();
     Entry n2 = root.Entries[1];
     // test the VNAME of n2, which points to the VNAME of n1 which also contains a reference
     Assert.AreEqual("First Node: A Value That Is A Name", FormattedReader.ParseValueRefs(n2, n2.FriendlyName));
 }
Ejemplo n.º 6
0
        public static IEnumerable <Entry> DepthFirstTraversal(this SectionEntry start)
        {
            // adapted from http://stackoverflow.com/a/5806795
            var visited = new HashSet <Entry>();
            var stack   = new Stack <Entry>();

            stack.Push(start);

            while (stack.Count != 0)
            {
                var current = stack.Pop();

                if (!visited.Add(current))
                {
                    continue;
                }

                yield return(current);

                var section = current as SectionEntry;
                if (section != null)
                {
                    var children = section.Entries.Where(n => !visited.Contains(n));

                    foreach (var neighbour in children.Reverse())
                    {
                        stack.Push(neighbour);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create Resource collector from file
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="header"></param>
        public Resources(Reader reader, Header header, Sections sections)
        {
            this.reader   = reader;
            this.header   = header;
            this.sections = sections;

            this.resourceTables = new List <ResourceDirectoryTable>();
            this.entries        = new List <Entry>();

            this.resourceSection = sections.getResourceSection();

            if (this.resourceSection == null)
            {
                throw new Exception("Fail to handle resources");
            }

            this.resourceBaseAddress = this.resourceSection.header.pointerToRawData.getValue();

            int baseOffset = this.resourceBaseAddress;

            // handle the root of the tree
            resourceTables.Add(new ResourceDirectoryTable(this, this.reader, this.entries, ref baseOffset));

            // read the next entry
            resourceTables[0].readEntries(ref baseOffset, true);
        }
Ejemplo n.º 8
0
        private static void InsertData()
        {
            using (var context = new ConferenceContext())
            {
                context.Database.EnsureCreated();

                var section1 = new SectionEntry
                {
                    Section  = "GIS",
                    City     = "Tomsk",
                    Name     = "Geoinformation Systems",
                    Location = "Lenina 2, 404"
                };

                var section2 = new SectionEntry
                {
                    Section  = "CS",
                    City     = "Tomsk",
                    Name     = "Computer Science",
                    Location = "Lenina 30, 206"
                };

                if (!context.SectionEntry.Any(s => s.Section == section1.Section))
                {
                    context.SectionEntry.Add(section1);
                }
                if (!context.SectionEntry.Any(s => s.Section == section2.Section))
                {
                    context.SectionEntry.Add(section2);
                }

                context.SaveChanges();
            }
        }
Ejemplo n.º 9
0
 public static void AddMany(this SectionEntry parent, params Entry[] items)
 {
     foreach (var item in items)
     {
         parent.Entries.Add(item);
         item.Parent = parent;
     }
 }
        public override bool Render()
        {
            RPLItemMeasurement rPLItemMeasurement = null;
            bool             flag           = true;
            string           author         = "";
            string           title          = "";
            string           description    = "";
            AutoFit          autoFit        = base.m_writer.AutoFit;
            float            num            = 0f;
            float            leftMargin     = 0f;
            float            rightMargin    = 0f;
            RPLPageLayout    rPLPageLayout  = null;
            List <RPLReport> rplReportCache = new List <RPLReport>();
            bool             flag2          = false;
            bool             flag3          = false;
            SectionEntry     sectionEntry   = null;

            while (!base.m_spbProcessing.Done)
            {
                if (!flag)
                {
                    base.m_writer.WritePageBreak();
                }
                base.m_spbProcessing.GetNextPage(out base.m_rplReport);
                RPLPageContent   rPLPageContent   = base.m_rplReport.RPLPaginatedPages[0];
                RPLReportSection rPLReportSection = rPLPageContent.GetNextReportSection();
                bool             flag4            = false;
                bool             flag5            = true;
                while (rPLReportSection != null)
                {
                    rPLItemMeasurement = rPLReportSection.Columns[0];
                    float           width  = rPLReportSection.BodyArea.Width;
                    RPLHeaderFooter footer = null;
                    SectionEntry    se     = null;
                    if (!flag5 || sectionEntry == null || string.CompareOrdinal(sectionEntry.SectionId, rPLReportSection.ID) != 0)
                    {
                        if (RSTrace.RenderingTracer.TraceVerbose)
                        {
                            RSTrace.RenderingTracer.Trace("The left or right margin is either <0 or the sum exceeds the page width.");
                        }
                        sectionEntry = (se = this.RenderHeaderFooters(rPLReportSection, flag5, ref flag4, rplReportCache, ref footer, ref flag2, ref flag3));
                    }
                    flag = base.SetFirstPageDimensions(flag, rPLPageContent, ref rPLPageLayout, ref leftMargin, ref rightMargin, ref num, ref title, ref author, ref description);
                    num  = base.RevisePageDimensions(leftMargin, rightMargin, num, width, autoFit);
                    base.RenderHeaderBetweenSections(rPLReportSection, flag5);
                    base.RenderBodyContent(width, rPLItemMeasurement);
                    rPLReportSection = base.AdvanceToNextSection(rPLPageContent, rPLReportSection, ref flag5, sectionEntry, footer, se);
                }
                if (!base.m_spbProcessing.Done && !flag4)
                {
                    base.m_rplReport.Release();
                }
            }
            base.m_writer.WriteParagraphEnd();
            base.m_writer.SetPageDimensions(base.m_pageHeight, num, leftMargin, rightMargin, rPLPageLayout.MarginTop, rPLPageLayout.MarginBottom);
            base.FinishRendering(rplReportCache, title, author, description);
            return(true);
        }
        internal override bool Render()
        {
            RPLItemMeasurement rPLItemMeasurement = null;
            bool             flag           = true;
            string           author         = "";
            string           title          = "";
            string           description    = "";
            AutoFit          autoFit        = m_writer.AutoFit;
            float            width          = 0f;
            float            leftMargin     = 0f;
            float            rightMargin    = 0f;
            RPLPageLayout    rplPageLayout  = null;
            List <RPLReport> rplReportCache = new List <RPLReport>();
            bool             hasHeaderSoFar = false;
            bool             hasFooterSoFar = false;
            SectionEntry     sectionEntry   = null;

            while (!m_spbProcessing.Done)
            {
                if (!flag)
                {
                    m_writer.WritePageBreak();
                }
                m_spbProcessing.GetNextPage(out m_rplReport);
                RPLPageContent   rPLPageContent   = m_rplReport.RPLPaginatedPages[0];
                RPLReportSection rPLReportSection = rPLPageContent.GetNextReportSection();
                bool             pageCached       = false;
                bool             firstSection     = true;
                while (rPLReportSection != null)
                {
                    rPLItemMeasurement = rPLReportSection.Columns[0];
                    float           width2 = rPLReportSection.BodyArea.Width;
                    RPLHeaderFooter footer = null;
                    SectionEntry    se     = null;
                    if (!firstSection || sectionEntry == null || string.CompareOrdinal(sectionEntry.SectionId, rPLReportSection.ID) != 0)
                    {
                        if (RSTrace.RenderingTracer.TraceVerbose)
                        {
                            RSTrace.RenderingTracer.Trace("The left or right margin is either <0 or the sum exceeds the page width.");
                        }
                        sectionEntry = (se = RenderHeaderFooters(rPLReportSection, firstSection, ref pageCached, rplReportCache, ref footer, ref hasHeaderSoFar, ref hasFooterSoFar));
                    }
                    flag  = SetFirstPageDimensions(flag, rPLPageContent, ref rplPageLayout, ref leftMargin, ref rightMargin, ref width, ref title, ref author, ref description);
                    width = RevisePageDimensions(leftMargin, rightMargin, width, width2, autoFit);
                    RenderHeaderBetweenSections(rPLReportSection, firstSection);
                    RenderBodyContent(width2, rPLItemMeasurement);
                    rPLReportSection = AdvanceToNextSection(rPLPageContent, rPLReportSection, ref firstSection, sectionEntry, footer, se);
                }
                if (!m_spbProcessing.Done && !pageCached)
                {
                    m_rplReport.Release();
                }
            }
            m_writer.WriteParagraphEnd();
            m_writer.SetPageDimensions(m_pageHeight, width, leftMargin, rightMargin, rplPageLayout.MarginTop, rplPageLayout.MarginBottom);
            FinishRendering(rplReportCache, title, author, description);
            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Indicate if import information exists
        /// </summary>
        /// <returns>True if import directory is valid</returns>
        public bool isImportPresent()
        {
            var importVirtualAddress = this.header.dataDirectoryHeader.importTableAddressDirectory.getVirtualAddress();

            // get the section that content the import address table
            SectionEntry importAddressTableSection = this.sections.getSectionFromVirtualAddress(importVirtualAddress);

            return(importAddressTableSection != null);
        }
Ejemplo n.º 13
0
        public void RecursiveSectionTest()
        {
            var          reader = new FormattedReader(new MemoryStream(Encoding.UTF8.GetBytes(RECURSIVE_FORMAT)));
            SectionEntry file   = reader.ReadFileFromString(RECURSIVE_FILE);
            var          second = (SectionEntry)((SectionEntry)((SectionEntry)((SectionEntry)((SectionEntry)file.Entries[0]).Entries[0]).Entries[2]).Entries[3]).Entries[3];

            Assert.AreEqual("Province", second.Entries[0].FriendlyName); //test that the second "from" was properly detected (by checking a value inside it)
            Assert.AreEqual("From", second.Entries[3].FriendlyName);     //test that the third "from" was properly detected
        }
Ejemplo n.º 14
0
        private SectionEntry GetSection1()
        {
            var section1 = new SectionEntry
            {
                Section  = "GIS",
                City     = "Tomsk",
                Name     = "Geoinformation Systems",
                Location = "Lenina 2, 404"
            };

            return(section1);
        }
Ejemplo n.º 15
0
        public void BasicReferenceTest()
        {
            SectionEntry root = GenerateTestTree();

            SectionEntry n1 = (SectionEntry)root.Entries[0];
            Entry n2 = root.Entries[1];
            Assert.AreEqual("First Node: A Value That Is A Name", FormattedReader.ParseValueRefs(n1, n1.FriendlyName)); //test the VNAME of n1 (relative value ref)
            Entry n1_1 = n1.Entries[0];
            Assert.AreEqual(n2, FormattedReader.ParseRef(n1_1, n1_1.Link)); //test the link of n1_1 (absolute ref)
            Entry n1_2 = n1.Entries[1];
            Assert.AreEqual(n1, FormattedReader.ParseRef(n1_2, n1_2.Link)); //test the link of n1_2 (relative ref that goes up the tree)
        }
Ejemplo n.º 16
0
        private SectionEntry GetSection2()
        {
            var section2 = new SectionEntry
            {
                Section  = "CS",
                City     = "Tomsk",
                Name     = "Computer Science",
                Location = "Lenina 30, 206"
            };

            return(section2);
        }
Ejemplo n.º 17
0
        public IEnumerable GetChildren(TreePath treePath)
        {
            if (this.RootSection == null)
            {
                return(null);
            }
            SectionEntry ed  = treePath.IsEmpty() ? this.RootSection : ((SectionEntry)treePath.LastNode);
            List <Entry> ret = new List <Entry>(ed.Entries);

            ret.Add(null);//a null entry, which will be the button for adding new entries
            return(ret);
        }
Ejemplo n.º 18
0
        private static SectionEntry GenerateTestTree()
        {
            SectionEntry root = new EntryGrouper();

            SectionEntry n1 = new SectionEntry("n1", "First Node: [!/n1-1:[VALUE]!]", null);
            root.Entries.Add(n1);
            n1.Parent = root;
            n1.Root = root;
            n1.Entries.Add(new ValueEntry("n1-1", "First Value", "string", "A Value That Is A Name", "!/n2", n1, root));
            n1.Entries.Add(new ValueEntry("n1-2", "Second Value", "misc", "something", "/..", n1, root));
            root.Entries.Add(new ValueEntry("n2", "[!/../n1:[VNAME]!]", "number", "a normal value", null, root, root));

            return root;
        }
Ejemplo n.º 19
0
        public void CompleteTraversalTest()
        {
            SectionEntry root = CreateTestTree();
            Entry        cur  = root.Entries[0];

            int n = 1;

            while (cur != null)
            {
                Assert.AreEqual(n.ToString(), cur.InternalName);
                cur = cur.Step();
                n++;
            }
        }
Ejemplo n.º 20
0
        public bool CanEdit(Entry entry)
        {
            SectionEntry ent = entry as SectionEntry;

            if (ent == null)
            {
                return(false);
            }
            if (!ent.Entries.Any(e => e.InternalName == "birth_name" || e.InternalName == "b_n"))
            {
                return(false);
            }

            return(true);
        }
        private void LoadSections(Stream mainStream, BinaryReader r)
        {
            int sectionCount = r.ReadUInt16();

            sections = new Dictionary <string, SectionEntry>((int)sectionCount);

            for (int sectionIndex = 0; sectionIndex < sectionCount; ++sectionIndex)
            {
                var section = new SectionEntry();
                section.name     = r.Read4C();
                section.size     = r.ReadUInt32();
                section.position = mainStream.Position;
                r.Skip((int)section.size - 8);
                sections.Add(section.name, section);
            }
        }
Ejemplo n.º 22
0
        public Entry GenerateDefault()
        {
            if (m_default == null)
            {
                m_default = new SectionEntry();
                m_default.InternalName = "";
                m_default.FriendlyName = "[!/birth_name:[VALUE]!]";
                ValueEntry bname = new ValueEntry();
                bname.InternalName = "birth_name";
                bname.FriendlyName = "Birth Name";
                bname.Parent       = m_default;
                m_default.Entries.Add(bname);
            }

            return(m_default.Clone());
        }
Ejemplo n.º 23
0
        public void FormattedReaderTest()
        {
            FormattedReader reader = new FormattedReader(TestsReference.FORMAT_PATH);
            SectionEntry    root   = reader.ReadFile(TestsReference.MIN_TEST_PATH);
            SectionEntry    player = new SectionEntry("player", "Player", null);

            player.Root   = root;
            player.Parent = root;
            player.Entries.Add(new ValueEntry("id", "Id", "number", "665369", null, player, root));
            player.Entries.Add(new ValueEntry("type", "Type", "number", "66", null, player, root));
            Assert.IsTrue(player.Equals(root.Entries[2]));
            Assert.AreEqual(12, root.Entries.Count);

            Entry  start   = root.Entries[0];
            string refpath = "..";

            Assert.AreEqual(start.Parent, FormattedReader.ParseRef(start, refpath));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Create a PE object from a file
        /// </summary>
        /// <param name="filePath"></param>
        public PE(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("Fail to open the executable");
            }

            this.fileName = new FileInfo(filePath).Name;

            this.reader = new Reader(filePath);

            this.header = new Header(this.reader);

            this.sections = new Sections(this.reader, this.header);

            // some times, executable could be import less (nasm compiled asm)
            // so idk how to handle this ...
            // throw new Exception("The import address table is not in any sections");
            if (isImportPresent())
            {
                this.imports = new Imports(this.reader, this.header, this.sections);
            }

            if (isResourcePresent())
            {
                this.resources = new Resources(this.reader, this.header, this.sections);
            }

            SectionEntry lastEntry = this.sections.getLastEntry();

            // calculate the EOF address
            this.endOfData = lastEntry.header.pointerToRawData.getValue() + lastEntry.header.sizeOfRawData.getValue();

            // check if there is more data
            this.EOFOverflow = this.endOfData != (int)this.reader.size();

            if (this.EOFOverflow)
            {
                overflowSize = (int)this.reader.size() - this.endOfData;
            }

            this.isMemoryPE = false;
        }
        private SectionEntry RenderHeaderFooters(RPLReportSection section, bool firstSection, ref bool pageCached, List <RPLReport> rplReportCache, ref RPLHeaderFooter footer, ref bool hasHeaderSoFar, ref bool hasFooterSoFar)
        {
            SectionEntry result = new SectionEntry(section);

            if (section.Footer != null)
            {
                footer = (section.Footer.Element as RPLHeaderFooter);
                if (footer.Children != null && footer.Children.Length != 0)
                {
                    hasFooterSoFar = true;
                }
            }
            if (section.Header != null)
            {
                RPLHeaderFooter rPLHeaderFooter = section.Header.Element as RPLHeaderFooter;
                if (rPLHeaderFooter.Children != null && rPLHeaderFooter.Children.Length != 0)
                {
                    hasHeaderSoFar = true;
                }
            }
            CachePage(ref pageCached, rplReportCache);
            m_inHeaderFooter = true;
            if (firstSection)
            {
                m_needsToResetTextboxes = true;
            }
            RPLItemMeasurement header = section.Header;

            if (hasHeaderSoFar)
            {
                m_writer.StartHeader();
                if (header != null)
                {
                    RenderRectangle((RPLContainer)header.Element, 0f, canGrow: true, header, new BorderContext(), inTablix: false, ignoreStyles: true);
                }
                m_writer.FinishHeader();
            }
            RPLItemMeasurement footer2 = section.Footer;

            if (hasFooterSoFar)
            {
                m_writer.StartFooter();
                if (footer2 != null)
                {
                    RenderRectangle((RPLContainer)footer2.Element, 0f, canGrow: true, footer2, new BorderContext(), inTablix: false, ignoreStyles: true);
                }
                m_writer.FinishFooter();
            }
            if (firstSection)
            {
                bool flag  = header != null;
                bool flag2 = flag && !(header.Element.ElementPropsDef as RPLHeaderFooterPropsDef).PrintOnFirstPage;
                bool flag3 = footer2 != null;
                bool flag4 = flag3 && !(footer2.Element.ElementPropsDef as RPLHeaderFooterPropsDef).PrintOnFirstPage;
                if ((flag2 || flag4) && (flag || flag3))
                {
                    if (hasHeaderSoFar)
                    {
                        m_writer.StartHeader(firstPage: true);
                        if (flag && !flag2)
                        {
                            RenderRectangle((RPLContainer)header.Element, 0f, canGrow: true, header, new BorderContext(), inTablix: false, ignoreStyles: true);
                        }
                        m_writer.FinishHeader();
                    }
                    if (hasFooterSoFar)
                    {
                        m_writer.StartFooter(firstPage: true);
                        if (flag3 && !flag4)
                        {
                            RenderRectangle((RPLContainer)footer2.Element, 0f, canGrow: true, footer2, new BorderContext(), inTablix: false, ignoreStyles: true);
                        }
                        m_writer.FinishFooter();
                    }
                    m_writer.HasTitlePage = true;
                }
                m_needsToResetTextboxes = false;
            }
            m_inHeaderFooter = false;
            return(result);
        }
Ejemplo n.º 26
0
			public Section(Stream stream)
			{
				BinaryReader rdr = new BinaryReader(stream);

				SectionLength = rdr.ReadUInt32();
				SizeUncompressed = rdr.ReadUInt32();
				SizeCompressed = rdr.ReadUInt32();
				EntryCount = rdr.ReadInt32();
				
				Entries = new ArrayList();

				long startPos = stream.Position;
				uint length = 0, o = 0;
				while (stream.Position < startPos + SectionLength)
				{
					SectionEntry entry = new SectionEntry(stream);
					length += entry.Length;
					entry.Offset = o;
					o += entry.Length;
                    Entries.Add(entry);
				}
				Debug.Assert(stream.Position == startPos + SectionLength, "bad section length encountered");
				Debug.Assert(length == SizeUncompressed, "section length mismatch");
			}
Ejemplo n.º 27
0
 private void bworker_DoWork(object sender, DoWorkEventArgs e)
 {
     System.Threading.Thread.CurrentThread.Name = "File Reader";
     m_resultEditor = reader.ReadFile(path);
 }