RZ_API RZ_OWN RzList /*<RzBinClass *>*/ *rz_bin_dex_classes(RZ_NONNULL RzBinDex *dex) {
	rz_return_val_if_fail(dex, NULL);

	DexClassDef *class_def;
	RzBinClass *bclass = NULL;
	RzList *classes = NULL;
	void **it;

	ut32 n_methods = rz_pvector_len(dex->method_ids);
	ut32 n_fields = rz_pvector_len(dex->field_ids);

	ut8 *inserted_methods = RZ_NEWS0(ut8, n_methods);
	ut8 *inserted_fields = RZ_NEWS0(ut8, n_fields);
	if ((n_methods > 0 && !inserted_methods) || (n_fields > 0 && !inserted_fields)) {
		free(inserted_fields);
		free(inserted_methods);
		return NULL;
	}

	classes = rz_list_newf((RzListFree)free_rz_bin_class);
	if (!classes) {
		free(inserted_fields);
		free(inserted_methods);
		return NULL;
	}

	rz_pvector_foreach (dex->class_defs, it) {
		class_def = (DexClassDef *)*it;
		bclass = RZ_NEW0(RzBinClass);
		if (!bclass) {
			break;
		}

		bclass->name = dex_resolve_type_id(dex, class_def->class_idx);
		bclass->super = dex_resolve_type_id(dex, class_def->superclass_idx);
		bclass->visibility = class_def->access_flags;
		bclass->visibility_str = rz_bin_dex_access_flags_readable(class_def->access_flags);
		bclass->index = class_def->class_idx;
		bclass->addr = class_def->offset;
		bclass->methods = dex_resolve_methods_in_class(dex, class_def, inserted_methods);
		bclass->fields = dex_resolve_fields_in_class(dex, class_def, inserted_fields);

		if (!rz_list_append(classes, bclass)) {
			free_rz_bin_class(bclass);
			break;
		}
	}
	free(inserted_fields);
	free(inserted_methods);

	return classes;
}
RZ_API RZ_OWN RzList   *rz_bin_dex_classes(RZ_NONNULL RzBinDex *dex) {
	rz_return_val_if_fail(dex, NULL);

	DexClassDef *class_def;
	RzBinClass *bclass = NULL;
	RzList *classes = NULL;
	void **it;

	ut32 n_methods = rz_pvector_len(dex->method_ids);
	ut32 n_fields = rz_pvector_len(dex->field_ids);

	ut8 *inserted_methods = RZ_NEWS0(ut8, n_methods);
	ut8 *inserted_fields = RZ_NEWS0(ut8, n_fields);
	if ((n_methods > 0 && !inserted_methods) || (n_fields > 0 && !inserted_fields)) {
		free(inserted_fields);
		free(inserted_methods);
		return NULL;
	}

	classes = rz_list_newf((RzListFree)free_rz_bin_class);
	if (!classes) {
		free(inserted_fields);
		free(inserted_methods);
		return NULL;
	}

	rz_pvector_foreach (dex->class_defs, it) {
		class_def = (DexClassDef *)*it;
		bclass = RZ_NEW0(RzBinClass);
		if (!bclass) {
			break;
		}

		bclass->name = dex_resolve_type_id(dex, class_def->class_idx);
		bclass->super = dex_resolve_type_id(dex, class_def->superclass_idx);
		bclass->visibility = class_def->access_flags;
		bclass->visibility_str = rz_bin_dex_access_flags_readable(class_def->access_flags);
		bclass->index = class_def->class_idx;
		bclass->addr = class_def->offset;
		bclass->methods = dex_resolve_methods_in_class(dex, class_def, inserted_methods);
		bclass->fields = dex_resolve_fields_in_class(dex, class_def, inserted_fields);

		if (!rz_list_append(classes, bclass)) {
			free_rz_bin_class(bclass);
			break;
		}
	}
	free(inserted_fields);
	free(inserted_methods);

	return classes;
}