diff --git a/.clang-format.todo b/.clang-format.todo new file mode 100644 index 0000000..736f523 --- /dev/null +++ b/.clang-format.todo @@ -0,0 +1,6 @@ +Language: Cpp +BasedOnStyle: llvm +Standard: c++11 +TabWidth: 4 +PointerAlignment: Right +NamespaceIndentation: None \ No newline at end of file diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..3adc292 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,49 @@ +Checks: ' + bugprone-* + ,cert-* + ,cppcoreguidelines-* + ,modernize-* + ,performance-* + ,readability-* + ,portability-* + ,clang-analyzer-unix + ,clang-analyzer-security + ,clang-analyzer-deadcode + ,clang-analyzer-core + ,clang-analyzer-cplusplus + ,clang-analyzer-optin + ,llvm-namespace-comment + ,readability-static-accessed-through-instance + ,misc-const-correctness + ,-bugprone-reserved-identifier + ,-bugprone-implicit-widening-of-multiplication-result + ,-bugprone-easily-swappable-parameters + ,-bugprone-narrowing-conversions + ,-cert-dcl37-c + ,-cert-dcl51-cpp + ,-cert-msc32-c + ,-cert-msc51-cpp + ,-cert-msc30-c + ,-cert-msc50-cpp + ,-modernize-use-trailing-return-type + ,-modernize-macro-to-enum + ,-modernize-use-nullptr + ,-modernize-use-using + ,-modernize-avoid-c-arrays + ,-modernize-use-auto + ,-readability-avoid-unconditional-preprocessor-if + ,-readability-identifier-length + ,-readability-isolate-declaration + ,-readability-magic-numbers + ,-readability-braces-around-statements + ,-readability-function-cognitive-complexity + ,-cppcoreguidelines-macro-to-enum + ,-cppcoreguidelines-macro-usage + ,-cppcoreguidelines-pro-bounds-pointer-arithmetic + ,-cppcoreguidelines-pro-type-cstyle-cast + ,-cppcoreguidelines-init-variables + ,-cppcoreguidelines-avoid-magic-numbers + ,-cppcoreguidelines-pro-bounds-array-to-pointer-decay + ,-cppcoreguidelines-avoid-c-arrays + ,-cppcoreguidelines-narrowing-conversions +' \ No newline at end of file diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ae32662..71afcb2 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,6 +1,6 @@ name: CMake -on: [push] +on: [push, pull_request] env: BUILD_TYPE: Release @@ -58,15 +58,15 @@ jobs: run: conan profile detect - name: Install deps with conan - run: conan install . -of ./build -s build_type=Release --build=missing + run: conan install . -of build -s build_type=$BUILD_TYPE --build=missing - name: Cmake - working-directory: ./build + working-directory: build run: bash conanbuild.sh && cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUSE_SYSTEM_LIBS=0 - name: Build - working-directory: ./build - run: cmake --build . + working-directory: build + run: cmake --build . --config Release build-fedora-system: if: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c9a27c..f092ef1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -69,7 +69,7 @@ jobs: name: libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm path: build/libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm - dll: + dll_amd64: if: true runs-on: windows-latest @@ -80,6 +80,13 @@ jobs: with: arch: x64 + - name: Cache Conan + uses: actions/cache@v3 + with: + key: conan-windows-amd64-${{ hashFiles('conanfile.py') }} + path: | + ~/.conan2/p + - name: Install Conan id: conan uses: turtlebrowser/get-conan@main @@ -98,7 +105,11 @@ jobs: - name: Create archive working-directory: ./build - run: Compress-Archive -Path Release/* -Destination bncsutil_${{ github.ref_name }}_amd64_dll.zip + run: | + New-Item -ItemType Directory -Path include/bncsutil -Force | Out-Null + Copy-Item -Path '../src/bncsutil/*.h' -Destination include/bncsutil + Compress-Archive -Path Release/* -DestinationPath bncsutil_${{ github.ref_name }}_amd64_dll.zip + Compress-Archive -Path include -DestinationPath "bncsutil_${{ github.ref_name }}_amd64_dll.zip" -Update - uses: actions/upload-artifact@v4 with: @@ -106,10 +117,59 @@ jobs: overwrite: true name: bncsutil_${{ github.ref_name }}_amd64_dll.zip path: build/bncsutil_${{ github.ref_name }}_amd64_dll.zip + + dll_x86: + if: true + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: x86 + + - name: Install Conan + id: conan + uses: turtlebrowser/get-conan@main + + - name: Cache Conan + uses: actions/cache@v3 + with: + key: conan-windows-x86-${{ hashFiles('conanfile.py') }} + path: | + ~/.conan2/p + + - name: Init conan + run: conan profile detect + + - name: Install dependencies + shell: cmd + run: conan install . -of build -s build_type=Release -s:h arch=x86 -o *:shared=False --build=missing + + - name: Build + shell: cmd + working-directory: ./build + run: .\conanbuild.bat && cmake .. -DCMAKE_GENERATOR_PLATFORM=x86 -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DBUILD_SHARED_LIBS=1 && cmake --build . --config Release + + - name: Create archive + working-directory: ./build + run: | + New-Item -ItemType Directory -Path include/bncsutil -Force | Out-Null + Copy-Item -Path '../src/bncsutil/*.h' -Destination include/bncsutil + Compress-Archive -Path Release/* -DestinationPath bncsutil_${{ github.ref_name }}_x86_dll.zip + Compress-Archive -Path include -DestinationPath "bncsutil_${{ github.ref_name }}_x86_dll.zip" -Update + + - uses: actions/upload-artifact@v4 + with: + retention-days: 1 + overwrite: true + name: bncsutil_${{ github.ref_name }}_x86_dll.zip + path: build/bncsutil_${{ github.ref_name }}_x86_dll.zip release: - needs: [deb, rpm, dll] + needs: [deb, rpm, dll_amd64, dll_x86] runs-on: ubuntu-latest steps: @@ -123,10 +183,15 @@ jobs: with: name: libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm - - name: Download dll + - name: Download dll amd64 uses: actions/download-artifact@v4 with: name: bncsutil_${{ github.ref_name }}_amd64_dll.zip + + - name: Download dll x86 + uses: actions/download-artifact@v4 + with: + name: bncsutil_${{ github.ref_name }}_x86_dll.zip - name: Create GitHub Release uses: softprops/action-gh-release@v1 @@ -135,6 +200,7 @@ jobs: libbncsutil-dev_${{ github.ref_name }}_amd64.deb libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm bncsutil_${{ github.ref_name }}_amd64_dll.zip + bncsutil_${{ github.ref_name }}_x86_dll.zip tag_name: ${{ github.ref_name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5815a4c..5830a5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,16 +37,19 @@ set(SOURCES "src/bncsutil/decodekey.cpp" "src/bncsutil/file.cpp" "src/bncsutil/libinfo.cpp" + "src/bncsutil/nls.c" "src/bncsutil/oldauth.cpp" + "src/bncsutil/pe.c" "src/bncsutil/sha1.c" + "src/bncsutil/stack.c" ) target_sources(bncsutil PRIVATE ${SOURCES} ${HEADERS}) if (WIN32) - set(USE_SYSTEM_LIBS 0) + option(USE_SYSTEM_LIBS "Use system libraries" OFF) else() - set(USE_SYSTEM_LIBS 1) + option(USE_SYSTEM_LIBS "Use system libraries" ON) endif() if (CMAKE_GENERATOR_PLATFORM EQUAL "x86") @@ -97,16 +100,20 @@ endif() install(TARGETS bncsutil RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(FILES ${HEADERS} DESTINATION include/bncsutil) -#CPack configurtion +#CPack configuration SET(CPACK_GENERATOR "DEB" "RPM") SET(CPACK_PACKAGE_NAME "bncsutil") SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Battle.Net Chat Service Utility") SET(CPACK_PACKAGE_VENDOR "bncsutil") -SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +SET(CPACK_PACKAGE_DESCRIPTION "\ +This will install the library to /usr/local/lib and header files to /usr/local/include.\n \ +Make sure these directories are in your library and include paths. \ +") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}") SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}") SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}") +set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local") #DEB configuration SET(CPACK_DEBIAN_PACKAGE_SECTION "libs") diff --git a/README.md b/README.md index 262a4a4..1d78ffa 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ BNCSUtil was originally written by Eric Naeseth (shadypalm88) and has since been maintained over the course of several years by the open source Battle.net community. # Usage -Add `bncsutil.h` to your include directory and link against `bncsutil.lib` or `libbncsutil.so`. +`#include ` and link against `bncsutil.lib` or `libbncsutil.so`. # Building @@ -30,6 +30,7 @@ Conan is used to install dependencies. GMP can't be installed as a shared librar In `cmd` or Visual Studio dev console run: +### amd64 ``` "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat" x64 conan install . -of build -s build_type=Release -o *:shared=False --build=missing @@ -39,6 +40,16 @@ cmake .. -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake cmake --build . --config Release ``` +### x86 +``` +"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat" x86 +conan install . -of build -s build_type=Release -s:h arch=x86 -o *:shared=False --build=missing +cd build +.\conanbuild.bat +cmake .. -G "Visual Studio 17 2022" -DCMAKE_GENERATOR_PLATFORM=x86 -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DBUILD_SHARED_LIBS=1 +cmake --build . --config Release +``` + Alternatively open `build/bncsutil.sln` and build from Visual Studio. ## Linux @@ -58,17 +69,24 @@ If you are using pyenv or building python3 from source, make sure you have `libb ``` conan install . -of build -s build_type=Release --build=missing cd build -./conanbuild.sh -cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DUSE_SYSTEM_LIBS=0 -cmake --build . --target install --config Release +bash conanbuild.sh +cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_LIBS=0 +cmake --build . --config Release ``` ## .deb and .rpm packages After invoking CMake, cd to build folder and generate them with `cpack -G "DEB"` and `cpack -G "RPM"`. You can then use `gdebi` to do a local install of .deb with automatic dependency resolution or `yum localinstall` on rpm distros. For dnf it's `dnf install .rpm`. -Note that this is a "devel" package which also includes header files. +Note that this is a "development" package which also includes header files. -Library installs to `/usr/lib`, include files in `/usr/include/bncsutil`. +Library installs to `/usr/local/lib`, include files in `/usr/local/include/bncsutil`. Packages are also available for download from github releases built on Debian Bookworm and Fedora latest. + +# Development with CLion +1. Run conan from cli as per build instructions above +2. Open the project +3. Tools -> CMake -> Change Project Root -> build +4. Settings -> Build, Execution, Deployment -> CMake -> Add at least this cmake option: -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake + diff --git a/conanfile.py b/conanfile.py index 70ca193..9f5fdd2 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,7 @@ from conan import ConanFile from conan.tools.files import copy +from conan.tools.files import rename +import os class Bncsutil(ConanFile): settings = "os", "compiler", "build_type", "arch" @@ -10,8 +12,23 @@ class Bncsutil(ConanFile): ) def generate(self): - for dep in self.dependencies.values(): - if dep.cpp_info.libdirs: - copy(self, "*.lib", dep.cpp_info.libdirs[0], self.build_folder) - if dep.cpp_info.bindirs: - copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder) \ No newline at end of file + # Workaround for a conan bug producing wrongly named libraries.. + if self.settings.os == "Windows": + gmp_libdir = self.dependencies["gmp"].cpp_info.libdir + gmp_from_name = f"{gmp_libdir}\libgmp.a" + gmp_to_name = f"{gmp_libdir}\gmp.lib" + gmpxx_from_name = f"{gmp_libdir}\libgmpxx.a" + gmpxx_to_name = f"{gmp_libdir}\gmpxx.lib" + + if os.path.isfile(gmp_from_name): + print("Renaming " + gmp_from_name + " to " + gmp_to_name) + rename(self, gmp_from_name, gmp_to_name) + if os.path.isfile(gmpxx_from_name): + print("Renaming " + gmpxx_from_name + " to " + gmpxx_to_name) + rename(self, gmpxx_from_name, gmpxx_to_name) + + for dep in self.dependencies.values(): + if dep.cpp_info.libdirs: + copy(self, "*.lib", dep.cpp_info.libdirs[0], self.build_folder) + if dep.cpp_info.bindirs: + copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder) \ No newline at end of file diff --git a/src/bncsutil/buffer.h b/src/bncsutil/buffer.h index 4f5709c..81249bb 100644 --- a/src/bncsutil/buffer.h +++ b/src/bncsutil/buffer.h @@ -23,6 +23,9 @@ * Boston, MA 02111-1307 USA */ +#ifndef BUFFER_H +#define BUFFER_H + #include typedef struct msg_buffer *msg_buffer_t; @@ -69,3 +72,5 @@ void buffer_add_32(msg_buffer_t, int32_t); void buffer_add_u32(msg_buffer_t, uint32_t); msg_reader_t create_reader(size_t initial_size); + +#endif /* BUFFER_H */ diff --git a/src/bncsutil/cdkeydecoder.cpp b/src/bncsutil/cdkeydecoder.cpp index 4573a97..aab52a5 100644 --- a/src/bncsutil/cdkeydecoder.cpp +++ b/src/bncsutil/cdkeydecoder.cpp @@ -31,7 +31,6 @@ #include // for isdigit(), isalnum(), and toupper() #include // for memcpy() #include // for sscanf() -// #include /** * Implementation-specific CD-key hash structure. diff --git a/src/bncsutil/cdkeydecoder.h b/src/bncsutil/cdkeydecoder.h index 0f845f1..424a62a 100644 --- a/src/bncsutil/cdkeydecoder.h +++ b/src/bncsutil/cdkeydecoder.h @@ -59,7 +59,7 @@ MCEXP(CDKeyDecoder) { inline char getHexValue(int v); inline int getNumValue(char v); - inline void mult(const int r, const int x, int* a, int dcByte); + inline void mult(int r, int x, int* a, int dcByte); public: /** diff --git a/src/bncsutil/checkrevision.cpp b/src/bncsutil/checkrevision.cpp index 7d360e2..2097ce9 100644 --- a/src/bncsutil/checkrevision.cpp +++ b/src/bncsutil/checkrevision.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #endif #ifndef HIWORD diff --git a/src/bncsutil/decodekey.cpp b/src/bncsutil/decodekey.cpp index c38276e..9c89a4b 100644 --- a/src/bncsutil/decodekey.cpp +++ b/src/bncsutil/decodekey.cpp @@ -35,11 +35,9 @@ #include #else #include - #include - #include + #include #endif -#include -#include +#include #ifdef __cplusplus extern "C" { @@ -117,14 +115,14 @@ MEXP(int) kd_quick(const char* cd_key, uint32_t client_token, CDKeyDecoder kd(cd_key, strlen(cd_key)); size_t hash_len; - if (!kd.isKeyValid()) + if (kd.isKeyValid() == 0) return 0; *public_value = kd.getVal1(); *product = kd.getProduct(); hash_len = kd.calculateHash(client_token, server_token); - if (!hash_len || hash_len > buffer_len) + if ((hash_len == 0U) || hash_len > buffer_len) return 0; kd.getHash(hash_buffer); @@ -143,7 +141,7 @@ MEXP(int) kd_init() { return 0;*/ InitializeCriticalSection(&kd_control); #else - if (pthread_mutex_init(&mutex, NULL)) + if (pthread_mutex_init(&mutex, NULL) != 0) return 0; #endif numDecoders = 0; @@ -183,18 +181,18 @@ unsigned int kd_findAvailable() { return i; } -MEXP(int) kd_create(const char* cdkey, int keyLength) { +MEXP(int) kd_create(const char* cdkey, const int keyLength) { unsigned int i; CDKeyDecoder** d; static int dcs_initialized = 0; - if (!dcs_initialized) { - if (!kd_init()) + if (dcs_initialized == 0) { + if (kd_init() == 0) return -1; dcs_initialized = 1; } - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; i = kd_findAvailable(); if (i == (unsigned int) -1) @@ -246,10 +244,10 @@ MEXP(int) kd_create(char* cdkey, int keyLength) { return (int) i; }*/ -MEXP(int) kd_free(int decoder) { +MEXP(int) kd_free(const int decoder) { CDKeyDecoder* d; - if (!kd_lock_decoders()) return 0; + if (kd_lock_decoders() == 0) return 0; if ((unsigned int) decoder >= sizeDecoders) return 0; @@ -269,7 +267,7 @@ MEXP(int) kd_val2Length(int decoder) { CDKeyDecoder* d; int value; - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; if ((unsigned int) decoder >= sizeDecoders) return -1; @@ -288,7 +286,7 @@ MEXP(int) kd_product(int decoder) { CDKeyDecoder* d; int value; - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; if ((unsigned int) decoder >= sizeDecoders) return -1; @@ -303,11 +301,11 @@ MEXP(int) kd_product(int decoder) { return value; } -MEXP(int) kd_val1(int decoder) { +MEXP(int) kd_val1(const int decoder) { CDKeyDecoder* d; int value; - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; if ((unsigned int) decoder >= sizeDecoders) return -1; @@ -326,7 +324,7 @@ MEXP(int) kd_val2(int decoder) { CDKeyDecoder* d; int value; - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; if ((unsigned int) decoder >= sizeDecoders) return -1; @@ -341,11 +339,11 @@ MEXP(int) kd_val2(int decoder) { return value; } -MEXP(int) kd_longVal2(int decoder, char* out) { +MEXP(int) kd_longVal2(const int decoder, char* out) { CDKeyDecoder* d; int value; - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; if ((unsigned int) decoder >= sizeDecoders) return -1; @@ -360,13 +358,13 @@ MEXP(int) kd_longVal2(int decoder, char* out) { return value; } -MEXP(int) kd_calculateHash(int decoder, uint32_t clientToken, - uint32_t serverToken) +MEXP(int) kd_calculateHash(const int decoder, const uint32_t clientToken, + const uint32_t serverToken) { CDKeyDecoder* d; int value; - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; if ((unsigned int) decoder >= sizeDecoders) return -1; @@ -381,11 +379,11 @@ MEXP(int) kd_calculateHash(int decoder, uint32_t clientToken, return value; } -MEXP(int) kd_getHash(int decoder, char* out) { +MEXP(int) kd_getHash(const int decoder, char* out) { CDKeyDecoder* d; int value; - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; if ((unsigned int) decoder >= sizeDecoders) return -1; @@ -400,11 +398,11 @@ MEXP(int) kd_getHash(int decoder, char* out) { return value; } -MEXP(int) kd_isValid(int decoder) { +MEXP(int) kd_isValid(const int decoder) { CDKeyDecoder* d; int value; - if (!kd_lock_decoders()) return -1; + if (kd_lock_decoders() == 0) return -1; if ((unsigned int) decoder >= sizeDecoders) return -1; diff --git a/src/bncsutil/decodekey.h b/src/bncsutil/decodekey.h index 5dc8033..fceb7d6 100644 --- a/src/bncsutil/decodekey.h +++ b/src/bncsutil/decodekey.h @@ -27,6 +27,8 @@ #ifndef DECODEKEY_H #define DECODEKEY_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/bncsutil/file.cpp b/src/bncsutil/file.cpp index bced9af..bf73482 100644 --- a/src/bncsutil/file.cpp +++ b/src/bncsutil/file.cpp @@ -11,8 +11,8 @@ typedef std::map mapping_map; #else #define BWIN 0 -#include -#include +#include +#include #include typedef std::map mapping_map; @@ -29,8 +29,6 @@ struct _file mapping_map mappings; }; -#include - #ifdef __cplusplus extern "C" { #endif @@ -184,7 +182,7 @@ void file_unmap(file_t file, const void* base) #else -file_t file_open(const char* filename, unsigned int mode_flags) +file_t file_open(const char* filename, const unsigned int mode_flags) { char mode[] = "rb"; file_t data; @@ -265,9 +263,9 @@ size_t file_size(file_t file) return size_of_file; } -void* file_map(file_t file, size_t len, off_t offset) +void* file_map(file_t file, const size_t len, const off_t offset) { - int fd = fileno(file->f); + const int fd = fileno(file->f); void* base = mmap((void*) 0, len, PROT_READ, MAP_SHARED, fd, offset); //const char* err; @@ -283,9 +281,9 @@ void* file_map(file_t file, size_t len, off_t offset) return base; } -void file_unmap(file_t file, const void* base) +void file_unmap(file_t file, const void* mapping) { - mapping_map::iterator item = file->mappings.find(base); + mapping_map::iterator item = file->mappings.find(mapping); size_t len; if (item == file->mappings.end()) { @@ -295,7 +293,7 @@ void file_unmap(file_t file, const void* base) len = (*item).second; - munmap((void*) base, len); + munmap((void*) mapping, len); file->mappings.erase(item); } diff --git a/src/bncsutil/file.h b/src/bncsutil/file.h index 3ff4bbd..8e45279 100644 --- a/src/bncsutil/file.h +++ b/src/bncsutil/file.h @@ -26,8 +26,6 @@ #ifndef _FILE_H_INCLUDED_ #define _FILE_H_INCLUDED_ 1 -#include - #ifdef MOS_WINDOWS typedef long off_t; #else @@ -45,7 +43,7 @@ typedef struct _file* file_t; #define FILE_WRITE (0x02) -file_t file_open(const char* filename, unsigned int mode); +file_t file_open(const char* filename, unsigned int mode_flags); void file_close(file_t file); size_t file_read(file_t file, void* ptr, size_t size, size_t count); size_t file_write(file_t file, const void* ptr, size_t size, @@ -59,4 +57,4 @@ void file_unmap(file_t file, const void* mapping); } #endif -#endif /* FILE */ +#endif /* _FILE_H_INCLUDED_ */ diff --git a/src/bncsutil/mutil.h b/src/bncsutil/mutil.h index 5cb5c59..981a132 100644 --- a/src/bncsutil/mutil.h +++ b/src/bncsutil/mutil.h @@ -36,7 +36,11 @@ /* Specific-Sized Integers */ #include "mutil_types.h" -#include +#ifdef __cplusplus +#include +#else +#include +#endif // functions for converting a string to a 64-bit number. #if defined(_MSC_VER) @@ -146,17 +150,18 @@ # define MUTIL_LIB_BUILD #endif +/** + * I think what this tries to do is differentiate if you are trying to build + * this as a library exporting symbols versus using the library from this same project + * ..which I don't think makes much sense. TODO: evaluate and nuke import part in the future + */ #ifdef MOS_WINDOWS # pragma comment(lib, "Version.lib") # ifdef MUTIL_LIB_BUILD -# if 1 -# define MEXP(type) __declspec(dllexport) type __stdcall -# else -# define MEXP(type) type __stdcall -# endif +# define MEXP(type) __declspec(dllexport) type __cdecl # define MCEXP(name) class __declspec(dllexport) name # else -# define MEXP(type) __declspec(dllimport) type __stdcall +# define MEXP(type) __declspec(dllimport) type __cdecl # define MCEXP(name) class __declspec(dllimport) name # endif #else @@ -174,6 +179,4 @@ #define NULL 0 #endif /* NULL */ -// #include - #endif /* MUTIL_H */ diff --git a/src/bncsutil/mutil_types.h b/src/bncsutil/mutil_types.h index e739799..0a3e6c4 100644 --- a/src/bncsutil/mutil_types.h +++ b/src/bncsutil/mutil_types.h @@ -29,7 +29,11 @@ #if defined(_MSC_VER) && (defined(HAVE_STDINT_H) && !HAVE_STDINT_H) #include "ms_stdint.h" #else +#ifdef __cplusplus +#include +#else #include #endif +#endif #endif /* BNCSUTIL_MUTIL_TYPES_H_INCLUDED */ diff --git a/src/bncsutil/nls.c b/src/bncsutil/nls.c index 7e5148b..c6c4e99 100644 --- a/src/bncsutil/nls.c +++ b/src/bncsutil/nls.c @@ -90,7 +90,7 @@ const char bncsutil_NLS_sig_n[] = { unsigned long nls_pre_seed(); -void nls_get_x(nls_t* nls, mpz_t x_c, const char* raw_salt); +void nls_get_x(const nls_t* nls, mpz_t x_c, const char* raw_salt); void nls_get_v_mpz(nls_t* nls, mpz_t v, mpz_t x); @@ -507,8 +507,7 @@ MEXP(void) nls_get_M1(nls_t* nls, char* out, const char* B, const char* salt) { } MEXP(int) nls_check_M2(nls_t* nls, const char* var_M2, const char* B, - const char* salt) -{ + const char* salt) { SHA1Context sha; char local_M2[20]; char* A; @@ -674,7 +673,7 @@ unsigned long nls_pre_seed() { #endif } -void nls_get_x(nls_t* nls, mpz_t x_c, const char* raw_salt) { +void nls_get_x(const nls_t* nls, mpz_t x_c, const char* raw_salt) { char* userpass; uint8_t hash[20], final_hash[20]; SHA1Context shac; diff --git a/src/bncsutil/pe.h b/src/bncsutil/pe.h index 1795a10..8742124 100644 --- a/src/bncsutil/pe.h +++ b/src/bncsutil/pe.h @@ -27,7 +27,11 @@ #define CM_PE_H_INCLUDED 1 #include "mutil.h" +#ifdef __cplusplus +#include +#else #include +#endif #ifdef __cplusplus extern "C" { diff --git a/src/bncsutil/sha1.c b/src/bncsutil/sha1.c index b639c36..ba9353b 100644 --- a/src/bncsutil/sha1.c +++ b/src/bncsutil/sha1.c @@ -38,8 +38,8 @@ (((word) << (bits)) | ((word) >> (32-(bits)))) /* Local Function Prototyptes */ -void SHA1PadMessage(SHA1Context *); -void SHA1ProcessMessageBlock(SHA1Context *); +void SHA1PadMessage(SHA1Context * /*context*/); +void SHA1ProcessMessageBlock(SHA1Context * /*context*/); /* * SHA1Reset