Skip to content

Commit 629a19e

Browse files
committed
Code Clean Up
1 parent 6720907 commit 629a19e

10 files changed

Lines changed: 121 additions & 145 deletions

src/abstract_elfheader.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
#include <cstring>
1616
#include <stdexcept>
1717

18-
#ifdef __APPLE__
19-
#include "endian.h"
20-
#elif WINDOWS
21-
#include <WinSock2.h>
22-
#include "endian.h"
18+
#if WINDOWS || __APPLE__
19+
#include "endian.hpp"
2320
#else
2421
#include <arpa/inet.h>
2522
#endif

src/abstract_programheader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <iostream>
88

99
#if __APPLE__ || WINDOWS
10-
#include "endian.h"
10+
#include "endian.hpp"
1111
#else
1212
#include <arpa/inet.h>
1313
#endif

src/abstract_sectionheader.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include <stdexcept>
88
#include <boost/foreach.hpp>
99

10-
#ifdef __APPLE__
11-
#include "endian.h"
12-
#elif WINDOWS
13-
#include "endian.h"
10+
#if WINDOWS || __APPLE__
11+
#include "endian.hpp"
1412
#else
1513
#include <arpa/inet.h>
1614
#endif

src/abstract_symbol.cpp

Lines changed: 90 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -5,84 +5,79 @@
55
#include <boost/lexical_cast.hpp>
66
#include <sstream>
77

8-
#ifdef __APPLE__
9-
#include "endian.h"
10-
#elif WINDOWS
11-
#include "endian.h"
8+
#if WINDOWS || __APPLE__
9+
#include "endian.hpp"
1210
#else
1311
#include <arpa/inet.h>
1412
#endif
1513

16-
namespace
14+
std::string getSymBinding(boost::uint8_t p_info)
1715
{
18-
std::string getSymBinding(boost::uint8_t p_info)
16+
std::string str;
17+
switch ((p_info >> 4) & 0x0f)
1918
{
20-
switch ((p_info >> 4) & 0x0f)
21-
{
22-
case elf::symbol::k_local:
23-
return "STB_LOCAL";
24-
case elf::symbol::k_global:
25-
return "STB_GLOBAL";
26-
case elf::symbol::k_weak:
27-
return "STB_WEAK";
28-
default:
29-
return boost::lexical_cast<std::string>((p_info >> 4) & 0x0f);
30-
}
19+
case elf::symbol::k_local:
20+
str = "STB_LOCAL";
21+
case elf::symbol::k_global:
22+
str = "STB_GLOBAL";
23+
case elf::symbol::k_weak:
24+
str = "STB_WEAK";
25+
default:
26+
str = boost::lexical_cast<std::string>((p_info >> 4) & 0x0f);
3127
}
28+
return str;
29+
}
3230

33-
std::string getSymType(boost::uint8_t p_info)
31+
std::string getSymType(boost::uint8_t p_info)
32+
{
33+
std::string str;
34+
switch (p_info & 0x0f)
3435
{
35-
switch (p_info & 0x0f)
36-
{
37-
case elf::symbol::k_notype:
38-
return "STT_NOTYPE";
39-
case elf::symbol::k_object:
40-
return "STT_OBJECT";
41-
case elf::symbol::k_function:
42-
return "STT_FUNC";
43-
case elf::symbol::k_section:
44-
return "STT_SECTION";
45-
case elf::symbol::k_file:
46-
return "STT_FILE";
47-
case elf::symbol::k_common:
48-
return "STT_COMMON";
49-
case elf::symbol::k_tls:
50-
return "STT_TLS";
51-
default:
52-
return boost::lexical_cast<std::string>(p_info & 0x0f);
53-
}
36+
case elf::symbol::k_notype:
37+
str = "STT_NOTYPE";
38+
case elf::symbol::k_object:
39+
str = "STT_OBJECT";
40+
case elf::symbol::k_function:
41+
str = "STT_FUNC";
42+
case elf::symbol::k_section:
43+
str = "STT_SECTION";
44+
case elf::symbol::k_file:
45+
str = "STT_FILE";
46+
case elf::symbol::k_common:
47+
str = "STT_COMMON";
48+
case elf::symbol::k_tls:
49+
str = "STT_TLS";
50+
default:
51+
str = boost::lexical_cast<std::string>(p_info & 0x0f);
5452
}
53+
54+
return str;
5555
}
5656

57-
AbstractSymbol::AbstractSymbol(const char* p_data, boost::uint32_t p_offset,
58-
bool p_is64, bool p_isLE) :
59-
m_symbol32(),
60-
m_symbol64(),
61-
m_name(),
62-
m_is64(p_is64),
63-
m_isLE(p_isLE)
57+
AbstractSymbol::AbstractSymbol(const char *p_data, boost::uint32_t p_offset,
58+
bool p_is64, bool p_isLE) : m_symbol32(),
59+
m_symbol64(),
60+
m_name(),
61+
m_is64(p_is64),
62+
m_isLE(p_isLE)
6463
{
6564
if (m_is64)
66-
{
67-
m_symbol64 = reinterpret_cast<const elf::symbol::symtable_entry64*>(p_data + p_offset);
68-
}
65+
m_symbol64 = reinterpret_cast<const elf::symbol::symtable_entry64 *>(p_data + p_offset);
6966
else
70-
{
71-
m_symbol32 = reinterpret_cast<const elf::symbol::symtable_entry32*>(p_data + p_offset);
72-
}
67+
m_symbol32 = reinterpret_cast<const elf::symbol::symtable_entry32 *>(p_data + p_offset);
7368

7469
std::stringstream value;
7570
value << "0x" << std::hex << getValue();
7671
m_name.assign(value.str());
7772
}
7873

79-
AbstractSymbol::AbstractSymbol(const AbstractSymbol& p_rhs) :
80-
m_symbol32(p_rhs.m_symbol32),
81-
m_symbol64(p_rhs.m_symbol64),
82-
m_name(p_rhs.m_name),
83-
m_is64(p_rhs.m_is64),
84-
m_isLE(p_rhs.m_isLE)
74+
AbstractSymbol::AbstractSymbol(const AbstractSymbol &p_rhs)
8575
{
76+
m_symbol32 = p_rhs.m_symbol32;
77+
m_symbol64 = p_rhs.m_symbol64;
78+
m_name = p_rhs.m_name;
79+
m_is64 = p_rhs.m_is64;
80+
m_isLE = p_rhs.m_isLE;
8681
}
8782

8883
AbstractSymbol::~AbstractSymbol()
@@ -91,29 +86,35 @@ AbstractSymbol::~AbstractSymbol()
9186

9287
boost::uint32_t AbstractSymbol::getStructSize() const
9388
{
89+
boost::uint32_t size;
9490
if (m_is64)
95-
{
96-
return sizeof(elf::symbol::symtable_entry64);
97-
}
98-
return sizeof(elf::symbol::symtable_entry32);
91+
size = sizeof(elf::symbol::symtable_entry64);
92+
else
93+
size = sizeof(elf::symbol::symtable_entry32);
94+
95+
return size;
9996
}
10097

10198
boost::uint8_t AbstractSymbol::getType() const
10299
{
100+
boost::uint8_t type;
103101
if (m_is64)
104-
{
105-
return m_symbol64->m_info & 0x0f;
106-
}
107-
return m_symbol32->m_info & 0x0f;
102+
type = m_symbol64->m_info & 0x0f;
103+
else
104+
type = m_symbol32->m_info & 0x0f;
105+
106+
return type;
108107
}
109108

110109
boost::uint8_t AbstractSymbol::getInfo() const
111110
{
111+
boost::uint8_t info;
112112
if (m_is64)
113-
{
114-
return m_symbol64->m_info;
115-
}
116-
return m_symbol32->m_info;
113+
info = m_symbol64->m_info;
114+
else
115+
info = m_symbol32->m_info;
116+
117+
return info;
117118
}
118119

119120
std::string AbstractSymbol::getTypeName() const
@@ -128,40 +129,44 @@ std::string AbstractSymbol::getBinding() const
128129

129130
boost::uint64_t AbstractSymbol::getValue() const
130131
{
132+
boost::uint64_t value;
131133
if (m_is64)
132-
{
133-
return m_isLE ? m_symbol64->m_address : htobe64(m_symbol64->m_address);
134-
}
135-
return m_isLE ? m_symbol32->m_address : ntohl(m_symbol32->m_address);
134+
value = m_isLE ? m_symbol64->m_address : htobe64(m_symbol64->m_address);
135+
else
136+
value = m_isLE ? m_symbol32->m_address : ntohl(m_symbol32->m_address);
137+
138+
return value;
136139
}
137140

138141
boost::uint32_t AbstractSymbol::getNameIndex() const
139142
{
143+
boost::uint32_t name;
140144
if (m_is64)
141-
{
142-
return m_isLE ? m_symbol64->m_name : ntohl(m_symbol64->m_name);
143-
}
144-
return m_isLE ? m_symbol32->m_name : ntohl(m_symbol32->m_name);
145+
name = m_isLE ? m_symbol64->m_name : ntohl(m_symbol64->m_name);
146+
else
147+
name = m_isLE ? m_symbol32->m_name : ntohl(m_symbol32->m_name);
148+
149+
return name;
145150
}
146151

147152
boost::uint16_t AbstractSymbol::getSectionIndex() const
148153
{
154+
boost::uint16_t index;
149155
if (m_is64)
150-
{
151-
return m_isLE ? m_symbol64->m_shndx : ntohs(m_symbol64->m_shndx);
152-
}
153-
return m_isLE ? m_symbol32->m_shndx : ntohs(m_symbol32->m_shndx);
156+
index = m_isLE ? m_symbol64->m_shndx : ntohs(m_symbol64->m_shndx);
157+
else
158+
index = m_isLE ? m_symbol32->m_shndx : ntohs(m_symbol32->m_shndx);
159+
160+
return index;
154161
}
155162

156-
const std::string& AbstractSymbol::getName() const
163+
const std::string &AbstractSymbol::getName() const
157164
{
158165
return m_name;
159166
}
160167

161-
void AbstractSymbol::setName(const std::string& p_name)
168+
void AbstractSymbol::setName(const std::string &p_name)
162169
{
163170
if (!p_name.empty())
164-
{
165171
m_name.assign(p_name);
166-
}
167-
}
172+
}

src/dynamicsection.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
#include <boost/foreach.hpp>
66
#include <boost/assign.hpp>
77

8-
#ifdef __APPLE__
9-
#include "endian.h"
10-
#elif WINDOWS
11-
#include "endian.h"
8+
#if WINDOWS || __APPLE__
9+
#include "endian.hpp"
1210
#else
1311
#include <arpa/inet.h>
1412
#endif

src/elfparser.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
#include "elfparser.hpp"
1212
#include "structures/elfheader.hpp"
1313
#include "datastructures/search_value.hpp"
14-
#include "../lib/hash-lib/md5.h"
15-
#include "../lib/hash-lib/sha256.h"
16-
#include "../lib/hash-lib/md5.h"
17-
#include "../lib/hash-lib/sha1.h"
14+
#include "../lib/hash-lib/md5.hpp"
15+
#include "../lib/hash-lib/sha256.hpp"
16+
#include "../lib/hash-lib/sha1.hpp"
1817

1918
#include <map>
2019
#include <set>

src/initarray.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#include <sstream>
33
#include <boost/foreach.hpp>
44

5-
#ifdef __APPLE__
6-
#include "endian.h"
7-
#elif WINDOWS
8-
#include "endian.h"
5+
#if WINDOWS || __APPLE__
6+
#include "endian.hpp"
97
#else
108
#include <arpa/inet.h>
119
#endif
@@ -73,4 +71,4 @@ std::string InitArray::printToStd() const
7371
}
7472

7573
return returnValue.str();
76-
}
74+
}

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void do_parsing(const std::string &p_fileName, bool p_printReasons,
103103
if (!parser.getFamily().empty())
104104
{
105105
std::cout <<"[Family: " << parser.getFamily() << "]" << std::endl << std::endl;
106-
std::cout <<"[SHA56: " << std::hex << parser.getSha256() << " ]" << std::endl;
106+
std::cout <<"[SHA256: " << std::hex << parser.getSha256() << " ]" << std::endl;
107107
std::cout <<"[SHA1: " << std::hex << parser.getSha1() << " ]" << std::endl;
108108
std::cout <<"[MD5: " << std::hex << parser.getMD5() << " ]" << std::endl << std::endl;
109109
}

src/programheaders.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#include <sstream>
88

99
ProgramHeaders::ProgramHeaders() : m_programHeaders()
10-
{ }
10+
{
11+
}
1112

1213
ProgramHeaders::~ProgramHeaders()
13-
{ }
14+
{
15+
}
1416

1517
void ProgramHeaders::setHeaders(const char *p_data, boost::uint16_t p_count,
1618
boost::uint16_t p_size, bool p_is64, bool p_isLE)
@@ -59,28 +61,17 @@ void ProgramHeaders::evaluate(std::vector<std::pair<boost::int32_t, std::string>
5961

6062
BOOST_FOREACH (const AbstractProgramHeader &header, m_programHeaders)
6163
{
62-
switch (header.getType())
64+
if (header.getType() == elf::k_pload)
6365
{
64-
case elf::k_pload:
6566
++load_count;
6667
found_load = true;
67-
break;
68-
default:
69-
break;
7068
}
7169
++entry_count;
7270
}
7371

7472
if (load_count > 2)
75-
{
7673
p_reasons.push_back(std::make_pair(30, std::string("Found 2+ PT_LOAD. Possible post-compilation addition of code (cryptor or packer)")));
77-
}
7874

79-
if (entry_count > 0)
80-
{
81-
if (!found_load)
82-
{
83-
p_reasons.push_back(std::make_pair(5, std::string("Didn't find PT_LOAD in the program headers")));
84-
}
85-
}
75+
if (entry_count > 0 && !found_load)
76+
p_reasons.push_back(std::make_pair(5, std::string("Didn't find PT_LOAD in the program headers")));
8677
}

0 commit comments

Comments
 (0)