1. C++ / Говнокод #25134

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    // HooksList.h
    #define PPCAT_NX(A, B) A ## B
    #define PPCAT(A, B) PPCAT_NX(A, B)
    
    #ifdef HOOKS_DEFS
        using namespace NtStructs;
        #define API_HOOK_DEF(module_name, hook_name, return_type, enabled, ...) \
            typedef return_type(WINAPI *PPCAT(hook_name, _ptr))(__VA_ARGS__); \
            return_type WINAPI PPCAT(hook_name, _hook)(__VA_ARGS__); \
            extern PPCAT(hook_name, _ptr) PPCAT(hook_name, _orig);
    #elif defined(HOOKS_LIST)
        #define API_HOOK_DEF(module_name, hook_name, return_type, enabled, ...) \
            {module_name, #hook_name, (LPVOID)PPCAT(hook_name, _hook), (LPVOID*)&PPCAT(hook_name, _orig), enabled},
    #elif defined(HOOKS_TYPES_DEF)
        using namespace NtStructs;
        #define API_HOOK_DEF(module_name, hook_name, return_type, enabled, ...) \
            typedef return_type(WINAPI *PPCAT(hook_name, _ptr))(__VA_ARGS__); \
            return_type WINAPI PPCAT(hook_name, _hook)(__VA_ARGS__);
    #elif defined(ORIGINAL_FUNCTIONS_TABLE_DEF)
        #define API_HOOK_DEF(module_name, hook_name, return_type, enabled, ...) \
            PPCAT(hook_name, _ptr) hook_name;
    #elif defined(ORIGINAL_FUNCTIONS_TABLE_FILL)
        #define API_HOOK_DEF(module_name, hook_name, return_type, enabled, ...) \
            (ORIGINAL_FUNCTIONS_TABLE_NAME).hook_name = PPCAT(hook_name, _orig);
    #else
        #define API_HOOK_DEF(...)
    #endif
    
    // NtCreateFile
    API_HOOK_DEF(L"ntdll", NtCreateFile, NTSTATUS, true,
                 PHANDLE            FileHandle,
                 ACCESS_MASK        DesiredAccess,
                 POBJECT_ATTRIBUTES ObjectAttributes,
                 PIO_STATUS_BLOCK   IoStatusBlock,
                 PLARGE_INTEGER     AllocationSize,
                 ULONG              FileAttributes,
                 ULONG              ShareAccess,
                 ULONG              CreateDisposition,
                 ULONG              CreateOptions,
                 PVOID              EaBuffer,
                 ULONG              EaLength)
    
    // NtDeleteFile
    API_HOOK_DEF(L"ntdll", NtDeleteFile, NTSTATUS, true,
                 POBJECT_ATTRIBUTES ObjectAttributes)
    // И так далее
    
    // В .cpp:
    static HookEntry hookEntries[] = {
    #define HOOKS_LIST
    #include "HooksList.h"
    #undef HOOKS_LIST
    };
    
    
    // ...
    static OriginalFunctions originalFuncsTable;
    #define ORIGINAL_FUNCTIONS_TABLE_FILL 1
    #define ORIGINAL_FUNCTIONS_TABLE_NAME originalFuncsTable
    #include "HooksList.h"
    #undef ORIGINAL_FUNCTIONS_TABLE_NAME
    #undef ORIGINAL_FUNCTIONS_TABLE_FILL

    Мокросы!..

    Запостил: gost, 30 Ноября 2018

    Комментарии (4) RSS

    Добавить комментарий