• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / RevilLib / 176

13 Apr 2026 04:45PM UTC coverage: 10.756% (+0.1%) from 10.614%
176

push

github

PredatorCZ
update database

770 of 7159 relevant lines covered (10.76%)

5900.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.39
/src/hashreg.cpp
1
#include "revil/hashreg.hpp"
2
#include "database.hpp"
3
#include "spike/except.hpp"
4
#include "spike/reflect/detail/reflector_class.hpp"
5
#include "spike/reflect/detail/reflector_enum.hpp"
6

7
extern "C" const revil::Header REDB;
8

9
using namespace revil;
10

11
REFLECT(ENUMERATION(Platform), ENUM_MEMBER(Auto), ENUM_MEMBER(Win32),
1✔
12
        ENUM_MEMBER(N3DS), ENUM_MEMBER(PS3), ENUM_MEMBER(X360),
13
        ENUM_MEMBER(CAFE), ENUM_MEMBER(NSW), ENUM_MEMBER(PS4),
14
        ENUM_MEMBER(Android), ENUM_MEMBER(IOS), ENUM_MEMBER(Win64));
15

16
namespace revil {
17

18
std::string_view GetExtension(uint32 hash, std::string_view title,
×
19
                              Platform platform_) {
20
  const uint8 platform = uint8(platform_) & PLATFORM_MASK;
×
21

22
  if (!title.empty()) {
×
23
    auto oKey = LowerBound(title, REDB.titles);
×
24

25
    if (oKey != REDB.titles.end() && std::string_view(oKey->name) == title) {
×
26
      for (auto &fx : oKey->data->fixups) {
×
27
        if (fx.platform == platform) {
×
28
          const ResourceClass *fClasses = fx.classes.operator->();
29

30
          for (size_t i = 0; i < fx.numItems; i++) {
×
31
            if (fClasses[i].hash == hash) {
×
32
              return fClasses[i].extension;
33
            }
34
          }
35
        }
36
      }
37
    }
38
  }
39

40
  auto foundClass = LowerBound(hash, REDB.resourceClasses[platform]);
×
41

42
  if (foundClass != REDB.resourceClasses[platform].end() &&
×
43
      foundClass->hash == hash) {
×
44
    return foundClass->extension;
45
  }
46

47
  foundClass = LowerBound(hash, REDB.resourceClasses[0]);
48

49
  if (foundClass != REDB.resourceClasses[0].end() && foundClass->hash == hash) {
×
50
    return foundClass->extension;
51
  }
52

53
  return {};
×
54
}
55

56
std::string_view GetClassName(uint32 hash) {
×
57
  auto foundResClass = LowerBound(hash, REDB.resourceClasses[0]);
58

59
  if (foundResClass != REDB.resourceClasses[0].end() &&
×
60
      foundResClass->hash == hash) {
×
61
    return foundResClass->name;
62
  }
63

64
  auto foundClass = LowerBound(hash, REDB.classes);
65

66
  if (foundClass != REDB.classes.end() && foundClass->hash == hash) {
×
67
    return foundClass->name;
68
  }
69

70
  return {};
×
71
}
72

73
void GetTitles(TitleCallback cb) {
×
74
  for (auto &p : REDB.titles) {
×
75
    cb(p.name);
×
76
  }
77
}
78

79
/* Lookup order:
80
  extCommon map
81
  if platform not auto lookup class from ext<platform> map
82
*/
83
std::vector<uint32> GetHash(std::string_view extension, std::string_view title,
×
84
                            Platform platform_) {
85
  auto supp = GetTitleSupport(title, platform_);
×
86
  const uint8 platform = uint8(platform_) & PLATFORM_MASK;
×
87

88
  std::vector<uint32> hashes;
×
89

90
  if (!title.empty()) {
×
91
    auto oKey = LowerBound(title, REDB.titles);
×
92

93
    if (oKey != REDB.titles.end() && std::string_view(oKey->name) == title) {
×
94
      for (auto &fx : oKey->data->fixups) {
×
95
        if (fx.platform == platform || fx.platform == 0) {
×
96
          const ResourceClass *fClasses = fx.classes.operator->();
97

98
          for (size_t i = 0; i < fx.numItems; i++) {
×
99
            if (std::string_view fExt(fClasses[i].extension); 
×
100
            fExt == extension) {
×
101
              hashes.emplace_back(fClasses[i].hash);
×
102
            }
103
          }
104
        }
105
      }
106
    }
107
  }
108

109
  if (hashes.empty()) {
×
110
    auto spn =
111
        ClassesFromExtension(REDB, extension, supp->arc.flags & DbArc_Version1);
×
112
    if (spn.size() > 0) {
×
113
      return {spn.begin(), spn.end()};
×
114
    }
115
  } else {
116
    return hashes;
117
  }
118

119
  // for backward compatibility, some extensions might have numerical (hashed)
120
  // extension (not found in main registry) if the extension has been added
121
  // later, just find it by hash and verify it in inverted registry
122
  auto cvted = strtoul(extension.data(), nullptr, 16);
×
123

124
  if (cvted < 0x10000) {
×
125
    return {};
×
126
  }
127

128
  auto extTranslated = GetExtension(cvted, title, platform_);
×
129

130
  if (extTranslated.empty()) {
×
131
    return {};
×
132
  }
133

134
  return GetHash(extTranslated, title, platform_);
×
135
}
136

137
Platforms GetPlatformSupport(std::string_view title) {
×
138
  auto found = LowerBound(title, REDB.titles);
×
139

140
  if (found == REDB.titles.end() || found->name != title) {
×
141
    throw es::RuntimeError("Coundn't find title.");
×
142
  }
143

144
  static const auto refl = GetReflectedEnum<Platform>();
145

146
  Platforms flags;
×
147

148
  for (uint32 i = 1; i < NUM_PLATFORMS; i++) {
×
149
    if (auto plat = found->data->support.operator->()[i - 1].operator->();
×
150
        plat) {
151
      flags.emplace_back(Platform(refl->values[i]));
×
152
    }
153
  }
154

155
  return flags;
×
156
}
157

158
const TitleSupport *GetTitleSupport(std::string_view title, Platform platform) {
×
159
  auto found = LowerBound(title, REDB.titles);
×
160

161
  if (found == REDB.titles.end() || found->name != title) {
×
162
    throw es::RuntimeError("Coundn't find title.");
×
163
  }
164

165
  if (platform == Platform::Auto) {
×
166
    platform = Platform::Win32;
167
  }
168

169
  auto platforms = found->data->support.operator->();
170

171
  auto foundSec = platforms[(uint8(platform) & PLATFORM_MASK) - 1].operator->();
×
172

173
  if (!foundSec && platform != Platform::Win32) {
×
174
    foundSec =
175
        platforms[(uint8(Platform::Win32) & PLATFORM_MASK) - 1].operator->();
176
  }
177

178
  if (!foundSec) {
×
179
    static const auto refl = GetReflectedEnum<Platform>();
180
    const bool inputPlatformBE = IsPlatformBigEndian(platform);
181

182
    for (uint32 i = 1; i < refl->numMembers; i++) {
×
183
      if (IsPlatformBigEndian(Platform(refl->values[i])) == inputPlatformBE &&
×
184
          platforms[i - 1].varPtr) {
×
185
        if (foundSec) {
×
186
          throw es::RuntimeError(
187
              "Ambiguous title support found from fallback.");
×
188
        }
189

190
        foundSec = platforms[i - 1].operator->();
191
      }
192
    }
193
  }
194

195
  if (!foundSec) {
×
196
    throw es::RuntimeError("Title support is null.");
×
197
  }
198

199
  return foundSec;
×
200
}
201

202
} // namespace revil
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc