public SectionHeader AddSection(SectionBase sb) { if (Sections.Count == 16) { throw new Exception("Maximum sections."); } SectionHeader ret = new SectionHeader(); ret.Name = sb.Name; ret.VirtualSize = CreateBlock(sb).Length; ret.VirtualAddress = GetNextVirtualAddress(); ret.SizeOfRawData = Align(ret.VirtualSize, Specific.FileAlignment); ret.PointerToRawData = GetNextPointerToRawData(); switch (ret.Name) { case ".text": ret.Characteristics = IMAGE_SCN.CNT_CODE | IMAGE_SCN.CNT_INITIALIZED_DATA | IMAGE_SCN.MEM_EXECUTE | IMAGE_SCN.MEM_READ; break; case ".rdata": ret.Characteristics = IMAGE_SCN.CNT_INITIALIZED_DATA | IMAGE_SCN.MEM_READ; break; case ".bss": ret.Characteristics = IMAGE_SCN.CNT_UNINITIALIZED_DATA | IMAGE_SCN.MEM_READ | IMAGE_SCN.MEM_WRITE; break; default: ret.Characteristics = IMAGE_SCN.CNT_INITIALIZED_DATA | IMAGE_SCN.MEM_READ | IMAGE_SCN.MEM_WRITE; break; } sb.Header = ret; Sections.Add(sb); return ret; }
public Block32 CreateBlock(SectionBase sb) { if (sb.Header != null) return sb.ToBlock(sb.Header.VirtualAddress); else return sb.ToBlock(GetNextVirtualAddress()); }