Advertisement
Guest User

Ruben Pointer

a guest
Feb 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main(){
  4.  
  5.     int x = 10;
  6.  
  7.     //Arrivo all'secondo byte usato in memoria dal mio int...
  8.     char *edit_x = (char *) &x + 1;
  9.     //                         offset rispetto all'inizio dell' int
  10.  
  11.     //aggiungo tramite lo xor (usato dal processore per le somme)
  12.     // il pattern di byte di 'A' che è il decimale 65 ovvero il binario 01000001
  13.     *edit_x = *edit_x ^ 'A';
  14.     *(edit_x + 1) = *(edit_x + 1) ^ 'A';
  15.     //ottento quindi il binario 01000001 01000001 00001010 00000000 pari a 4276490
  16.     std::cout << x << std::endl;
  17.  
  18.     //se lo rifaccio eliminerò il byte modificato e ritornero a 0001010 00000000 00000000 00000000 ovvero 10
  19.     *edit_x = *edit_x ^ 'A';
  20.     *(edit_x + 1) = *(edit_x + 1) ^ 'A';
  21.     std::cout << x << std::endl;
  22.  
  23.     //Usato per mostrare l'indirizzo puntato da edit_x
  24.     std::cout << (void *) edit_x << " " << &x << std::endl;
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement