RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
dumper.h
1#ifndef DUMPER_H
2#define DUMPER_H
3
4#include <iostream>
5#include <iomanip>
6#include <set>
7#include <vector>
8#include "../common.h"
9#include "../unicode.h"
10#include "../linker/image.h"
11
12namespace Dumper
13{
14
15class Dumper;
16
18{
19public:
20 virtual ~Encoding() = default;
21
22 virtual char32_t GetChar(uint8_t const *& input, size_t& length) = 0;
23
24 char32_t operator[](uint8_t input)
25 {
26 uint8_t const * input_pointer = &input;
27 size_t length = 1;
28 return GetChar(input_pointer, length);
29 }
30};
31
33{
34public:
35 char32_t (* codepage)[256];
36
37 SingleByteEncoding() = delete;
38 SingleByteEncoding(const SingleByteEncoding& ) = delete;
39
40 SingleByteEncoding(char32_t (& codepage)[256])
41 : codepage(&codepage)
42 {
43 assert(this->codepage != nullptr);
44 }
45
46 char32_t GetChar(uint8_t const *& input, size_t& length) override;
47};
48
49// TODO: untested
50class UTF8Encoding : public Encoding
51{
52public:
54 {
55 }
56
57 char32_t GetChar(uint8_t const *& input, size_t& length) override;
58};
59
60class UTF16Encoding : public Encoding
61{
62public:
63 ::EndianType endiantype;
64
65 UTF16Encoding(::EndianType endiantype)
66 : endiantype(endiantype)
67 {
68 }
69
70 char32_t GetChar(uint8_t const *& input, size_t& length) override;
71};
72
73// TODO: untested
74class UTF32Encoding : public Encoding
75{
76public:
77 ::EndianType endiantype;
78
79 UTF32Encoding(::EndianType endiantype)
80 : endiantype(endiantype)
81 {
82 }
83
84 char32_t GetChar(uint8_t const *& input, size_t& length) override;
85};
86
90template <typename ... Ts>
91 class Display
92{
93public:
94 virtual ~Display() { }
95
97 virtual bool IsMissing(std::tuple<Ts...>& values)
98 {
99 //return is_missing(values);
100 return values == std::tuple<Ts...>();
101 }
102
104 virtual void DisplayValue(Dumper& dump, std::tuple<Ts...> values) = 0;
105};
106
110class ChoiceDisplay : public Display<offset_t>
111{
112public:
116 std::map<offset_t, std::string> names;
120 std::string default_name;
121
133 std::shared_ptr<Display<offset_t>> secondary_display;
134
135 ChoiceDisplay(std::map<offset_t, std::string> names, std::string default_name, bool missing_on_value, offset_t missing_value, std::shared_ptr<Display<offset_t>> secondary_display)
137 {
138 }
139
148 static std::shared_ptr<ChoiceDisplay> Make(std::map<offset_t, std::string> names, std::string default_name = "unknown", std::shared_ptr<Display<offset_t>> secondary_display = nullptr)
149 {
150 return std::make_shared<ChoiceDisplay>(names, default_name, false, 0, secondary_display);
151 }
152
162 static std::shared_ptr<ChoiceDisplay> Make(std::map<offset_t, std::string> names, offset_t missing_value, std::string default_name = "unknown", std::shared_ptr<Display<offset_t>> secondary_display = nullptr)
163 {
164 return std::make_shared<ChoiceDisplay>(names, default_name, true, missing_value, secondary_display);
165 }
166
174 static std::shared_ptr<ChoiceDisplay> Make(std::map<offset_t, std::string> names, std::shared_ptr<Display<offset_t>> secondary_display)
175 {
176 return std::make_shared<ChoiceDisplay>(names, "unknown", false, 0, secondary_display);
177 }
178
187 static std::shared_ptr<ChoiceDisplay> Make(std::map<offset_t, std::string> names, offset_t missing_value, std::shared_ptr<Display<offset_t>> secondary_display)
188 {
189 return std::make_shared<ChoiceDisplay>(names, "unknown", true, missing_value, secondary_display);
190 }
191
199 static std::shared_ptr<ChoiceDisplay> Make(std::string on_true, std::string on_false)
200 {
201 std::map<offset_t, std::string> names;
202 /* TODO: alternative?
203 default_name = on_true;
204 names[0] = on_false;
205 */
206 names[0] = on_false;
207 names[1] = on_true;
208 return std::make_shared<ChoiceDisplay>(names, "", false, 0, nullptr);
209 }
210
217 static std::shared_ptr<ChoiceDisplay> Make(std::string on_true)
218 {
219 std::map<offset_t, std::string> names;
220 /* TODO: alternative?
221 default_name = on_true;
222 missing_on_value = true;
223 missing_value = 0;
224 */
225 names[1] = on_true;
226 return std::make_shared<ChoiceDisplay>(names, "unknown", false, 0, nullptr);
227 }
228
229 bool IsMissing(std::tuple<offset_t>& values) override;
230 void DisplayValue(Dumper& dump, std::tuple<offset_t> values) override;
231};
232
236class HexDisplay : public Display<offset_t>
237{
238public:
239 unsigned width;
240 HexDisplay(unsigned width)
241 : width(width)
242 {
243 }
244
251 static std::shared_ptr<HexDisplay> Make(unsigned width = 8)
252 {
253 return std::make_shared<HexDisplay>(width);
254 }
255
256 void DisplayValue(Dumper& dump, std::tuple<offset_t> values) override;
257};
258
262class DecDisplay : public Display<offset_t>
263{
264public:
265 std::string suffix;
266 bool enable_signed = false;
267 DecDisplay(std::string suffix, bool enable_signed)
268 : suffix(suffix), enable_signed(enable_signed)
269 {
270 }
271
278 static std::shared_ptr<DecDisplay> Make(bool enable_signed)
279 {
280 return std::make_shared<DecDisplay>("", enable_signed);
281 }
282
290 static std::shared_ptr<DecDisplay> Make(std::string suffix = "", bool enable_signed = false)
291 {
292 return std::make_shared<DecDisplay>(suffix, enable_signed);
293 }
294
295 void DisplayValue(Dumper& dump, std::tuple<offset_t> values) override;
296};
297
301class SegmentedDisplay : public Display<offset_t, offset_t>
302{
303public:
304 unsigned width;
305 SegmentedDisplay(unsigned width)
306 : width(width)
307 {
308 }
309
316 static std::shared_ptr<SegmentedDisplay> Make(unsigned width = 4)
317 {
318 return std::make_shared<SegmentedDisplay>(width);
319 }
320
321 void DisplayValue(Dumper& dump, std::tuple<offset_t, offset_t> values) override;
322};
323
327class VersionDisplay : public Display<offset_t, offset_t>
328{
329public:
330 std::string separator;
331 VersionDisplay(std::string separator)
332 : separator(separator)
333 {
334 }
335
342 static std::shared_ptr<VersionDisplay> Make(std::string separator = ".")
343 {
344 return std::make_shared<VersionDisplay>(separator);
345 }
346
347 void DisplayValue(Dumper& dump, std::tuple<offset_t, offset_t> values) override;
348};
349
353template <typename ... Ts>
354 class SectionedDisplay : public Display<offset_t, Ts...>
355{
356public:
357 std::string suffix;
358 std::shared_ptr<Display<Ts...>> offset_display;
359
360 SectionedDisplay(std::string suffix, std::shared_ptr<Display<Ts...>> offset_display)
361 : suffix(suffix), offset_display(offset_display)
362 {
363 }
364
371 static std::shared_ptr<SectionedDisplay> Make(std::shared_ptr<Display<Ts...>> offset_display)
372 {
373 return Make("", offset_display);
374 }
375
383 static std::shared_ptr<SectionedDisplay> Make(std::string suffix, std::shared_ptr<Display<Ts...>> offset_display)
384 {
385 return std::make_shared<SectionedDisplay>(suffix, offset_display);
386 }
387
388 void DisplayValue(Dumper& dump, std::tuple<offset_t, Ts...> values) override;
389};
390
394class BitFieldDisplay : public HexDisplay, public std::enable_shared_from_this<BitFieldDisplay>
395{
396public:
398 {
399 public:
400 unsigned offset, length;
401 std::shared_ptr<Display<offset_t>> display;
402 bool optional_field;
403 std::string label;
404
405 BitField(unsigned offset, unsigned length, std::shared_ptr<Display<offset_t>> display, bool optional_field, std::string label)
406 : offset(offset), length(length), display(display), optional_field(optional_field), label(label)
407 {
408 }
409
410 bool ShouldDisplay(std::tuple<offset_t>& values)
411 {
412 return !optional_field || !display->IsMissing(values);
413 }
414 };
415
416 std::map<unsigned, std::unique_ptr<BitField>> bitfields;
417
418 BitFieldDisplay(unsigned width)
419 : HexDisplay(width)
420 {
421 }
422
429 static std::shared_ptr<BitFieldDisplay> Make(unsigned width = 8)
430 {
431 return std::make_shared<BitFieldDisplay>(width);
432 }
433
434 std::shared_ptr<BitFieldDisplay> AddBitField(unsigned offset, unsigned length, std::shared_ptr<Display<offset_t>> display, bool optional_field)
435 {
436 bitfields[offset] = std::make_unique<BitField>(offset, length, display, optional_field, "");
437 return shared_from_this();
438 }
439
440 std::shared_ptr<BitFieldDisplay> AddBitField(unsigned offset, unsigned length, std::string label, std::shared_ptr<Display<offset_t>> display, bool optional_field = false)
441 {
442 bitfields[offset] = std::make_unique<BitField>(offset, length, display, optional_field, label);
443 return shared_from_this();
444 }
445
446 void DisplayValue(Dumper& dump, std::tuple<offset_t> values) override;
447};
448
452class StringDisplay : public Display<std::string>
453{
454public:
458 offset_t width;
459 std::string open_quote, close_quote;
460
461 StringDisplay(size_t width, std::string open_quote, std::string close_quote)
462 : width(width), open_quote(open_quote), close_quote(close_quote)
463 {
464 }
465
474 static std::shared_ptr<StringDisplay> Make(size_t width, std::string open_quote, std::string close_quote)
475 {
476 return std::make_shared<StringDisplay>(width, open_quote, close_quote);
477 }
478
486 static std::shared_ptr<StringDisplay> Make(size_t width, std::string quote = "")
487 {
488 return std::make_shared<StringDisplay>(width, quote, quote);
489 }
490
497 static std::shared_ptr<StringDisplay> Make(std::string quote = "")
498 {
499 return std::make_shared<StringDisplay>(-1, quote, quote);
500 }
501
502 bool IsMissing(std::tuple<std::string>& values) override;
503 void DisplayValue(Dumper& dump, std::tuple<std::string> values) override;
504
505 using Display<std::string>::IsMissing;
506 bool IsMissing(std::tuple<offset_t>& values);
507 using Display<std::string>::DisplayValue;
508 void DisplayValue(Dumper& dump, std::tuple<offset_t> values);
509};
510
514class Field
515{
516public:
518 std::string label;
523
524 Field(std::string label, bool optional_field, bool internal)
526 {
527 }
528
529 virtual ~Field();
530
531 virtual bool ShouldDisplay() = 0;
532 virtual void DisplayValue(Dumper& dump) = 0;
533};
534
538template <typename ... Ts>
539 class FieldOf : public Field
540{
541public:
543 std::shared_ptr<Display<Ts...>> display;
544 std::tuple<Ts...> values;
545
546 FieldOf(std::string label, std::shared_ptr<Display<Ts...>> display, Ts... values, bool optional_field = false, bool internal = false)
547 : Field(label, optional_field, internal), display{display}, values{values...}
548 {
549 }
550
551 bool ShouldDisplay() override
552 {
553 return !internal && (!optional_field || !display->IsMissing(values));
554 }
555
556 void DisplayValue(Dumper& dump) override
557 {
558 display->DisplayValue(dump, values);
559 }
560};
561
566{
567public:
568 std::string name;
569
570 std::map<std::string, std::shared_ptr<Field>> field_names;
571 std::vector<std::shared_ptr<Field>> fields;
572
573 Container(std::string name = "")
574 : name(name)
575 {
576 }
577
578 virtual ~Container();
579
580 std::shared_ptr<Field> FindField(std::string name)
581 {
582 auto it = field_names.find(name);
583 if(it == field_names.end())
584 return nullptr;
585 return it->second;
586 }
587
588 template <typename T>
589 T GetField(std::string name, offset_t default_value = T())
590 {
591 auto it = field_names.find(name);
592 if(it == field_names.end())
593 return default_value;
594 if(auto field = std::dynamic_pointer_cast<FieldOf<T>>(it->second))
595 {
596 return std::get<0>(field->values);
597 }
598 return default_value;
599 }
600
601#if 0
602 offset_t GetField(std::string name, int index, offset_t default_value)
603 {
604 auto it = field_names.find(name);
605 if(it == field_names.end())
606 return default_value;
607 return it->second->values[index];
608 }
609#endif
610
611 void AddField(std::shared_ptr<Field> field)
612 {
613 fields.push_back(field);
614 field_names[field->label] = field;
615 }
616
617 void AddField(size_t index, std::shared_ptr<Field> field)
618 {
619 fields.insert(fields.begin() + index, field);
620 field_names[field->label] = field;
621 }
622
623 template <typename D, typename ... Ts>
624 void AddField(std::string label, std::shared_ptr<D> display, Ts... values)
625 {
626 AddField(std::make_shared<FieldOf<Ts...>>(label, display, values..., false, false));
627 }
628
629 template <typename D, typename ... Ts>
630 void AddOptionalField(std::string label, std::shared_ptr<D> display, Ts... values)
631 {
632 AddField(std::make_shared<FieldOf<Ts...>>(label, display, values..., true, false));
633 }
634
635 template <typename D, typename ... Ts>
636 void AddHiddenField(std::string label, std::shared_ptr<D> display, Ts... values)
637 {
638 AddField(std::make_shared<FieldOf<Ts...>>(label, display, values..., false, true));
639 }
640
641 template <typename D, typename ... Ts>
642 void InsertField(size_t index, std::string label, std::shared_ptr<D> display, Ts... values)
643 {
644 AddField(index, std::make_shared<FieldOf<Ts...>>(label, display, values..., false, false));
645 }
646
647 template <typename D, typename ... Ts>
648 void InsertOptionalField(size_t index, std::string label, std::shared_ptr<D> display, Ts... values)
649 {
650 AddField(index, std::make_shared<FieldOf<Ts...>>(label, display, values..., true, false));
651 }
652
653 template <typename D, typename ... Ts>
654 void InsertHiddenField(size_t index, std::string label, std::shared_ptr<D> display, Ts... values)
655 {
656 AddField(index, std::make_shared<FieldOf<Ts...>>(label, display, values..., false, true));
657 }
658
659 virtual void Display(Dumper& dump);
660};
661
665class Region : public Container
666{
667public:
668 Region(std::string name, offset_t offset, offset_t length, unsigned display_width)
669 : Container(name)
670 {
671 AddField("Offset", HexDisplay::Make(display_width), offset);
672 AddField("Length", HexDisplay::Make(display_width), length);
673 }
674
675 static std::shared_ptr<Region> Make(std::string name, offset_t offset, offset_t length, unsigned display_width)
676 {
677 return std::make_shared<Region>(name, offset, length, display_width);
678 }
679
680// void Display(Dumper& dump);
681};
682
686class Entry : public Container
687{
688public:
689 offset_t number;
690 offset_t offset;
691 unsigned display_width;
692
693 Entry(std::string name, offset_t number, offset_t offset = offset_t(-1), unsigned display_width = 8)
694 : Container(name), number(number), offset(offset), display_width(display_width)
695 {
696 }
697
698 void Display(Dumper& dump) override;
699};
700
704class Block : public Region
705{
706public:
713
714 static SingleByteEncoding encoding_default;
715 static SingleByteEncoding encoding_cp437;
716 static SingleByteEncoding encoding_st;
717 static SingleByteEncoding encoding_iso8859_1;
718 static SingleByteEncoding encoding_windows1252;
719 static SingleByteEncoding encoding_macroman;
720 static UTF8Encoding encoding_utf8;
721 static UTF16Encoding encoding_utf16le;
722 static UTF16Encoding encoding_utf16be;
723 static UTF32Encoding encoding_utf32le;
724 static UTF32Encoding encoding_utf32be;
725
726 std::shared_ptr<Linker::Image> image;
727
728 std::set<offset_t> signal_starts;
729 std::set<offset_t> signal_ends;
730
737 void AddSignal(offset_t off, offset_t len)
738 {
739 offset_t end = off + len - 1;
740 signal_starts.insert(off);
741 signal_ends.insert(end);
742 }
743
744 Block(std::string name, offset_t offset, std::shared_ptr<Linker::Image> image, offset_t address, unsigned display_width,
745 unsigned offset_display_width = 8, unsigned address_display_width = -1u, unsigned position_display_width = -1u)
746 : Region(name, offset, image ? image->ImageSize() : 0, display_width),
751 image(image)
752 {
753 AddField("Address", HexDisplay::Make(display_width), address);
754 }
755
756 static std::shared_ptr<Block> Make(std::string name, offset_t offset, std::shared_ptr<Linker::Image> image, offset_t address, unsigned display_width,
757 unsigned offset_display_width = 8, unsigned address_display_width = -1u, unsigned position_display_width = -1u)
758 {
759 return std::make_shared<Block>(name, offset, image, address, display_width, offset_display_width, address_display_width, position_display_width);
760 }
761
762 void Display(Dumper& dump) override;
763};
764
773{
774public:
775 std::ostream& out;
776 bool use_ansi;
777
778 SingleByteEncoding * encoding;
779 Encoding * string_encoding;
780
781 Dumper(std::ostream& out)
782 : out(out), use_ansi(true), encoding(nullptr), string_encoding(nullptr)
783 {
784 }
785
786 SingleByteEncoding * SetEncoding(SingleByteEncoding& encoding, bool force = false)
787 {
788 SingleByteEncoding * old_encoding = this->encoding;
789 if(this->encoding == nullptr || force)
790 {
791 this->encoding = &encoding;
792 }
793 return old_encoding;
794 }
795
796 Encoding * SetStringEncoding(Encoding& encoding)
797 {
798 Encoding * old_encoding = this->string_encoding;
799 this->string_encoding = &encoding;
800 return old_encoding;
801 }
802
803 void SetTitle(std::string title)
804 {
805 out << "=== " << title << " ===" << std::endl;
806 }
807
808// std::vector<Field> fields;
809
813 void PrintHex(offset_t value, unsigned width, std::string prefix = "0x")
814 {
815 out << prefix << std::hex << std::setw(width) << std::setfill('0') << value;
816 }
817
818#if 0
822 void PrintHex(offset_t value, unsigned width, bool prefixed)
823 {
824 PrintHex(value, width, prefixed ? "0x" : "");
825 }
826#endif
827
831 void PrintDec(offset_t value, std::string prefix = "#")
832 {
833 out << prefix << std::dec << value;
834 }
835
839 void PrintDecSigned(relative_offset_t value, std::string prefix = "#")
840 {
841 out << prefix << std::dec << value;
842 }
843
844#if 0
848 void PrintDec(offset_t value, bool prefixed)
849 {
850 PrintDec(value, prefixed ? "#" : "");
851 }
852#endif
853
857 void PutChar(char32_t c)
858 {
859 /* TODO: this should depend on the current locale */
860 const char32_t * input = &c;
861 char * output = nullptr;
862 size_t size;
863 UTF32ToUTF8(input, output, 0, size);
864 std::vector<char> buffer(size);
865 output = buffer.data();
866 UTF32ToUTF8(input, output, size, size);
867 out << std::string(buffer.data(), buffer.size());
868 }
869
870 void PutEncodedString(std::string encoded_string, bool terminate_at_null = false)
871 {
872 uint8_t const * input = reinterpret_cast<uint8_t *>(encoded_string.data());
873 size_t length = encoded_string.size();
874 char32_t c;
875 while((c = (string_encoding ? string_encoding : encoding)->GetChar(input, length)) != char32_t(-1) || (terminate_at_null && c == U'\0'))
876 {
877 PutChar(c);
878 }
879 }
880
881 void PutEncodedString(offset_t width, std::string encoded_string, char32_t padding)
882 {
883 uint8_t const * input = reinterpret_cast<uint8_t *>(encoded_string.data());
884 size_t length = encoded_string.size();
885 char32_t c;
886 while(width > 0 && (c = (string_encoding ? string_encoding : encoding)->GetChar(input, length)) != char32_t(-1))
887 {
888 PutChar(c);
889 width --;
890 }
891 while(width > 0)
892 {
893 PutChar(padding);
894 width --;
895 }
896 }
897
902 {
903 if(use_ansi)
904 out << "\33[4m";
905 }
906
911 {
912 if(use_ansi)
913 out << "\33[m";
914 }
915};
916
917template <unsigned I, size_t ... Is, typename ... Ts>
918 inline auto rest_(std::tuple<Ts...> elements, std::index_sequence<Is...> s)
919{
920 return std::make_tuple(std::get<I + Is>(elements)...);
921}
922
923template <unsigned I, typename ... Ts>
924 inline auto rest(std::tuple<Ts...> elements)
925{
926 return rest_<I>(elements, std::make_index_sequence<sizeof...(Ts) - I>());
927}
928
929template <typename ... Ts>
930 void SectionedDisplay<Ts...>::DisplayValue(Dumper& dump, std::tuple<offset_t, Ts...> values)
931{
932 dump.PrintDec(std::get<0>(values), "");
933 dump.out << suffix << ':';
934 offset_display->DisplayValue(dump, rest<1>(values));
935}
936
937}
938
939#endif /* DUMPER_H */
Definition dumper.h:398
A value that is separated into bitfields, typically bit flags.
Definition dumper.h:395
static std::shared_ptr< BitFieldDisplay > Make(unsigned width=8)
Create a bit field display.
Definition dumper.h:429
A region within a file that can be dumped, decompiled, and it may contain fixups.
Definition dumper.h:705
unsigned offset_display_width
Displaying in-file offsets.
Definition dumper.h:708
void AddSignal(offset_t off, offset_t len)
Add a relocation inside the image block.
Definition dumper.h:737
unsigned position_display_width
Displaying in-segment positions.
Definition dumper.h:710
unsigned address_display_width
Displaying in-memory addresses.
Definition dumper.h:712
Represents an enumerated value, with named options.
Definition dumper.h:111
static std::shared_ptr< ChoiceDisplay > Make(std::map< offset_t, std::string > names, offset_t missing_value, std::string default_name="unknown", std::shared_ptr< Display< offset_t > > secondary_display=nullptr)
Create a choice display.
Definition dumper.h:162
std::map< offset_t, std::string > names
Maps values to names.
Definition dumper.h:116
std::shared_ptr< Display< offset_t > > secondary_display
Alternative representation, appearing in parentheses after the value.
Definition dumper.h:133
static std::shared_ptr< ChoiceDisplay > Make(std::string on_true)
Creates a boolean choice that is either present with name or not present at all.
Definition dumper.h:217
bool missing_on_value
If false, any value not listed in names is missing, otherwise only missing_value is missing.
Definition dumper.h:125
static std::shared_ptr< ChoiceDisplay > Make(std::string on_true, std::string on_false)
Creates a boolean choice.
Definition dumper.h:199
std::string default_name
Name for values not contained in names.
Definition dumper.h:120
static std::shared_ptr< ChoiceDisplay > Make(std::map< offset_t, std::string > names, offset_t missing_value, std::shared_ptr< Display< offset_t > > secondary_display)
Create a choice display.
Definition dumper.h:187
offset_t missing_value
The single missing value, only used for missing_on_value true.
Definition dumper.h:129
static std::shared_ptr< ChoiceDisplay > Make(std::map< offset_t, std::string > names, std::string default_name="unknown", std::shared_ptr< Display< offset_t > > secondary_display=nullptr)
Create a choice display.
Definition dumper.h:148
static std::shared_ptr< ChoiceDisplay > Make(std::map< offset_t, std::string > names, std::shared_ptr< Display< offset_t > > secondary_display)
Create a choice display.
Definition dumper.h:174
A record whose values should be displayed together, as a collection.
Definition dumper.h:566
Represents a field with a decimal display, usually indices into an array or similar,...
Definition dumper.h:263
static std::shared_ptr< DecDisplay > Make(bool enable_signed)
Creates a decimal display.
Definition dumper.h:278
static std::shared_ptr< DecDisplay > Make(std::string suffix="", bool enable_signed=false)
Creates a decimal display.
Definition dumper.h:290
This class represents an entry that can be displayed in a file dump.
Definition dumper.h:92
virtual bool IsMissing(std::tuple< Ts... > &values)
Returns true if the specified value is such that it should not be displayed.
Definition dumper.h:97
virtual void DisplayValue(Dumper &dump, std::tuple< Ts... > values)=0
Prints the value through the Dumper, different types of fields can be displayed in different ways.
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:773
void PrintDecSigned(relative_offset_t value, std::string prefix="#")
Displays a decimal value (default prefix is "#")
Definition dumper.h:839
void PrintHex(offset_t value, unsigned width, std::string prefix="0x")
Displays a hexadecimal value (default prefix is "0x")
Definition dumper.h:813
void EndUnderline()
ANSI escape sequence to remove all formatting.
Definition dumper.h:910
void PrintDec(offset_t value, std::string prefix="#")
Displays a decimal value (default prefix is "#")
Definition dumper.h:831
void BeginUnderline()
ANSI escape sequence to add underline.
Definition dumper.h:901
void PutChar(char32_t c)
Displays a Unicode character as a UTF-8 byte sequence.
Definition dumper.h:857
Definition dumper.h:18
A brief record, such as a relocation or imported library.
Definition dumper.h:687
A typed representation of a named value within a structure.
Definition dumper.h:540
std::shared_ptr< Display< Ts... > > display
The method to show it in.
Definition dumper.h:543
A representation of a named value within a structure.
Definition dumper.h:515
std::string label
The name to be displayed.
Definition dumper.h:518
bool internal
The field should not be displayed, it is for internal use (alternatively, it can be displayed through...
Definition dumper.h:522
bool optional_field
If the field is optional, it will not be displayed for certain values.
Definition dumper.h:520
Represents a field with a hexadecimal display, typically bitfields, addresses, sizes,...
Definition dumper.h:237
static std::shared_ptr< HexDisplay > Make(unsigned width=8)
Creates a hexadecimal display.
Definition dumper.h:251
A record that represents a region within the file.
Definition dumper.h:666
A display with a prefix for a section.
Definition dumper.h:355
static std::shared_ptr< SectionedDisplay > Make(std::string suffix, std::shared_ptr< Display< Ts... > > offset_display)
Create a sectioned display of an unsigned decimal and a secondary value.
Definition dumper.h:383
static std::shared_ptr< SectionedDisplay > Make(std::shared_ptr< Display< Ts... > > offset_display)
Create a sectioned display of an unsigned decimal and a secondary value.
Definition dumper.h:371
A value displayed as a colon-separated pair, typically 8086 segmented addresses.
Definition dumper.h:302
static std::shared_ptr< SegmentedDisplay > Make(unsigned width=4)
Create a segmented display of two hexadecimal values.
Definition dumper.h:316
Definition dumper.h:33
A display for a fixed or variable length string field.
Definition dumper.h:453
offset_t width
The width of the string field, exactly this many characters will be shown, unless it is offset_t(-1),...
Definition dumper.h:458
static std::shared_ptr< StringDisplay > Make(size_t width, std::string quote="")
Create a string display.
Definition dumper.h:486
static std::shared_ptr< StringDisplay > Make(size_t width, std::string open_quote, std::string close_quote)
Create a string display.
Definition dumper.h:474
static std::shared_ptr< StringDisplay > Make(std::string quote="")
Create a string display.
Definition dumper.h:497
Definition dumper.h:61
Definition dumper.h:75
Definition dumper.h:51
A value displayed as a separated pair, such as a version number.
Definition dumper.h:328
static std::shared_ptr< VersionDisplay > Make(std::string separator=".")
Create a version display of two unsigned decimal values.
Definition dumper.h:342