Skip to content

Commit

Permalink
Merge pull request #2 from Wend4r/fix-errors-by_standards
Browse files Browse the repository at this point in the history
Clang: fix errors by standards
  • Loading branch information
qubka authored Feb 13, 2024
2 parents 8c8d2e7 + fda775a commit b257d6e
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 33 deletions.
1 change: 1 addition & 0 deletions include/dynohook/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "mem_accessor.h"
#include "ihook.h"
#include "platform.h"
#include <asmjit/asmjit.h>

namespace dyno {
Expand Down
8 changes: 4 additions & 4 deletions include/dynohook/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ namespace dyno {
#define DYNO_LOG_WARN(msg) dyno::Log::log(msg, dyno::ErrorLevel::WARN)
#define DYNO_LOG_ERR(msg) dyno::Log::log(msg, dyno::ErrorLevel::ERR)
#else
#define DYNO_LOG(lvl, msg)
#define DYNO_LOG_INFO(lvl, msg)
#define DYNO_LOG_WARN(lvl, msg)
#define DYNO_LOG_ERR(lvl, msg)
#define DYNO_LOG(msg)
#define DYNO_LOG_INFO(msg)
#define DYNO_LOG_WARN(msg)
#define DYNO_LOG_ERR(msg)
#endif
6 changes: 3 additions & 3 deletions include/dynohook/mem_protector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace dyno {
class MemProtector {
public:
MemProtector() = delete;
MemProtector(uintptr_t address, size_t length, ProtFlag prot, MemAccessor& accessor, bool unsetOnDestroy = true);
MemProtector(std::uintptr_t address, std::size_t length, ProtFlag prot, MemAccessor& accessor, bool unsetOnDestroy = true);
~MemProtector();

ProtFlag originalProt() const {
Expand All @@ -25,8 +25,8 @@ namespace dyno {
private:
MemAccessor& m_accessor;

uintptr_t m_address;
size_t m_length;
std::uintptr_t m_address;
std::size_t m_length;
bool m_status;
bool m_unsetLater;

Expand Down
2 changes: 2 additions & 0 deletions include/dynohook/nat_hook.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "platform.h"

#if DYNO_ARCH_X86 == 32
#include <dynohook/x86_hook.h>
#elif DYNO_ARCH_X86 == 64
Expand Down
2 changes: 1 addition & 1 deletion include/dynohook/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
#endif

// optimization
#if DYNO_PLATFORM_GCC_COMPATIBLE
#if DYNO_PLATFORM_GCC_COMPATIBLE && !(defined(DYNO_PLATFORM_CLANG) && DYNO_PLATFORM_CLANG)
#define DYNO_OPTS_OFF _Pragma("GCC push_options") _Pragma("GCC optimize (\"O0\")")
#define DYNO_OPTS_ON _Pragma("GCC pop_options")
#elif DYNO_PLATFORM_MSVC
Expand Down
7 changes: 4 additions & 3 deletions include/dynohook/virtuals/vhook.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once

#include <dynohook/nat_hook.h>
#include <cstdint>

namespace dyno {
class VHook final : public NatHook {
public:
VHook(uintptr_t fnAddress, const ConvFunc& convention);
VHook(std::uintptr_t fnAddress, const ConvFunc& convention);
~VHook() override;

bool hook() override;
Expand All @@ -15,12 +16,12 @@ namespace dyno {
return HookMode::VTableSwap;
}

const uintptr_t& getAddress() const override {
const std::uintptr_t& getAddress() const override {
return m_fnAddress;
}

private:
// address of the original function
uintptr_t m_fnAddress;
std::uintptr_t m_fnAddress;
};
}
2 changes: 2 additions & 0 deletions src/convention.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <dynohook/convention.h>

#include <cstring>

using namespace dyno;

ICallingConvention::ICallingConvention(std::vector<DataObject> arguments, DataObject returnType, size_t alignment) :
Expand Down
4 changes: 3 additions & 1 deletion src/core.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <dynohook/core.h>
#include <dynohook/os.h>

#include <cstring>

namespace dyno {

uintptr_t findPattern(uintptr_t rangeStart, size_t len, const char* pattern) {
Expand Down Expand Up @@ -36,7 +38,7 @@ uintptr_t findPattern(uintptr_t rangeStart, size_t len, const char* pattern) {
}

size_t getPatternSize(const char* pattern) {
const size_t l = strlen(pattern);
const size_t l = std::strlen(pattern);

// c = 2 * b + (b - 1) . 2 chars per byte + b - 1 spaces between
return (l + 1) / 3;
Expand Down
1 change: 1 addition & 0 deletions src/detours/detour.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <dynohook/detours/detour.h>
#include <dynohook/log.h>

#include <cmath>

Expand Down
7 changes: 7 additions & 0 deletions src/detours/x64_detour.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#include <dynohook/core.h>
#include <dynohook/log.h>
#include <dynohook/detours/x64_detour.h>

#include <asmtk/asmtk.h>
#include <Zydis/Register.h>

#include <algorithm>
#include <iterator>
#include <map>
#include <set>

using namespace std::string_literals;

using namespace dyno;
Expand Down
15 changes: 9 additions & 6 deletions src/fb_allocator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <dynohook/core.h>
#include <dynohook/fb_allocator.h>

#include <cstring>

void* ALLOC_NewBlock(ALLOC_Allocator* self) {
ALLOC_Block* pBlock = NULL;

Expand Down Expand Up @@ -85,7 +88,7 @@ void* ALLOC_Calloc(ALLOC_HANDLE hAlloc, size_t num, size_t size) {
pMem = ALLOC_Alloc(hAlloc, n);

if (pMem) {
memset(pMem, 0, n);
std::memset(pMem, 0, n);
}
return pMem;
}
Expand All @@ -112,13 +115,13 @@ void ALLOC_Free(ALLOC_HANDLE hAlloc, void* pBlock) {
using namespace dyno;

FBAllocator::FBAllocator(uintptr_t min, uintptr_t max, uint8_t blockSize, uint8_t blockCount) :
m_min{min},
m_max{max},
m_dataPool{0},
m_maxBlocks{blockCount},
m_alloc2Supported{boundedAllocSupported()},
m_usedBlocks{0},
m_maxBlocks{blockCount},
m_blockSize{blockSize},
m_alloc2Supported{boundedAllocSupported()} {
m_min{min},
m_max{max},
m_dataPool{0} {
}

FBAllocator::~FBAllocator() {
Expand Down
1 change: 1 addition & 0 deletions src/hook.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <dynohook/hook.h>
#include <dynohook/log.h>

using namespace dyno;

Expand Down
24 changes: 14 additions & 10 deletions src/instruction.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <dynohook/instruction.h>
#include <dynohook/mem_accessor.h>

#include <cstring>

using namespace dyno;

Instruction::Instruction(
Expand All @@ -15,26 +17,28 @@ Instruction::Instruction(
std::string&& opStr,
Mode mode
) : m_accessor{accessor},
m_address{address},
m_displacement{displacement},
m_dispOffset{displacementOffset},
m_dispSize{0},
m_isRelative{isRelative},

m_register{0},
m_isIndirect{isIndirect},
m_isCalling{false},
m_isBranching{false},
m_isRelative{isRelative},
m_hasDisplacement{false},
m_hasImmediate{false},
m_displacement{displacement},

m_address{address},
m_immediate{0},
m_immediateSize{0},
m_register{0},
m_dispOffset{displacementOffset},
m_dispSize{0},

m_mode{mode},
m_uid{s_counter++},

m_bytes{std::move(bytes)},
m_mnemonic{std::move(mnemonic)},
m_opStr{std::move(opStr)},

m_uid{s_counter++},
m_mode{mode} {
m_opStr{std::move(opStr)} {
}

void Instruction::setDestination(uintptr_t dest) {
Expand Down
2 changes: 2 additions & 0 deletions src/log.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <dynohook/log.h>

#include <iostream>

using namespace dyno;

void Log::registerLogger(std::shared_ptr<Logger> logger) {
Expand Down
3 changes: 3 additions & 0 deletions src/mem_accessor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <dynohook/core.h>
#include <dynohook/mem_accessor.h>
#include <dynohook/mem_protector.h>
#include <dynohook/os.h>

#include <cstring>

using namespace dyno;

#if DYNO_PLATFORM_WINDOWS
Expand Down
8 changes: 4 additions & 4 deletions src/mem_protector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

using namespace dyno;

MemProtector::MemProtector(uintptr_t address, size_t length, ProtFlag prot, MemAccessor& accessor, bool unsetOnDestroy) :
MemProtector::MemProtector(std::uintptr_t address, std::size_t length, ProtFlag prot, MemAccessor& accessor, bool unsetOnDestroy) :
m_accessor{accessor},
m_address{address},
m_length{length},
m_unsetLater{unsetOnDestroy},
m_accessor{accessor},
m_status{false} {
m_status{false},
m_unsetLater{unsetOnDestroy} {
m_origProtection = m_accessor.mem_protect(address, length, prot, m_status);
}

Expand Down
2 changes: 2 additions & 0 deletions src/range_allocator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <dynohook/range_allocator.h>
#include <dynohook/fb_allocator.h>

#include <algorithm>

using namespace dyno;

RangeAllocator::RangeAllocator(uint8_t blockSize, uint8_t blockCount) : m_maxBlocks{blockCount}, m_blockSize{blockSize} {
Expand Down
4 changes: 4 additions & 0 deletions src/registers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <dynohook/registers.h>

#include <array>
#include <algorithm>
#include <cstring>

using namespace dyno;

Register Registers::s_none(NONE, SIZE_INVALID);
Expand Down
3 changes: 2 additions & 1 deletion src/virtuals/vhook.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <dynohook/log.h>
#include <dynohook/virtuals/vhook.h>

using namespace dyno;

VHook::VHook(uintptr_t fnAddress, const ConvFunc& convention) : NatHook(convention), m_fnAddress{fnAddress} {
VHook::VHook(std::uintptr_t fnAddress, const ConvFunc& convention) : NatHook(convention), m_fnAddress{fnAddress} {
assert(fnAddress != 0 && "Function address cannot be null");
}

Expand Down
4 changes: 4 additions & 0 deletions src/virtuals/vtable.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <dynohook/virtuals/vtable.h>
#include <dynohook/core.h>
#include <dynohook/log.h>
#include <dynohook/mem_protector.h>

#include <cstring>

using namespace dyno;

VTable::VTable(void* pClass, std::shared_ptr<VHookCache> hookCache) : m_class{(void***)pClass}, m_hookCache{std::move(hookCache)} {
Expand Down
1 change: 1 addition & 0 deletions src/x64_hook.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <dynohook/x64_hook.h>
#include <dynohook/log.h>

using namespace dyno;
using namespace asmjit;
Expand Down

0 comments on commit b257d6e

Please sign in to comment.