public virtual bool build_lib() { this.hunkFile.libs = new List<Lib>(); var lib_segments = new List<object>(); var seek_lib = true; var seek_main = false; int hunk_no = -1; uint lib_file_offset = ~0u; List<List<Hunk>> segment_list = null; List<Hunk> segment = null; foreach (var e in this.hunkFile.hunks) { var hunk_type = e.HunkType; // seeking for a LIB hunk if (seek_lib) { if (hunk_type == HunkType.HUNK_LIB) { segment_list = new List<List<Hunk>>(); lib_segments.Add(segment_list); seek_lib = false; seek_main = true; hunk_no = 0; // get start address of lib hunk in file lib_file_offset = ((LibraryHunk) e).lib_file_offset; } else throw new BadImageFormatException(string.Format("Expected lib hunk in lib: {0} {1}/{1:X}", e.HunkType, hunk_type)); } else if (seek_main) { // end of lib? -> index! if (hunk_type == HunkType.HUNK_INDEX) { seek_main = false; seek_lib = true; var lib_units = new List<LibUnit>(); if (!this.resolve_index_hunks((IndexHunk) e, segment_list, lib_units)) throw new BadImageFormatException("Error resolving index hunks."); var lib = new Lib { units = lib_units, lib_no = this.hunkFile.libs.Count, index = (IndexHunk) e }; this.hunkFile.libs.Add(lib); } else if (unit_valid_main_hunks.Contains(hunk_type)) { // start of a hunk segment = new List<Hunk> { e }; e.hunk_no = hunk_no; ++hunk_no; segment_list.Add(segment); seek_main = false; // calculate relative lib address var hunk_lib_offset = e.FileOffset - lib_file_offset; e.hunk_lib_offset = hunk_lib_offset; } else throw new BadImageFormatException(string.Format("Expected main hunk in lib: {0} {1}/{1:X}.", e.HunkType, (int) hunk_type)); } else { // end hunk if (hunk_type == HunkType.HUNK_END) { seek_main = true; // extra contents } else if (unit_valid_extra_hunks.Contains(hunk_type)) { segment.Add(e); } else throw new BadImageFormatException(string.Format("Unexpected hunk in lib: {0} {1}/{1:X}.", e.HunkType, (int) hunk_type)); } } return true; }
public virtual bool build_lib() { this.hunkFile.libs = new List <Lib>(); var lib_segments = new List <object>(); var seek_lib = true; var seek_main = false; int hunk_no = -1; uint lib_file_offset = ~0u; List <List <Hunk> > segment_list = null; List <Hunk> segment = null; foreach (var e in this.hunkFile.hunks) { var hunk_type = e.HunkType; // seeking for a LIB hunk if (seek_lib) { if (hunk_type == HunkType.HUNK_LIB) { segment_list = new List <List <Hunk> >(); lib_segments.Add(segment_list); seek_lib = false; seek_main = true; hunk_no = 0; // get start address of lib hunk in file lib_file_offset = ((LibraryHunk)e).lib_file_offset; } else { throw new BadImageFormatException(string.Format("Expected lib hunk in lib: {0} {1}/{1:X}", e.HunkType, hunk_type)); } } else if (seek_main) { // end of lib? -> index! if (hunk_type == HunkType.HUNK_INDEX) { seek_main = false; seek_lib = true; var lib_units = new List <LibUnit>(); if (!this.resolve_index_hunks((IndexHunk)e, segment_list, lib_units)) { throw new BadImageFormatException("Error resolving index hunks."); } var lib = new Lib { units = lib_units, lib_no = this.hunkFile.libs.Count, index = (IndexHunk)e }; this.hunkFile.libs.Add(lib); } else if (unit_valid_main_hunks.Contains(hunk_type)) { // start of a hunk segment = new List <Hunk> { e }; e.hunk_no = hunk_no; ++hunk_no; segment_list.Add(segment); seek_main = false; // calculate relative lib address var hunk_lib_offset = e.FileOffset - lib_file_offset; e.hunk_lib_offset = hunk_lib_offset; } else { throw new BadImageFormatException(string.Format("Expected main hunk in lib: {0} {1}/{1:X}.", e.HunkType, (int)hunk_type)); } } else { // end hunk if (hunk_type == HunkType.HUNK_END) { seek_main = true; // extra contents } else if (unit_valid_extra_hunks.Contains(hunk_type)) { segment.Add(e); } else { throw new BadImageFormatException(string.Format("Unexpected hunk in lib: {0} {1}/{1:X}.", e.HunkType, (int)hunk_type)); } } } return(true); }