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.
25 #include <boost/random.hpp>
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
;
36 * @brief generate a random number of type UINT8
40 UINT8
utils::random_uint8()
42 return uint8_uniform(random_generator
);
47 * @brief reformat the string showing some memory address.
49 * @param input input 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')))
62 while (str_iter
!= input
.end())
64 output
.push_back(*str_iter
);
73 * @brief convert an ADDRINT to a hexadecimal 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();
88 * @brief determine if a memory address is located in the input message buffer.
90 * @param memory_address examined memory address
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