libPeConv
A library to load, manipulate, dump PE files.
Loading...
Searching...
No Matches
exported_func.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <windows.h>
9#include <string>
10#include <algorithm>
11#include <set>
12
13namespace peconv {
14
15 const DWORD INVALID_ORD_VALUE = DWORD(-1);
16
20 size_t forwarder_name_len(BYTE* fPtr);
21
25 std::string get_dll_shortname(const std::string& str);
26
30 std::string get_func_name(const std::string& str);
31
35 std::string ordinal_to_string(DWORD func_ordinal);
36
40 bool is_ordinal_string(const std::string& str);
41
45 DWORD ordinal_string_to_val(const std::string& str);
46
50 std::string format_dll_func(const std::string& str);
51
56 {
57 public:
61 static std::string formatName(std::string name);
62
64 static bool isTheSameFuncName(const peconv::ExportedFunc& func1, const peconv::ExportedFunc& func2);
65
67 static bool isTheSameDllName(const peconv::ExportedFunc& func1, const peconv::ExportedFunc& func2);
68
70 static bool isTheSameFunc(const peconv::ExportedFunc& func1, const peconv::ExportedFunc& func2);
71
72 std::string libName;
73 std::string funcName;
76
77 //default constructor:
79
80 ExportedFunc(const ExportedFunc& other);
81 ExportedFunc(std::string libName, std::string funcName, DWORD funcOrdinal);
82 ExportedFunc(std::string libName, DWORD funcOrdinal);
83 ExportedFunc(const std::string &forwarderName);
84
91 bool operator < (const ExportedFunc& other) const
92 {
93 //if only one function is named, give the preference to the named one:
94 const size_t thisNameLen = this->funcName.length();
95 const size_t otherNameLen = other.funcName.length();
96 if (thisNameLen == 0 && otherNameLen > 0) {
97 return false;
98 }
99 if (thisNameLen > 0 && otherNameLen == 0) {
100 return true;
101 }
102 //select by shorter lib name:
103 int cmp = libName.compare(other.libName);
104 if (cmp != 0) {
105 return cmp < 0;
106 }
107 if (thisNameLen == 0 || otherNameLen == 0) {
108 return this->funcOrdinal < other.funcOrdinal;
109 }
110 if (thisNameLen != otherNameLen) {
111 return thisNameLen < otherNameLen;
112 }
113 cmp = funcName.compare(other.funcName);
114 return cmp < 0;
115 }
116
120 std::string toString() const;
121
125 std::string nameToString() const;
126
127 bool isValid() const
128 {
129 return (funcName != "" || funcOrdinal != INVALID_ORD_VALUE);
130 }
131 };
132
133}; //namespace peconv
134
bool operator<(const ExportedFunc &other) const
Definition: exported_func.h:91
std::string funcName
Definition: exported_func.h:73
bool isValid() const
static bool isTheSameFunc(const peconv::ExportedFunc &func1, const peconv::ExportedFunc &func2)
Compares functions' names. If function is defined by an ordinal, compares ordinals....
std::string nameToString() const
static bool isTheSameDllName(const peconv::ExportedFunc &func1, const peconv::ExportedFunc &func2)
Compares functions' DLL names.
static bool isTheSameFuncName(const peconv::ExportedFunc &func1, const peconv::ExportedFunc &func2)
Compares functions' names. If function is defined by an ordinal, compares ordinals....
static std::string formatName(std::string name)
std::string toString() const
bool is_ordinal_string(const std::string &str)
std::string ordinal_to_string(DWORD func_ordinal)
size_t forwarder_name_len(BYTE *fPtr)
std::string get_func_name(const std::string &str)
std::string format_dll_func(const std::string &str)
const DWORD INVALID_ORD_VALUE
Definition: exported_func.h:15
DWORD ordinal_string_to_val(const std::string &str)
std::string get_dll_shortname(const std::string &str)