File tree Expand file tree Collapse file tree 17 files changed +153
-139
lines changed
Expand file tree Collapse file tree 17 files changed +153
-139
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ target_compile_options(ktool PUBLIC
2828 -Wstrict-overflow=5 -Wundef -Wnull-dereference -funsigned-char
2929 -fno-exceptions -Wcast-align -Wfloat-equal -Wredundant-decls
3030 -Wstrict-overflow=5 -Wundef -Wnull-dereference -funsigned-char -Wformat=2
31- -DBUILD_KERNEL -Wno-address-of-packed-member)
31+ -DBUILD_KERNEL -Wno-address-of-packed-member -Wthread-safety )
3232
3333target_link_options (ktool PUBLIC -stdlib=libc++)
3434target_link_options (ktool PUBLIC -fuse-ld=lld)
@@ -45,7 +45,8 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
4545 "-fsanitize=address" "-fsanitize=undefined" )
4646elseif (CMAKE_BUILD_TYPE STREQUAL "Release" )
4747 set_target_properties (ktool PROPERTIES OUTPUT_NAME "ktool_release" )
48- target_compile_options (ktool PRIVATE "-O3" "-Wno-unused-parameter" "-Wno-gnu-statement-expression-from-macro-expansion" )
48+ target_compile_options (ktool PRIVATE "-O3" "-Wno-unused-parameter"
49+ "-Wno-gnu-statement-expression-from-macro-expansion" )
4950 target_link_options (ktool PRIVATE "-O3" )
5051endif ()
5152
Original file line number Diff line number Diff line change @@ -49,9 +49,14 @@ namespace ADT {
4949 }
5050
5151 [[nodiscard]] constexpr static
52- auto FromEnd (const uint64_t Begin, const uint64_t End) noexcept {
53- assert (Begin <= End);
54- return Range::FromSize (Begin, (End - Begin));
52+ auto FromEnd (const uint64_t Begin, const uint64_t End) noexcept
53+ -> std::optional<Range>
54+ {
55+ if (Begin <= End) {
56+ return Range::FromSize (Begin, (End - Begin));
57+ }
58+
59+ return std::nullopt ;
5560 }
5661
5762 [[nodiscard]] constexpr auto front () const noexcept {
Original file line number Diff line number Diff line change @@ -540,9 +540,8 @@ namespace MachO {
540540 return this ->Kind ;
541541 }
542542
543- [[nodiscard]]
544- constexpr auto string () const noexcept -> std::string_view {
545- return this ->String ;
543+ [[nodiscard]] constexpr auto string () const noexcept {
544+ return std::string_view (this ->String );
546545 }
547546
548547 constexpr auto setKind (const ExportTrieExportKind Kind) noexcept
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ namespace Objects {
6262
6363 constexpr Error (const OpenError Kind) noexcept : Kind(Kind) {}
6464
65+ [[nodiscard]]
6566 static inline auto invalidAddress (const uint64_t Address) noexcept {
6667 auto Result = Error (OpenError::InvalidAddress);
6768 Result.InvalidAddress .Address = Address;
Original file line number Diff line number Diff line change @@ -104,7 +104,8 @@ namespace Utils {
104104 : Begin(Begin), Size(Size) {}
105105
106106 explicit PrintRange (const ADT::Range Range) noexcept
107- : Begin(Range.front()), Size(Range.size()) {}
107+ : Begin(static_cast <T>(Range.front())),
108+ Size(static_cast <U>(Range.size())) {}
108109
109110 [[nodiscard]] constexpr auto front () const noexcept {
110111 return this ->Begin ;
@@ -140,17 +141,6 @@ namespace Utils {
140141 bool Value;
141142 };
142143
143- auto
144- PrintOffsetSizeInfo (FILE *OutFile,
145- const ADT::Range Range,
146- bool Is64Bit,
147- bool IsSize64Bit,
148- bool IsOutOfBounds,
149- std::string_view OffsetKey,
150- std::string_view SizeKey,
151- std::string_view Prefix = " " ,
152- std::string_view Suffix = " " ) noexcept -> int ;
153-
154144 auto
155145 PrintDylibOrdinalPath (FILE *OutFile,
156146 uint8_t DylibOrdinal,
Original file line number Diff line number Diff line change @@ -38,7 +38,12 @@ namespace ADT {
3838 return Error::InvalidFormat;
3939 }
4040
41- const auto Range = ADT::Range::FromEnd (Offset, OffsetEndOpt.value ());
41+ const auto RangeOpt = ADT::Range::FromEnd (Offset, OffsetEndOpt.value ());
42+ if (!RangeOpt.has_value ()) {
43+ return Error::InvalidFormat;
44+ }
45+
46+ const auto Range = RangeOpt.value ();
4247 const auto Predicate = [Range](const ADT::Range RhsRange) noexcept {
4348 return Range.overlaps (RhsRange);
4449 };
Original file line number Diff line number Diff line change @@ -129,11 +129,11 @@ namespace MachO {
129129 for (const auto &SegInfo : this ->List | std::views::filter (Filter)) {
130130 const uint64_t VmIndex = SegInfo.VmRange .indexForLoc (VmAddr);
131131 if (!SegInfo.FileRange .hasIndex (VmIndex)) {
132- return std:: nullopt ;
132+ continue ;
133133 }
134134
135135 if (!SegInfo.FileRange .hasEndIndex (VmIndex + Size)) {
136- return std:: nullopt ;
136+ continue ;
137137 }
138138
139139 return SegInfo.FileRange .locForIndex (VmIndex);
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ namespace Objects {
111111
112112 auto FileSize = uint64_t ();
113113 if (Header->is64Bit ()) {
114- for (const auto & Segment :
114+ for (const auto Segment :
115115 LoadCommandsMap |
116116 ::MachO::LCMapFilterType<
117117 ::MachO::SegmentCommand64>(IsBigEndian))
@@ -140,7 +140,7 @@ namespace Objects {
140140 FileSize = NewFileSize.value ();
141141 }
142142 } else {
143- for (const auto & Segment :
143+ for (const auto Segment :
144144 LoadCommandsMap |
145145 ::MachO::LCMapFilterType<
146146 ::MachO::SegmentCommand>(IsBigEndian))
Original file line number Diff line number Diff line change @@ -122,6 +122,6 @@ namespace Objects {
122122 });
123123 }
124124
125- return ADT::Range::FromEnd (Base, End);
125+ return ADT::Range::FromEnd (Base, End). value () ;
126126 }
127127}
Original file line number Diff line number Diff line change @@ -45,11 +45,11 @@ namespace Operations {
4545 if (!Flags.empty ()) {
4646 std::println (OutFile, " " );
4747 if (Flags.hasNonWeakDefinition ()) {
48- std::println (OutFile, " \t\t Has Non-Weak Definition" );
48+ std::println (OutFile, " \t\t " " Has Non-Weak Definition" );
4949 }
5050
5151 if (Flags.isWeakImport ()) {
52- std::println (OutFile, " \t\t Weak -Import" );
52+ std::println (OutFile, " \t\t " " Weak -Import" );
5353 }
5454 } else {
5555 std::println (OutFile, " None" );
You can’t perform that action at this time.
0 commit comments