public string load(string filename) { BinaryReaderLittleIndian b = new BinaryReaderLittleIndian(File.Open(filename, FileMode.Open)); if (b.ReadByte() != 0x42 || b.ReadByte() != 0x42 || b.ReadByte() != 0x43) { return("Missing magic bytes"); } Dictionary <UInt32, BBLblock> blocks = new Dictionary <UInt32, BBLblock>(); while (b.PeekChar() != -1) { byte type = b.ReadByte(); if (type == 0x1) { UInt32 pid = b.ReadUInt32(); UInt32 id = b.ReadByte() + (1000 * pid); string module = ""; for (byte[] chrs = b.ReadBytes(1); chrs[0] != 0x00; chrs = b.ReadBytes(1)) { module += System.Text.Encoding.ASCII.GetString(chrs); } module = module.ToUpper(); if (!data.ContainsKey(module)) { data[module] = new Dictionary <uint, bool>(); } id2module[id] = module; module2id[module] = id; } if (type == 0x2) { UInt32 pid = b.ReadUInt32(); UInt32 id = b.ReadByte() + (1000 * pid); UInt32 rva = b.ReadUInt32(); if (!id2module.ContainsKey(id)) { return("RVA refers to ID " + id + " that is not before defined"); } if (!data[id2module[id]].ContainsKey(rva)) { count++; } data[id2module[id]][rva] = true; } } return(null); }
public bool load(string filename) { data.Clear(); dataRanges.Clear(); BinaryReaderLittleIndian b = new BinaryReaderLittleIndian(File.Open(filename, FileMode.Open)); if (b.ReadByte() != 0x42 || b.ReadByte() != 0x42 || b.ReadByte() != 0x4C) { return(false); } while (b.PeekChar() != -1) { UInt32 fnameLen = b.ReadUInt32(); String fname = System.Text.Encoding.ASCII.GetString(b.ReadBytes((int)fnameLen)); fname = fname.ToUpper(); Dictionary <UInt32, BBLblock> blocks = new Dictionary <UInt32, BBLblock>(); dataRanges[fname] = b.ReadUInt32(); while (true) { BBLblock block; block.rva = b.ReadUInt32(); block.offset = b.ReadUInt32(); block.value = b.ReadByte(); if (block.rva == 0) { break; } blocks[block.rva] = block; } data[fname] = blocks; } return(true); }