+ if (!merge)
+ baton.entitlements_ = entitlements;
+ else {
+#ifndef LDID_NOPLIST
+ Analyze(mach_header, fun([&](const char *data, size_t size) {
+ baton.entitlements_.assign(data, size);
+ }));
+
+ if (baton.entitlements_.empty())
+ baton.entitlements_ = entitlements;
+ else if (!entitlements.empty()) {
+ auto combined(plist(baton.entitlements_));
+ _scope({ plist_free(combined); });
+ _assert(plist_get_node_type(combined) == PLIST_DICT);
+
+ auto merging(plist(entitlements));
+ _scope({ plist_free(merging); });
+ _assert(plist_get_node_type(merging) == PLIST_DICT);
+
+ plist_dict_iter iterator(NULL);
+ plist_dict_new_iter(merging, &iterator);
+ _scope({ free(iterator); });
+
+ for (;;) {
+ char *key(NULL);
+ plist_t value(NULL);
+ plist_dict_next_item(merging, iterator, &key, &value);
+ if (key == NULL)
+ break;
+ _scope({ free(key); });
+ plist_dict_set_item(combined, key, plist_copy(value));
+ }
+
+ char *xml(NULL);
+ uint32_t size;
+ plist_to_xml(combined, &xml, &size);
+ _scope({ free(xml); });
+
+ baton.entitlements_.assign(xml, size);
+ }
+#else
+ _assert(false);
+#endif
+ }
+
+ if (!baton.entitlements_.empty()) {