KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
strings.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 strings.hpp
7// @brief Class for managing the list of strings, these strings
8// follow an specific format where a `string_data_off` is used
9// to point to an `string_data_item`
10
11#ifndef KUNAI_DEX_PARSER_STRINGS_HPP
12#define KUNAI_DEX_PARSER_STRINGS_HPP
13
14#include <iostream>
15#include <vector>
16#include <algorithm>
17#include <unordered_map>
18
19#include "Kunai/Utils/kunaistream.hpp"
20
21namespace KUNAI
22{
23namespace DEX
24{
27 using ordered_strings_t = std::vector<std::string>;
28
29 using offset_string_t = std::unordered_map<std::uint32_t, std::string*>;
30
33 class Strings
34 {
36 std::uint32_t strings_offset;
38 std::uint32_t number_of_strings;
40 ordered_strings_t ordered_strings;
42 offset_string_t offset_strings;
43
44 public:
46 Strings() = default;
47
51
53 ~Strings() = default;
54
59 void parse_strings(std::uint32_t strings_offset,
60 std::uint32_t number_of_strings,
61 stream::KunaiStream* stream);
62
63 const ordered_strings_t& get_ordered_strings() const
64 {
65 return ordered_strings;
66 }
67
70 const offset_string_t& get_offset_strings() const
71 {
72 return offset_strings;
73 }
74
78 std::string* get_string_from_offset(std::uint32_t offset);
79
83 std::string& get_string_by_id(std::uint32_t id);
84
87 std::uint32_t get_number_of_strings() const
88 {
89 return number_of_strings;
90 }
91
96 friend std::ostream& operator<<(std::ostream& os, const Strings& entry);
97
100 void to_xml(std::ofstream& fos);
101 };
102}
103}
104
105#endif // KUNAI_DEX_PARSER_DEXSTRINGS_HPP
Storage class for all the strings of the DEX file.
Definition strings.hpp:34
std::string * get_string_from_offset(std::uint32_t offset)
Return a pointer to an string giving an offset.
std::uint32_t get_number_of_strings() const
Get the number of the strings stored.
Definition strings.hpp:87
Strings(Strings &str)
Copy constructors of strings.
std::string & get_string_by_id(std::uint32_t id)
Get reference to string by a given id.
~Strings()=default
destructor of the strings.
Strings()=default
Constructor of string class.
void to_xml(std::ofstream &fos)
Dump the Strings to an XML.
friend std::ostream & operator<<(std::ostream &os, const Strings &entry)
pretty print the list of strings.
const offset_string_t & get_offset_strings() const
Return the offset strings map as constant.
Definition strings.hpp:70
void parse_strings(std::uint32_t strings_offset, std::uint32_t number_of_strings, stream::KunaiStream *stream)
Parse the strings from the DEX file.
Class to manage an input file stream given for the analysis.
Definition kunaistream.hpp:20
utilities
Definition analysis.hpp:23