KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
header.hpp
1//--------------------------------------------------------------------*- C++ -*-
2// Kunai-static-analyzer: library for doing analysis of dalvik files
3// @author Farenain <kunai.static.analysis@gmail.com>
4// @author Ernesto Java <javaernesto@gmail.com>
5//
6// @file header.hpp
7// @brief File to manage the structure of the DEX header
8// this will be useful for the other classes that will use
9// the values from this header
10#ifndef KUNAI_DEX_PARSER_HEADER_HPP
11#define KUNAI_DEX_PARSER_HEADER_HPP
12
13
14#include "Kunai/Utils/logger.hpp"
15#include "Kunai/Utils/kunaistream.hpp"
16#include "Kunai/Exceptions/parser_exception.hpp"
17#include <iostream>
18#include <iomanip>
19
20namespace KUNAI
21{
22 namespace DEX
23 {
24 class Header
25 {
26 public:
27#pragma pack(1)
32 {
33 std::uint8_t magic[8];
34 std::int32_t checksum;
35 std::uint8_t signature[20];
36 std::uint32_t file_size;
37 std::uint32_t header_size;
38 std::uint32_t endian_tag;
39 std::uint32_t link_size;
40 std::uint32_t link_off;
41 std::uint32_t map_off;
42 std::uint32_t string_ids_size;
43 std::uint32_t string_ids_off;
44 std::uint32_t type_ids_size;
45 std::uint32_t type_ids_off;
46 std::uint32_t proto_ids_size;
47 std::uint32_t proto_ids_off;
48 std::uint32_t field_ids_size;
49 std::uint32_t field_ids_off;
50 std::uint32_t method_ids_size;
51 std::uint32_t method_ids_off;
52 std::uint32_t class_defs_size;
53 std::uint32_t class_defs_off;
54 std::uint32_t data_size;
55 std::uint32_t data_off;
56 };
57#pragma pack()
58
59 private:
61 struct dexheader_t dexheader;
62
63 public:
65 Header() = default;
66
70
73 Header(Header& header)
74 {
75 memcpy(&dexheader, &header.dexheader, sizeof(dexheader_t));
76 }
77
79 ~Header() = default;
80
86 {
87 return dexheader;
88 }
89
94 {
95 return dexheader;
96 }
97
100 std::uint64_t get_dex_header_size() const
101 {
102 return sizeof(dexheader_t);
103 }
104
109 friend std::ostream &operator<<(std::ostream &os, const Header &entry);
110
113 void to_xml(std::ofstream &fos);
114 };
115 } // namespace DEX
116} // namespace KUNAI
117
118#endif
Definition header.hpp:25
std::uint64_t get_dex_header_size() const
Obtain the size of the dex header structure.
Definition header.hpp:100
dexheader_t & get_dex_header()
Obtain a reference of the dex header struct just in case in the future DEX modification is allowed.
Definition header.hpp:93
Header()=default
DEX header constructor.
Header(Header &header)
Copy constructor of dex header.
Definition header.hpp:73
friend std::ostream & operator<<(std::ostream &os, const Header &entry)
Pretty printer for the operator << of the DEX header.
void to_xml(std::ofstream &fos)
Dump the content of the DEX header to an XML file.
const dexheader_t & get_dex_header_const() const
Obtain a constant reference of the dex header struct if no value will be modified,...
Definition header.hpp:85
void parse_headers(stream::KunaiStream *stream)
Internal function for parsing the dex headers.
~Header()=default
destructor of DEX header
Class to manage an input file stream given for the analysis.
Definition kunaistream.hpp:20
utilities
Definition analysis.hpp:23
Structure with the definition of the DEX header all these values are later used for parsing the other...
Definition header.hpp:32
std::uint32_t data_size
offset of the class definitions
Definition header.hpp:54
std::uint32_t method_ids_size
offset of the fields
Definition header.hpp:50
std::uint32_t type_ids_off
number of types
Definition header.hpp:45
std::uint8_t signature[20]
checksum to see if file is correct
Definition header.hpp:35
std::uint32_t class_defs_size
offset of the methods
Definition header.hpp:52
std::uint32_t data_off
data area, containing all the support data for the tables listed above
Definition header.hpp:55
std::uint32_t link_size
type of endianess of the file
Definition header.hpp:39
std::uint32_t string_ids_off
number of strings
Definition header.hpp:43
std::uint32_t field_ids_off
number of fields
Definition header.hpp:49
std::uint32_t method_ids_off
number of methods
Definition header.hpp:51
std::uint32_t proto_ids_off
number of prototypes
Definition header.hpp:47
std::uint32_t file_size
signature of dex
Definition header.hpp:36
std::uint32_t link_off
data for statically linked files
Definition header.hpp:40
std::uint32_t header_size
current file size
Definition header.hpp:37
std::uint32_t proto_ids_size
offset of the types
Definition header.hpp:46
std::int32_t checksum
magic bytes from dex, different values are possible
Definition header.hpp:34
std::uint32_t type_ids_size
offset of the strings
Definition header.hpp:44
std::uint32_t class_defs_off
number of class definitions
Definition header.hpp:53
std::uint32_t field_ids_size
offset of the prototypes
Definition header.hpp:48
std::uint32_t endian_tag
size of this header
Definition header.hpp:38