RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
format.h
1#ifndef FORMAT_H
2#define FORMAT_H
3
4#include <map>
5#include <optional>
6#include <string>
7#include "../common.h"
8#include "reader.h"
9#include "writer.h"
10
11namespace Dumper
12{
13 class Dumper;
14}
15
16namespace Linker
17{
18 class Module;
19
23 class Format
24 {
25 public:
26 offset_t file_offset;
27
28 Format(offset_t file_offset = 0)
29 : file_offset(file_offset)
30 {
31 }
32
33 virtual ~Format();
37 virtual void Clear();
41 virtual void ReadFile(Reader& in) = 0;
45 virtual void WriteFile(Writer& out) = 0;
49 virtual void Dump(Dumper::Dumper& dump);
50 };
51
55 class OutputFormat : public virtual Format
56 {
57 public:
61 virtual bool AddSupplementaryOutputFormat(std::string subformat);
65 virtual void SetOptions(std::map<std::string, std::string>& options);
66
70 std::optional<std::string> FetchOption(std::map<std::string, std::string>& options, std::string name);
71
75 std::string FetchOption(std::map<std::string, std::string>& options, std::string name, std::string default_value);
76
80 std::optional<offset_t> FetchIntegerOption(std::map<std::string, std::string>& options, std::string name);
81
85 virtual void SetModel(std::string model);
89 virtual void SetLinkScript(std::string script_file, std::map<std::string, std::string>& options);
93 virtual void ProcessModule(Linker::Module& object);
98 virtual void CalculateValues();
102 virtual void GenerateFile(std::string filename, Linker::Module& module);
109 virtual std::string GetDefaultExtension(Linker::Module& module, std::string filename);
115 virtual std::string GetDefaultExtension(Linker::Module& module);
116 /* x86 only */
128 virtual bool FormatSupportsSegmentation() const;
134 virtual bool FormatIs16bit() const;
141 virtual bool FormatIsLinear() const;
142 /* general */
149 virtual bool FormatSupportsResources() const;
153 virtual bool FormatSupportsLibraries() const; /* imports/exports, fileformat level support, not system support */
154 virtual unsigned FormatAdditionalSectionFlags(std::string section_name) const;
155 };
156
160 class InputFormat : public virtual Format
161 {
162 public:
167 virtual void SetupOptions(std::shared_ptr<OutputFormat> format);
171 virtual void ProduceModule(Module& module, Reader& rd) = 0;
172 /* x86 only */
184 virtual bool FormatProvidesSegmentation() const;
185 /* w65 only */
189 virtual bool FormatRequiresDataStreamFix() const;
190 /* general */
197 virtual bool FormatProvidesResources() const;
201 virtual bool FormatProvidesLibraries() const;
202 };
203}
204
205#endif /* FORMAT_H */
A class to control the output of a file analysis.
Definition dumper.h:550
A class to encode a general file format.
Definition format.h:24
virtual void WriteFile(Writer &out)=0
Stores data in memory to file.
virtual void ReadFile(Reader &in)=0
Loads file into memory.
virtual void Dump(Dumper::Dumper &dump)
Display file contents in a nice manner.
Definition format.cc:11
virtual void Clear()
Resets all fields to their default values, deallocate memory.
Definition format.cc:16
A class that provides a general interface to loading a module.
Definition format.h:161
virtual bool FormatRequiresDataStreamFix() const
Whether the generated file might contain bugs that require fixing.
Definition format.cc:160
virtual void SetupOptions(std::shared_ptr< OutputFormat > format)
Initializes the reader for linking purposes.
Definition format.cc:151
virtual bool FormatProvidesLibraries() const
Whether the format enables importing/exporting libraries.
Definition format.cc:170
virtual void ProduceModule(Module &module, Reader &rd)=0
Reads a file and loads the information into a module object.
virtual bool FormatProvidesResources() const
Whether the format supports resources.
Definition format.cc:165
virtual bool FormatProvidesSegmentation() const
Whether the format enables multiple x86 segments.
Definition format.cc:155
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:20
A class that provides a general interface to setting up generation for a format.
Definition format.h:56
virtual bool FormatSupportsSegmentation() const
Whether the format supports multiple segments.
Definition format.cc:114
virtual void ProcessModule(Linker::Module &object)
Processes the module object and initializes format fields.
Definition format.cc:84
virtual bool FormatSupportsLibraries() const
Whether the format supports libraries.
Definition format.cc:141
virtual std::string GetDefaultExtension(Linker::Module &module)
Provides a default filename for the output file.
virtual bool FormatIsLinear() const
Whether the address space is linear or segmented.
Definition format.cc:124
virtual void GenerateFile(std::string filename, Linker::Module &module)
The main function that handles processing, calculating and generating the final image.
Definition format.cc:92
virtual void SetLinkScript(std::string script_file, std::map< std::string, std::string > &options)
Selects a script file to use for linking.
Definition format.cc:79
virtual bool FormatIs16bit() const
Whether the format is 16-bit or not.
Definition format.cc:119
std::optional< offset_t > FetchIntegerOption(std::map< std::string, std::string > &options, std::string name)
Convenience method to look up option by name and convert it to integer.
Definition format.cc:55
virtual void SetOptions(std::map< std::string, std::string > &options)
Passes command line parameters as settings over to format object.
Definition format.cc:25
std::optional< std::string > FetchOption(std::map< std::string, std::string > &options, std::string name)
Convenience method to look up option by name.
Definition format.cc:29
virtual std::string GetDefaultExtension(Linker::Module &module, std::string filename)
Appends a default extension to the filename.
virtual void SetModel(std::string model)
Sets the way memory is organized, typically modifying a built-in script.
Definition format.cc:71
virtual void CalculateValues()
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition format.cc:88
virtual bool AddSupplementaryOutputFormat(std::string subformat)
If the output format actually drives multiple output formats (resource file, apple double,...
Definition format.cc:20
virtual bool FormatSupportsResources() const
Whether the format supports resources.
Definition format.cc:136
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15