@Override public void write(DataOut out) { out.ushort("registers_size", registersSize); out.ushort("ins_size", insSize); out.ushort("outs_size", outsSize); out.ushort("tries_size", tries == null ? 0 : tries.size()); out.uint("debug_info_off", debugInfo == null ? 0 : debugInfo.offset); out.uint("insn_size", insn_size); ByteBuffer b = ByteBuffer.allocate(insn_size * 2).order(ByteOrder.LITTLE_ENDIAN); for (Insn insn : insns) { insn.write(b); out.bytes("insn", b.array()); if (tries != null && tries.size() > 0) { if ((insn_size & 0x01) != 0) {// padding out.skip("padding", 2); out.uint("start_addr", ti.start.offset); out.ushort("insn_count", ti.end.offset - ti.start.offset); lastEnd = ti.end.offset; out.ushort("handler_off", ti.handler.handler_off); out.uleb128("size", handlers.size()); for (EncodedCatchHandler h : handlers) { out.sleb128("size", (h.catchAll != null ? -size : size)); for (AddrPair ap : h.addPairs) { out.uleb128("type_idx", (ap.type.index)); out.uleb128("addr", (ap.addr.offset));
public void write(DataOut out) { out.begin("Section:" + sectionType); List<T> items = this.items; if (sectionType == SectionType.TYPE_STRING_DATA_ITEM) { Buffer buff = new Buffer(); for (int i = 0; i < items.size(); i++) { T t = items.get(i); items.set(i, null); addPadding(out, sectionType.alignment); if (out.offset() != t.offset) { throw new RuntimeException(); } StringDataItem stringDataItem = (StringDataItem) t; stringDataItem.write(out, buff); buff.reset(); } } else { for (int i = 0; i < items.size(); i++) { T t = items.get(i); items.set(i, null); addPadding(out, sectionType.alignment); if (out.offset() != t.offset) { System.err.println("Error for type:" + this.sectionType + ", " + t.index); throw new RuntimeException(); } t.write(out); } } out.end(); }
@Override public void write(DataOut out) { out.uleb128("startline", firstLine); if (parameterNames == null) { out.uleb128("szParams", 0); } else { out.uleb128("szParams", parameterNames.length); for (StringIdItem s : parameterNames) { out.uleb128p1("param_name_index", s == null ? -1 : s.index); out.sbyte("DBG_SET_FILE", DBG_SET_FILE); out.uleb128p1("filename", fileName.index); out.sbyte("DBG_START_LOCAL_EXTENDED", DBG_START_LOCAL_EXTENDED); out.uleb128("reg", opNode.reg); out.uleb128p1("name", opNode.name.index); out.uleb128p1("type", opNode.type.index); out.uleb128p1("sig", opNode.sig.index); break; case DBG_START_LOCAL: { out.sbyte("DBG_START_LOCAL", DBG_START_LOCAL); out.uleb128("reg", opNode.reg); out.uleb128p1("name", opNode.name.index); out.uleb128p1("type", opNode.type.index); out.sbyte("DBG_RESTART_LOCAL", DBG_RESTART_LOCAL); out.uleb128("reg", opNode.reg); break; case DBG_END_LOCAL: {
public void write(DataOut out) { out.uint("magic", 0x0A786564); out.uint("version", version); out.skip4("checksum"); out.skip("signature", 20); out.uint("file_size", fileSize); out.uint("head_size", 0x70); out.uint("endian_tag", 0x12345678); out.skip("link_size,link_off", 8); out.uint("map_off", mapSection.items.size() == 0 ? 0 : mapSection.offset); out.uint("string_ids_size", stringIdSection.items.size()); out.uint("string_ids_off", stringIdSection.items.size() == 0 ? 0 : stringIdSection.offset); out.uint("type_ids_size", typeIdSection.items.size()); out.uint("type_ids_off", typeIdSection.items.size() == 0 ? 0 : typeIdSection.offset); out.uint("proto_ids_size", protoIdSection.items.size()); out.uint("proto_ids_off", protoIdSection.items.size() == 0 ? 0 : protoIdSection.offset); out.uint("field_ids_size", fieldIdSection.items.size()); out.uint("field_ids_off", fieldIdSection.items.size() == 0 ? 0 : fieldIdSection.offset); out.uint("method_ids_size", methodIdSection.items.size()); out.uint("method_ids_off", methodIdSection.items.size() == 0 ? 0 : methodIdSection.offset); out.uint("class_defs_size", classDefSection.items.size()); out.uint("class_defs_off", classDefSection.items.size() == 0 ? 0 : classDefSection.offset); out.uint("data_size", fileSize - mapSection.offset); // every thing after map is data section out.uint("data_off", mapSection.offset);// map is the first in data section }
public void write(DataOut out) { int valueArg = getValueArg(); out.ubyte("(value_arg << 5 | value_type", valueArg << 5 | valueType); switch (valueType) { case VALUE_NULL: out.bytes("value_short", encodeSint(valueArg + 1, (Short) value)); break; case VALUE_CHAR: out.bytes("value_char", encodeSint(valueArg + 1, (Character) value)); break; case VALUE_INT: out.bytes("value_int", encodeSint(valueArg + 1, (Integer) value)); break; case VALUE_LONG: out.bytes("value_long", encodeLong(valueArg + 1, (Long) value)); break; case VALUE_DOUBLE: out.bytes("value_double", writeRightZeroExtendedValue(valueArg+1,Double.doubleToLongBits( ((Number) value).doubleValue()))); break; case VALUE_FLOAT: out.bytes("value_float", writeRightZeroExtendedValue(valueArg+1,((long)Float.floatToIntBits((((Number) value).floatValue())))<<32)); break; case VALUE_STRING: case VALUE_METHOD: case VALUE_ENUM: out.bytes("value_xidx", encodeLong(valueArg + 1, ((BaseItem) value).index)); break; case VALUE_ARRAY: {
private void write(DataOut out) { List<SectionItem<?>> list = new ArrayList<>(mapItem.items); // mapItem is useless now this.mapItem = null; for (int i = 0; i < list.size(); i++) { SectionItem<?> section = list.get(i); list.set(i, null); BaseItem.addPadding(out, out.offset(), section.sectionType.alignment); if (out.offset() != section.offset) { throw new RuntimeException(section.sectionType + " start with different position, planned:" + section.offset + ", but is:" + out.offset()); } section.write(out); } }
static public void addPadding(DataOut out, int offset, int alignment) { int x = offset % alignment; if (x != 0) { out.skip("padding", alignment - x);// Padding } }
@Override public void write(DataOut out) { out.ubyte("visibility", visibility.value); annotation.write(out); } }
public void write(DataOut out) { out.begin("Section:" + sectionType); List<T> items = this.items; if (sectionType == SectionType.TYPE_STRING_DATA_ITEM) { Buffer buff = new Buffer(); for (int i = 0; i < items.size(); i++) { T t = items.get(i); items.set(i, null); addPadding(out, sectionType.alignment); if (out.offset() != t.offset) { throw new RuntimeException(); } StringDataItem stringDataItem = (StringDataItem) t; stringDataItem.write(out, buff); buff.reset(); } } else { for (int i = 0; i < items.size(); i++) { T t = items.get(i); items.set(i, null); addPadding(out, sectionType.alignment); if (out.offset() != t.offset) { System.err.println("Error for type:" + this.sectionType + ", " + t.index); throw new RuntimeException(); } t.write(out); } } out.end(); }
@Override public void write(DataOut out) { out.uleb128("startline", firstLine); if (parameterNames == null) { out.uleb128("szParams", 0); } else { out.uleb128("szParams", parameterNames.length); for (StringIdItem s : parameterNames) { out.uleb128p1("param_name_index", s == null ? -1 : s.index); out.sbyte("DBG_SET_FILE", DBG_SET_FILE); out.uleb128p1("filename", fileName.index); out.sbyte("DBG_START_LOCAL_EXTENDED", DBG_START_LOCAL_EXTENDED); out.uleb128("reg", opNode.reg); out.uleb128p1("name", opNode.name.index); out.uleb128p1("type", opNode.type.index); out.uleb128p1("sig", opNode.sig.index); break; case DBG_START_LOCAL: { out.sbyte("DBG_START_LOCAL", DBG_START_LOCAL); out.uleb128("reg", opNode.reg); out.uleb128p1("name", opNode.name.index); out.uleb128p1("type", opNode.type.index); out.sbyte("DBG_RESTART_LOCAL", DBG_RESTART_LOCAL); out.uleb128("reg", opNode.reg); break; case DBG_END_LOCAL: {