KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
kunai-lib
include
Kunai
DEX
parser
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
20
namespace
KUNAI
21
{
22
namespace
DEX
23
{
24
class
Header
25
{
26
public
:
27
#pragma pack(1)
31
struct
dexheader_t
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
69
void
parse_headers
(
stream::KunaiStream
* stream);
70
73
Header
(
Header
& header)
74
{
75
memcpy(&dexheader, &header.dexheader,
sizeof
(
dexheader_t
));
76
}
77
79
~Header
() =
default
;
80
85
const
dexheader_t
&
get_dex_header_const
()
const
86
{
87
return
dexheader;
88
}
89
93
dexheader_t
&
get_dex_header
()
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
KUNAI::DEX::Header
Definition
header.hpp:25
KUNAI::DEX::Header::get_dex_header_size
std::uint64_t get_dex_header_size() const
Obtain the size of the dex header structure.
Definition
header.hpp:100
KUNAI::DEX::Header::get_dex_header
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
KUNAI::DEX::Header::Header
Header()=default
DEX header constructor.
KUNAI::DEX::Header::Header
Header(Header &header)
Copy constructor of dex header.
Definition
header.hpp:73
KUNAI::DEX::Header::operator<<
friend std::ostream & operator<<(std::ostream &os, const Header &entry)
Pretty printer for the operator << of the DEX header.
KUNAI::DEX::Header::to_xml
void to_xml(std::ofstream &fos)
Dump the content of the DEX header to an XML file.
KUNAI::DEX::Header::get_dex_header_const
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
KUNAI::DEX::Header::parse_headers
void parse_headers(stream::KunaiStream *stream)
Internal function for parsing the dex headers.
KUNAI::DEX::Header::~Header
~Header()=default
destructor of DEX header
KUNAI::stream::KunaiStream
Class to manage an input file stream given for the analysis.
Definition
kunaistream.hpp:20
KUNAI
utilities
Definition
analysis.hpp:23
KUNAI::DEX::Header::dexheader_t
Structure with the definition of the DEX header all these values are later used for parsing the other...
Definition
header.hpp:32
KUNAI::DEX::Header::dexheader_t::data_size
std::uint32_t data_size
offset of the class definitions
Definition
header.hpp:54
KUNAI::DEX::Header::dexheader_t::method_ids_size
std::uint32_t method_ids_size
offset of the fields
Definition
header.hpp:50
KUNAI::DEX::Header::dexheader_t::type_ids_off
std::uint32_t type_ids_off
number of types
Definition
header.hpp:45
KUNAI::DEX::Header::dexheader_t::signature
std::uint8_t signature[20]
checksum to see if file is correct
Definition
header.hpp:35
KUNAI::DEX::Header::dexheader_t::class_defs_size
std::uint32_t class_defs_size
offset of the methods
Definition
header.hpp:52
KUNAI::DEX::Header::dexheader_t::data_off
std::uint32_t data_off
data area, containing all the support data for the tables listed above
Definition
header.hpp:55
KUNAI::DEX::Header::dexheader_t::link_size
std::uint32_t link_size
type of endianess of the file
Definition
header.hpp:39
KUNAI::DEX::Header::dexheader_t::string_ids_off
std::uint32_t string_ids_off
number of strings
Definition
header.hpp:43
KUNAI::DEX::Header::dexheader_t::field_ids_off
std::uint32_t field_ids_off
number of fields
Definition
header.hpp:49
KUNAI::DEX::Header::dexheader_t::method_ids_off
std::uint32_t method_ids_off
number of methods
Definition
header.hpp:51
KUNAI::DEX::Header::dexheader_t::proto_ids_off
std::uint32_t proto_ids_off
number of prototypes
Definition
header.hpp:47
KUNAI::DEX::Header::dexheader_t::file_size
std::uint32_t file_size
signature of dex
Definition
header.hpp:36
KUNAI::DEX::Header::dexheader_t::link_off
std::uint32_t link_off
data for statically linked files
Definition
header.hpp:40
KUNAI::DEX::Header::dexheader_t::header_size
std::uint32_t header_size
current file size
Definition
header.hpp:37
KUNAI::DEX::Header::dexheader_t::proto_ids_size
std::uint32_t proto_ids_size
offset of the types
Definition
header.hpp:46
KUNAI::DEX::Header::dexheader_t::checksum
std::int32_t checksum
magic bytes from dex, different values are possible
Definition
header.hpp:34
KUNAI::DEX::Header::dexheader_t::type_ids_size
std::uint32_t type_ids_size
offset of the strings
Definition
header.hpp:44
KUNAI::DEX::Header::dexheader_t::class_defs_off
std::uint32_t class_defs_off
number of class definitions
Definition
header.hpp:53
KUNAI::DEX::Header::dexheader_t::field_ids_size
std::uint32_t field_ids_size
offset of the prototypes
Definition
header.hpp:48
KUNAI::DEX::Header::dexheader_t::endian_tag
std::uint32_t endian_tag
size of this header
Definition
header.hpp:38
Generated by
1.9.8