forked from geohot/eda-2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.h
97 lines (74 loc) · 2.65 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// util.h -- May 9, 2009
// by geohot
// part of "The Embedded Disassembler"
// released under GPLv3, see http://gplv3.fsf.org/
#ifndef EDA_UTIL_H_
#define EDA_UTIL_H_
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
namespace eda {
class Address;
const std::string kXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
#ifdef WIN32
const std::string kDataDirectory = "..\\eda-2\\Data\\";
#else
const std::string kDataDirectory = "../../../eda-2/Data/";
#endif
#ifdef WIN32
const std::string kBaseDirectory = "..\\eda-2\\";
#else
const std::string kBaseDirectory = "../../../eda-2/";
#endif
// Returns things like 9 and 0x4F
std::string immed(uint32_t data);
// Signed
std::string immed_signed(int32_t data);
uint32_t stoi(const std::string& num);
std::string MakeWellFormedXML(const std::string& in);
bool file_to_string(const std::string& filename, std::string* out);
int find_matching(const std::string& s, int start, char open, char close);
std::vector<int> FetchGAIsFromAddresses(const std::vector<Address*>& a);
void SerializeToXML(std::ostringstream& out, const std::vector<int>* v, std::string name, std::string item);
void StringSplit(const char* a, const std::string& in, std::vector<std::string>* argv);
void StringSplit(char a, const std::string& in, std::vector<std::string>* argv);
// LOG(INFO)
// LOG(ERROR)
#ifdef WIN32
#define THIS_FILE ((strrchr(__FILE__, 0x5C) ?: __FILE__ - 1) + 1)
#else
#define THIS_FILE ((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)
#endif
//#define LOG std::cout << std::endl << std::hex << THIS_FILE << "--" << __PRETTY_FUNCTION__ << ": "
//#define LOG std::cout << std::dec << THIS_FILE << "--" << __PRETTY_FUNCTION__ << ": "
//#define LOG std::cout << std::dec << THIS_FILE << "--" << __FUNCTION__ << ": "
//#define INFO std::cout << std::dec << THIS_FILE << ": "
#define LOG(x) Logging(x, THIS_FILE, __PRETTY_FUNCTION__, __FUNCTION__, __LINE__).stream()
#define INFO 0
#define WARNING 1
#define DEBUG 3
#ifndef WIN32
// This is a problem on windows
#define ERROR 2
#endif
class Logging {
public:
Logging(int level, const char* file, const char* pretty_function, const char* function, int line_number);
~Logging() {
// Is the .str needed?
//std::cout << stream_.str() << std::endl;
std::cout << std::endl;
}
std::ostream& stream() { return std::cout; } //return stream_; }
//private:
//std::ostringstream stream_;
};
//inline uint32_t rol(uint32_t data, int len);
#define rol(data, len) ((data << len) | (data >> (32-len)))
//inline uint32_t ror(uint32_t data, int len);
#define ror(data, len) ((data >> len) | (data << (32-len)))
}
#endif