Блокировка исходящего трафика в виде .asi

SafeModeOfficial

Новичок
Автор темы
8
0
Приветствую всех. Хочу написать .asi для блокировки конкретного айпи, чтобы gta_sa.exe не могла до нее добраться. Прошу о помощи и советах как начать. (Это будет моим первым проектом)
 

atomlin

Известный
579
380
Хукнуть отправку подключения к серверу (RakPeer::SendConnectionRequest( const char* host, unsigned short remotePort, char* passwordData, int passwordDataLength ))
(Можно хукнуть и socketlayer, но тогда будет ломаться connectfix)
(Ниже offset под r1)

C++:
#include <iostream>
#include <thread>

#include "Windows.h"

uintptr_t dwSAMP = 0xFF;

void* SetCallHook(uintptr_t HookAddress, void* DetourFunction)
{
    uintptr_t OriginalFunction = *reinterpret_cast<uintptr_t*>(HookAddress + 1) + HookAddress + 5;
    DWORD oldProt;
    VirtualProtect(reinterpret_cast<void*>(HookAddress + 1), sizeof(uintptr_t), PAGE_READWRITE, &oldProt);
    *reinterpret_cast<uintptr_t*>(HookAddress + 1) = reinterpret_cast<uintptr_t>(DetourFunction) - HookAddress - 5;
    VirtualProtect(reinterpret_cast<void*>(HookAddress + 1), sizeof(uintptr_t), oldProt, &oldProt);
    return reinterpret_cast<void*>(OriginalFunction);
}

using SendConnectionRequest = bool(__fastcall*)(void*, void*, const char*, unsigned short, char*, int);
SendConnectionRequest pSendConnectionRequest = nullptr;

int __fastcall ConnectionHook(void* EDX, void* thats, const char* host, unsigned short remotePort, char* passwordData, int passwordDataLength)
{
    if (!strncmp(host, "127.0.0.1", 9))
        return 0;

    return pSendConnectionRequest(EDX, thats, host, remotePort, passwordData, passwordDataLength);
}

void Hooking()
{
    pSendConnectionRequest = reinterpret_cast<SendConnectionRequest>(SetCallHook(dwSAMP + 0x3CB16, &ConnectionHook));
}

BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
        {
            dwSAMP = reinterpret_cast<uintptr_t>(GetModuleHandleA("samp.dll"));
            std::thread(Hooking).detach();

            break;
        }
    }
    return TRUE;
}
 
Последнее редактирование:

SafeModeOfficial

Новичок
Автор темы
8
0
Хукнуть отправку подключения к серверу (RakPeer::SendConnectionRequest( const char* host, unsigned short remotePort, char* passwordData, int passwordDataLength ))
(Можно хукнуть и socketlayer, но тогда будет ломаться connectfix)
(Ниже offset под r1)

C++:
#include <iostream>
#include <thread>

#include "Windows.h"

uintptr_t dwSAMP = 0xFF;

void* SetCallHook(uintptr_t HookAddress, void* DetourFunction)
{
    uintptr_t OriginalFunction = *reinterpret_cast<uintptr_t*>(HookAddress + 1) + HookAddress + 5;
    DWORD oldProt;
    VirtualProtect(reinterpret_cast<void*>(HookAddress + 1), sizeof(uintptr_t), PAGE_READWRITE, &oldProt);
    *reinterpret_cast<uintptr_t*>(HookAddress + 1) = reinterpret_cast<uintptr_t>(DetourFunction) - HookAddress - 5;
    VirtualProtect(reinterpret_cast<void*>(HookAddress + 1), sizeof(uintptr_t), oldProt, &oldProt);
    return reinterpret_cast<void*>(OriginalFunction);
}

using SendConnectionRequest = bool(__fastcall*)(void*, void*, const char*, unsigned short, char*, int);
SendConnectionRequest pSendConnectionRequest = nullptr;

int __fastcall ConnectionHook(void* EDX, void* thats, const char* host, unsigned short remotePort, char* passwordData, int passwordDataLength)
{
    if (!strncmp(host, "127.0.0.1", 9))
        return 0;

    return pSendConnectionRequest(EDX, thats, host, remotePort, passwordData, passwordDataLength);
}

void Hooking()
{
    pSendConnectionRequest = reinterpret_cast<SendConnectionRequest>(SetCallHook(dwSAMP + 0x3CB16, &ConnectionHook));
}

BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
        {
            dwSAMP = reinterpret_cast<uintptr_t>(GetModuleHandleA("samp.dll"));
            std::thread(Hooking).detach();

            break;
        }
    }
    return TRUE;
}
Как я понял он провеяет айпи хоста, и если он соотвествует, то полностью блокирует все подключения?