static DexEncodedMethod *dex_new_encoded_method(RzBuffer *buf, ut64 base, ut64 *diff_value_prev, bool first, RzPVector *method_ids) {
	DexEncodedMethod *encoded_method = RZ_NEW0(DexEncodedMethod);
	if (!encoded_method) {
		return NULL;
	}
	ut64 diff_value = 0;
	ut64 code_offset = 0;

	encoded_method->offset = rz_buf_tell(buf) + base;
	rz_buf_uleb128(buf, &diff_value);
	rz_buf_uleb128(buf, &encoded_method->access_flags);
	rz_buf_uleb128(buf, &code_offset);

	if (first) {
		encoded_method->method_idx = diff_value;
		*diff_value_prev = diff_value;
	} else {
		encoded_method->method_idx = *diff_value_prev + diff_value;
		*diff_value_prev = encoded_method->method_idx;
	}

	if (code_offset > 0) {
		read_le16_at_or_fail(buf, encoded_method->registers_size, code_offset, dex_new_encoded_method_fail);
		read_le16_at_or_fail(buf, encoded_method->ins_size, code_offset + 2, dex_new_encoded_method_fail);
		read_le16_at_or_fail(buf, encoded_method->outs_size, code_offset + 4, dex_new_encoded_method_fail);
		read_le16_at_or_fail(buf, encoded_method->tries_size, code_offset + 6, dex_new_encoded_method_fail);
		read_le32_at_or_fail(buf, encoded_method->debug_info_offset, code_offset + 8, dex_new_encoded_method_fail);
		read_le32_at_or_fail(buf, encoded_method->code_size, code_offset + 12, dex_new_encoded_method_fail);
		encoded_method->code_size *= sizeof(ut16); // code ushort[insns_size]
		encoded_method->code_offset = code_offset + 16 + base;

		if (encoded_method->method_idx < rz_pvector_len(method_ids)) {
			DexMethodId *method_id = (DexMethodId *)rz_pvector_at(method_ids, encoded_method->method_idx);
			if (method_id) {
				method_id->code_offset = encoded_method->code_offset;
				method_id->code_size = encoded_method->code_size;
			}
		}
	}
	return encoded_method;

dex_new_encoded_method_fail:
	free(encoded_method);
	return NULL;
}
static DexEncodedMethod *dex_new_encoded_method(RzBuffer *buf, ut64 base, ut64 *diff_value_prev, bool first, RzPVector *method_ids) {
	DexEncodedMethod *encoded_method = RZ_NEW0(DexEncodedMethod);
	if (!encoded_method) {
		return NULL;
	}
	ut64 diff_value = 0;
	ut64 code_offset = 0;

	encoded_method->offset = rz_buf_tell(buf) + base;
	rz_buf_uleb128(buf, &diff_value);
	rz_buf_uleb128(buf, &encoded_method->access_flags);
	rz_buf_uleb128(buf, &code_offset);

	if (first) {
		encoded_method->method_idx = diff_value;
		*diff_value_prev = diff_value;
	} else {
		encoded_method->method_idx = *diff_value_prev + diff_value;
		*diff_value_prev = encoded_method->method_idx;
	}

	if (code_offset > 0) {
		read_le16_at_or_fail(buf, encoded_method->registers_size, code_offset, dex_new_encoded_method_fail);
		read_le16_at_or_fail(buf, encoded_method->ins_size, code_offset + 2, dex_new_encoded_method_fail);
		read_le16_at_or_fail(buf, encoded_method->outs_size, code_offset + 4, dex_new_encoded_method_fail);
		read_le16_at_or_fail(buf, encoded_method->tries_size, code_offset + 6, dex_new_encoded_method_fail);
		read_le32_at_or_fail(buf, encoded_method->debug_info_offset, code_offset + 8, dex_new_encoded_method_fail);
		read_le32_at_or_fail(buf, encoded_method->code_size, code_offset + 12, dex_new_encoded_method_fail);
		encoded_method->code_size *= sizeof(ut16);  
		encoded_method->code_offset = code_offset + 16 + base;

		if (encoded_method->method_idx < rz_pvector_len(method_ids)) {
			DexMethodId *method_id = (DexMethodId *)rz_pvector_at(method_ids, encoded_method->method_idx);
			if (method_id) {
				method_id->code_offset = encoded_method->code_offset;
				method_id->code_size = encoded_method->code_size;
			}
		}
	}
	return encoded_method;

dex_new_encoded_method_fail:
	free(encoded_method);
	return NULL;
}