at & une compilation 64

 

1. Le premier assemblage at & 64

  1 .section .data
   2  strFormat: 
  3 .asciz " % s \ n " 
  4  strUseLibc: 
  5 .asciz " Salut, si vous me voyez, vous avez appelé c lib :) " 
  6  strUseSyscall: 
  7 .asciz " Et si vous me voyez , vous avez appelé syscall. \ n " 
  8  endOfStrUseSyscall: 
  9  
 10 .section .text
  11 .globl _start
  12  _start: 
 13 # Le paramètre transmis par l'appel de fonction n'utilise plus la méthode push
  14 movq $ strFormat,% rdi
  15 movq $ strUseLibc, appel % rsi
  16     printf
  17  
 18 # Le registre d'appels système a changé, int 0x80 a également été remplacé par syscall
  19 movq $ 1 ,% rdi
  20 movq $ strUseSyscall,% rsi
  21 movq $ (endOfStrUseSyscall-strUseSyscall),% rdx
  22 movq $ 1 ,% rax
  23  syscall 
 24  
 25 #En outre, le numéro de l'appel système est également différent
  26 movq $ 127 ,% rdi # Renvoie intentionnellement une valeur non nulle
  27 movq $ 60 ,% rax
  28  syscall

 

2 Convertissez de c en assembleur, puis compilez en bin 

Derrière la compilation GCC

http://tinylab.org/behind-the-gcc-compiler/

1 #include <stdio.h>
 2 #include <unistd.h>
 3  
4  int   sum ( int a) {
 5          return a ;
6 }
 7  int main () {
 8          int b = 0 ;
9          b = somme ( 1 ) ;
10          printf ( " bonjour:% d \ n " , b) ;
11          _exit ( 0 ) ;
12 }
1 gcc -S   test .c -fno-asynchronous-unwind-tables -fno-exceptions -fno-stack-protector
 2 sed -i -e " s # main # _start # g "  test .s
 3 gcc -c test .s
 4 #ld -o test  test .o /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o / usr / lib / x86_64-linux-gnu / crtn. o -lc --dynamic-linker / lib64 / ld-linux-x86- 64 .so. 2 
5 ld -o test  test .o -lc --dynamic-linker / lib64 / ld-linux-x86- 64 .so. 2

 

Je suppose que tu aimes

Origine www.cnblogs.com/mysqlinternal/p/12736401.html
conseillé
Classement