summaryrefslogtreecommitdiff
path: root/utils/zenutils/source/shared/pe.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/zenutils/source/shared/pe.cpp')
-rw-r--r--[-rwxr-xr-x]utils/zenutils/source/shared/pe.cpp256
1 files changed, 128 insertions, 128 deletions
diff --git a/utils/zenutils/source/shared/pe.cpp b/utils/zenutils/source/shared/pe.cpp
index c86ec6c8cc..10070074dd 100755..100644
--- a/utils/zenutils/source/shared/pe.cpp
+++ b/utils/zenutils/source/shared/pe.cpp
@@ -1,128 +1,128 @@
1/* zenutils - Utilities for working with creative firmwares. 1/* zenutils - Utilities for working with creative firmwares.
2 * Copyright 2007 (c) Rasmus Ry <rasmus.ry{at}gmail.com> 2 * Copyright 2007 (c) Rasmus Ry <rasmus.ry{at}gmail.com>
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 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 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 6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. 7 * (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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 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 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */ 17 */
18 18
19#include "pe.h" 19#include "pe.h"
20 20
21 21
22shared::pe_file::pe_file(PeLib::PeFile* pef) : _pef(pef) 22shared::pe_file::pe_file(PeLib::PeFile* pef) : _pef(pef)
23{ 23{
24} 24}
25shared::pe_file::~pe_file() 25shared::pe_file::~pe_file()
26{ 26{
27 if (_pef != NULL) 27 if (_pef != NULL)
28 delete _pef; 28 delete _pef;
29} 29}
30 30
31bool shared::pe_file::is_valid() const 31bool shared::pe_file::is_valid() const
32{ 32{
33 if (_pef->getBits() == 32) 33 if (_pef->getBits() == 32)
34 { 34 {
35 PeLib::PeHeader32& pef32 = static_cast<PeLib::PeFile32*>(_pef)->peHeader(); 35 PeLib::PeHeader32& pef32 = static_cast<PeLib::PeFile32*>(_pef)->peHeader();
36 if (!pef32.isValid()) 36 if (!pef32.isValid())
37 return false; 37 return false;
38 return true; 38 return true;
39 } 39 }
40 else if (_pef->getBits() == 64) 40 else if (_pef->getBits() == 64)
41 { 41 {
42 PeLib::PeHeader64& pef64 = static_cast<PeLib::PeFile64*>(_pef)->peHeader(); 42 PeLib::PeHeader64& pef64 = static_cast<PeLib::PeFile64*>(_pef)->peHeader();
43 if (!pef64.isValid()) 43 if (!pef64.isValid())
44 return false; 44 return false;
45 return true; 45 return true;
46 } 46 }
47 return false; 47 return false;
48} 48}
49 49
50bool shared::pe_file::read(const std::string& filename) 50bool shared::pe_file::read(const std::string& filename)
51{ 51{
52 if (_pef != NULL) 52 if (_pef != NULL)
53 { 53 {
54 delete _pef; 54 delete _pef;
55 _pef = NULL; 55 _pef = NULL;
56 } 56 }
57 57
58 _pef = PeLib::openPeFile(filename); 58 _pef = PeLib::openPeFile(filename);
59 if (!_pef) 59 if (!_pef)
60 { 60 {
61 return false; 61 return false;
62 } 62 }
63 if (_pef->readMzHeader()) 63 if (_pef->readMzHeader())
64 { 64 {
65 delete _pef; 65 delete _pef;
66 return false; 66 return false;
67 } 67 }
68 if (!_pef->mzHeader().isValid()) 68 if (!_pef->mzHeader().isValid())
69 { 69 {
70 delete _pef; 70 delete _pef;
71 return false; 71 return false;
72 } 72 }
73 if (_pef->readPeHeader()) 73 if (_pef->readPeHeader())
74 { 74 {
75 delete _pef; 75 delete _pef;
76 return false; 76 return false;
77 } 77 }
78 if (!is_valid()) 78 if (!is_valid())
79 { 79 {
80 delete _pef; 80 delete _pef;
81 return false; 81 return false;
82 } 82 }
83 return true; 83 return true;
84} 84}
85 85
86bool shared::pe_file::find_section(const std::string& name, section_info& info) const 86bool shared::pe_file::find_section(const std::string& name, section_info& info) const
87{ 87{
88 if (_pef->getBits() == 32) 88 if (_pef->getBits() == 32)
89 return find_section(static_cast<PeLib::PeFile32*>(_pef), 89 return find_section(static_cast<PeLib::PeFile32*>(_pef),
90 name, info); 90 name, info);
91 else if (_pef->getBits() == 64) 91 else if (_pef->getBits() == 64)
92 return find_section(static_cast<PeLib::PeFile64*>(_pef), 92 return find_section(static_cast<PeLib::PeFile64*>(_pef),
93 name, info); 93 name, info);
94 return false; 94 return false;
95} 95}
96 96
97bool shared::pe_file::add_section(const std::string& name, 97bool shared::pe_file::add_section(const std::string& name,
98 const bytes& buffer, section_info& info) 98 const bytes& buffer, section_info& info)
99{ 99{
100 if (_pef->getBits() == 32) 100 if (_pef->getBits() == 32)
101 { 101 {
102 return add_section(static_cast<PeLib::PeFile32*>(_pef), 102 return add_section(static_cast<PeLib::PeFile32*>(_pef),
103 name, buffer, info); 103 name, buffer, info);
104 } 104 }
105 else if (_pef->getBits() == 64) 105 else if (_pef->getBits() == 64)
106 { 106 {
107 return add_section(static_cast<PeLib::PeFile64*>(_pef), 107 return add_section(static_cast<PeLib::PeFile64*>(_pef),
108 name, buffer, info); 108 name, buffer, info);
109 } 109 }
110 return false; 110 return false;
111} 111}
112 112
113dword shared::pe_file::get_image_base() const 113dword shared::pe_file::get_image_base() const
114{ 114{
115 if (_pef->getBits() == 32) 115 if (_pef->getBits() == 32)
116 return static_cast<PeLib::PeFile32*>(_pef)->peHeader().getImageBase(); 116 return static_cast<PeLib::PeFile32*>(_pef)->peHeader().getImageBase();
117 else 117 else
118 return static_cast<PeLib::PeFile64*>(_pef)->peHeader().getImageBase(); 118 return static_cast<PeLib::PeFile64*>(_pef)->peHeader().getImageBase();
119 return 0; 119 return 0;
120} 120}
121dword shared::pe_file::pa_to_va(dword pa) const 121dword shared::pe_file::pa_to_va(dword pa) const
122{ 122{
123 if (_pef->getBits() == 32) 123 if (_pef->getBits() == 32)
124 return static_cast<PeLib::PeFile32*>(_pef)->peHeader().offsetToVa(pa); 124 return static_cast<PeLib::PeFile32*>(_pef)->peHeader().offsetToVa(pa);
125 else 125 else
126 return static_cast<PeLib::PeFile64*>(_pef)->peHeader().offsetToVa(pa); 126 return static_cast<PeLib::PeFile64*>(_pef)->peHeader().offsetToVa(pa);
127 return 0; 127 return 0;
128} 128}