+void print_upkg_exports(struct upkg *pkg)
+{
+ for (unsigned i = 0; i < pkg->export_count; i++) {
+ const char *name, *package, *class;
+
+ name = upkg_export_name(pkg, i);
+ class = upkg_export_class(pkg, i, &package);
+
+ if (!name || !class)
+ continue;
+
+ printf("%u - %s (%s.%s)\n", i+1, name, package, class);
+ }
+}
+
+int package_info(struct upkg *pkg)
+{
+ printf("Version: %u\n", pkg->version);
+ printf("License: %u\n", pkg->license);
+ printf("GUID: ");
+ print_guid(pkg->guid);
+
+ printf("Flags: %lx\n", pkg->flags);
+ if (verbose >= 1) {
+ print_upkg_flags("\t", pkg->flags);
+ }
+
+ if (verbose >= 1) {
+ printf("Names: %lu\n", pkg->name_count);
+ if (verbose >= 2) {
+ for (unsigned long i = 0; i < pkg->name_count; i++) {
+ printf("\t%s\n", upkg_get_name(pkg, i));
+ }
+ }
+ }
+
+ printf("Exports: %lu\n", pkg->export_count);
+ if (verbose >= 1) print_upkg_exports(pkg);
+ printf("Imports: %lu\n", pkg->import_count);
+
+ return EXIT_SUCCESS;
+}
+
+static int export(struct upkg *pkg, GObject *obj, unsigned idx)
+{
+ struct upkg_file *f = upkg_export_open(pkg, idx);
+ char name[256];
+ FILE *of;
+ int rc = -1;
+
+ if (u_object_deserialize(obj, f) != 0) {
+ goto out;
+ }
+
+ if (U_OBJECT_IS_LOADABLE(obj) && u_object_load(obj) != 0) {
+ goto out;
+ }
+
+ u_object_export_name(obj, name, sizeof name);
+
+ printf("exporting %s to %s\n", upkg_export_name(pkg, idx), name);
+ of = fopen(name, "wb");
+ if (!of) {
+ perror(name);
+ goto out;
+ }
+
+ rc = u_object_export(obj, of);
+
+ if (fclose(of) != 0) {
+ perror(name);
+ rc = -1;
+ goto out;
+ }
+
+ if (U_OBJECT_IS_LOADABLE(obj)) {
+ u_object_unload(obj);
+ }
+
+out:
+ upkg_export_close(f);
+ return rc;
+}
+
+int package_export(struct upkg *pkg)
+{
+ const char *class, *package;
+ GObject *obj;
+ GType type;
+ int rc = EXIT_SUCCESS;
+
+ for (unsigned i = 0; i < pkg->export_count; i++) {
+ class = upkg_export_class(pkg, i, &package);
+ if (!class) {
+ fprintf(stderr, "error getting class information.\n");
+ return EXIT_FAILURE;
+ }
+
+ type = module_get_class(package, class);
+ if (!type) continue;
+
+ obj = g_object_new(type, NULL);
+ if (U_OBJECT_IS_EXPORTABLE(obj)) {
+ if (export(pkg, obj, i) != 0) {
+ rc = EXIT_FAILURE;
+ }
+ }
+ g_object_unref(obj);
+ }
+
+ return rc;
+}
+