SHARE
TWEET

dnload hello_world.cpp @ 944a8fc3aa946d97fba6aab6f1ace771970

a guest Feb 27th, 2019 80 in 163 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ########################################
  2. # Elf32_Ehdr or Elf64_Ehdr #############
  3. ########################################
  4. .globl ehdr
  5. ehdr:
  6.   # e_ident[EI_MAG0], magic value 0x7F
  7.   .byte 0x7f
  8.   # e_ident[EI_MAG1] to e_indent[EI_MAG3], magic value "ELF"
  9.   .ascii "ELF"
  10.   # e_ident[EI_CLASS], ELFCLASS32 = 1, ELFCLASS64 = 2
  11.   .byte 0x1
  12.   # e_ident[EI_DATA], ELFDATA2LSB = 1, ELFDATA2MSB = 2
  13.   .byte 0x1
  14.   # e_ident[EI_VERSION], EV_CURRENT = 1
  15.   .byte 0x1
  16.   # e_ident[EI_OSABI], ELFOSABI_SYSV = 0, ELFOSABI_LINUX = 3, ELFOSABI_FREEBSD = 9
  17.   .byte 0x3
  18.   # e_ident[EI_ABIVERSION], always 0
  19.   .byte 0x0
  20.   # e_indent[EI_MAG10 to EI_MAG15], unused
  21.   .byte 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
  22.   # e_type, ET_EXEC = 2
  23.   .short 0x2
  24.   # e_machine, EM_386 = 3, EM_ARM = 40, EM_X86_64 = 62
  25.   .short 0x3
  26.   # e_version, EV_CURRENT = 1
  27.   .long 0x1
  28.   # e_entry, execution starting point
  29.   .long _start
  30.   # e_phoff, offset from start to program headers
  31.   .long phdr_interp - ehdr
  32.   # e_shoff, start of section headers
  33.   .long 0x0
  34.   # e_flags, unused
  35.   .long 0x0
  36.   # e_ehsize, Elf32_Ehdr size
  37.   .short ehdr_end - ehdr
  38.   # e_phentsize, Elf32_Phdr size
  39.   .short phdr_interp_end - phdr_interp
  40.   # e_phnum, Elf32_Phdr count, PT_LOAD, [PT_LOAD (bss)], PT_INTERP, PT_DYNAMIC
  41.   .short 0x3
  42.   # e_shentsize, Elf32_Shdr size
  43.   .short 0x0
  44.   # e_shnum, Elf32_Shdr count
  45.   .short 0x0
  46.   # e_shstrndx, index of section containing string table of section header names
  47.   .short 0x0
  48. .globl ehdr_end
  49. ehdr_end:
  50. ########################################
  51. # Elf32_Phdr, PT_INTERP ################
  52. ########################################
  53. .globl phdr_interp
  54. phdr_interp:
  55.   # p_type, PT_INTERP = 3
  56.   .long 0x3
  57.   # p_offset, offset of block
  58.   .long interp - ehdr
  59.   # p_vaddr, address of block
  60.   .long interp
  61.   # p_paddr, unused
  62.   .long 0x0
  63.   # p_filesz, block size on disk
  64.   .long interp_end - interp
  65.   # p_memsz, block size in memory
  66.   .long interp_end - interp
  67.   # p_flags, ignored
  68.   .long 0x0
  69.   # p_align, 1 for strtab
  70.   .long 0x1
  71. .globl phdr_interp_end
  72. phdr_interp_end:
  73. ########################################
  74. # Elf32_Phdr, PT_LOAD ##################
  75. ########################################
  76. .globl phdr_load
  77. phdr_load:
  78.   # p_type, PT_LOAD = 1
  79.   .long 0x1
  80.   # p_offset, offset of program start
  81.   .long 0x0
  82.   # p_vaddr, program virtual address
  83.   .long 0x2000000
  84.   # p_paddr, unused
  85.   .long 0x0
  86.   # p_filesz, program size on disk
  87.   .long end - ehdr
  88.   # p_memsz, program size in memory
  89.   .long bss_end - ehdr
  90.   # p_flags, rwx = 7
  91.   .long 0x7
  92.   # p_align, usually 0x1000
  93.   .long 0x1000
  94. .globl phdr_load_end
  95. phdr_load_end:
  96. ########################################
  97. # Elf32_Phdr, PT_DYNAMIC ###############
  98. ########################################
  99. .globl phdr_dynamic
  100. phdr_dynamic:
  101.   # p_type, PT_DYNAMIC = 2
  102.   .long 0x2
  103.   # p_offset, offset of block
  104.   .long dynamic - ehdr
  105.   # p_vaddr, address of block
  106.   .long dynamic
  107.   # p_paddr, unused
  108.   .long 0x0
  109.   # p_filesz, block size on disk
  110.   .long dynamic_end - dynamic
  111.   # p_memsz, block size in memory
  112.   .long dynamic_end - dynamic
  113.   # p_flags, ignored
  114.   .byte 0x0
  115.   .byte 0x0
  116.   .byte 0x0
  117.   .byte 0x0
  118. .globl dynamic
  119. dynamic:
  120.   # p_align
  121.   # d_tag, DT_NEEDED = 1
  122.   .byte 0x1
  123.   .byte 0x0
  124.   .byte 0x0
  125.   .byte 0x0
  126. .globl phdr_dynamic_end
  127. phdr_dynamic_end:
  128. ########################################
  129. # PT_DYNAMIC ###########################
  130. ########################################
  131.   # d_un, library name offset in strtab
  132.   .long strtab_libc_so_6 - strtab
  133.   # d_tag, DT_SYMTAB = 6
  134.   .long 0x6
  135.   # d_un
  136.   .long 0x0
  137.   # d_tag, DT_STRTAB = 5
  138.   .long 0x5
  139.   # d_un
  140.   .long strtab
  141.   # d_tag, DT_DEBUG = 21
  142.   .long 0x15
  143. .globl dynamic_r_debug
  144. dynamic_r_debug:
  145.   # d_un
  146.   .long 0x0
  147.   # d_tag, DT_NULL = 0
  148.   .long 0x0
  149.   # d_un
  150.   .long 0x0
  151. .globl dynamic_end
  152. dynamic_end:
  153. ########################################
  154. # PT_INTERP ############################
  155. ########################################
  156. .globl interp
  157. interp:
  158.   # path to interpreter
  159.   .ascii "/lib/ld-linux.so.2"
  160. .globl strtab
  161. strtab:
  162.   # interpreter terminating zero
  163.   # initial zero
  164.   .byte 0x0
  165. .globl interp_end
  166. interp_end:
  167. ########################################
  168. # DT_STRTAB ############################
  169. ########################################
  170. .globl strtab_libc_so_6
  171. strtab_libc_so_6:
  172.   # symbol name string
  173.   .ascii "libc.so.6"
  174.   # string terminating zero
  175.   .byte 0x0
  176. .globl strtab_end
  177. strtab_end:
  178. ########################################
  179. # sections 'None' ######################
  180. ########################################
  181. .LC0:
  182.     .string "Hello World!"
  183.     .balign 1
  184.     .type   _ZL14g_symbol_table, @object
  185.     .size   _ZL14g_symbol_table, 4
  186. _ZL14g_symbol_table:
  187.     .long   -1794341244
  188.     .ident  "GCC: (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0"
  189.     .file   "hello_world.cpp"
  190.     .globl  _start
  191.     .type   _start, @function
  192. _start:
  193.     movl    _ZL14g_symbol_table, %eax
  194.     movl    %eax, (%esp)
  195.     movl    dynamic_r_debug, %eax
  196.     movl    4(%eax), %esi
  197. .L5:
  198.     movl    12(%esi), %esi
  199.     movl    8(%esi), %eax
  200. .L2:
  201.     addl    $8, %eax
  202.     cmpl    $5, (%eax)
  203.     jne .L2
  204.     movl    4(%eax), %ecx
  205.     movl    (%esi), %edx
  206.     cmpl    %edx, %ecx
  207.     jnb .L3
  208.     addl    %edx, %ecx
  209. .L3:
  210.     movl    12(%eax), %eax
  211.     cmpl    %eax, %edx
  212.     jbe .L10
  213.     addl    %edx, %eax
  214. .L10:
  215.     cmpl    %ecx, %eax
  216.     jnb .L5
  217.     movl    (%eax), %edi
  218.     addl    %ecx, %edi
  219.     xorl    %ebx, %ebx
  220. .L9:
  221.     incl    %edi
  222.     movzbl  -1(%edi), %ebp
  223.     testl   %ebp, %ebp
  224.     jne .L6
  225.     cmpl    %ebx, (%esp)
  226.     jne .L13
  227.     addl    4(%eax), %edx
  228.     movl    %edx, _ZL14g_symbol_table
  229.     pushl   $.LC0
  230.     call    *%edx
  231. #APP
  232. # 59 "src/dnload.h" 1
  233.     int $0x3
  234. .L6:
  235.     imull   $65599, %ebx, %ebx
  236.     addl    %ebp, %ebx
  237.     jmp .L9
  238. .L13:
  239.     addl    $16, %eax
  240.     jmp .L10
  241.     .size   _start, .-_start
  242. .globl end
  243. end:
  244. .globl bss_start
  245. bss_start:
  246. .globl bss_end
  247. .equ bss_end, bss_start + 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top