diff options
Diffstat (limited to 'utils/zenutils/source/shared/utils.h')
-rwxr-xr-x | utils/zenutils/source/shared/utils.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/utils/zenutils/source/shared/utils.h b/utils/zenutils/source/shared/utils.h new file mode 100755 index 0000000000..ca9e291514 --- /dev/null +++ b/utils/zenutils/source/shared/utils.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* zenutils - Utilities for working with creative firmwares. | ||
2 | * Copyright 2007 (c) Rasmus Ry <rasmus.ry{at}gmail.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
17 | */ | ||
18 | |||
19 | #ifndef SHARED_UTILS_H_INCLUDED | ||
20 | #define SHARED_UTILS_H_INCLUDED | ||
21 | |||
22 | #include <vector> | ||
23 | #include <pelib/PeLib.h> | ||
24 | |||
25 | #ifndef byte | ||
26 | typedef PeLib::byte byte; | ||
27 | #endif | ||
28 | #ifndef word | ||
29 | typedef PeLib::word word; | ||
30 | #endif | ||
31 | #ifndef dword | ||
32 | typedef PeLib::dword dword; | ||
33 | #endif | ||
34 | |||
35 | namespace shared { | ||
36 | typedef std::vector<byte> bytes; | ||
37 | |||
38 | inline dword swap(dword val) | ||
39 | { | ||
40 | return ((val & 0xFF) << 24) | ||
41 | | ((val & 0xFF00) << 8) | ||
42 | | ((val & 0xFF0000) >> 8) | ||
43 | | ((val & 0xFF000000) >> 24); | ||
44 | } | ||
45 | |||
46 | template <typename _Type> | ||
47 | inline void reverse(_Type* start, _Type* end) | ||
48 | { | ||
49 | while (start < end) | ||
50 | { | ||
51 | *start ^= *end; | ||
52 | *end ^= *start; | ||
53 | *start ^= *end; | ||
54 | start++; | ||
55 | end--; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | std::string replace_extension(const std::string& filename, const std::string& extension); | ||
60 | std::string remove_extension(const std::string& filename); | ||
61 | std::string get_path(const std::string& filename); | ||
62 | std::string double_quote(const std::string& str); | ||
63 | |||
64 | bool inflate_to_file(const bytes& buffer, const char* filename); | ||
65 | bool deflate_to_file(const bytes& buffer, const char* filename); | ||
66 | }; //namespace shared | ||
67 | |||
68 | #endif //SHARED_UTILS_H_INCLUDED | ||