void ProcessIndex() { if (mobi_header.skel_index != 0xffffffff) { skeleton_table = new List <Skeleton_item>(); INDX_Section_Main main_indx = new INDX_Section_Main(GetSectionData(mobi_header.skel_index), "INDX(Skeleton)"); sections[mobi_header.skel_index] = main_indx; main_indx.ReadTag(); for (uint i = 0; i < main_indx.header.any_count; i++) { INDX_Section_Extra ext_indx = new INDX_Section_Extra(GetSectionData(mobi_header.skel_index + i + 1), main_indx); ext_indx.ReadTagMap(); sections[mobi_header.skel_index + i + 1] = ext_indx; for (int j = 0; j < ext_indx.texts.Length; j++) { List <int> values = (List <int>)(ext_indx.tagmaps[j][1]);//有点毛病……结果OK skeleton_table.Add(new Skeleton_item(ext_indx.texts[j], values[0], values[2], values[3])); } } } if (mobi_header.frag_index != 0xffffffff) { Hashtable ctoc_dict = new Hashtable(); frag_table = new List <Fragment_item>(); INDX_Section_Main main_indx = new INDX_Section_Main(GetSectionData(mobi_header.frag_index), "INDX(Fragment)"); sections[mobi_header.frag_index] = main_indx; main_indx.ReadTag(); int ctoc_off = 0; for (uint i = 0; i < main_indx.header.ctoc_count; i++) { uint off = mobi_header.frag_index + main_indx.header.any_count + 1 + i; CTOC_Section ctoc = new CTOC_Section(GetSectionData(off)); sections[off] = ctoc; foreach (int key in ctoc.ctoc_data.Keys) { ctoc_dict[key + ctoc_off] = ctoc.ctoc_data[key]; } ctoc_off += 0x10000; } for (uint i = 0; i < main_indx.header.any_count; i++) { INDX_Section_Extra ext_indx = new INDX_Section_Extra(GetSectionData(mobi_header.frag_index + i + 1), main_indx); sections[mobi_header.frag_index + i + 1] = ext_indx; ext_indx.ReadTagMap(); for (int j = 0; j < ext_indx.texts.Length; j++) { List <int> values = (List <int>)(ext_indx.tagmaps[j][2]);//有点毛病……结果OK frag_table.Add(new Fragment_item(ext_indx.texts[j], (string)ctoc_dict[values[0]], values[1], values[2], values[3], values[4])); } } } if (mobi_header.guide_index != 0xffffffff) { Hashtable ctoc_dict = new Hashtable(); guide_table = new List <Guide_item>(); INDX_Section_Main main_indx = new INDX_Section_Main(GetSectionData(mobi_header.guide_index), "INDX(Guide)"); sections[mobi_header.guide_index] = main_indx; main_indx.ReadTag(); int ctoc_off = 0; for (uint i = 0; i < main_indx.header.ctoc_count; i++) { uint off = mobi_header.guide_index + main_indx.header.any_count + 1 + i; CTOC_Section ctoc = new CTOC_Section(GetSectionData(off)); sections[off] = ctoc; foreach (int key in ctoc.ctoc_data.Keys) { ctoc_dict[key + ctoc_off] = ctoc.ctoc_data[key]; } ctoc_off += 0x10000; } for (uint i = 0; i < main_indx.header.any_count; i++) { INDX_Section_Extra ext_indx = new INDX_Section_Extra(GetSectionData(mobi_header.guide_index + i + 1), main_indx); sections[mobi_header.guide_index + i + 1] = ext_indx; ext_indx.ReadTagMap(); for (int j = 0; j < ext_indx.texts.Length; j++) { List <int> values = (List <int>)(ext_indx.tagmaps[j][1]);//有点毛病……结果OK guide_table.Add(new Guide_item(ext_indx.texts[j], (string)ctoc_dict[values[0]], values[1])); } } } if (mobi_header.ncx_index != 0xffffffff) { ncx_table = new List <NCX_item>(); Hashtable ctoc_dict = new Hashtable(); INDX_Section_Main main_indx = new INDX_Section_Main(GetSectionData(mobi_header.ncx_index), "INDX(NCX)"); sections[mobi_header.ncx_index] = main_indx; main_indx.ReadTag(); int ctoc_off = 0; for (uint i = 0; i < main_indx.header.ctoc_count; i++) { uint off = mobi_header.ncx_index + main_indx.header.any_count + 1 + i; CTOC_Section ctoc = new CTOC_Section(GetSectionData(off)); sections[off] = ctoc; foreach (int key in ctoc.ctoc_data.Keys) { ctoc_dict[key + ctoc_off] = ctoc.ctoc_data[key]; } ctoc_off += 0x10000; } for (uint i = 0; i < main_indx.header.any_count; i++) { INDX_Section_Extra ext_indx = new INDX_Section_Extra(GetSectionData(mobi_header.ncx_index + i + 1), main_indx); sections[mobi_header.ncx_index + i + 1] = ext_indx; ext_indx.ReadTagMap(); for (int j = 0; j < ext_indx.tagmaps.Length; j++) { NCX_item item = new NCX_item(); item.name = ext_indx.texts[j]; foreach (var k in ext_indx.tagmaps[j]) { List <int> a = (List <int>)((DictionaryEntry)k).Value; item.fid = a[4]; item.off = a[5]; item.position = a[0]; item.length = a[1]; item.title = (string)ctoc_dict[a[2]]; break; } ncx_table.Add(item); } } } }
void ProcessIndex() { if (mobi_header.skel_index != 0xffffffff) { skeleton_table = new List <Skeleton_item>(); INDX_Section_Main main_indx = new INDX_Section_Main(GetSectionData(mobi_header.skel_index), "INDX(Skeleton)"); sections[mobi_header.skel_index] = main_indx; main_indx.ReadTag(); for (uint i = 0; i < main_indx.header.any_count; i++) { INDX_Section_Extra ext_indx = new INDX_Section_Extra(GetSectionData(mobi_header.skel_index + i + 1), main_indx); ext_indx.ReadTagMap(); sections[mobi_header.skel_index + i + 1] = ext_indx; for (int j = 0; j < ext_indx.texts.Length; j++) { List <int> values = (List <int>)(ext_indx.tagmaps[j][1]);//有点毛病……结果OK skeleton_table.Add(new Skeleton_item(ext_indx.texts[j], values[0], values[2], values[3])); } } } if (mobi_header.frag_index != 0xffffffff) { Hashtable ctoc_dict = new Hashtable(); frag_table = new List <Fragment_item>(); INDX_Section_Main main_indx = new INDX_Section_Main(GetSectionData(mobi_header.frag_index), "INDX(Fragment)"); sections[mobi_header.frag_index] = main_indx; main_indx.ReadTag(); int ctoc_off = 0; for (uint i = 0; i < main_indx.header.ctoc_count; i++) { uint off = mobi_header.frag_index + main_indx.header.any_count + 1 + i; CTOC_Section ctoc = new CTOC_Section(GetSectionData(off)); sections[off] = ctoc; foreach (int key in ctoc.ctoc_data.Keys) { ctoc_dict[key + ctoc_off] = ctoc.ctoc_data[key]; } ctoc_off += 0x10000; } for (uint i = 0; i < main_indx.header.any_count; i++) { INDX_Section_Extra ext_indx = new INDX_Section_Extra(GetSectionData(mobi_header.frag_index + i + 1), main_indx); sections[mobi_header.frag_index + i + 1] = ext_indx; ext_indx.ReadTagMap(); for (int j = 0; j < ext_indx.texts.Length; j++) { List <int> values = (List <int>)(ext_indx.tagmaps[j][2]);//有点毛病……结果OK frag_table.Add(new Fragment_item(ext_indx.texts[j], (string)ctoc_dict[values[0]], values[1], values[2], values[3], values[4])); } } } if (mobi_header.guide_index != 0xffffffff) { Hashtable ctoc_dict = new Hashtable(); guide_table = new List <Guide_item>(); INDX_Section_Main main_indx = new INDX_Section_Main(GetSectionData(mobi_header.guide_index), "INDX(Guide)"); sections[mobi_header.guide_index] = main_indx; main_indx.ReadTag(); int ctoc_off = 0; for (uint i = 0; i < main_indx.header.ctoc_count; i++) { uint off = mobi_header.guide_index + main_indx.header.any_count + 1 + i; CTOC_Section ctoc = new CTOC_Section(GetSectionData(off)); sections[off] = ctoc; foreach (int key in ctoc.ctoc_data.Keys) { ctoc_dict[key + ctoc_off] = ctoc.ctoc_data[key]; } ctoc_off += 0x10000; } for (uint i = 0; i < main_indx.header.any_count; i++) { INDX_Section_Extra ext_indx = new INDX_Section_Extra(GetSectionData(mobi_header.guide_index + i + 1), main_indx); sections[mobi_header.guide_index + i + 1] = ext_indx; ext_indx.ReadTagMap(); for (int j = 0; j < ext_indx.texts.Length; j++) { List <int> values = (List <int>)(ext_indx.tagmaps[j][1]);//有点毛病……结果OK guide_table.Add(new Guide_item(ext_indx.texts[j], (string)ctoc_dict[values[0]], values[1])); } } } if (mobi_header.ncx_index != 0xffffffff) { index_info_table = new List <IndexInfo_item>(); Hashtable ctoc_dict = new Hashtable(); INDX_Section_Main main_indx = new INDX_Section_Main(GetSectionData(mobi_header.ncx_index), "INDX(NCX)"); sections[mobi_header.ncx_index] = main_indx; main_indx.ReadTag(); int ctoc_off = 0; for (uint i = 0; i < main_indx.header.ctoc_count; i++) { uint off = mobi_header.ncx_index + main_indx.header.any_count + 1 + i; CTOC_Section ctoc = new CTOC_Section(GetSectionData(off)); sections[off] = ctoc; foreach (int key in ctoc.ctoc_data.Keys) { ctoc_dict[key + ctoc_off] = ctoc.ctoc_data[key]; } ctoc_off += 0x10000; } for (uint i = 0; i < main_indx.header.any_count; i++) { INDX_Section_Extra ext_indx = new INDX_Section_Extra(GetSectionData(mobi_header.ncx_index + i + 1), main_indx); sections[mobi_header.ncx_index + i + 1] = ext_indx; ext_indx.ReadTagMap(); for (int j = 0; j < ext_indx.tagmaps.Length; j++) { IndexInfo_item item = new IndexInfo_item(); item.name = ext_indx.texts[j]; foreach (var k in ext_indx.tagmaps[j]) { List <int> a = (List <int>)((DictionaryEntry)k).Value; item.position = a[0]; item.length = a[1]; item.title = (string)ctoc_dict[a[2]]; item.level = a[3]; if (item.level > 0) { item.parent = a[4]; item.fid = a[5]; item.off = a[6]; } else { switch (a.Count) { case 6: item.fid = a[4]; item.off = a[5]; break; case 8: item.children_start = a[4]; item.children_end = a[5]; item.fid = a[6]; item.off = a[7]; break; default: throw new Exception("Unhandled Error at INDX"); } } break; } index_info_table.Add(item); //Console.WriteLine($"{item.name} {item.fid} {item.off} {item.title}"); } } } }