clang-format and fix release build

This commit is contained in:
Luke Street 2025-09-26 12:10:56 -06:00
parent f83d228cc1
commit 8b29e1bcbb
3 changed files with 42 additions and 46 deletions

View File

@ -51,15 +51,16 @@ struct PEExportDirectory {
#define FOR_256_2(a, b) \ #define FOR_256_2(a, b) \
FOR_256_3(a, b, 0, 0) \ FOR_256_3(a, b, 0, 0) \
FOR_256_3(a, b, 0, 1) \ FOR_256_3(a, b, 0, 1) \
FOR_256_3(a, b, 0, 2) FOR_256_3(a, b, 0, 3) FOR_256_3(a, b, 1, 0) FOR_256_3(a, b, 1, 1) FOR_256_3(a, b, 1, 2) \ FOR_256_3(a, b, 0, 2) \
FOR_256_3(a, b, 1, 3) FOR_256_3(a, b, 2, 0) FOR_256_3(a, b, 2, 1) FOR_256_3(a, b, 2, 2) FOR_256_3(a, b, 2, 3) \ FOR_256_3(a, b, 0, 3) FOR_256_3(a, b, 1, 0) FOR_256_3(a, b, 1, 1) FOR_256_3(a, b, 1, 2) FOR_256_3(a, b, 1, 3) \
FOR_256_3(a, b, 3, 0) FOR_256_3(a, b, 3, 1) FOR_256_3(a, b, 3, 2) FOR_256_3(a, b, 3, 3) FOR_256_3(a, b, 2, 0) FOR_256_3(a, b, 2, 1) FOR_256_3(a, b, 2, 2) FOR_256_3(a, b, 2, 3) FOR_256_3(a, b, 3, 0) \
FOR_256_3(a, b, 3, 1) FOR_256_3(a, b, 3, 2) FOR_256_3(a, b, 3, 3)
#define FOR_256 \ #define FOR_256 \
FOR_256_2(0, 0) \ FOR_256_2(0, 0) \
FOR_256_2(0, 1) \ FOR_256_2(0, 1) \
FOR_256_2(0, 2) FOR_256_2(0, 3) FOR_256_2(1, 0) FOR_256_2(1, 1) FOR_256_2(1, 2) FOR_256_2(1, 3) FOR_256_2(2, 0) \ FOR_256_2(0, 2) \
FOR_256_2(2, 1) FOR_256_2(2, 2) FOR_256_2(2, 3) FOR_256_2(3, 0) FOR_256_2(3, 1) FOR_256_2(3, 2) \ FOR_256_2(0, 3) FOR_256_2(1, 0) FOR_256_2(1, 1) FOR_256_2(1, 2) FOR_256_2(1, 3) FOR_256_2(2, 0) FOR_256_2(2, 1) \
FOR_256_2(3, 3) FOR_256_2(2, 2) FOR_256_2(2, 3) FOR_256_2(3, 0) FOR_256_2(3, 1) FOR_256_2(3, 2) FOR_256_2(3, 3)
static int stubIndex = 0; static int stubIndex = 0;
static char stubDlls[0x100][0x100]; static char stubDlls[0x100][0x100];
@ -624,7 +625,7 @@ HMODULE loadModule(const char *dllName) {
return nullptr; return nullptr;
} }
std::string requested(dllName); std::string requested(dllName);
DEBUG_LOG("loadModule(%s)\n", requested.c_str()); DEBUG_LOG("loadModule(%s)\n", requested.c_str());
std::lock_guard<std::recursive_mutex> lock(registry().mutex); std::lock_guard<std::recursive_mutex> lock(registry().mutex);
ensureInitialized(); ensureInitialized();

View File

@ -1,5 +1,5 @@
#include "common.h"
#include "resources.h" #include "resources.h"
#include "common.h"
namespace { namespace {
@ -56,8 +56,7 @@ bool resourceNameEquals(const uint8_t *base, uint32_t nameField, const std::u16s
} }
const ImageResourceDirectoryEntry *findEntry(const uint8_t *base, const ImageResourceDirectory *dir, const ImageResourceDirectoryEntry *findEntry(const uint8_t *base, const ImageResourceDirectory *dir,
const wibo::ResourceIdentifier &ident, const wibo::ResourceIdentifier &ident, uint32_t rsrcSize) {
uint32_t rsrcSize) {
const auto *entries = resourceEntries(dir); const auto *entries = resourceEntries(dir);
if (ident.isString) { if (ident.isString) {
for (uint16_t i = 0; i < dir->numberOfNamedEntries; ++i) { for (uint16_t i = 0; i < dir->numberOfNamedEntries; ++i) {
@ -75,7 +74,8 @@ const ImageResourceDirectoryEntry *findEntry(const uint8_t *base, const ImageRes
return nullptr; return nullptr;
} }
const ImageResourceDirectory *entryAsDirectory(const uint8_t *base, const ImageResourceDirectoryEntry *entry, uint32_t rsrcSize) { const ImageResourceDirectory *entryAsDirectory(const uint8_t *base, const ImageResourceDirectoryEntry *entry,
uint32_t rsrcSize) {
if (!(entry->offsetToData & RESOURCE_DATA_IS_DIRECTORY)) if (!(entry->offsetToData & RESOURCE_DATA_IS_DIRECTORY))
return nullptr; return nullptr;
uint32_t offset = entry->offsetToData & ~RESOURCE_DATA_IS_DIRECTORY; uint32_t offset = entry->offsetToData & ~RESOURCE_DATA_IS_DIRECTORY;
@ -84,7 +84,8 @@ const ImageResourceDirectory *entryAsDirectory(const uint8_t *base, const ImageR
return reinterpret_cast<const ImageResourceDirectory *>(base + offset); return reinterpret_cast<const ImageResourceDirectory *>(base + offset);
} }
const wibo::ImageResourceDataEntry *entryAsData(const uint8_t *base, const ImageResourceDirectoryEntry *entry, uint32_t rsrcSize) { const wibo::ImageResourceDataEntry *entryAsData(const uint8_t *base, const ImageResourceDirectoryEntry *entry,
uint32_t rsrcSize) {
if (entry->offsetToData & RESOURCE_DATA_IS_DIRECTORY) if (entry->offsetToData & RESOURCE_DATA_IS_DIRECTORY)
return nullptr; return nullptr;
uint32_t offset = entry->offsetToData; uint32_t offset = entry->offsetToData;
@ -93,14 +94,10 @@ const wibo::ImageResourceDataEntry *entryAsData(const uint8_t *base, const Image
return reinterpret_cast<const wibo::ImageResourceDataEntry *>(base + offset); return reinterpret_cast<const wibo::ImageResourceDataEntry *>(base + offset);
} }
uint16_t primaryLang(uint16_t lang) { uint16_t primaryLang(uint16_t lang) { return lang & 0x3FFu; }
return lang & 0x3FFu;
}
const ImageResourceDirectoryEntry *selectLanguageEntry(const ImageResourceDirectory *dir, const ImageResourceDirectoryEntry *selectLanguageEntry(const ImageResourceDirectory *dir, const uint8_t *base,
const uint8_t *base, uint32_t rsrcSize, std::optional<uint16_t> desired,
uint32_t rsrcSize,
std::optional<uint16_t> desired,
uint16_t &chosenLang) { uint16_t &chosenLang) {
const auto *entries = resourceEntries(dir); const auto *entries = resourceEntries(dir);
uint16_t total = dir->numberOfNamedEntries + dir->numberOfIdEntries; uint16_t total = dir->numberOfNamedEntries + dir->numberOfIdEntries;
@ -143,10 +140,8 @@ const ImageResourceDirectoryEntry *selectLanguageEntry(const ImageResourceDirect
namespace wibo { namespace wibo {
bool Executable::findResource(const ResourceIdentifier &type, bool Executable::findResource(const ResourceIdentifier &type, const ResourceIdentifier &name,
const ResourceIdentifier &name, std::optional<uint16_t> language, ResourceLocation &out) const {
std::optional<uint16_t> language,
ResourceLocation &out) const {
const uint8_t *base = reinterpret_cast<const uint8_t *>(rsrcBase); const uint8_t *base = reinterpret_cast<const uint8_t *>(rsrcBase);
if (!base) { if (!base) {
wibo::lastError = ERROR_RESOURCE_DATA_NOT_FOUND; wibo::lastError = ERROR_RESOURCE_DATA_NOT_FOUND;
@ -201,9 +196,7 @@ bool resourceEntryBelongsToExecutable(const Executable &exe, const ImageResource
return ptr >= base && (ptr + sizeof(*entry)) <= (base + exe.rsrcSize); return ptr >= base && (ptr + sizeof(*entry)) <= (base + exe.rsrcSize);
} }
static bool isIntegerIdentifier(const void *ptr) { static bool isIntegerIdentifier(const void *ptr) { return ((uintptr_t)ptr >> 16) == 0; }
return ((uintptr_t)ptr >> 16) == 0;
}
static std::u16string ansiToU16String(const char *str) { static std::u16string ansiToU16String(const char *str) {
std::u16string result; std::u16string result;

View File

@ -148,11 +148,13 @@ std::string wideStringToString(const uint16_t *src, int len) {
std::string result(count, '\0'); std::string result(count, '\0');
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
uint16_t value = src[i]; uint16_t value = src[i];
#ifndef NDEBUG
if (i > 0) if (i > 0)
hexDump << ' '; hexDump << ' ';
hexDump << "0x" << value; hexDump << "0x" << value;
if (value > 0xFF) if (value > 0xFF)
sawWide = true; sawWide = true;
#endif
result[i] = static_cast<char>(value & 0xFF); result[i] = static_cast<char>(value & 0xFF);
} }