/// <summary> /// Read the CodeView subsection directory /// </summary> /// https://github.com/JWasm/JWasm/blob/master/dbgcv.c public static List <Subsection> ReadSubsectionDirectory(LeImageReader fp, int dlfaBase) { // get number of subsections var cdnt = fp.ReadLeUInt16(); var subsecs = new List <Subsection>(); foreach (var i in Enumerable.Range(0, cdnt)) { // read subsection headers var usst = fp.ReadLeUInt16(); var module = fp.ReadLeUInt16(); var lfoStart = fp.ReadLeInt32(); var cb = fp.ReadLeUInt16(); // read subsection data var rdr = new LeImageReader(fp.Bytes, (uint)(lfoStart + dlfaBase)); var data = rdr.ReadBytes(cb); var sst = (SST)usst; // mash the subsection into one var FACTORY = new Dictionary <SST, Func <SST, ushort, byte[], Subsection> > { { SST.SST_MODULES, (s, m, d) => new sstModules(s, m, d) }, { SST.SST_PUBLICS, (s, m, d) => new sstPublics(s, m, d) }, { SST.SST_TYPE, (s, m, d) => new CodeViewTypes(s, m, d) } }; if (FACTORY.ContainsKey(sst)) { subsecs.Add(FACTORY[sst](sst, module, data)); } else { subsecs.Add(new Subsection(sst, module, data)); } } return(subsecs); }
public void ApplyRelocations(uint rvaReloc, uint size, uint baseOfImage, RelocationDictionary relocations) { ImageReader rdr = new LeImageReader(RawImage, rvaReloc); uint rvaStop = rvaReloc + size; while (rdr.Offset < rvaStop) { // Read fixup block header. uint page = rdr.ReadLeUInt32(); int cbBlock = rdr.ReadLeInt32(); if (page == 0 || cbBlock == 0) { break; } uint offBlockEnd = (uint)((int)rdr.Offset + cbBlock - 8); while (rdr.Offset < offBlockEnd) { ApplyRelocation(baseOfImage, page, rdr, relocations); } } }