Исходник Autistically Syscalling x86

Начинающий
Статус
Оффлайн
Регистрация
1 Ноя 2022
Сообщения
15
Реакции[?]
11
Поинты[?]
0
Hallo:
[[ nodiscard ]] const __declspec( naked ) std::ptrdiff_t allocate_stub( const std::ptrdiff_t wow64 ) {
    _asm mov eax, 24; index
    _asm mov edx, wow64; translation
    _asm call edx; make call
    _asm retn 24; add esp
}

[[ nodiscard ]] const std::ptrdiff_t mem_allocate( const std::ptrdiff_t wow64, const std::size_t size, const std::ptrdiff_t addr = 0 ) {
    using call_t = std::int32_t( __stdcall* )( std::ptrdiff_t, const std::ptrdiff_t*,
        std::uint32_t, const std::size_t*, std::uint32_t, std::uint32_t );

    ptr< call_t >( &allocate_stub )( -1, &addr, 0, &size, 0x3000, 0x40 );
    return addr;
}

template< std::uint32_t id, typename... arg_t >
const std::uint8_t create_call( const std::ptrdiff_t wow64, const arg_t... args ) {
    std::uint8_t bytes[ 15 ] = {
       0xb8, 0x00, 0x00, 0x00, 0x00,
       0xba, 0x00, 0x00, 0x00, 0x00,
       0xff, 0xd2,
       0xc2, 0x00, 0x00
    };

    auto ctx{ mem_allocate( wow64, sizeof bytes ) };
    if ( !ctx )
        return 0;

    *ptr< std::uint32_t* >( &bytes[ 0x1 ] ) = id;
    *ptr< std::uint32_t* >( &bytes[ 0x6 ] ) = wow64;
    *ptr< std::uint16_t* >( &bytes[ 0xd ] ) = ( sizeof( arg_t ) + ... );

    for ( std::size_t i{ }; i < sizeof bytes; i++ )
        ptr< std::uint8_t* >( ctx )[ i ] = bytes[ i ];

    auto ret{ ptr< std::int32_t( __stdcall* )( arg_t... ) >( ctx )( args... ) };
    mem_free( wow64 );
    return !!ret;
}

[[ nodiscard ]] const std::ptrdiff_t wow64_translation( const std::ptrdiff_t module ) {
    auto ctx{ ptr< std::uint8_t* >( module ) };
    if ( !ctx )
        return 0;

    while ( ctx[ 10 ] != 0xb8 || ctx[ 15 ] != 0xba || ctx[ 20 ] != 0xff || ctx[ 21 ] != 0xd2 )
        ctx++;

    return *ptr< std::ptrdiff_t* >( ctx + 0x10 );
}
 
Последнее редактирование:
BLTN
Участник
Статус
Оффлайн
Регистрация
23 Апр 2022
Сообщения
664
Реакции[?]
306
Поинты[?]
37K
Hallo:
[[ nodiscard ]] const __declspec( naked ) std::ptrdiff_t alloc_stub( const std::ptrdiff_t wow64 ) {
    _asm mov eax, 24; index
    _asm mov edx, wow64; translation
    _asm call edx; make call
    _asm retn 24; add esp
}

[[ nodiscard ]] const std::ptrdiff_t mem_alloc( const std::ptrdiff_t wow64, const std::size_t size, const std::ptrdiff_t addr = 0 ) {
    using call_t = std::int32_t( __stdcall* )( std::ptrdiff_t, const std::ptrdiff_t*,
        std::uint32_t, const std::size_t*, std::uint32_t, std::uint32_t );

    ptr< call_t >( &alloc_stub )( -1, &addr, 0, &size, 0x3000, 0x40 );
    return addr;
}

template< std::uint32_t id, typename... arg_t >
const std::uint8_t create_call( const std::ptrdiff_t wow64, const arg_t... args ) {
    std::uint8_t bytes[ 15 ] = {
       0xb8, 0x00, 0x00, 0x00, 0x00,
       0xba, 0x00, 0x00, 0x00, 0x00,
       0xff, 0xd2,
       0xc2, 0x00, 0x00
    };

    auto ctx{ mem_alloc( wow64, sizeof bytes ) };
    if ( !ctx )
        return 0;

    *ptr< std::uint32_t* >( &bytes[ 0x1 ] ) = id;
    *ptr< std::uint32_t* >( &bytes[ 0x6 ] ) = wow64;
    *ptr< std::uint16_t* >( &bytes[ 0xd ] ) = ( sizeof( arg_t ) + ... );

    for ( std::size_t i{ }; i < sizeof bytes; i++ )
        ptr< std::uint8_t* >( ctx )[ i ] = bytes[ i ];

    auto ret{ ptr< std::int32_t( __stdcall* )( arg_t... ) >( ctx )( args... ) };
    mem_free( wow64 );
    return !!ret;
}

[[ nodiscard ]] const std::ptrdiff_t wow64_translation( const std::ptrdiff_t module ) {
    auto ctx{ ptr< std::uint8_t* >( module ) };
    if ( !ctx )
        return 0;

    while ( ctx[ 10 ] != 0xb8 || ctx[ 15 ] != 0xba || ctx[ 20 ] != 0xff || ctx[ 21 ] != 0xd2 )
        ctx++;

    return *ptr< std::ptrdiff_t* >( ctx + 0x10 );
}
Нахуя ты слизал тред с юц при этом не дав никаких объяснений работы, 90% юзеров не смогуть этим даже воспользоваться
 
Начинающий
Статус
Оффлайн
Регистрация
8 Июн 2019
Сообщения
147
Реакции[?]
21
Поинты[?]
0
Hallo:
[[ nodiscard ]] const __declspec( naked ) std::ptrdiff_t allocate_stub( const std::ptrdiff_t wow64 ) {
    _asm mov eax, 24; index
    _asm mov edx, wow64; translation
    _asm call edx; make call
    _asm retn 24; add esp
}

[[ nodiscard ]] const std::ptrdiff_t mem_allocate( const std::ptrdiff_t wow64, const std::size_t size, const std::ptrdiff_t addr = 0 ) {
    using call_t = std::int32_t( __stdcall* )( std::ptrdiff_t, const std::ptrdiff_t*,
        std::uint32_t, const std::size_t*, std::uint32_t, std::uint32_t );

    ptr< call_t >( &allocate_stub )( -1, &addr, 0, &size, 0x3000, 0x40 );
    return addr;
}

template< std::uint32_t id, typename... arg_t >
const std::uint8_t create_call( const std::ptrdiff_t wow64, const arg_t... args ) {
    std::uint8_t bytes[ 15 ] = {
       0xb8, 0x00, 0x00, 0x00, 0x00,
       0xba, 0x00, 0x00, 0x00, 0x00,
       0xff, 0xd2,
       0xc2, 0x00, 0x00
    };

    auto ctx{ mem_allocate( wow64, sizeof bytes ) };
    if ( !ctx )
        return 0;

    *ptr< std::uint32_t* >( &bytes[ 0x1 ] ) = id;
    *ptr< std::uint32_t* >( &bytes[ 0x6 ] ) = wow64;
    *ptr< std::uint16_t* >( &bytes[ 0xd ] ) = ( sizeof( arg_t ) + ... );

    for ( std::size_t i{ }; i < sizeof bytes; i++ )
        ptr< std::uint8_t* >( ctx )[ i ] = bytes[ i ];

    auto ret{ ptr< std::int32_t( __stdcall* )( arg_t... ) >( ctx )( args... ) };
    mem_free( wow64 );
    return !!ret;
}

[[ nodiscard ]] const std::ptrdiff_t wow64_translation( const std::ptrdiff_t module ) {
    auto ctx{ ptr< std::uint8_t* >( module ) };
    if ( !ctx )
        return 0;

    while ( ctx[ 10 ] != 0xb8 || ctx[ 15 ] != 0xba || ctx[ 20 ] != 0xff || ctx[ 21 ] != 0xd2 )
        ctx++;

    return *ptr< std::ptrdiff_t* >( ctx + 0x10 );
}
я хоть и не гуру но вроде так будет лучше
C++:
[[nodiscard]] const std::ptrdiff_t allocate_stub(const std::ptrdiff_t wow64) {
    std::ptrdiff_t index = 24;
    std::ptrdiff_t translation = wow64;
    std::ptrdiff_t(*call_func)(void) = reinterpret_cast<std::ptrdiff_t(*)(void)>(translation);
    return call_func();
}

[[nodiscard]] const std::ptrdiff_t mem_allocate(const std::ptrdiff_t wow64, const std::size_t size, std::ptrdiff_t addr = 0) {
    using call_t = std::int32_t(__stdcall*)(std::ptrdiff_t, const std::ptrdiff_t*, std::uint32_t, const std::size_t*, std::uint32_t, std::uint32_t);
    call_t allocate = reinterpret_cast<call_t>(&allocate_stub);
    allocate(-1, &addr, 0, &size, 0x3000, 0x40);
    return addr;
}

template<std::uint32_t id, typename... arg_t>
[[nodiscard]] const std::uint8_t create_call(const std::ptrdiff_t wow64, const arg_t... args) {
    std::uint8_t bytes[15] = {
        0xb8, 0x00, 0x00, 0x00, 0x00,
        0xba, 0x00, 0x00, 0x00, 0x00,
        0xff, 0xd2,
        0xc2, 0x00, 0x00
    };

    std::ptrdiff_t ctx{ mem_allocate(wow64, sizeof bytes) };
    if (!ctx)
        return 0;

    *reinterpret_cast<std::uint32_t*>(&bytes[0x1]) = id;
    *reinterpret_cast<std::ptrdiff_t*>(&bytes[0x6]) = wow64;
    *reinterpret_cast<std::uint16_t*>(&bytes[0xd]) = (sizeof(arg_t) + ...);

    for (std::size_t i{}; i < sizeof bytes; i++)
        *reinterpret_cast<std::uint8_t*>(ctx + i) = bytes[i];

    using func_t = std::int32_t(__stdcall*)(arg_t...);
    func_t func = reinterpret_cast<func_t>(ctx);
    std::int32_t ret = func(args...);
    mem_free(wow64);
    return !!ret;
}

[[nodiscard]] const std::ptrdiff_t wow64_translation(const std::ptrdiff_t module) {
    auto ctx{ ptr< std::uint8_t* >(module) };
    if (!ctx)
        return 0;

    while (ctx[10] != 0xb8 || ctx[15] != 0xba || ctx[20] != 0xff || ctx[21] != 0xd2)
        ctx++;

    return *reinterpret_cast<std::ptrdiff_t*>(ctx + 0x10);
}
 
Начинающий
Статус
Оффлайн
Регистрация
3 Апр 2021
Сообщения
104
Реакции[?]
15
Поинты[?]
1K
Hallo:
[[ nodiscard ]] const __declspec( naked ) std::ptrdiff_t allocate_stub( const std::ptrdiff_t wow64 ) {
    _asm mov eax, 24; index
    _asm mov edx, wow64; translation
    _asm call edx; make call
    _asm retn 24; add esp
}

[[ nodiscard ]] const std::ptrdiff_t mem_allocate( const std::ptrdiff_t wow64, const std::size_t size, const std::ptrdiff_t addr = 0 ) {
    using call_t = std::int32_t( __stdcall* )( std::ptrdiff_t, const std::ptrdiff_t*,
        std::uint32_t, const std::size_t*, std::uint32_t, std::uint32_t );

    ptr< call_t >( &allocate_stub )( -1, &addr, 0, &size, 0x3000, 0x40 );
    return addr;
}

template< std::uint32_t id, typename... arg_t >
const std::uint8_t create_call( const std::ptrdiff_t wow64, const arg_t... args ) {
    std::uint8_t bytes[ 15 ] = {
       0xb8, 0x00, 0x00, 0x00, 0x00,
       0xba, 0x00, 0x00, 0x00, 0x00,
       0xff, 0xd2,
       0xc2, 0x00, 0x00
    };

    auto ctx{ mem_allocate( wow64, sizeof bytes ) };
    if ( !ctx )
        return 0;

    *ptr< std::uint32_t* >( &bytes[ 0x1 ] ) = id;
    *ptr< std::uint32_t* >( &bytes[ 0x6 ] ) = wow64;
    *ptr< std::uint16_t* >( &bytes[ 0xd ] ) = ( sizeof( arg_t ) + ... );

    for ( std::size_t i{ }; i < sizeof bytes; i++ )
        ptr< std::uint8_t* >( ctx )[ i ] = bytes[ i ];

    auto ret{ ptr< std::int32_t( __stdcall* )( arg_t... ) >( ctx )( args... ) };
    mem_free( wow64 );
    return !!ret;
}

[[ nodiscard ]] const std::ptrdiff_t wow64_translation( const std::ptrdiff_t module ) {
    auto ctx{ ptr< std::uint8_t* >( module ) };
    if ( !ctx )
        return 0;

    while ( ctx[ 10 ] != 0xb8 || ctx[ 15 ] != 0xba || ctx[ 20 ] != 0xff || ctx[ 21 ] != 0xd2 )
        ctx++;

    return *ptr< std::ptrdiff_t* >( ctx + 0x10 );
}
Обратите внимание, что данное использование inline-ассемблера и работа с памятью являются опасными и могут привести к нестабильной работе программы или даже к потенциальным уязвимостям без должной защиты.
 
Начинающий
Статус
Оффлайн
Регистрация
12 Ноя 2022
Сообщения
63
Реакции[?]
23
Поинты[?]
3K
Есть подозрение что автор самовыражается с помощью ptrdiff_t. Тут он везде семантически неправильно использован и может быть заменён на uintptr_t там где предполагаются вычисления. А там где не предполагаются - void* потому что его можно скастить static кастом вместо reinterpret
 
Пользователь
Статус
Оффлайн
Регистрация
8 Апр 2022
Сообщения
557
Реакции[?]
88
Поинты[?]
53K
Есть подозрение что автор самовыражается с помощью ptrdiff_t. Тут он везде семантически неправильно использован и может быть заменён на uintptr_t там где предполагаются вычисления. А там где не предполагаются - void* потому что его можно скастить static кастом вместо reinterpret
Чего плохого самовыражаться кодом?
 
Сверху Снизу