protected internal override Cell ReadCellPayload(DexFile file, UInt32 rowIndex, Column column, Cell[] cells, ref UInt32 offset) { Cell result; Tables.encoded_catch_handler_row.columns colIdx = (Tables.encoded_catch_handler_row.columns)column.Index; switch (colIdx) { case Tables.encoded_catch_handler_row.columns.handlers: Int32 handler_size = (Int32)cells[(UInt32)Tables.encoded_catch_handler_row.columns.size].Value; UInt32[] indexes = file.GetSectionTable(TableType.encoded_type_addr_pair).ReadInnerSection(file, ref offset, (UInt32)Math.Abs(handler_size)); result = new Cell(column, (UInt32)indexes.Length, indexes); break; case Tables.encoded_catch_handler_row.columns.catch_all_addr: Int32 handler_size1 = (Int32)cells[(UInt32)Tables.encoded_catch_handler_row.columns.size].Value; if (handler_size1 <= 0) { Int32 catch_add_addr = file.ReadULeb128(ref offset); result = new Cell(column, (UInt32)catch_add_addr, (UInt32)catch_add_addr); } else { result = new Cell(column, 0, null); } break; default: result = base.ReadCellPayload(file, rowIndex, column, cells, ref offset); break; } return(result); }
/// <summary>Read data from section and returns indexes of added rows</summary> /// <param name="file">DEX file reader</param> /// <param name="offset">Offset from begginging of the file</param> /// <param name="maxItems">Maximum structures in the section</param> /// <returns>Row indexes</returns> protected internal UInt32[] ReadInnerSection(DexFile file, ref UInt32 offset, UInt32 maxItems) { UInt32 rowIndex = this.RowsCount; UInt32 index = 0; List <UInt32> result = new List <UInt32>(); while (index < maxItems) { UInt32 startOffset = offset; Cell[] cells = new Cell[this.Columns.Length]; for (UInt32 loop = 0; loop < cells.Length; loop++) { Column column = this.Columns[loop]; cells[loop] = this.ReadCellPayload(file, rowIndex, column, cells, ref offset); } if (this.AddRowToTable(rowIndex, startOffset, cells)) { result.Add(rowIndex); index++; rowIndex++; } } return(result.ToArray()); }
protected internal override Cell ReadCellPayload(DexFile file, UInt32 rowIndex, Column column, Cell[] cells, ref UInt32 offset) { Cell result; switch ((annotation_directory_row.columns)column.Index) { case annotation_directory_row.columns.field_annotations: UInt32 fields_size = cells[(UInt16)annotation_directory_row.columns.fields_size].RawValue; UInt32[] field_annotations = file.GetSectionTable(TableType.field_annotation).ReadInnerSection(file, ref offset, fields_size); result = new Cell(column, fields_size, field_annotations); break; case annotation_directory_row.columns.method_annotations: UInt32 annotated_methods_size = cells[(UInt16)annotation_directory_row.columns.annotated_methods_size].RawValue; UInt32[] method_annotations = file.GetSectionTable(TableType.method_annotation).ReadInnerSection(file, ref offset, annotated_methods_size); result = new Cell(column, annotated_methods_size, method_annotations); break; case annotation_directory_row.columns.parameter_annotations: UInt32 annotated_parameters_size = cells[(UInt16)annotation_directory_row.columns.annotated_parameters_size].RawValue; UInt32[] parameter_annotations = file.GetSectionTable(TableType.parameter_annotation).ReadInnerSection(file, ref offset, annotated_parameters_size); result = new Cell(column, annotated_parameters_size, parameter_annotations); break; default: result = base.ReadCellPayload(file, rowIndex, column, cells, ref offset); break; } return(result); }
internal BaseTable(DexFile file, TableType type) { if (file == null) { throw new ArgumentNullException("file"); } this._file = file; this._table = this._file.GetSectionTable(type); }
public JavaReverser(JavaReversingContext context, DexFile input) { if (null == context) { throw new ArgumentNullException(); } if (null == input) { throw new REException(); } _context = context; _input = input; _objectResolver = (IResolver)input; _treeHandler = new SourceCodeTreeHandler(context.BaseSourceCodeDirectory); EnsureStorage(); return; }
internal virtual void ReadSection(DexFile file, UInt32 offset, UInt32 maxItems) { UInt32 rowIndex = 0; while (rowIndex < maxItems) { UInt32 startOffset = offset; Cell[] cells = new Cell[this.Columns.Length]; for (UInt32 loop = 0; loop < cells.Length; loop++) { Column column = this.Columns[loop]; cells[loop] = this.ReadCellPayload(file, rowIndex, column, cells, ref offset); } if (this.AddRowToTable(rowIndex, startOffset, cells)) { rowIndex++; } } }
protected internal override Cell ReadCellPayload(DexFile file, UInt32 rowIndex, Column column, Cell[] cells, ref uint offset) { Cell result; switch ((code_row.columns)column.Index) { case code_row.columns.tries: UInt32 tries_size = cells[(UInt32)code_row.columns.tries_size].RawValue; UInt32[] indexes = file.GetSectionTable(TableType.try_item).ReadInnerSection(file, ref offset, tries_size); result = new Cell(column, tries_size, indexes); break; case code_row.columns.handlers: UInt32 tries_size1 = cells[(UInt32)code_row.columns.tries_size].RawValue; if (tries_size1 > 0) { Int32 handler_list_size = file.ReadULeb128(ref offset); UInt32[] indexes1 = file.GetSectionTable(TableType.encoded_catch_handler_list).ReadInnerSection(file, ref offset, (UInt32)handler_list_size); UInt32 p = (UInt32)sizeof(UInt32); UInt32 padding = ((offset) % p) != 0 ? (p - (offset) % p) : 0; offset += padding; result = new Cell(column, tries_size1, indexes1); //throw new NotImplementedException(); } else { result = new Cell(column, 0, null); } break; default: result = base.ReadCellPayload(file, rowIndex, column, cells, ref offset); break; } return(result); }
protected internal override Cell ReadCellPayload(DexFile file, UInt32 rowIndex, Column column, Cell[] cells, ref UInt32 offset) { Cell result; switch ((class_data_row.columns)column.Index) { case class_data_row.columns.static_fields: UInt32 static_fields_size = cells[(UInt32)class_data_row.columns.static_fields_size].RawValue; UInt32[] static_fields = file.GetSectionTable(TableType.encoded_field).ReadInnerSection(file, ref offset, static_fields_size); result = new Cell(column, static_fields_size, static_fields); break; case class_data_row.columns.instance_fields: UInt32 instance_fields_size = cells[(UInt32)class_data_row.columns.instance_fields_size].RawValue; UInt32[] instance_fields = file.GetSectionTable(TableType.encoded_field).ReadInnerSection(file, ref offset, instance_fields_size); result = new Cell(column, instance_fields_size, instance_fields); break; case class_data_row.columns.direct_methods: UInt32 direct_methods_size = cells[(UInt32)class_data_row.columns.direct_methods_size].RawValue; UInt32[] direct_methods = file.GetSectionTable(TableType.encoded_method).ReadInnerSection(file, ref offset, direct_methods_size); result = new Cell(column, direct_methods_size, direct_methods); break; case class_data_row.columns.virtual_methods: UInt32 virtual_methods_size = cells[(UInt32)class_data_row.columns.virtual_methods_size].RawValue; UInt32[] virtual_methods = file.GetSectionTable(TableType.encoded_method).ReadInnerSection(file, ref offset, virtual_methods_size); result = new Cell(column, virtual_methods_size, virtual_methods); break; default: result = base.ReadCellPayload(file, rowIndex, column, cells, ref offset); break; } return(result); }
internal RowReference(DexFile file, TableType type, UInt32 rowIndex) { this._file = file; this._type = type; this._rowIndex = rowIndex; }
/// <summary>Read cell data from loaded file</summary> /// <param name="file">DEX file</param> /// <param name="rowIndex">Row index</param> /// <param name="column">Cell column</param> /// <param name="cells">All cells from current row</param> /// <param name="offset">Offset from beggining of current file</param> /// <returns>Structured data</returns> protected internal virtual Cell ReadCellPayload(DexFile file, UInt32 rowIndex, Column column, Cell[] cells, ref UInt32 offset) { return(new Cell(file, column, ref offset)); }
static void ReadDex(String filePath) { using (DexFile info = new DexFile(StreamLoader.FromFile(filePath))) { var items = info.STRING_ID_ITEM; foreach (string_data_row row in info.STRING_DATA_ITEM) { Utils.ConsoleWriteMembers(row); } Utils.ConsoleWriteMembers(info.header); foreach (DexApi.map_item mapItem in info.map_list) { Utils.ConsoleWriteMembers(mapItem); } foreach (annotation_set_row row in info.ANNOTATION_SET_ITEM) { Utils.ConsoleWriteMembers(row); } foreach (annotation_set_ref_row row in info.ANNOTATION_SET_REF_LIST) { Utils.ConsoleWriteMembers(row); } foreach (annotation_directory_row row in info.ANNOTATIONS_DIRECTORY_ITEM) { Utils.ConsoleWriteMembers(row); } foreach (field_annotation_row row in info.field_annotation) { Utils.ConsoleWriteMembers(row); } foreach (parameter_annotation_row row in info.parameter_annotation) { Utils.ConsoleWriteMembers(row); } foreach (method_annotation_row row in info.method_annotation) { Utils.ConsoleWriteMembers(row); } foreach (class_data_row row in info.CLASS_DATA_ITEM) { Utils.ConsoleWriteMembers(row); } foreach (encoded_field_row row in info.encoded_field) { Utils.ConsoleWriteMembers(row); } foreach (encoded_method_row row in info.encoded_method) { Utils.ConsoleWriteMembers(row); } foreach (code_row row in info.CODE_ITEM) { Utils.ConsoleWriteMembers(row); } foreach (try_item_row row in info.try_item) { Utils.ConsoleWriteMembers(row); } foreach (encoded_catch_handler_row row in info.encoded_catch_handler_list) { Utils.ConsoleWriteMembers(row); } foreach (encoded_type_addr_pair_row row in info.encoded_type_addr_pair) { Utils.ConsoleWriteMembers(row); } foreach (type_list_row row in info.TYPE_LIST) { Utils.ConsoleWriteMembers(row); } foreach (type_id_row row in info.TYPE_ID_ITEM) { Utils.ConsoleWriteMembers(row); } foreach (proto_id_row row in info.PROTO_ID_ITEM) { Utils.ConsoleWriteMembers(row); } foreach (field_id_row row in info.FIELD_ID_ITEM) { Utils.ConsoleWriteMembers(row); } foreach (method_id_row row in info.METHOD_ID_ITEM) { Utils.ConsoleWriteMembers(row); } foreach (class_def_row row in info.CLASS_DEF_ITEM) { Utils.ConsoleWriteMembers(row); } } }
internal Cell(DexFile file, Column column, ref UInt32 offset) { if (file == null) { throw new ArgumentNullException("file"); } if (column == null) { throw new ArgumentNullException("column"); } this._column = column; switch (column.ColumnType) { case ColumnType.Byte: Byte bValue = file.Loader.ReadBytes(offset, 1)[0]; this._rawValue = bValue; this._value = bValue; offset++; break; case ColumnType.UInt16: UInt16 sValue = file.PtrToStructure <UInt16>(offset); this._rawValue = sValue; this._value = sValue; offset += sizeof(UInt16); break; case ColumnType.UInt32: UInt32 iValue = file.PtrToStructure <UInt32>(offset); this._rawValue = iValue; this._value = iValue; offset += sizeof(UInt32); break; case ColumnType.SLeb128: Int32 slValue = file.ReadSLeb128(ref offset); this._rawValue = (UInt32)slValue; //HACK: Here can be signed integer this._value = slValue; break; case ColumnType.ULeb128: Int32 ulValue = file.ReadULeb128(ref offset); this._rawValue = checked ((UInt32)ulValue); this._value = ulValue; break; case ColumnType.String: Int32 utf16_size = file.ReadULeb128(ref offset); this._rawValue = (UInt32)utf16_size; if (utf16_size > 0) { Byte[] bytes = file.Loader.ReadBytes(offset, (UInt32)utf16_size); this._value = Encoding.UTF8.GetString(bytes); offset += (UInt32)utf16_size; } break; case ColumnType.UInt16Array: UInt32 itemsCount = this._rawValue = file.Loader.PtrToStructure <UInt32>(offset); offset += (UInt32)sizeof(UInt32); UInt16[] type_idxs = new UInt16[itemsCount]; if (itemsCount > 0) { for (UInt32 loop = 0; loop < itemsCount; loop++) { type_idxs[loop] = file.Loader.PtrToStructure <UInt16>(offset); offset += (UInt32)sizeof(UInt16); } //TODO: Dex.TYPE.CODE_ITEM padding может быть, а может и не быть... Надо проверять... UInt32 p = (UInt32)sizeof(UInt32); UInt32 padding = ((offset) % p) != 0 ? (p - (offset) % p) : 0; offset += padding; } this._value = type_idxs; break; case ColumnType.UInt32Array: UInt32 itemsCount1 = this._rawValue = file.Loader.PtrToStructure <UInt32>(offset); offset += (UInt32)sizeof(UInt32); UInt32[] type_idxs1 = new UInt32[itemsCount1]; for (UInt32 loop = 0; loop < itemsCount1; loop++) { type_idxs1[loop] = file.Loader.PtrToStructure <UInt32>(offset); offset += (UInt32)sizeof(UInt32); } this._value = type_idxs1; break; default: throw new NotImplementedException(String.Format("Type {0} not implemented", column.ColumnType)); } }
protected internal override Cell ReadCellPayload(DexFile file, UInt32 rowIndex, Column column, Cell[] cells, ref UInt32 offset) { offset = file.STRING_ID_ITEM[rowIndex].string_data_off; return(base.ReadCellPayload(file, rowIndex, column, cells, ref offset)); }