Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdint>
- #include <iostream>
- #include <Zydis/Zydis.h>
- void dump_shell( uint8_t* data, ZyanUSize length ) {
- constexpr bool is_x86 = sizeof( uintptr_t ) == 4;
- ZydisDecoder decoder;
- ZydisFormatter formatter;
- ZydisDecodedInstruction instruction;
- ZydisDecoderInit(
- &decoder,
- is_x86 ? ZYDIS_MACHINE_MODE_LONG_COMPAT_32 : ZYDIS_MACHINE_MODE_LONG_64,
- is_x86 ? ZYDIS_ADDRESS_WIDTH_32 : ZYDIS_ADDRESS_WIDTH_64
- );
- ZydisFormatterInit( &formatter, ZYDIS_FORMATTER_STYLE_INTEL_MASM );
- printf( "shellcode_crafter::make_shellcode(\n" );
- while ( ZYAN_SUCCESS( ZydisDecoderDecodeBuffer( &decoder, data, length, &instruction ) ) ) {
- char formatted_disasm[ 256 ];
- ZydisFormatterFormatInstruction( &formatter, &instruction, formatted_disasm, sizeof( formatted_disasm ), 0 );
- printf( "\t\"" );
- for ( size_t i = 0; i < instruction.length; i++ )
- printf( "\\x%02X", data[ i ] );
- printf( "\" // %s\n", formatted_disasm );
- data += instruction.length;
- length -= instruction.length;
- }
- printf( ");\n" );
- }
- int main( ) {
- dump_shell( rawData, sizeof( rawData ) );
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement