private List <ChapterListModel> GetChapterList(int chaptercount, int headlenth, byte[] buff, int key) { List <ChapterListModel> list = new List <ChapterListModel>(); ChapterListStruct blockFileList = new ChapterListStruct(); int num = 0; for (int i = 0; i < chaptercount; i++) { ChapterListModel model = new ChapterListModel(); byte[] buffs = new byte[0x18]; Array.Copy(buff, num, buffs, 0, buffs.Length); byte[] data = new byte[4]; Array.Copy(buffs, 12, data, 0, 4); Array.Copy(this.ebk3_data.pbk_sys_data_decode(data, key), 0, buffs, 12, 4); blockFileList = new ByteToStructEbk3().GetBlockFileList(buffs); model.chapter_index1 = blockFileList.chapter_index1; model.chapter_level2 = blockFileList.chapter_level2; model.chapter_data_type3 = blockFileList.chapter_data_type3; model.chapter_data_block_offset4 = blockFileList.chapter_data_block_offset4; model.chapter_content_decompresss_offset5 = blockFileList.chapter_content_decompresss_offset5; model.chapter_content_decompress_length6 = blockFileList.chapter_content_decompress_length6; model.chapter_name_length7 = blockFileList.chapter_name_length7; byte[] buffer3 = new byte[model.chapter_name_length7]; Array.Copy(buff, num + buffs.Length, buffer3, 0, buffer3.Length); model.chapter_name_data8 = Encoding.Unicode.GetString(this.ebk3_data.pbk_sys_data_decode(buffer3, key), 0, buffer3.Length); num += buffs.Length + buffer3.Length; list.Add(model); } return(list); }
private string Getchapter(byte[] blockdata, int type) { blockStruct blockStruct = new blockStruct(); GetData data = new GetData(); blockStruct = new ByteToStructEbk3().GetBlockStruct(blockdata); byte[] buffer = new byte[blockStruct.header_length - 12]; Array.Copy(blockdata, 12, buffer, 0, buffer.Length); blockinfoModel recodeBlockModel = this.GetRecodeBlockModel(this.ebk3_data.pbk_sys_data_decode(buffer, (int)blockStruct.decode_key), 11); if (recodeBlockModel.file_list_offset11 != 0) { byte[] buffer2 = new byte[blockdata.Length - recodeBlockModel.file_list_offset11]; Array.Copy(blockdata, (int)recodeBlockModel.file_list_offset11, buffer2, 0, buffer2.Length); } byte[] buffer3 = new byte[4]; Array.Copy(blockdata, (int)blockStruct.header_length, buffer3, 0, 4); int num = (int)BitConverter.ToUInt32(this.ebk3_data.pbk_sys_data_decode(buffer3, (int)blockStruct.decode_key), 0); int num2 = (int)(blockStruct.header_length + 4); byte[] buffer4 = new byte[0x1400000]; int num3 = 0; int num4 = 0; byte[] buffer5 = new byte[num * 4]; Array.Copy(blockdata, num2, buffer5, 0, buffer5.Length); byte[] buffer6 = this.ebk3_data.pbk_sys_data_decode(buffer5, (int)blockStruct.decode_key); for (int i = 0; i < num; i++) { byte[] buffer7 = new byte[4]; Array.Copy(buffer6, i * 4, buffer7, 0, 4); int num6 = (int)BitConverter.ToUInt32(buffer7, 0); byte[] buff = new byte[num6]; Array.Copy(blockdata, (num2 + (num * 4)) + num4, buff, 0, buff.Length); byte[] buffer9 = new byte[num6]; byte[] buffer10 = DeCompress.Decompress(data.decodeingtext(buff, (int)blockStruct.decode_key)); Array.Copy(buffer10, 0, buffer4, num3, buffer10.Length); num4 += num6; num3 += buffer10.Length; } byte[] bytes = new byte[num3]; Array.Copy(buffer4, 0, bytes, 0, bytes.Length); if (type == 0) { return(Encoding.Unicode.GetString(bytes, 0, bytes.Length)); } return(Encoding.Unicode.GetString(bytes, 0, bytes.Length)); }
public BookInfo Open(byte[] buffer) { EBK3HeadStruct headStruct = new EBK3HeadStruct(); EBK3HeadInfoModel recodeModel = new EBK3HeadInfoModel(); ChapterHeadModelStruct chapterHeadModelStruct = new ChapterHeadModelStruct(); new blockinfoModel(); new ChapterListModel(); DynDataStruct dynDataStruct = new DynDataStruct(); headStruct = new ByteToStructEbk3().GetHeadStruct(buffer); int key = (int)headStruct.decode_key; byte[] buffer2 = new byte[headStruct.header_length]; Array.Copy(buffer, 0, buffer2, 0, buffer2.Length); byte[] data = new byte[buffer2.Length - 0x10]; Array.Copy(buffer, 0x10, data, 0, data.Length); recodeModel = GetRecodeModel(this.ebk3_data.pbk_sys_data_decode(data, key), (int)recodeModel.modellenth); byte[] buffs = new byte[0x10]; Array.Copy(buffer, (int)recodeModel.chapter_dyn_info_offset5, buffs, 0, buffs.Length); dynDataStruct = new ByteToStructEbk3().GetDynDataStruct(buffs); byte[] buffer5 = new byte[dynDataStruct.chapter_list_length]; Array.Copy(buffer, (int)dynDataStruct.chapter_list_offset, buffer5, 0, buffer5.Length); chapterHeadModelStruct = new ByteToStructEbk3().GetChapterHeadModelStruct(buffer5); byte[] buff = new byte[buffer5.Length - 8]; Array.Copy(buffer5, 8, buff, 0, buff.Length); this.mChapterList = this.GetChapterList((int)chapterHeadModelStruct.chapter_count, (int)chapterHeadModelStruct.chapter_name_header_length, buff, key); this.mChapterList = this.SortChapterList(this.mChapterList); BookInfo info = new BookInfo(); info.BookName = recodeModel.name; info.Author = recodeModel.author; for (int i = 0; i < this.mChapterList.Count; i++) { ChapterListModel model2 = this.mChapterList[i]; if ((model2.chapter_data_type3 != 0) && (info.Text == "")) { byte[] blockdata = new byte[buffer.Length - model2.chapter_data_block_offset4]; Array.Copy(buffer, (int)model2.chapter_data_block_offset4, blockdata, 0, blockdata.Length); string chapter = this.Getchapter(blockdata, 1); info.Text = chapter; } } byte[] bytes = Encoding.Unicode.GetBytes(info.Text); int num3 = 0; int myindex = 0; for (int j = 0; j < this.mChapterList.Count; j++) { ChapterListModel model3 = this.mChapterList[j]; if (model3.chapter_data_type3 == 1) { if (num3 == 0) { BookItems items = new BookItems(model3.chapter_name_data8, 0, model3.chapter_name_data8.Length); info.ChaterList.Add(items); } else { ChapterListModel model4 = this.mChapterList[j - 1]; int num6 = (int)model4.chapter_content_decompresss_offset5; int num7 = (int)model4.chapter_content_decompress_length6; byte[] buffer9 = new byte[num7]; Array.Copy(bytes, num6, buffer9, 0, num7); string str2 = Encoding.Unicode.GetString(buffer9, 0, buffer9.Length); myindex += str2.Replace("\r\n", "\n").Length; BookItems items2 = new BookItems(model3.chapter_name_data8, myindex, model3.chapter_name_data8.Length); info.ChaterList.Add(items2); } num3++; } } return(info); }
private string GetOneChapter(byte[] blockdata, int type, int mChapterIndex) { blockStruct blockStruct = new blockStruct(); GetData data = new GetData(); blockStruct = new ByteToStructEbk3().GetBlockStruct(blockdata); byte[] buffer = new byte[blockStruct.header_length - 12]; Array.Copy(blockdata, 12, buffer, 0, buffer.Length); blockinfoModel recodeBlockModel = this.GetRecodeBlockModel(this.ebk3_data.pbk_sys_data_decode(buffer, (int)blockStruct.decode_key), 13); if (recodeBlockModel.file_list_offset11 != 0) { byte[] buffer2 = new byte[blockdata.Length - recodeBlockModel.file_list_offset11]; Array.Copy(blockdata, (int)recodeBlockModel.file_list_offset11, buffer2, 0, buffer2.Length); } byte[] buffer3 = new byte[4]; Array.Copy(blockdata, (int)blockStruct.header_length, buffer3, 0, 4); int num = (int)BitConverter.ToUInt32(this.ebk3_data.pbk_sys_data_decode(buffer3, (int)blockStruct.decode_key), 0); int num2 = (int)(blockStruct.header_length + 4); byte[] buffer4 = new byte[num * 4]; Array.Copy(blockdata, num2, buffer4, 0, buffer4.Length); byte[] buffer5 = this.ebk3_data.pbk_sys_data_decode(buffer4, (int)blockStruct.decode_key); uint num3 = this.mChapterList[mChapterIndex].chapter_content_decompresss_offset5 / 0x10000; if (num3 > num) { return(""); } int num4 = 0; int num5 = (int)(this.mChapterList[mChapterIndex].chapter_content_decompresss_offset5 % 0x10000); int num6 = 0; for (int i = 0; i < num3; i++) { byte[] buffer6 = new byte[4]; Array.Copy(buffer5, i * 4, buffer6, 0, 4); num6 = (int)BitConverter.ToUInt32(buffer6, 0); num4 += num6; } byte[] buffer7 = new byte[4]; Array.Copy(buffer5, (int)(num3 * 4), buffer7, 0, 4); num6 = (int)BitConverter.ToUInt32(buffer7, 0); byte[] buff = new byte[num6]; Array.Copy(blockdata, (num2 + (num * 4)) + num4, buff, 0, buff.Length); byte[] buffer9 = new byte[num6]; byte[] buffer10 = DeCompress.Decompress(data.decodeingtext(buff, (int)blockStruct.decode_key)); byte[] bytes = new byte[this.mChapterList[mChapterIndex].chapter_content_decompress_length6]; string str = ""; if ((num5 + bytes.Length) < 0x10000) { Array.Copy(buffer10, num5, bytes, 0, bytes.Length); } else { Array.Copy(buffer10, num5, bytes, 0, 0x10000 - num5); } if ((num5 + this.mChapterList[mChapterIndex].chapter_content_decompress_length6) > 0x10000L) { num3++; if (num3 >= num) { return(""); } int num1 = ((int)(num5 + this.mChapterList[mChapterIndex].chapter_content_decompress_length6)) % 0x10000; num6 = 0; num4 = 0; for (int j = 0; j < num3; j++) { byte[] buffer12 = new byte[4]; Array.Copy(buffer5, j * 4, buffer12, 0, 4); num6 = (int)BitConverter.ToUInt32(buffer12, 0); num4 += num6; } buffer7 = new byte[4]; Array.Copy(buffer5, (int)(num3 * 4), buffer7, 0, 4); num6 = (int)BitConverter.ToUInt32(buffer7, 0); buff = new byte[num6]; Array.Copy(blockdata, (num2 + (num * 4)) + num4, buff, 0, buff.Length); buffer9 = new byte[num6]; Array.Copy(DeCompress.Decompress(data.decodeingtext(buff, (int)blockStruct.decode_key)), 0, bytes, 0x10000 - num5, bytes.Length - (0x10000 - num5)); } if (type != 0) { str = Encoding.Unicode.GetString(bytes, 0, bytes.Length); } return(str); }