Skip to content

Commit 9661547

Browse files
committed
Simplification
1 parent bffe7a7 commit 9661547

File tree

4 files changed

+23
-56
lines changed

4 files changed

+23
-56
lines changed

src/IDAStringList.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ void IDAStringList::Populate()
2424

2525
for (size_t i = 0; i < currentQuantity; i++)
2626
{
27-
string_info_t si;
28-
get_strlist_item(i, &si);
27+
std::shared_ptr<IDAString> si = std::make_shared<IDAString>();
28+
get_strlist_item(i, si.get());
2929

30-
m_stringList[si.ea] = std::make_shared<IDAString>(si.ea, si.type, si.length);
30+
m_stringList[si->ea] = si;
3131
}
3232
}
3333

@@ -36,25 +36,16 @@ void IDAStringList::Refresh()
3636
refresh_strlist(inf.minEA, inf.maxEA);
3737
}
3838

39-
IDAString::IDAString()
40-
: m_type(-1),
41-
m_length(0),
42-
m_address(0)
39+
IDAString::IDAString()
4340
{
44-
45-
}
46-
47-
IDAString::IDAString(ea_t address, int type, unsigned int len)
48-
: m_type(type),
49-
m_length(len),
50-
m_address(address)
51-
{
52-
41+
type = -1;
42+
ea = 0;
43+
length = 0;
5344
}
5445

5546
std::string IDAString::Read() const
5647
{
57-
if (m_type == 0)
48+
if (type == 0)
5849
return ReadA();
5950
else
6051
{
@@ -65,10 +56,10 @@ std::string IDAString::Read() const
6556

6657
std::string IDAString::ReadA() const
6758
{
68-
std::unique_ptr<unsigned char[]> buf(new unsigned char[m_length]);
69-
get_many_bytes(m_address, buf.get(), m_length);
59+
std::unique_ptr<unsigned char[]> buf(new unsigned char[length]);
60+
get_many_bytes(ea, buf.get(), length);
7061

71-
for (unsigned int i = 0; i < m_length; ++i)
62+
for (int i = 0; i < length; ++i)
7263
{
7364
if (buf.get()[i] == '\0')
7465
break;
@@ -80,13 +71,13 @@ std::string IDAString::ReadA() const
8071
}
8172
}
8273

83-
return std::string((char*)buf.get(), m_length);
74+
return std::string((char*)buf.get(), length);
8475
}
8576

8677
std::wstring IDAString::ReadW() const
8778
{
88-
std::unique_ptr<wchar_t[]> buf(new wchar_t[m_length]);
89-
get_many_bytes(m_address, buf.get(), m_length);
79+
std::unique_ptr<wchar_t[]> buf(new wchar_t[length]);
80+
get_many_bytes(ea, buf.get(), length);
9081

91-
return std::wstring(buf.get(), m_length);
82+
return std::wstring(buf.get(), length);
9283
}

src/IDAStringList.hpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,14 @@
77
#include <pro.h>
88
#include <strlist.hpp>
99

10-
class IDAString
10+
class IDAString : public string_info_t
1111
{
1212
public:
1313
IDAString();
14-
IDAString(ea_t address, int type, unsigned int len);
1514

1615
std::string Read() const;
1716
std::string ReadA() const;
1817
std::wstring ReadW() const;
19-
20-
operator int() const {
21-
return m_type;
22-
}
23-
24-
ea_t GetEA() const {
25-
return m_address;
26-
}
27-
28-
int GetType() const {
29-
return m_type;
30-
}
31-
32-
int GetLength() const {
33-
return m_length;
34-
}
35-
36-
private:
37-
// eh, can't hurt.
38-
ea_t m_address;
39-
40-
int m_type;
41-
unsigned int m_length;
4218
};
4319

4420
// Purpose: faster than looping through the entire string list every time we want to check something.

src/Plugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void Plugin::OnRun(int arg)
2222
if (arg == -1)
2323
PLUGIN.flags |= PLUGIN_UNL;
2424

25-
msg("Stringref plugin ran.\n");
25+
msg("Stringref plugin ran.\n");
2626

2727
std::vector<RefInfo> references;
2828
FillReferences(references);
@@ -87,7 +87,7 @@ void Plugin::OnXRef(xrefblk_t* xref, std::vector<RefInfo>& references)
8787

8888
auto strInfo = m_stringList[opcodeRef];
8989

90-
if (!strInfo || strInfo->GetType() == -1)
90+
if (!strInfo || strInfo->type == -1)
9191
continue;
9292

9393
xrefblk_t stringXref;

src/Plugin.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class Plugin
3737
void SortAndPrint(std::vector<RefInfo>& references);
3838

3939
public:
40-
static constexpr int flags = 0;
41-
static constexpr char* comment = "Finds string reference near a reference.";
42-
static constexpr char* name = "String Reference Locator";
43-
static constexpr char* help = "Find String References Near Reference";
44-
static constexpr char* hotkey = "Ctrl+Alt+Q";
40+
static constexpr int flags = 0;
41+
static constexpr char* comment = "Finds string references near a reference.";
42+
static constexpr char* name = "String Reference Locator";
43+
static constexpr char* help = "Finds string references near a reference.";
44+
static constexpr char* hotkey = "Ctrl+Alt+Q";
4545

4646
private:
4747
IDAStringList m_stringList;

0 commit comments

Comments
 (0)