diff --git a/.clang-format b/.clang-format index 5036dcb..4a24aec 100644 --- a/.clang-format +++ b/.clang-format @@ -17,19 +17,29 @@ AlignConsecutiveMacros: AcrossEmptyLines: false AcrossComments: false AllowAllParametersOfDeclarationOnNextLine: false +AllowAllArgumentsOnNextLine: false +AlignOperands: AlignAfterOperator +AlignConsecutiveBitFields: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false AllowShortLambdasOnASingleLine: All +AllowShortBlocksOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakTemplateDeclarations: 'Yes' BinPackArguments: false BinPackParameters: false -BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Custom +BreakBeforeBinaryOperators: NonAssignment ColumnLimit: 120 CommentPragmas: '^ IWYU pragma:' ConstructorInitializerIndentWidth: 0 IndentWidth: 4 Language: Cpp MaxEmptyLinesToKeep: 2 +PackConstructorInitializers: CurrentLine PointerAlignment: Left TabWidth: 4 UseTab: Never diff --git a/src/pe_editor/CxxOptAdder.h b/src/pe_editor/CxxOptAdder.h index 51e2fd6..4f7336f 100644 --- a/src/pe_editor/CxxOptAdder.h +++ b/src/pe_editor/CxxOptAdder.h @@ -8,7 +8,8 @@ class CxxOptsAdder { public: inline CxxOptsAdder(cxxopts::Options& options, const std::string& groupName = "") - : options(options), adder(options.add_options(groupName)) {} + : options(options), + adder(options.add_options(groupName)) {} inline CxxOptsAdder& add(const std::string& opts, diff --git a/src/pe_editor/FakeSymbol.cpp b/src/pe_editor/FakeSymbol.cpp index f4ea7cf..bc0efca 100644 --- a/src/pe_editor/FakeSymbol.cpp +++ b/src/pe_editor/FakeSymbol.cpp @@ -7,38 +7,22 @@ namespace pe_editor::FakeSymbol { inline demangler::ms_demangle::SpecialIntrinsicKind consumeSpecialIntrinsicKind(StringView& MangledName) { using namespace demangler::ms_demangle; using namespace demangler; - if (MangledName.consumeFront("?_7")) - return SpecialIntrinsicKind::Vftable; - if (MangledName.consumeFront("?_8")) - return SpecialIntrinsicKind::Vbtable; - if (MangledName.consumeFront("?_9")) - return SpecialIntrinsicKind::VcallThunk; - if (MangledName.consumeFront("?_A")) - return SpecialIntrinsicKind::Typeof; - if (MangledName.consumeFront("?_B")) - return SpecialIntrinsicKind::LocalStaticGuard; - if (MangledName.consumeFront("?_C")) - return SpecialIntrinsicKind::StringLiteralSymbol; - if (MangledName.consumeFront("?_P")) - return SpecialIntrinsicKind::UdtReturning; - if (MangledName.consumeFront("?_R0")) - return SpecialIntrinsicKind::RttiTypeDescriptor; - if (MangledName.consumeFront("?_R1")) - return SpecialIntrinsicKind::RttiBaseClassDescriptor; - if (MangledName.consumeFront("?_R2")) - return SpecialIntrinsicKind::RttiBaseClassArray; - if (MangledName.consumeFront("?_R3")) - return SpecialIntrinsicKind::RttiClassHierarchyDescriptor; - if (MangledName.consumeFront("?_R4")) - return SpecialIntrinsicKind::RttiCompleteObjLocator; - if (MangledName.consumeFront("?_S")) - return SpecialIntrinsicKind::LocalVftable; - if (MangledName.consumeFront("?__E")) - return SpecialIntrinsicKind::DynamicInitializer; - if (MangledName.consumeFront("?__F")) - return SpecialIntrinsicKind::DynamicAtexitDestructor; - if (MangledName.consumeFront("?__J")) - return SpecialIntrinsicKind::LocalStaticThreadGuard; + if (MangledName.consumeFront("?_7")) return SpecialIntrinsicKind::Vftable; + if (MangledName.consumeFront("?_8")) return SpecialIntrinsicKind::Vbtable; + if (MangledName.consumeFront("?_9")) return SpecialIntrinsicKind::VcallThunk; + if (MangledName.consumeFront("?_A")) return SpecialIntrinsicKind::Typeof; + if (MangledName.consumeFront("?_B")) return SpecialIntrinsicKind::LocalStaticGuard; + if (MangledName.consumeFront("?_C")) return SpecialIntrinsicKind::StringLiteralSymbol; + if (MangledName.consumeFront("?_P")) return SpecialIntrinsicKind::UdtReturning; + if (MangledName.consumeFront("?_R0")) return SpecialIntrinsicKind::RttiTypeDescriptor; + if (MangledName.consumeFront("?_R1")) return SpecialIntrinsicKind::RttiBaseClassDescriptor; + if (MangledName.consumeFront("?_R2")) return SpecialIntrinsicKind::RttiBaseClassArray; + if (MangledName.consumeFront("?_R3")) return SpecialIntrinsicKind::RttiClassHierarchyDescriptor; + if (MangledName.consumeFront("?_R4")) return SpecialIntrinsicKind::RttiCompleteObjLocator; + if (MangledName.consumeFront("?_S")) return SpecialIntrinsicKind::LocalVftable; + if (MangledName.consumeFront("?__E")) return SpecialIntrinsicKind::DynamicInitializer; + if (MangledName.consumeFront("?__F")) return SpecialIntrinsicKind::DynamicAtexitDestructor; + if (MangledName.consumeFront("?__J")) return SpecialIntrinsicKind::LocalStaticThreadGuard; return SpecialIntrinsicKind::None; } @@ -49,13 +33,11 @@ std::optional getFakeSymbol(const std::string& fn, bool removeVirtu Demangler demangler; StringView name(fn.c_str()); - if (!name.consumeFront('?')) - return std::nullopt; + if (!name.consumeFront('?')) return std::nullopt; SpecialIntrinsicKind specialIntrinsicKind = consumeSpecialIntrinsicKind(name); - if (specialIntrinsicKind != SpecialIntrinsicKind::None) - return std::nullopt; + if (specialIntrinsicKind != SpecialIntrinsicKind::None) return std::nullopt; SymbolNode* symbolNode = demangler.demangleDeclarator(name); if (symbolNode == nullptr diff --git a/src/pe_editor/Filter.h b/src/pe_editor/Filter.h index be9faa2..3bf88c6 100644 --- a/src/pe_editor/Filter.h +++ b/src/pe_editor/Filter.h @@ -21,8 +21,8 @@ const std::vector prefix = { }; inline bool matchSkip(std::string_view name) { - return ctre::match(name) || ctre::match(name) || - ctre::match(name); + return ctre::match(name) || ctre::match(name) + || ctre::match(name); } } // namespace pe_editor::filter diff --git a/src/pe_editor/PdbReader.cpp b/src/pe_editor/PdbReader.cpp index d411cbd..59a0219 100644 --- a/src/pe_editor/PdbReader.cpp +++ b/src/pe_editor/PdbReader.cpp @@ -84,14 +84,10 @@ inline bool IsError(PDB::ErrorCode errorCode) { } inline bool HasValidDBIStreams(const PDB::RawFile& rawPdbFile, const PDB::DBIStream& dbiStream) { - if (IsError(dbiStream.HasValidImageSectionStream(rawPdbFile))) - return false; - if (IsError(dbiStream.HasValidPublicSymbolStream(rawPdbFile))) - return false; - if (IsError(dbiStream.HasValidGlobalSymbolStream(rawPdbFile))) - return false; - if (IsError(dbiStream.HasValidSectionContributionStream(rawPdbFile))) - return false; + if (IsError(dbiStream.HasValidImageSectionStream(rawPdbFile))) return false; + if (IsError(dbiStream.HasValidPublicSymbolStream(rawPdbFile))) return false; + if (IsError(dbiStream.HasValidGlobalSymbolStream(rawPdbFile))) return false; + if (IsError(dbiStream.HasValidSectionContributionStream(rawPdbFile))) return false; return true; } } // namespace @@ -108,11 +104,9 @@ std::unique_ptr> loadFunctions(const PDB::RawFile& rawPdbFile, const PDB::CodeView::DBI::Record* record = publicSymbolStream.GetRecord(symbolRecordStream, hashRecord); const uint32_t rva = imageSectionStream.ConvertSectionOffsetToRVA(record->data.S_PUB32.section, record->data.S_PUB32.offset); - if (rva == 0u) - continue; + if (rva == 0u) continue; const std::string symbol(record->data.S_PUB32.name); - if (symbol.empty()) - continue; + if (symbol.empty()) continue; const bool isFunction = (bool)(record->data.S_PUB32.flags & PDB::CodeView::DBI::PublicSymbolFlags::Function); func->push_back(PdbSymbol(symbol, rva, isFunction)); } diff --git a/src/pe_editor/PdbReader.h b/src/pe_editor/PdbReader.h index dbea30a..5d2b61a 100644 --- a/src/pe_editor/PdbReader.h +++ b/src/pe_editor/PdbReader.h @@ -1,9 +1,9 @@ #pragma once #include +#include #include #include -#include struct PdbSymbol { std::string name; diff --git a/src/pe_editor/PeEditor.cpp b/src/pe_editor/PeEditor.cpp index 7415857..de534a8 100644 --- a/src/pe_editor/PeEditor.cpp +++ b/src/pe_editor/PeEditor.cpp @@ -22,8 +22,7 @@ namespace pe_editor { inline void pause() { - if (config::shouldPause) - system("pause"); + if (config::shouldPause) system("pause"); } inline void exitWith(int code) { @@ -48,7 +47,7 @@ void parseArgs(int argc, char** argv) { value()->default_value("false") ) .add("p,pause", "Pause before exit (will be true if no arg passed)", value()->default_value("false")) - .add("n,new", "Use LiteLoader v3 preview mode", value()->default_value("false")) + .add("O,old", "Use old mode for LiteLoaderBDS", value()->default_value("false")) .add( "b,bak", "Add a suffix \".bak\" to original server exe (will be true if no arg passed)", @@ -97,7 +96,7 @@ void parseArgs(int argc, char** argv) { config::backupBds = optionsResult["bak"].as(); config::shouldPause = optionsResult["pause"].as(); config::choosePdbFile = optionsResult["choose-pdb-file"].as(); - config::liteloader3 = optionsResult["new"].as(); + config::oldMode = optionsResult["old"].as(); config::outputDir = optionsResult["output-dir"].as(); config::bdsExePath = optionsResult["exe"].as(); config::bdsPdbPath = optionsResult["pdb"].as(); @@ -108,8 +107,7 @@ bool filterSymbols(const PdbSymbol& symbol) { return false; } for (const auto& a : pe_editor::filter::prefix) { - if (symbol.name.starts_with(a)) - return false; + if (symbol.name.starts_with(a)) return false; } return !pe_editor::filter::matchSkip(symbol.name); } @@ -239,12 +237,12 @@ int generateSymbolListFile() { struct ImportDllName { static constexpr auto liteloader2 = "LLPreLoader.dll"; - static constexpr auto liteloader3 = "PreLoader.dll"; + static constexpr auto levilamina = "PreLoader.dll"; }; struct ImportFunctionName { static constexpr auto liteloader2 = "dlsym_real"; - static constexpr auto liteloader3 = "pl_resolve_symbol"; + static constexpr auto levilamina = "pl_resolve_symbol"; }; int generateModdedBds() { @@ -275,8 +273,8 @@ int generateModdedBds() { std::unordered_set exportedFunctionsNames; auto names = originBds.exportedFunctions - | std::views::filter([](const exported_function& fn) { return fn.has_name(); }) - | std::views::transform([](const exported_function& fn) { return fn.get_name(); }); + | std::views::filter([](const exported_function& fn) { return fn.has_name(); }) + | std::views::transform([](const exported_function& fn) { return fn.get_name(); }); std::ranges::copy(names, std::inserter(exportedFunctionsNames, exportedFunctionsNames.end())); auto filtered = data::filteredSymbols | std::views::filter([&](const PdbSymbol& symbol) { @@ -315,9 +313,9 @@ int generateModdedBds() { imported_functions_list imports = get_imported_functions(*originBds.pe); import_library preLoader; imported_function func; - func.set_name(config::liteloader3 ? ImportFunctionName::liteloader3 : ImportFunctionName::liteloader2); + func.set_name(!config::oldMode ? ImportFunctionName::levilamina : ImportFunctionName::liteloader2); func.set_iat_va(0x1); - preLoader.set_name(config::liteloader3 ? ImportDllName::liteloader3 : ImportDllName::liteloader2); + preLoader.set_name(!config::oldMode ? ImportDllName::levilamina : ImportDllName::liteloader2); preLoader.add_import(func); imports.push_back(preLoader); section& attachedImportedSection = originBds.pe->add_section(ImportSection); @@ -392,7 +390,7 @@ int main(int argc, char** argv) { } logger->info("Configurations:"); - logger->info("\tLiteLoader v3 Mode: \t\t[{}]", config::liteloader3); + logger->info("\tOld Mode: \t\t\t[{}]", config::oldMode); logger->info("\tBDS Executable File: \t\t[{}]", getPathUtf8(config::bdsExePath.wstring())); logger->info("\tBDS PDB File: \t\t\t[{}]", getPathUtf8(config::bdsPdbPath.wstring())); logger->info("\tOutput Dir: \t\t\t[{}]", getPathUtf8(config::outputDir.wstring())); diff --git a/src/pe_editor/PeEditor.h b/src/pe_editor/PeEditor.h index 5d810f8..03b8ff4 100644 --- a/src/pe_editor/PeEditor.h +++ b/src/pe_editor/PeEditor.h @@ -24,7 +24,7 @@ inline bool genSymbolList = false; inline bool backupBds = false; inline bool shouldPause = false; inline bool choosePdbFile = false; -inline bool liteloader3 = false; +inline bool oldMode = false; inline std::filesystem::path outputDir; inline std::filesystem::path bdsExePath; diff --git a/src/pe_editor/StringUtils.cpp b/src/pe_editor/StringUtils.cpp index c467c0d..b5ddbe8 100644 --- a/src/pe_editor/StringUtils.cpp +++ b/src/pe_editor/StringUtils.cpp @@ -3,7 +3,7 @@ #include namespace pe_editor::StringUtils { -std::wstring str2wstr(std::string_view str, UINT codePage) { +std::wstring str2wstr(std::string_view str, uint codePage) { int size = MultiByteToWideChar(codePage, 0, str.data(), static_cast(str.size()), nullptr, 0); std::wstring wstr(size, 0); MultiByteToWideChar(codePage, 0, str.data(), static_cast(str.size()), wstr.data(), size); diff --git a/src/pe_editor/StringUtils.h b/src/pe_editor/StringUtils.h index e19d68f..c6087af 100644 --- a/src/pe_editor/StringUtils.h +++ b/src/pe_editor/StringUtils.h @@ -4,10 +4,10 @@ namespace pe_editor::StringUtils { -using UINT = unsigned int; -#define CP_UTF8 65001 +using uint = unsigned int; +constexpr uint UTF8 = 65001; -std::wstring str2wstr(std::string_view str, UINT codePage = CP_UTF8); +std::wstring str2wstr(std::string_view str, uint codePage = UTF8); std::string wstr2str(std::wstring_view wstr); diff --git a/xmake-requires.lock b/xmake-requires.lock index 0658ffd..369a47b 100644 --- a/xmake-requires.lock +++ b/xmake-requires.lock @@ -9,7 +9,7 @@ commit = "fa285a31269c7a407167ff2942d1e1da5b4bbd81", url = "https://github.com/xmake-io/xmake-repo.git" }, - version = "3.26.4-msvc4" + version = "3.27.2-msvc1" }, ["ctre#31fecfc4"] = { repo = { diff --git a/xmake.lua b/xmake.lua index 6f287ad..3cc5de8 100644 --- a/xmake.lua +++ b/xmake.lua @@ -23,6 +23,6 @@ target("PeEditor") add_files("src/**.cpp") add_includedirs("src") add_cxflags("/utf-8") - add_defines("UNICODE", "PE_EDITOR_VERSION=\"v3.3.0\"") + add_defines("UNICODE", "PE_EDITOR_VERSION=\"v3.4.0\"") add_syslinks("user32", "comdlg32") add_packages("llvm-prebuilt", "raw_pdb", "pe_bliss", "cxxopts", "fmt", "spdlog", "ctre", "demangler")