public void ReadCString() { var img = new LeImageReader(new byte[] { 0x12, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x00, 0x12 }, 1); StringConstant str = img.ReadCString(PrimitiveType.Char); Assert.AreEqual("Hello world!", str.ToString()); }
private List <ImageSegment> LoadPrimarySections() { List <ImageSegment> segments = new List <ImageSegment>((int)hdr.NumberOfSections + 1); int i; for (i = 0; i < hdr.NumberOfSections; i++) { XbeSectionHeader sectionHeader = rdr.ReadStruct <XbeSectionHeader>(); XbeSection section = new XbeSection(sectionHeader); string sectionName = rdr.ReadAt <string>(section.NameAddress - ctx.BaseAddress, (rdr) => { return(rdr.ReadCString(PrimitiveType.Char, Encoding.ASCII).ToString()); }); long sectionOffset = section.Address - ctx.EntryPointAddress; AccessMode accessFlgs = AccessMode.Read; if (sectionHeader.Flags.HasFlag(XbeSectionFlags.Executable)) { accessFlgs |= AccessMode.Execute; } if (sectionHeader.Flags.HasFlag(XbeSectionFlags.Writable)) { accessFlgs |= AccessMode.Write; } ImageSegment segment = new ImageSegment( sectionName, new ByteMemoryArea(section.Address, rdr.ReadAt <byte[]>(sectionOffset, (rdr) => { return(rdr.CreateBinaryReader().ReadBytes((int)sectionHeader.RawSize)); })), accessFlgs); segments.Add(segment); } return(segments); }