retdec
intel_hex_parser.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_FILEFORMAT_FILE_FORMAT_INTEL_HEX_INTEL_HEX_PARSER_INTEL_HEX_PARSER_H
8 #define RETDEC_FILEFORMAT_FILE_FORMAT_INTEL_HEX_INTEL_HEX_PARSER_INTEL_HEX_PARSER_H
9 
10 #include <fstream>
11 #include <iostream>
12 #include <vector>
13 
14 #include "retdec/common/address.h"
16 
17 namespace retdec {
18 namespace fileformat {
19 
24 {
25  public:
26  unsigned long long index = 0;
28  std::vector<unsigned char> data;
29 
32  bool operator<(IntelHexSection const &a) const;
34 };
35 
40 {
41  private:
43  bool mode;
44  bool hasEP;
45  std::uint16_t upperAddress;
46  std::uint16_t segmenetAddress;
47  std::uint32_t EIP;
48  std::uint16_t CS;
49  std::uint16_t IP;
52  unsigned long long index;
53  public:
54  std::string errorDesc;
55  std::vector<IntelHexSection> sections;
56  private:
59  bool parse();
60  void handleData(const IntelHexToken &token);
61  void setOffset(const IntelHexToken &token);
62  void setSegment(const IntelHexToken &token);
63  void setEIP(const IntelHexToken &token);
64  void setCSIP(const IntelHexToken &token);
66  public:
68 
71  bool parseFile(const std::string &pathToFile);
72  bool parseStream(std::istream &inputStream);
74 
77  bool hasEntryPoint() const;
78  unsigned long long getEntryPoint() const;
79  std::vector<IntelHexSection> getSectionsByAlignment(unsigned long long alignByValue = 0x10000);
81 
84  static unsigned long long strToInt(const std::string &str);
85  static bool isHexadec(char c);
86  static bool isHexadec(const std::string &vec);
88 };
89 
90 } // namespace fileformat
91 } // namespace retdec
92 
93 #endif
Definition: address.h:21
The IntelHexParser class - Intel HEX semantical analysis.
Definition: intel_hex_parser.h:40
IntelHexTokenizer tokenizer
Tokenizer.
Definition: intel_hex_parser.h:42
IntelHexSection actualSection
Actual section (one section may be constructed from more than one record)
Definition: intel_hex_parser.h:50
bool parseStream(std::istream &inputStream)
Definition: intel_hex_parser.cpp:221
bool hasEntryPoint() const
Definition: intel_hex_parser.cpp:236
void setCSIP(const IntelHexToken &token)
Definition: intel_hex_parser.cpp:179
std::uint32_t EIP
Entry point (EIP register)
Definition: intel_hex_parser.h:47
std::uint16_t IP
Entry point instruction (IP register)
Definition: intel_hex_parser.h:49
bool mode
true when 32bit address mode, false when 20bit segment mode
Definition: intel_hex_parser.h:43
std::uint16_t CS
Entry point segment (CS register)
Definition: intel_hex_parser.h:48
static unsigned long long strToInt(const std::string &str)
Definition: intel_hex_parser.cpp:316
void handleData(const IntelHexToken &token)
Definition: intel_hex_parser.cpp:88
bool hasEP
true if entry point record is in file
Definition: intel_hex_parser.h:44
IntelHexParser()
Definition: intel_hex_parser.cpp:28
void setEIP(const IntelHexToken &token)
Definition: intel_hex_parser.cpp:169
unsigned long long index
Indexing.
Definition: intel_hex_parser.h:52
bool parseFile(const std::string &pathToFile)
Definition: intel_hex_parser.cpp:205
bool parse()
Definition: intel_hex_parser.cpp:46
std::uint16_t upperAddress
Upper 16bits of 32bit address.
Definition: intel_hex_parser.h:45
std::string errorDesc
Error description.
Definition: intel_hex_parser.h:54
unsigned long long getEntryPoint() const
Definition: intel_hex_parser.cpp:245
static bool isHexadec(char c)
Definition: intel_hex_parser.cpp:328
std::vector< IntelHexSection > getSectionsByAlignment(unsigned long long alignByValue=0x10000)
Definition: intel_hex_parser.cpp:261
std::vector< IntelHexSection > sections
Sections (access after methods parseFile() or parseStream() only)
Definition: intel_hex_parser.h:55
void setOffset(const IntelHexToken &token)
Definition: intel_hex_parser.cpp:149
void setSegment(const IntelHexToken &token)
Definition: intel_hex_parser.cpp:159
std::uint16_t segmenetAddress
Segment address.
Definition: intel_hex_parser.h:46
retdec::common::Address actualAddress
Address of last byte saved to actual section.
Definition: intel_hex_parser.h:51
The IntelHexSection class - Intel HEX pseudosection.
Definition: intel_hex_parser.h:24
bool operator<(IntelHexSection const &a) const
Definition: intel_hex_parser.cpp:20
retdec::common::Address address
Definition: intel_hex_parser.h:27
unsigned long long index
Definition: intel_hex_parser.h:26
std::vector< unsigned char > data
Definition: intel_hex_parser.h:28
The Token class - output of tokenizer.
Definition: intel_hex_tokenizer.h:21
The Tokenizer class - Intel HEX lexical analysis.
Definition: intel_hex_tokenizer.h:57
Address, address pair and other derived class representation.
Definition of IntelHexToken and IntelHexTokenizer classes.
Definition: archive_wrapper.h:19