#define MH_OBJECT 0x1
#define MH_EXECUTE 0x2
#define MH_DYLIB 0x6
+#define MH_DYLINKER 0x7
#define MH_BUNDLE 0x8
#define MH_DYLIB_STUB 0x9
_assert(
Swap(mach_header_->filetype) == MH_EXECUTE ||
Swap(mach_header_->filetype) == MH_DYLIB ||
+ Swap(mach_header_->filetype) == MH_DYLINKER ||
Swap(mach_header_->filetype) == MH_BUNDLE
);
}
return Sign(data.data(), data.size(), proxy, identifier, entitlements, merge, requirements, key, slots, flags, platform, progress);
}
-Bundle Sign(const std::string &root, Folder &folder, const std::string &key, std::map<std::string, Hash> &remote, const std::string &requirements, const Functor<std::string (const std::string &, const std::string &)> &alter, const Progress &progress) {
+struct State {
+ std::map<std::string, Hash> files;
+ std::map<std::string, std::string> links;
+
+ void Merge(const std::string &root, const State &state) {
+ for (const auto &entry : state.files)
+ files[root + entry.first] = entry.second;
+ for (const auto &entry : state.links)
+ links[root + entry.first] = entry.second;
+ }
+};
+
+Bundle Sign(const std::string &root, Folder &folder, const std::string &key, State &remote, const std::string &requirements, const Functor<std::string (const std::string &, const std::string &)> &alter, const Progress &progress) {
std::string executable;
std::string identifier;
rules2.insert(Rule{20, NoMode, "^version\\.plist$"});
}
- std::map<std::string, Hash> local;
+ State local;
std::string failure(mac ? "Contents/|Versions/[^/]*/Resources/" : "");
Expression nested("^(Frameworks/[^/]*\\.framework|PlugIns/[^/]*\\.appex(()|/[^/]*.app))/(" + failure + ")Info\\.plist$");
return false;
});
- std::map<std::string, std::string> links;
-
folder.Find("", fun([&](const std::string &name) {
if (exclude(name))
return;
- if (local.find(name) != local.end())
+ if (local.files.find(name) != local.files.end())
return;
- auto &hash(local[name]);
+ auto &hash(local.files[name]);
folder.Open(name, fun([&](std::streambuf &data, size_t length, const void *flag) {
progress(root + name);
if (exclude(name))
return;
- links[name] = read();
+ local.links[name] = read();
}));
auto plist(plist_new_dict());
bool old(&version.second == &rules1);
- for (const auto &hash : local)
+ for (const auto &hash : local.files)
for (const auto &rule : version.second)
if (rule(hash.first)) {
if (!old && mac && excludes.find(hash.first) != excludes.end());
break;
}
- for (const auto &link : links)
- for (const auto &rule : version.second)
- if (rule(link.first)) {
- if (rule.mode_ != OmitMode) {
- auto entry(plist_new_dict());
- plist_dict_set_item(entry, "symlink", plist_new_string(link.second.c_str()));
- if (rule.mode_ == OptionalMode)
- plist_dict_set_item(entry, "optional", plist_new_bool(true));
- plist_dict_set_item(files, link.first.c_str(), entry);
- }
+ if (!old)
+ for (const auto &link : local.links)
+ for (const auto &rule : version.second)
+ if (rule(link.first)) {
+ if (rule.mode_ != OmitMode) {
+ auto entry(plist_new_dict());
+ plist_dict_set_item(entry, "symlink", plist_new_string(link.second.c_str()));
+ if (rule.mode_ == OptionalMode)
+ plist_dict_set_item(entry, "optional", plist_new_bool(true));
+ plist_dict_set_item(files, link.first.c_str(), entry);
+ }
- break;
- }
+ break;
+ }
if (!old && mac)
for (const auto &bundle : bundles) {
}
folder.Save(signature, true, NULL, fun([&](std::streambuf &save) {
- HashProxy proxy(local[signature], save);
+ HashProxy proxy(local.files[signature], save);
char *xml(NULL);
uint32_t size;
plist_to_xml(plist, &xml, &size);
progress(root + executable);
folder.Save(executable, true, flag, fun([&](std::streambuf &save) {
Slots slots;
- slots[1] = local.at(info);
- slots[3] = local.at(signature);
- bundle.hash = Sign(NULL, 0, buffer, local[executable], save, identifier, entitlements, false, requirements, key, slots, length, 0, false, Progression(progress, root + executable));
+ slots[1] = local.files.at(info);
+ slots[3] = local.files.at(signature);
+ bundle.hash = Sign(NULL, 0, buffer, local.files[executable], save, identifier, entitlements, false, requirements, key, slots, length, 0, false, Progression(progress, root + executable));
}));
}));
- for (const auto &entry : local)
- remote[root + entry.first] = entry.second;
-
+ remote.Merge(root, local);
return bundle;
}
Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &requirements, const Functor<std::string (const std::string &, const std::string &)> &alter, const Progress &progress) {
- std::map<std::string, Hash> local;
+ State local;
return Sign(root, folder, key, local, requirements, alter, progress);
}
#endif
#endif
}
+static void usage(const char *argv0) {
+ fprintf(stderr, "usage: %s -S[entitlements.xml] <binary>\n", argv0);
+ fprintf(stderr, " %s -e MobileSafari\n", argv0);
+ fprintf(stderr, " %s -S cat\n", argv0);
+ fprintf(stderr, " %s -Stfp.xml gdb\n", argv0);
+}
+
#ifndef LDID_NOTOOLS
int main(int argc, char *argv[]) {
#ifndef LDID_NOSMIME
std::vector<std::string> files;
if (argc == 1) {
- fprintf(stderr, "usage: %s -S[entitlements.xml] <binary>\n", argv[0]);
- fprintf(stderr, " %s -e MobileSafari\n", argv[0]);
- fprintf(stderr, " %s -S cat\n", argv[0]);
- fprintf(stderr, " %s -Stfp.xml gdb\n", argv[0]);
- exit(0);
+ usage(argv[0]);
+ return 0;
}
for (int argi(1); argi != argc; ++argi)
} break;
default:
- goto usage;
+ usage(argv[0]);
+ return 1;
break;
}
_assert(flag_S || key.empty());
_assert(flag_S || flag_I == NULL);
- if (files.empty()) usage: {
- exit(0);
- }
+ if (files.empty())
+ return 0;
size_t filei(0), filee(0);
_foreach (file, files) try {