-
Notifications
You must be signed in to change notification settings - Fork 10
/
signature.h
113 lines (90 loc) · 2.51 KB
/
signature.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef SIGTOOL_SIGNATURE_H
#define SIGTOOL_SIGNATURE_H
#include <iostream>
#include <vector>
#include <memory>
#include <arpa/inet.h>
#include <cmath>
#include "magic_numbers.h"
#include "hash.h"
namespace SigTool {
struct Emittable {
virtual void emit(std::ostream& os) = 0;
virtual size_t length() = 0;
};
struct Blob : public Emittable {
virtual CSSlot slotType() = 0;
};
struct SuperBlob : public Emittable {
constexpr static const int headerSize = 3 * sizeof(uint32_t);
std::vector<std::shared_ptr<Blob>> blobs;
void emit(std::ostream &os) override;
size_t length() override;
};
struct CodeDirectory : public Blob {
struct data_t {
uint32_t magic;
uint32_t length;
uint32_t version;
uint32_t flags;
uint32_t hashOffset;
uint32_t identOffset;
uint32_t nSpecialSlots;
uint32_t nCodeSlots;
uint32_t codeLimit;
uint8_t hashSize;
uint8_t hashType;
uint8_t platform;
uint8_t pageSize;
uint32_t spare2;
uint32_t scatterOffset;
uint32_t teamOffset;
uint32_t spare3;
uint64_t codeLimit64;
uint64_t execSegBase;
uint64_t execSegLimit;
uint64_t execSegFlags;
} __attribute__((packed)) data {};
CodeDirectory() noexcept;
CSSlot slotType() override {
return CSSLOT_CODEDIRECTORY;
}
size_t length() override;
void emit(std::ostream& os) override;
void setSpecialHash(int index, const Hash& value);
void setPageSize(uint16_t pageSize);
void setCodeLimit(uint64_t codeLimit);
void addCodeHash(const Hash& value);
std::string identifier;
std::vector<Hash> codeHashes;
private:
Hash specialHashes[7]{};
};
// Only empty requirements supported
struct Requirements : public Blob {
CSSlot slotType() override {
return CSSLOT_REQUIREMENTS;
}
void emit(std::ostream &os) override;
size_t length() override;
};
struct Entitlements : public Blob {
std::string entitlements;
explicit Entitlements(std::string entitlements)
: entitlements{std::move(entitlements)} {}
CSSlot slotType() override {
return CSSLOT_ENTITLEMENTS;
}
void emit(std::ostream &os) override;
size_t length() override;
};
// Only empty signatures supported
struct Signature : public Blob {
CSSlot slotType() override {
return CSSLOT_SIGNATURESLOT;
}
void emit(std::ostream &os) override;
size_t length() override;
};
};
#endif //SIGTOOL_SIGNATURE_H