X-Git-Url: https://git.saurik.com/ldid.git/blobdiff_plain/a0c715e9c070b60702407b8713b3874593ff833d..043e30006254b050f5a5628bfaa84a0abf888e7a:/ldid.hpp diff --git a/ldid.hpp b/ldid.hpp index ad85f03..503ebc5 100644 --- a/ldid.hpp +++ b/ldid.hpp @@ -3,14 +3,161 @@ #include #include +#include +#include #include #include +#include namespace ldid { -typedef std::map Slots; +// I wish Apple cared about providing quality toolchains :/ -void Sign(void *idata, size_t isize, std::streambuf &output, const std::string &name, const std::string &entitlements, const std::string &key, const Slots &slots); +template +class Functor; + +template +class Functor { + public: + virtual Type_ operator ()(Args_... args) const = 0; +}; + +template +class FunctorImpl; + +template +class FunctorImpl : + public Functor +{ + private: + const Value_ *value_; + + public: + FunctorImpl(const Value_ &value) : + value_(&value) + { + } + + virtual Type_ operator ()(Args_... args) const { + return (*value_)(args...); + } +}; + +template +FunctorImpl fun(const Function_ &value) { + return value; +} + +struct Progress { + virtual void operator()(const std::string &value) const = 0; + virtual void operator()(double value) const = 0; +}; + +class Folder { + public: + virtual void Save(const std::string &path, bool edit, const void *flag, const Functor &code) = 0; + virtual bool Look(const std::string &path) const = 0; + virtual void Open(const std::string &path, const Functor &code) const = 0; + virtual void Find(const std::string &path, const Functor &code, const Functor &)> &link) const = 0; +}; + +class DiskFolder : + public Folder +{ + private: + const std::string path_; + std::map commit_; + + protected: + std::string Path(const std::string &path) const; + + private: + void Find(const std::string &root, const std::string &base, const Functor &code, const Functor &)> &link) const; + + public: + DiskFolder(const std::string &path); + ~DiskFolder(); + + virtual void Save(const std::string &path, bool edit, const void *flag, const Functor &code); + virtual bool Look(const std::string &path) const; + virtual void Open(const std::string &path, const Functor &code) const; + virtual void Find(const std::string &path, const Functor &code, const Functor &)> &link) const; +}; + +class SubFolder : + public Folder +{ + private: + Folder &parent_; + std::string path_; + + public: + SubFolder(Folder &parent, const std::string &path); + + virtual void Save(const std::string &path, bool edit, const void *flag, const Functor &code); + virtual bool Look(const std::string &path) const; + virtual void Open(const std::string &path, const Functor &code) const; + virtual void Find(const std::string &path, const Functor &code, const Functor &)> &link) const; +}; + +class UnionFolder : + public Folder +{ + private: + struct Reset { + const void *flag_; + std::streambuf *data_; + }; + + Folder &parent_; + std::set deletes_; + + std::map remaps_; + mutable std::map resets_; + + std::string Map(const std::string &path) const; + void Map(const std::string &path, const Functor &code, const std::string &file, const Functor &)> &save) const; + + public: + UnionFolder(Folder &parent); + + virtual void Save(const std::string &path, bool edit, const void *flag, const Functor &code); + virtual bool Look(const std::string &path) const; + virtual void Open(const std::string &path, const Functor &code) const; + virtual void Find(const std::string &path, const Functor &code, const Functor &)> &link) const; + + void operator ()(const std::string &from) { + deletes_.insert(from); + } + + void operator ()(const std::string &from, const std::string &to) { + operator ()(from); + remaps_[to] = from; + } + + void operator ()(const std::string &from, const void *flag, std::streambuf &data) { + operator ()(from); + auto &reset(resets_[from]); + reset.flag_ = flag; + reset.data_ = &data; + } +}; + +struct Hash { + uint8_t sha1_[0x14]; + uint8_t sha256_[0x20]; +}; + +struct Bundle { + std::string path; + Hash hash; +}; + +Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &requirements, const Functor &alter, const Progress &progress); + +typedef std::map Slots; + +Hash Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, const std::string &requirements, const std::string &key, const Slots &slots, uint32_t flags, bool platform, const Progress &progress); }