Skip to content

Commit c4b4314

Browse files
committed
project Many bugs fixes. Other style changes and fixes
1 parent b64cdbe commit c4b4314

39 files changed

+474
-453
lines changed

include/ADT/MemoryMap.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ namespace ADT {
132132
return reinterpret_cast<T *>(AdjBase);
133133
}
134134

135+
template <typename T = uint8_t, bool Verify = true>
136+
[[nodiscard]] inline auto
137+
getSpan(const uint64_t Offset, const uint64_t Count) const noexcept
138+
-> std::optional<std::span<T>>
139+
{
140+
if constexpr (Verify) {
141+
const auto EndOpt =
142+
Utils::AddMulAndCheckOverflow(Offset, sizeof(T), Count);
143+
144+
if (!EndOpt.has_value() || this->size() < EndOpt.value()) {
145+
return std::nullopt;
146+
}
147+
}
148+
149+
const auto AdjBase =
150+
reinterpret_cast<uint64_t>(this->base()) + Offset;
151+
152+
return std::span(reinterpret_cast<T *>(AdjBase), Count);
153+
}
154+
135155
template <typename T = uint8_t, bool Verify = true>
136156
[[nodiscard]] inline auto getRange(const Range &Range) const noexcept
137157
-> std::optional<std::span<T>>

include/ADT/Tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ namespace ADT {
569569
-> const TreeNode &
570570
{
571571
const auto RootDepthLevel = static_cast<uint64_t>(1);
572-
if (NodePrinterFunc(OutFile, 0, RootDepthLevel, *this)) {
572+
if (NodePrinterFunc(OutFile, /*DepthLevel=*/0, RootDepthLevel, *this)) {
573573
std::println(OutFile);
574574
}
575575

include/DyldSharedCache/Headers.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,50 +127,52 @@ namespace DyldSharedCache {
127127
constexpr auto setAuthData(const bool Value = true) noexcept
128128
-> decltype(*this)
129129
{
130-
this->setValueForMask(Masks::AuthData, 0, Value);
130+
this->setValueForMask(Masks::AuthData, /*Shift=*/0, Value);
131131
return *this;
132132
}
133133

134134
constexpr auto setDirtyData(const bool Value = true) noexcept
135135
-> decltype(*this)
136136
{
137-
this->setValueForMask(Masks::DirtyData, 0, Value);
137+
this->setValueForMask(Masks::DirtyData, /*Shift=*/0, Value);
138138
return *this;
139139
}
140140

141141
constexpr auto setConstData(const bool Value = true) noexcept
142142
-> decltype(*this)
143143
{
144-
this->setValueForMask(Masks::ConstData, 0, Value);
144+
this->setValueForMask(Masks::ConstData, /*Shift=*/0, Value);
145145
return *this;
146146
}
147147

148148
constexpr auto setTextStubs(const bool Value = true) noexcept
149149
-> decltype(*this)
150150
{
151-
this->setValueForMask(Masks::TextStubs, 0, Value);
151+
this->setValueForMask(Masks::TextStubs, /*Shift=*/0, Value);
152152
return *this;
153153
}
154154

155155
constexpr
156156
auto setDynamicConfigData(const bool Value = true) noexcept
157157
-> decltype(*this)
158158
{
159-
this->setValueForMask(Masks::DynamicConfigData, 0, Value);
159+
this->setValueForMask(Masks::DynamicConfigData,
160+
/*Shift=*/0,
161+
Value);
160162
return *this;
161163
}
162164

163165
constexpr auto setReadOnlyData(const bool Value = true) noexcept
164166
-> decltype(*this)
165167
{
166-
this->setValueForMask(Masks::ReadOnlyData, 0, Value);
168+
this->setValueForMask(Masks::ReadOnlyData, /*Shift=*/0, Value);
167169
return *this;
168170
}
169171

170172
constexpr auto setConstTproData(const bool Value = true) noexcept
171173
-> decltype(*this)
172174
{
173-
this->setValueForMask(Masks::ConstTproData, 0, Value);
175+
this->setValueForMask(Masks::ConstTproData, /*Shift=*/0, Value);
174176
return *this;
175177
}
176178
};
@@ -396,23 +398,23 @@ namespace DyldSharedCache {
396398
constexpr auto setIsProduction(const bool Value = true) noexcept
397399
-> decltype(*this)
398400
{
399-
setValueForMask(Kind::IsProduction, 0, Value);
401+
setValueForMask(Kind::IsProduction, /*Shift=*/0, Value);
400402
return *this;
401403
}
402404

403405
constexpr auto
404406
setNoMissingWeakSuperclasses(const bool Value = true) noexcept
405407
-> decltype(*this)
406408
{
407-
setValueForMask(Kind::IsProduction, 0, Value);
409+
setValueForMask(Kind::IsProduction, /*Shift=*/0, Value);
408410
return *this;
409411
}
410412

411413
constexpr
412414
auto setLargeSharedCache(const bool Value = true) noexcept
413415
-> decltype(*this)
414416
{
415-
setValueForMask(Kind::LargeSharedCache, 0, Value);
417+
setValueForMask(Kind::LargeSharedCache, /*Shift=*/0, Value);
416418
return *this;
417419
}
418420
};

include/DyldSharedCache/PatchInfo.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,20 @@ namespace DyldSharedCache {
8787
uint32_t PatchExportsCount;
8888
};
8989

90+
enum class PatchKind : uint32_t {
91+
Regular,
92+
CFObj2,
93+
ObjcClass = 8
94+
};
95+
9096
struct ImageExportV2 {
9197
uint32_t DylibOffsetOfImpl;
9298
uint32_t ExportNameOffset : 28;
9399
uint32_t PatchKind : 4;
100+
101+
[[nodiscard]] constexpr auto patchKind() const noexcept {
102+
return ::DyldSharedCache::PatchKind(this->PatchKind);
103+
}
94104
};
95105

96106
struct ImageClientsV2 {
@@ -376,12 +386,11 @@ namespace DyldSharedCache {
376386
};
377387

378388
explicit
379-
PatchInfo(
380-
const DyldSharedCache::DeVirtualizer &DeVirtualizer,
381-
const uint32_t ImageIndex,
382-
const uint64_t ImageBaseAddress,
383-
const PatchInfoVersion Version,
384-
const DyldSharedCache::PatchInfoV3 &Header) noexcept
389+
PatchInfo(const DyldSharedCache::DeVirtualizer &DeVirtualizer,
390+
const uint32_t ImageIndex,
391+
const uint64_t ImageBaseAddress,
392+
const PatchInfoVersion Version,
393+
const DyldSharedCache::PatchInfoV3 &Header) noexcept
385394
: DeVirtualizer(DeVirtualizer), Version(Version),
386395
ImageIndex(ImageIndex), ImageBaseAddress(ImageBaseAddress),
387396
HeaderV3(&Header) {}
@@ -416,8 +425,8 @@ namespace DyldSharedCache {
416425
}
417426

418427
[[nodiscard]] auto
419-
collectListOfExportPatchesForRange(
420-
PatchLocationMap &Map,
421-
ADT::Range VmRange) const noexcept -> ParseResult;
428+
collectListOfExportPatchesForRange(PatchLocationMap &Map,
429+
ADT::Range VmRange) const noexcept
430+
-> ParseResult;
422431
};
423432
}

include/MachO/BindInfo.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,16 @@ namespace MachO {
291291
constexpr auto setIsWeakImport(const bool Value = true) noexcept
292292
-> decltype(*this)
293293
{
294-
this->setValueForMask(FlagsEnum::WeakImport, 0, Value);
294+
this->setValueForMask(FlagsEnum::WeakImport, /*Shift=*/0, Value);
295295
return *this;
296296
}
297297

298298
constexpr auto setHasNonWeakDefinition(const bool Value = true) noexcept
299299
-> decltype(*this)
300300
{
301-
this->setValueForMask(FlagsEnum::NonWeakDefinition, 0, Value);
301+
this->setValueForMask(FlagsEnum::NonWeakDefinition,
302+
/*Shift=*/0,
303+
Value);
302304
return *this;
303305
}
304306
};
@@ -323,15 +325,15 @@ namespace MachO {
323325

324326
constexpr auto setOpcode(const Opcode Value) noexcept -> decltype(*this)
325327
{
326-
this->setValueForMask(Masks::Opcode, 0, Value);
328+
this->setValueForMask(Masks::Opcode, /*Shift=*/0, Value);
327329
return *this;
328330
}
329331

330332
auto setImmediate(const uint8_t Value) noexcept
331333
-> decltype(*this)
332334
{
333335
assert(Value <= 0xF);
334-
this->setValueForMask(Masks::Immediate, 0, Value);
336+
this->setValueForMask(Masks::Immediate, /*Shift=*/0, Value);
335337

336338
return *this;
337339
}

include/MachO/ExportTrie.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,28 @@ namespace MachO {
132132
}
133133

134134
constexpr auto setKind(const Kind Kind) noexcept -> decltype(*this) {
135-
setValueForMask(Masks::Kind, 0, Kind);
135+
setValueForMask(Masks::Kind, /*Shift=*/0, Kind);
136136
return *this;
137137
}
138138

139139
constexpr auto setWeak(const bool Value = true) noexcept
140140
-> decltype(*this)
141141
{
142-
setValueForMask(Masks::WeakDefinition, 0, Value);
142+
setValueForMask(Masks::WeakDefinition, /*Shift=*/0, Value);
143143
return *this;
144144
}
145145

146146
constexpr auto setReexport(const bool Value = true) noexcept
147147
-> decltype(*this)
148148
{
149-
setValueForMask(Masks::Reexport, 0, Value);
149+
setValueForMask(Masks::Reexport, /*Shift=*/0, Value);
150150
return *this;
151151
}
152152

153153
constexpr auto setStubAndResolver(const bool Value = true) noexcept
154154
-> decltype(*this)
155155
{
156-
setValueForMask(Masks::StubAndResolver, 0, Value);
156+
setValueForMask(Masks::StubAndResolver, /*Shift=*/0, Value);
157157
return *this;
158158
}
159159
};

0 commit comments

Comments
 (0)