diff --git a/src/windows-emulator/apiset/default_apiset.hpp b/src/windows-emulator/apiset/default_apiset.hpp index 8d86f98b..ebcaf38f 100644 --- a/src/windows-emulator/apiset/default_apiset.hpp +++ b/src/windows-emulator/apiset/default_apiset.hpp @@ -3,6 +3,8 @@ #include // Windows 11 - APISET-W11.24H2-26100.2605 + +// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) const uint8_t apiset_w11[] = { 0x78, 0xDA, 0xCD, 0x7D, 0x0F, 0x7C, 0xCD, 0xD5, 0xFF, 0xFF, 0x9D, 0x26, 0xCA, 0xD2, 0xAA, 0x29, 0xA2, 0x52, 0x11, 0x0A, 0x6D, 0xD7, 0xBF, 0x91, 0x24, 0xAD, 0xA2, 0x54, 0xF2, 0x2F, 0xB1, 0xD8, 0xFF, 0x3F, 0xDC, 0x6D, 0xD7, 0xBD, @@ -1369,6 +1371,8 @@ const uint8_t apiset_w11[] = { }; // Windows 10 - APISET-W10.22H2-19045.5247 + +// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) const uint8_t apiset_w10[] = { 0x78, 0xDA, 0xCD, 0x7D, 0x0B, 0x5C, 0x94, 0x45, 0xF7, 0xFF, 0x62, 0x58, 0x98, 0x64, 0x64, 0x98, 0x9A, 0x98, 0x9A, 0x98, 0x5A, 0x6A, 0x88, 0x37, 0x2C, 0x53, 0xF2, 0x52, 0x5A, 0x54, 0xE6, 0x2D, 0x2F, 0xA4, 0xDC, 0x2F, 0xBA, 0x0B, diff --git a/src/windows-emulator/devices/afd_types.hpp b/src/windows-emulator/devices/afd_types.hpp index dd0d106e..b05ed79e 100644 --- a/src/windows-emulator/devices/afd_types.hpp +++ b/src/windows-emulator/devices/afd_types.hpp @@ -2,6 +2,8 @@ #include "../std_include.hpp" +// NOLINTBEGIN(modernize-use-using,cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + typedef LONG TDI_STATUS; template @@ -171,3 +173,5 @@ struct AFD_POLL_INFO64 #define AFD_NO_OPERATION 39 #define AFD_VALIDATE_GROUP 40 #define AFD_GET_UNACCEPTED_CONNECT_DATA 41 + +// NOLINTEND(modernize-use-using,cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) diff --git a/src/windows-emulator/file_system.hpp b/src/windows-emulator/file_system.hpp index ce2d33d0..e39fd320 100644 --- a/src/windows-emulator/file_system.hpp +++ b/src/windows-emulator/file_system.hpp @@ -43,8 +43,8 @@ class file_system } #endif - const char root_drive[2] = {win_path.get_drive().value_or('c'), 0}; - auto root = this->root_ / root_drive; + const std::array root_drive{win_path.get_drive().value_or('c'), 0}; + auto root = this->root_ / root_drive.data(); auto path = this->root_ / win_path.to_portable_path(); path = weakly_canonical(path); diff --git a/src/windows-emulator/io_device.hpp b/src/windows-emulator/io_device.hpp index 43e8b1cf..b76ff6cc 100644 --- a/src/windows-emulator/io_device.hpp +++ b/src/windows-emulator/io_device.hpp @@ -151,7 +151,7 @@ class io_device_container : public io_device void work(windows_emulator& win_emu) override { this->assert_validity(); - return this->device_->work(win_emu); + this->device_->work(win_emu); } void serialize_object(utils::buffer_serializer& buffer) const override diff --git a/src/windows-emulator/logger.cpp b/src/windows-emulator/logger.cpp index 80c8247f..ea4dc2ee 100644 --- a/src/windows-emulator/logger.cpp +++ b/src/windows-emulator/logger.cpp @@ -73,17 +73,20 @@ namespace std::string_view format(va_list* ap, const char* message) { - thread_local char buffer[0x1000]; + thread_local std::array buffer{}; #ifdef _WIN32 - const int count = _vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer), message, *ap); + const int count = _vsnprintf_s(buffer.data(), buffer.size(), buffer.size(), message, *ap); #else - const int count = vsnprintf(buffer, sizeof(buffer), message, *ap); + const int count = vsnprintf(buffer.data(), buffer.size(), message, *ap); #endif if (count < 0) + { return {}; - return {buffer, static_cast(count)}; + } + + return {buffer.data(), static_cast(count)}; } #define format_to_string(msg, str) \ @@ -110,36 +113,42 @@ void logger::print(const color c, const std::string_view message) const print_colored(message, get_color_type(c)); } +// NOLINTNEXTLINE(cert-dcl50-cpp) void logger::print(const color c, const char* message, ...) const { format_to_string(message, data); this->print(c, data); } +// NOLINTNEXTLINE(cert-dcl50-cpp) void logger::info(const char* message, ...) const { format_to_string(message, data); this->print(color::cyan, data); } +// NOLINTNEXTLINE(cert-dcl50-cpp) void logger::warn(const char* message, ...) const { format_to_string(message, data); this->print(color::yellow, data); } +// NOLINTNEXTLINE(cert-dcl50-cpp) void logger::error(const char* message, ...) const { format_to_string(message, data); this->print(color::red, data); } +// NOLINTNEXTLINE(cert-dcl50-cpp) void logger::success(const char* message, ...) const { format_to_string(message, data); this->print(color::green, data); } +// NOLINTNEXTLINE(cert-dcl50-cpp) void logger::log(const char* message, ...) const { format_to_string(message, data); diff --git a/src/windows-emulator/module/mapped_module.hpp b/src/windows-emulator/module/mapped_module.hpp index b058a2b2..dfe2b268 100644 --- a/src/windows-emulator/module/mapped_module.hpp +++ b/src/windows-emulator/module/mapped_module.hpp @@ -41,7 +41,7 @@ struct mapped_module uint64_t find_export(const std::string_view export_name) const { - for (auto& symbol : this->exports) + for (const auto& symbol : this->exports) { if (symbol.name == export_name) { diff --git a/src/windows-emulator/module/module_mapping.cpp b/src/windows-emulator/module/module_mapping.cpp index a85f5ea0..17cc4857 100644 --- a/src/windows-emulator/module/module_mapping.cpp +++ b/src/windows-emulator/module/module_mapping.cpp @@ -9,11 +9,11 @@ namespace { uint64_t get_first_section_offset(const PENTHeaders_t& nt_headers, const uint64_t nt_headers_offset) { - const uint8_t* nt_headers_addr = reinterpret_cast(&nt_headers); + const auto* nt_headers_addr = reinterpret_cast(&nt_headers); size_t optional_header_offset = reinterpret_cast(&(nt_headers.OptionalHeader)) - reinterpret_cast(&nt_headers); size_t optional_header_size = nt_headers.FileHeader.SizeOfOptionalHeader; - const uint8_t* first_section_addr = nt_headers_addr + optional_header_offset + optional_header_size; + const auto* first_section_addr = nt_headers_addr + optional_header_offset + optional_header_size; const auto first_section_absolute = reinterpret_cast(first_section_addr); const auto absolute_base = reinterpret_cast(&nt_headers); @@ -32,7 +32,7 @@ namespace void collect_exports(mapped_module& binary, const utils::safe_buffer_accessor buffer, const PEOptionalHeader_t& optional_header) { - auto& export_directory_entry = optional_header.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; + const auto& export_directory_entry = optional_header.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; if (export_directory_entry.VirtualAddress == 0 || export_directory_entry.Size == 0) { return; @@ -88,7 +88,7 @@ namespace return; } - const auto directory = &optional_header.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC]; + const auto* directory = &optional_header.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC]; if (directory->Size == 0) { return; @@ -209,7 +209,7 @@ mapped_module map_module_from_data(memory_manager& memory, const std::span>(nt_headers_offset).get(); - auto& optional_header = nt_headers.OptionalHeader; + const auto& optional_header = nt_headers.OptionalHeader; if (nt_headers.FileHeader.Machine != PEMachineType::AMD64) { diff --git a/src/windows-emulator/process_context.cpp b/src/windows-emulator/process_context.cpp index a7a58700..947543bb 100644 --- a/src/windows-emulator/process_context.cpp +++ b/src/windows-emulator/process_context.cpp @@ -16,6 +16,7 @@ namespace void setup_gdt(x64_emulator& emu, memory_manager& memory) { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) constexpr uint64_t gdtr[4] = {0, GDT_ADDR, GDT_LIMIT, 0}; emu.write_register(x64_register::gdtr, &gdtr, sizeof(gdtr)); memory.allocate_memory(GDT_ADDR, GDT_LIMIT, memory_permission::read); diff --git a/src/windows-emulator/process_context.hpp b/src/windows-emulator/process_context.hpp index e0ae016b..2118c59c 100644 --- a/src/windows-emulator/process_context.hpp +++ b/src/windows-emulator/process_context.hpp @@ -50,8 +50,7 @@ struct process_context void setup(x64_emulator& emu, memory_manager& memory, const application_settings& app_settings, const mapped_module& executable, const mapped_module& ntdll, const apiset::container& apiset_container); - handle create_thread(memory_manager& memory, const uint64_t start_address, const uint64_t argument, - const uint64_t stack_size); + handle create_thread(memory_manager& memory, uint64_t start_address, uint64_t argument, uint64_t stack_size); void serialize(utils::buffer_serializer& buffer) const; void deserialize(utils::buffer_deserializer& buffer); diff --git a/src/windows-emulator/registry/hive_parser.cpp b/src/windows-emulator/registry/hive_parser.cpp index e8e3dfe0..c6892433 100644 --- a/src/windows-emulator/registry/hive_parser.cpp +++ b/src/windows-emulator/registry/hive_parser.cpp @@ -9,6 +9,8 @@ namespace constexpr uint64_t MAIN_ROOT_OFFSET = 0x1000; constexpr uint64_t MAIN_KEY_BLOCK_OFFSET = MAIN_ROOT_OFFSET + 0x20; + // NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + struct offset_entry_t { int32_t offset; @@ -53,6 +55,8 @@ namespace char name[255]; }; + // NOLINTEND(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + bool read_file_data_safe(std::ifstream& file, const uint64_t offset, void* buffer, const size_t size) { if (file.bad()) @@ -171,7 +175,7 @@ void hive_key::parse(std::ifstream& file) const auto offset = read_file_object(file, MAIN_ROOT_OFFSET + this->value_offsets_ + 4, i); const auto value = read_file_object(file, MAIN_ROOT_OFFSET + offset); - std::string value_name(value.name, std::min(value.name_len, static_cast(sizeof(value.name)))); + std::string value_name(value.name, std::min(value.name_len, static_cast(sizeof(value.name)))); raw_hive_value raw_value{}; raw_value.parsed = false; @@ -200,7 +204,7 @@ void hive_key::parse(std::ifstream& file) const auto entry_offsets = this->subkey_block_offset_ + offsetof(offsets_t, entries); - for (short i = 0; i < item.count; ++i) + for (int16_t i = 0; i < item.count; ++i) { const auto offset_entry = read_file_object(file, MAIN_ROOT_OFFSET + entry_offsets, i); diff --git a/src/windows-emulator/registry/hive_parser.hpp b/src/windows-emulator/registry/hive_parser.hpp index 249fb0f8..3677f821 100644 --- a/src/windows-emulator/registry/hive_parser.hpp +++ b/src/windows-emulator/registry/hive_parser.hpp @@ -42,7 +42,7 @@ class hive_key return &entry->second; } - const hive_value* get_value(std::ifstream& file, const std::string_view name); + const hive_value* get_value(std::ifstream& file, std::string_view name); private: struct raw_hive_value : hive_value diff --git a/src/windows-emulator/std_include.hpp b/src/windows-emulator/std_include.hpp index 4a6c82b2..05cf0d0b 100644 --- a/src/windows-emulator/std_include.hpp +++ b/src/windows-emulator/std_include.hpp @@ -62,4 +62,5 @@ #include "platform/platform.hpp" +// NOLINTNEXTLINE(google-global-names-in-headers) using namespace std::literals; diff --git a/src/windows-emulator/windows_path.hpp b/src/windows-emulator/windows_path.hpp index d909aae3..8429c102 100644 --- a/src/windows-emulator/windows_path.hpp +++ b/src/windows-emulator/windows_path.hpp @@ -163,7 +163,7 @@ class windows_path throw std::runtime_error("Device path can not be computed for relative paths!"); } - const auto drive_index = *this->drive_ - 'a'; + const auto drive_index = this->drive_.value_or('a') - 'a'; const auto drive_number = std::to_string(drive_index + 1); const std::u16string number(drive_number.begin(), drive_number.end());