public override uint ReadLong(uint address) { byte[] memory = new byte[4]; ReadMemory(address, 4, memory); return(Endian.Swap(System.BitConverter.ToUInt32(memory, 0))); }
public override ushort ReadWord(uint address) { byte[] memory = new byte[2]; ReadMemory(address, 2, memory); return(Endian.Swap(System.BitConverter.ToUInt16(memory, 0))); }
public bool Read(string filename) { //try { m_Symbols = new List <SymbolEntry>(); m_Filenames = new List <FilenameSection>(); byte[] data = System.IO.File.ReadAllBytes(filename); if (data.Length > 0) { GCHandle pinnedData = GCHandle.Alloc(data, GCHandleType.Pinned); IntPtr stream = pinnedData.AddrOfPinnedObject(); FilenameHeader filenameHeader = new FilenameHeader(); ChunkHeader chunkHeader = new ChunkHeader(); FilenameSection filenameSection = new FilenameSection(); AddressEntry addressEntry = new AddressEntry(); SymbolChunk symbolChunk = new SymbolChunk(); SymbolEntry symbolEntry = new SymbolEntry(); string readString; int bytesRead = 0; int currentLine = 0; //Read file header FileHeader fileHeader = new FileHeader(); bytesRead += Serialise(ref stream, out fileHeader); //Iterate over chunks while (bytesRead < data.Length) { //Read chunk header bytesRead += Serialise(ref stream, out chunkHeader); //What is it? switch (chunkHeader.chunkId) { case ChunkId.Filename: { //Read filename header bytesRead += Serialise(ref stream, out filenameHeader); filenameHeader.length = Endian.Swap(filenameHeader.length); //Read string bytesRead += Serialise(ref stream, filenameHeader.length, out readString); if (filenameHeader.flags == 0x1) { //This is the filename passed for assembly m_AssembledFile = readString; } else { //If filename already exists, continue adding data to it int sectionIdx = m_Filenames.FindIndex(element => element.filename == readString); if (sectionIdx >= 0) { //Continue filenameSection = m_Filenames[sectionIdx]; //Fetch line counter currentLine = filenameSection.addresses[filenameSection.addresses.Count - 1].lineTo; } else { //This is the first address in a filename chunk filenameSection = new FilenameSection(); filenameSection.addresses = new List <AddressEntry>(); filenameSection.filename = readString; //Reset line counter currentLine = 0; } //Chunk payload contains address addressEntry.address = chunkHeader.payload; addressEntry.lineFrom = currentLine; addressEntry.lineTo = filenameHeader.firstLine; currentLine = filenameHeader.firstLine; filenameSection.addresses.Add(addressEntry); //Add to filename list m_Filenames.Add(filenameSection); } break; } case ChunkId.Address: { //Chunk payload contains address addressEntry.address = chunkHeader.payload; //Set line range addressEntry.lineFrom = currentLine; currentLine++; addressEntry.lineTo = currentLine; //Add filenameSection.addresses.Add(addressEntry); break; } case ChunkId.AddressWithCount: { //Read line count byte lineCount = 0; bytesRead += Serialise(ref stream, out lineCount); //Chunk payload contains address addressEntry.address = chunkHeader.payload; //Set line range addressEntry.lineFrom = currentLine; currentLine += lineCount; addressEntry.lineTo = currentLine; //Add filenameSection.addresses.Add(addressEntry); break; } case ChunkId.Symbol: { //Read symbol string length byte stringLength = 0; bytesRead += Serialise(ref stream, out stringLength); //Read string bytesRead += Serialise(ref stream, stringLength, out symbolEntry.name); //Payload contains address symbolEntry.address = chunkHeader.payload; m_Symbols.Add(symbolEntry); break; } case ChunkId.EndOfSection: //Nothing of interest break; default: short mysteryWord = 0; bytesRead += Serialise(ref stream, out mysteryWord); break; } } pinnedData.Free(); //Build address to file/line map m_Addr2FileLine = new Dictionary <uint, Tuple <string, int> >(); foreach (FilenameSection section in m_Filenames) { foreach (AddressEntry address in section.addresses) { if (!m_Addr2FileLine.ContainsKey(address.address)) { m_Addr2FileLine[address.address] = new Tuple <string, int>(section.filename, address.lineTo); } } } return(true); } } //catch (Exception e) //{ // Console.WriteLine(e.Message); //} return(false); }