Still cannot know why it does not work
[PathExplorer.git] / src / utilities / utils.cpp
blob6e329ddd4ad57ddf678fd2edefcb7a9a429b9a94
1 /*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2013 Ta Thanh Dinh <email>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "utils.h"
22 #include "../main.h"
23 #include <sstream>
24 #include <ctime>
25 #include <boost/random.hpp>
27 namespace utilities
30 // initialize a random generator and a uniform distribution
31 boost::random::taus88 random_generator(static_cast<unsigned int>(std::time(0)));
32 boost::random::uniform_int_distribution<UINT8> uint8_uniform;
35 /**
36 * @brief generate a random number of type UINT8
38 * @return UINT8
40 UINT8 utils::random_uint8()
42 return uint8_uniform(random_generator);
46 /**
47 * @brief reformat the string showing some memory address.
49 * @param input input string
50 * @return std::string
52 std::string utils::remove_leading_zeros(std::string input)
54 std::string::iterator str_iter = input.begin();
55 std::string output("0x");
57 while ((str_iter != input.end()) && ((*str_iter == '0') || (*str_iter == 'x')))
59 ++str_iter;
62 while (str_iter != input.end())
64 output.push_back(*str_iter);
65 ++str_iter;
68 return output;
72 /**
73 * @brief convert an ADDRINT to a hexadecimal string
75 * @param input ...
76 * @return std::string
78 std::string utils::addrint2hexstring(ADDRINT input)
80 std::stringstream num_stream;
81 num_stream << "0x" << std::hex << input;
82 return num_stream.str();
87 /**
88 * @brief determine if a memory address is located in the input message buffer.
90 * @param memory_address examined memory address
91 * @return bool
93 bool utils::is_in_input_buffer(ADDRINT memory_address)
95 return ((received_message_address <= memory_address) &&
96 (memory_address < received_message_address + received_message_length));
99 } // end of utilities namespace