diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-06-19 11:58:16 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-06-19 11:58:16 +0200 |
| commit | c66d1f5c0af70161f4ad4c4175f4280e95b55dfd (patch) | |
| tree | f8e5e5d6dc921054182e478be742ac30258c56c6 /mz/mz_header.hpp | |
| download | openwar-c66d1f5c0af70161f4ad4c4175f4280e95b55dfd.tar.gz openwar-c66d1f5c0af70161f4ad4c4175f4280e95b55dfd.tar.bz2 openwar-c66d1f5c0af70161f4ad4c4175f4280e95b55dfd.zip | |
Initial commit of a mz-header parser.
Diffstat (limited to 'mz/mz_header.hpp')
| -rw-r--r-- | mz/mz_header.hpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/mz/mz_header.hpp b/mz/mz_header.hpp new file mode 100644 index 0000000..ad5f419 --- /dev/null +++ b/mz/mz_header.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include <cstdint> +#include <cstddef> +#include <stdexcept> +#include <istream> +#include <ostream> + +#include <boost/serialization/strong_typedef.hpp> + +BOOST_STRONG_TYPEDEF(uint16_t, Magic); + +struct NotAMZFileException : public std::runtime_error { + NotAMZFileException(); +}; + +struct UnexpectedEOS : public std::runtime_error { + UnexpectedEOS(); + + UnexpectedEOS(std::string location); +}; + +struct MZHeader { + Magic magic; + uint16_t bytes_in_last_block; + uint16_t blocks_in_file; + uint16_t num_relocs; + uint16_t header_paragraphs; + uint16_t min_extra_paragraphs; + uint16_t max_extra_paragraphs; + uint16_t ss; + uint16_t sp; + uint16_t checksum; + uint16_t ip; + uint16_t cs; + uint16_t reloc_table_offset; + uint16_t overlay_number; +}; + +uint16_t parse_uint16_t(std::istream& is, std::string name = ""); + +MZHeader parse_mz_file(std::istream& is); + +void print_mz_header(MZHeader const& header); + +std::ostream& operator<<(std::ostream& os, MZHeader const& header); + |
