]> git.saurik.com Git - ldid.git/blame - ldid.hpp
Store SHA256 as hash2 in files2 for CodeDirectory.
[ldid.git] / ldid.hpp
CommitLineData
a0c715e9
JF
1#ifndef LDID_HPP
2#define LDID_HPP
3
4#include <cstdlib>
5#include <map>
42d1472e 6#include <sstream>
a0c715e9
JF
7#include <streambuf>
8#include <string>
42d1472e 9#include <vector>
a0c715e9
JF
10
11namespace ldid {
12
e6a376fc
JF
13// I wish Apple cared about providing quality toolchains :/
14
15template <typename Function_>
16class Functor;
17
18template <typename Type_, typename... Args_>
19class Functor<Type_ (Args_...)> {
20 public:
21 virtual Type_ operator ()(Args_... args) const = 0;
22};
23
24template <typename Function_>
25class FunctorImpl;
26
27template <typename Value_, typename Type_, typename... Args_>
28class FunctorImpl<Type_ (Value_::*)(Args_...) const> :
29 public Functor<Type_ (Args_...)>
30{
31 private:
32 const Value_ *value_;
33
34 public:
35 FunctorImpl(const Value_ &value) :
36 value_(&value)
37 {
38 }
39
40 virtual Type_ operator ()(Args_... args) const {
41 return (*value_)(args...);
42 }
43};
44
45template <typename Function_>
46FunctorImpl<decltype(&Function_::operator())> fun(const Function_ &value) {
47 return value;
48}
49
23c11ee8
JF
50class Folder {
51 public:
fefcecb0
JF
52 virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code) = 0;
53 virtual bool Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code) = 0;
23c11ee8
JF
54 virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code) = 0;
55};
56
57class DiskFolder :
58 public Folder
59{
60 private:
61 const std::string path_;
62 std::map<std::string, std::string> commit_;
63
64 std::string Path(const std::string &path);
65
54a0f854
JF
66 void Find(const std::string &root, const std::string &base, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)>&code);
67
23c11ee8
JF
68 public:
69 DiskFolder(const std::string &path);
70 ~DiskFolder();
71
fefcecb0
JF
72 virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code);
73 virtual bool Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code);
23c11ee8
JF
74 virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
75};
76
77class SubFolder :
78 public Folder
79{
80 private:
2443500c 81 Folder &parent_;
23c11ee8
JF
82 std::string path_;
83
84 public:
2443500c 85 SubFolder(Folder &parent, const std::string &path);
23c11ee8 86
fefcecb0
JF
87 virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code);
88 virtual bool Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code);
23c11ee8
JF
89 virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
90};
91
886cb3f1
JF
92class UnionFolder :
93 public Folder
94{
95 private:
4d453c35
JF
96 class StringBuffer :
97 public std::stringbuf
98 {
99 public:
100 StringBuffer() {
101 }
102
103 StringBuffer(const StringBuffer &rhs) :
104 std::stringbuf(rhs.str())
105 {
106 }
107 };
108
886cb3f1 109 Folder &parent_;
7c49f771
JF
110 std::set<std::string> deletes_;
111
112 std::map<std::string, std::string> remaps_;
fefcecb0 113 std::map<std::string, std::pair<StringBuffer, const void *>> resets_;
7c49f771
JF
114
115 std::string Map(const std::string &path);
fefcecb0 116 void Map(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code, const std::string &file, const Functor<void (const Functor<void (std::streambuf &, const void *)> &)> &save);
886cb3f1
JF
117
118 public:
119 UnionFolder(Folder &parent);
120
fefcecb0
JF
121 virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code);
122 virtual bool Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code);
886cb3f1
JF
123 virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
124
7c49f771
JF
125 void operator ()(const std::string &from) {
126 deletes_.insert(from);
127 }
128
129 void operator ()(const std::string &from, const std::string &to) {
130 operator ()(from);
131 remaps_[to] = from;
132 }
133
fefcecb0
JF
134 std::stringbuf &operator ()(const std::string &from, const void *flag) {
135 operator ()(from);
136 auto &reset(resets_[from]);
137 reset.second = flag;
138 return reset.first;
886cb3f1
JF
139 }
140};
141
9ec8439b 142std::string Bundle(const std::string &root, Folder &folder, const std::string &key, const std::string &entitlements, const std::string &requirement);
2dcf3faf 143
23c11ee8 144typedef std::map<uint32_t, std::vector<char>> Slots;
a0c715e9 145
9914b1b3 146void Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, const std::string &requirement, const std::string &key, const Slots &slots);
a0c715e9
JF
147
148}
149
150#endif//LDID_HPP