8#include "../dumper/dumper.h"
9#include "../linker/module.h"
10#include "../linker/segment.h"
11#include "../linker/segment_manager.h"
12#include "../linker/writer.h"
18 typedef char OSType[4];
45 format_type type = DOUBLE;
57 hfs_type home_file_system = HFS_UNDEFINED;
76 virtual void CalculateValues();
80 static const char TXT_undefined[16];
81 static const char TXT_Macintosh[16];
82 static const char TXT_ProDOS[16];
83 static const char TXT_MS_DOS[16];
84 static const char TXT_UNIX[16];
85 static const char TXT_VAX_VMS[16];
88 std::vector<std::shared_ptr<Entry>> entries;
101 ID_MacintoshFileInfo,
113 AppleSingleDouble(format_type type,
unsigned version, hfs_type home_file_system)
114 : type(type), version(version), home_file_system(version == 1 ? home_file_system : HFS_UNDEFINED)
116 assert(type == SINGLE || type == DOUBLE);
119 AppleSingleDouble(format_type type, hfs_type home_file_system)
120 : type(type), version(1), home_file_system(home_file_system)
122 assert(type == SINGLE || type == DOUBLE);
125 AppleSingleDouble(format_type type,
unsigned version = 2)
126 : type(type), version(version), home_file_system(HFS_UNDEFINED)
128 assert(type == SINGLE || type == DOUBLE);
132 explicit AppleSingleDouble(AppleSingleDouble& other, format_type type)
133 : type(type), version(other.version), home_file_system(other.home_file_system)
135 if(type == SINGLE && other.type == DOUBLE)
139 for(
auto entry : other.entries)
141 if(type == DOUBLE && entry->id == ID_DataFork)
143 entries.push_back(entry);
147 explicit AppleSingleDouble(AppleSingleDouble& other)
148 : type(other.type), version(other.version), home_file_system(other.home_file_system)
150 for(
auto entry : other.entries)
152 entries.push_back(entry);
156 void SetOptions(std::map<std::string, std::string>& options)
override;
157 void SetModel(std::string model)
override;
158 void SetLinkScript(std::string script_file, std::map<std::string, std::string>& options)
override;
160 std::shared_ptr<const Entry> FindEntry(uint32_t
id)
const;
161 std::shared_ptr<Entry> FindEntry(uint32_t
id);
164 std::shared_ptr<Entry> GetFileDatesInfo();
165 std::shared_ptr<Entry> GetMacintoshFileInfo();
166 std::shared_ptr<Entry> GetAUXFileInfo();
167 std::shared_ptr<Entry> GetProDOSFileInfo();
168 std::shared_ptr<Entry> GetMSDOSFileInfo();
170 std::shared_ptr<Entry> GetDataFork();
171 std::shared_ptr<Entry> GetResourceFork();
172 std::shared_ptr<Entry> GetFinderInfo();
175 void SetCreationDate(uint32_t CreationDate);
176 void SetModificationDate(uint32_t ModificationDate);
177 void SetBackupDate(uint32_t BackupDate);
178 void SetAccessDate(uint32_t AccessDate);
179 void SetMacintoshAttributes(uint32_t Attributes);
180 void SetProDOSAccess(uint16_t Access);
181 void SetProDOSFileType(uint16_t FileType);
182 void SetProDOSAUXType(uint32_t AUXType);
183 void SetMSDOSAttributes(uint16_t Attributes);
185 uint32_t GetCreationDate();
186 uint32_t GetModificationDate();
187 uint32_t GetMacintoshAttributes();
195 std::string PrefixFilename(std::string prefix, std::string filename);
196 std::string PrefixFilename(std::string prefix, std::string filename,
size_t limit);
197 std::string ReplaceExtension(std::string filename, std::string extension,
size_t limit);
199 std::string GetUNIXDoubleFilename(std::string filename);
200 std::string GetMacOSXDoubleFilename(std::string filename);
201 std::string GetProDOSDoubleFilename(std::string filename);
202 std::string GetMSDOSDoubleFilename(std::string filename);
214 : Entry(AppleSingleDouble::ID_DataFork)
241 memory_model_t memory_model = MODEL_DEFAULT;
244 void SetOptions(std::map<std::string, std::string>& options)
override;
246 void SetModel(std::string model)
override;
257 Resource(
const char type[4], uint16_t
id, uint8_t attributes = 0)
258 : id(
id), attributes(attributes)
260 memcpy(this->type, type, 4);
263 Resource(
const char type[4], uint16_t
id, std::string name, uint8_t attributes = 0)
264 : id(
id), name(name), attributes(attributes)
266 memcpy(this->type, type, 4);
273 std::optional<std::string> name;
277 uint16_t name_offset = 0;
278 uint32_t data_offset = 0;
291 std::shared_ptr<Linker::Segment> resource;
318 uint32_t above_a5 = 0;
319 uint32_t below_a5 = 0;
320 std::vector<Entry> near_entries;
321 std::vector<Entry> far_entries;
331 MOVE_DATA_SP = 0x3F3C,
343 std::shared_ptr<JumpTableCodeResource> jump_table;
344 std::shared_ptr<Linker::Segment> image;
346 CodeResource(uint16_t
id, std::shared_ptr<JumpTableCodeResource> jump_table)
347 :
Resource(
"CODE",
id), jump_table(jump_table)
352 uint32_t a5_address = 0;
353 uint32_t base_address = 0;
357 std::set<uint16_t> near_entries;
358 std::set<uint32_t> far_entries;
359 std::set<uint32_t> a5_relocations;
360 std::set<uint32_t> segment_relocations;
363 uint32_t first_near_entry_offset;
364 uint32_t first_far_entry_offset;
365 uint32_t a5_relocation_offset;
366 uint32_t segment_relocation_offset;
367 uint32_t resource_size;
375 uint32_t MeasureRelocations(std::set<uint32_t>& relocations)
const;
377 void WriteRelocations(
Linker::Writer& wr,
const std::set<uint32_t>& relocations)
const;
393 uint16_t attributes = 0;
394 std::map<uint32_t, std::map<uint16_t, std::shared_ptr<Resource>>> resources;
397 uint32_t data_offset = 0, data_length = 0, map_offset = 0, map_length = 0;
398 uint16_t name_list_offset = 0;
399 std::map<uint32_t, uint16_t> reference_list_offsets;
402 std::shared_ptr<JumpTableCodeResource> jump_table;
403 std::vector<std::shared_ptr<CodeResource>> codes;
404 std::map<std::shared_ptr<Linker::Segment>, std::shared_ptr<CodeResource>> segments;
405 std::shared_ptr<Linker::Segment> a5world;
407 void AddResource(std::shared_ptr<Resource> resource);
409 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
417 void CalculateValues()
override;
437 : Entry(AppleSingleDouble::ID_RealName), name(name)
452 : Entry(AppleSingleDouble::ID_Comment)
462 : Entry(AppleSingleDouble::ID_IconBW)
472 : Entry(AppleSingleDouble::ID_IconColor)
483 : Entry(AppleSingleDouble::ID_FileInfo)
497 uint32_t CreationDate;
498 uint32_t ModificationDate;
499 uint32_t LastBackupDate;
503 uint32_t ModificationDate = 0,
504 uint32_t LastBackupDate = 0,
505 uint32_t Attributes = 0)
506 : CreationDate(CreationDate), ModificationDate(ModificationDate), LastBackupDate(LastBackupDate), Attributes(Attributes)
520 uint32_t CreationDate;
521 uint32_t ModificationDate;
526 ProDOS(uint32_t CreationDate = 0,
527 uint32_t ModificationDate = 0,
529 uint16_t FileType = 0,
530 uint32_t AUXType = 0)
531 : CreationDate(CreationDate), ModificationDate(ModificationDate), Access(Access), FileType(FileType), AUXType(AUXType)
545 uint32_t ModificationDate;
548 MSDOS(uint32_t ModificationDate = 0,
549 uint16_t Attributes = 0)
550 : ModificationDate(ModificationDate), Attributes(Attributes)
564 uint32_t CreationDate;
566 uint32_t ModificationDate;
568 AUX(uint32_t CreationDate = 0,
569 uint32_t AccessDate = 0,
570 uint32_t ModificationDate = 0)
571 : CreationDate(CreationDate), AccessDate(AccessDate), ModificationDate(ModificationDate)
586 uint32_t CreationDate;
587 uint32_t ModificationDate;
592 uint32_t CreationDate = 0,
593 uint32_t ModificationDate = 0,
594 uint32_t BackupDate = 0,
595 uint32_t AccessDate = 0)
596 : Entry(AppleSingleDouble::ID_FileDatesInfo),
597 CreationDate(CreationDate), ModificationDate(ModificationDate), BackupDate(BackupDate), AccessDate(AccessDate)
616 char Type[4] = {
'?',
'?',
'?',
'?' };
617 char Creator[4] = {
'?',
'?',
'?',
'?' };
619 Point Location = { 0, 0 };
622 : Entry(AppleSingleDouble::ID_FinderInfo)
641 : Entry(AppleSingleDouble::ID_MacintoshFileInfo), Attributes(Attributes)
661 uint16_t FileType = 0,
662 uint32_t AUXType = 0)
663 : Entry(AppleSingleDouble::ID_ProDOSFileInfo), Access(Access), FileType(FileType), AUXType(AUXType)
681 : Entry(AppleSingleDouble::ID_MSDOSFileInfo), Attributes(Attributes)
697 : Entry(AppleSingleDouble::ID_AFPShortName)
708 : Entry(AppleSingleDouble::ID_AFPFileInfo)
719 : Entry(AppleSingleDouble::ID_AFPDirectoryID)
739 version_t version, minimum_version;
741 uint16_t secondary_header_size = 0;
742 mutable uint16_t crc = 0;
744 uint8_t attributes = 0;
745 uint32_t creation = 0;
746 uint32_t modification = 0;
748 std::string generated_file_name;
751 :
AppleSingleDouble(AppleSingleDouble::DOUBLE), version(version), minimum_version(version <= MACBIN2 ? version : MACBIN2)
755 MacBinary(version_t version, version_t minimum_version)
756 :
AppleSingleDouble(AppleSingleDouble::DOUBLE), version(version), minimum_version(version < minimum_version ? version : minimum_version)
761 :
AppleSingleDouble(apple, AppleSingleDouble::DOUBLE), version(version), minimum_version(version < minimum_version ? version : minimum_version)
766 static uint16_t crc_step[256];
768 void CRC_Initialize()
const;
770 void CRC_Step(uint8_t
byte = 0)
const;
774 void WriteData(
Linker::Writer& wr,
size_t count,
const void * data)
const;
776 void WriteData(
Linker::Writer& wr,
size_t count, std::string text)
const;
778 void WriteWord(
Linker::Writer& wr,
size_t bytes, uint64_t value)
const;
806 TARGET_RESOURCE_FORK,
809 target_format_t target;
812 enum produce_format_t
814 PRODUCE_RESOURCE_FORK = 1 << 0,
815 PRODUCE_FINDER_INFO = 1 << 1,
816 PRODUCE_APPLE_DOUBLE = 1 << 2,
817 PRODUCE_MAC_BINARY = 1 << 3,
819 produce_format_t produce;
828 unsigned apple_single_double_version = 2;
830 AppleSingleDouble::hfs_type home_file_system = AppleSingleDouble::HFS_UNDEFINED;
832 MacBinary::version_t macbinary_version = MacBinary::MACBIN3, macbinary_minimum_version = MacBinary::MACBIN2;
834 MacDriver(target_format_t target = TARGET_DATA_FORK)
836 produce(target == TARGET_NONE ? PRODUCE_MAC_BINARY
837 : target == TARGET_DATA_FORK ? PRODUCE_APPLE_DOUBLE
838 : produce_format_t(0))
842 MacDriver(target_format_t target,
int produce)
843 : target(target), produce(produce_format_t(produce))
852 std::shared_ptr<AppleSingleDouble> container;
854 std::map<std::string, std::string> options;
856 std::string script_file;
857 std::map<std::string, std::string> script_options;
860 void SetOptions(std::map<std::string, std::string>& options)
override;
862 void SetModel(std::string model)
override;
864 void SetLinkScript(std::string script_file, std::map<std::string, std::string>& options)
override;
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition macos.cc:22
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:27
offset_t WriteFile(Linker::Writer &out) const override
Stores data in memory to file.
Definition macos.cc:32
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:38
AppleSingle & AppleDouble.
Definition macos.h:34
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition macos.cc:58
bool FormatSupportsResources() const override
Whether the format supports resources.
Definition macos.cc:17
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition macos.cc:12
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition macos.cc:541
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition macos.cc:688
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:628
void SetModel(std::string model) override
Sets the way memory is organized, typically modifying a built-in script.
Definition macos.cc:65
std::string GetDefaultExtension(Linker::Module &module) const override
Provides a default filename for the output file.
Definition macos.cc:724
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:575
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:567
void SetLinkScript(std::string script_file, std::map< std::string, std::string > &options) override
Selects a script file to use for linking.
Definition macos.cc:70
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1415
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1410
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1426
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1390
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1395
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1405
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1371
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1376
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1385
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1333
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1344
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1328
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1354
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1366
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1349
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1431
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1436
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1450
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1504
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1499
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1512
MacBinary is an alternative format to AppleSingle for representing a Macintosh file on a non-Macintos...
Definition macos.h:729
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:1672
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1680
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1707
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition macos.cc:1718
This is not actually a file format, but an interface to permit generating multiple binary outputs for...
Definition macos.h:799
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition macos.cc:1904
bool FormatSupportsResources() const override
Whether the format supports resources.
Definition macos.cc:1726
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1909
void SetLinkScript(std::string script_file, std::map< std::string, std::string > &options) override
Selects a script file to use for linking.
Definition macos.cc:1772
bool AddSupplementaryOutputFormat(std::string subformat) override
If the output format actually drives multiple output formats (resource file, apple double,...
Definition macos.cc:1731
void SetModel(std::string model) override
Sets the way memory is organized, typically modifying a built-in script.
Definition macos.cc:1767
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition macos.cc:1778
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition macos.cc:1762
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1461
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1466
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1474
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1479
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1494
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1484
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1310
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1323
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1315
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:938
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition macos.cc:862
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:866
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:876
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:967
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:778
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:790
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:783
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:774
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition macos.cc:770
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:857
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition macos.cc:795
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:823
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition macos.cc:799
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:811
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition macos.cc:753
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:758
offset_t ImageSize() const override=0
Retrieves size of stored data.
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:765
A Macintosh resource fork.
Definition macos.h:229
std::string GetDefaultExtension(Linker::Module &module) const override
Provides a default filename for the output file.
Definition macos.cc:1305
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition macos.cc:1295
offset_t ImageSize() const override
Retrieves size of stored data.
Definition macos.cc:1220
void OnNewSegment(std::shared_ptr< Linker::Segment > segment) override
Callback function when allocating a new segment When the linker script runs, it creates segments cons...
Definition macos.cc:982
void SetModel(std::string model) override
Sets the way memory is organized, typically modifying a built-in script.
Definition macos.cc:734
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition macos.cc:729
bool FormatSupportsResources() const override
Whether the format supports resources.
Definition macos.h:231
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition macos.cc:1284
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition macos.cc:1225
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:586
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
A helper class to collect sections into segments.
Definition segment_manager.h:32
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15