| 22 | |
| 23 | namespace BinaryNinjaDebugger { |
| 24 | struct ModuleNameAndOffset |
| 25 | { |
| 26 | // TODO: maybe we should use DebugModule instead of its name |
| 27 | // Update: We are not using a DebugModule here because the base address information of it can be outdated; |
| 28 | // instead, we only keep a name and an offset. |
| 29 | std::string module; |
| 30 | uint64_t offset; |
| 31 | |
| 32 | ModuleNameAndOffset() : module(""), offset(0) {} |
| 33 | ModuleNameAndOffset(std::string mod, uint64_t off) : module(mod), offset(off) {} |
| 34 | bool operator==(const ModuleNameAndOffset& other) const |
| 35 | { |
| 36 | return IsSameBaseModule(other) && (offset == other.offset); |
| 37 | } |
| 38 | bool operator<(const ModuleNameAndOffset& other) const |
| 39 | { |
| 40 | if (module < other.module) |
| 41 | return true; |
| 42 | if (module > other.module) |
| 43 | return false; |
| 44 | return offset < other.offset; |
| 45 | } |
| 46 | bool operator>(const ModuleNameAndOffset& other) const |
| 47 | { |
| 48 | if (module > other.module) |
| 49 | return true; |
| 50 | if (module < other.module) |
| 51 | return false; |
| 52 | return offset > other.offset; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | static std::string GetPathBaseName(const std::string& path) |
| 57 | { |
| 58 | #ifdef WIN32 |
| 59 | // TODO: someone please write it on Windows! |
| 60 | char baseName[MAX_PATH]; |
| 61 | _splitpath(path.c_str(), NULL, NULL, baseName, NULL); |
| 62 | return std::string(baseName); |
| 63 | #else |
| 64 | return basename(strdup(path.c_str())); |
| 65 | #endif |
| 66 | } |
| 67 | |
| 68 | |
| 69 | bool IsSameBaseModule(const ModuleNameAndOffset& other) const |
| 70 | { |
| 71 | return ((module == other.module) || (GetPathBaseName(module) == GetPathBaseName(other.module))); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | bool IsSameBaseModule(const std::string& other) const |
| 76 | { |
| 77 | return ((module == other) || (GetPathBaseName(module) == GetPathBaseName(other))); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | static bool IsSameBaseModule(const std::string& module1, const std::string& module2) |
no outgoing calls
no test coverage detected