Advertisement
es3n1n

shellcode converter

Mar 8th, 2022
858
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdint>
  2. #include <iostream>
  3. #include <Zydis/Zydis.h>
  4.  
  5.  
  6. void dump_shell( uint8_t* data, ZyanUSize length ) {
  7.     constexpr bool is_x86 = sizeof( uintptr_t ) == 4;
  8.  
  9.     ZydisDecoder decoder;
  10.     ZydisFormatter formatter;
  11.     ZydisDecodedInstruction instruction;
  12.  
  13.     ZydisDecoderInit(
  14.         &decoder,
  15.         is_x86 ? ZYDIS_MACHINE_MODE_LONG_COMPAT_32 : ZYDIS_MACHINE_MODE_LONG_64,
  16.         is_x86 ? ZYDIS_ADDRESS_WIDTH_32 : ZYDIS_ADDRESS_WIDTH_64
  17.     );
  18.     ZydisFormatterInit( &formatter, ZYDIS_FORMATTER_STYLE_INTEL_MASM );
  19.  
  20.     printf( "shellcode_crafter::make_shellcode(\n" );
  21.     while ( ZYAN_SUCCESS( ZydisDecoderDecodeBuffer( &decoder, data, length, &instruction ) ) ) {
  22.         char formatted_disasm[ 256 ];
  23.         ZydisFormatterFormatInstruction( &formatter, &instruction, formatted_disasm, sizeof( formatted_disasm ), 0 );
  24.  
  25.         printf( "\t\"" );
  26.         for ( size_t i = 0; i < instruction.length; i++ )
  27.             printf( "\\x%02X", data[ i ] );
  28.         printf( "\" // %s\n", formatted_disasm );
  29.  
  30.         data += instruction.length;
  31.         length -= instruction.length;
  32.     }
  33.     printf( ");\n" );
  34. }
  35.  
  36.  
  37. int main( ) {
  38.  
  39.     dump_shell( rawData, sizeof( rawData ) );
  40.  
  41.     return EXIT_SUCCESS;
  42. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement