Advertisement
forest98

[BETA][LINUX] Grub_restore 0.2b

Jun 19th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. /*[BETA] Grub_restore 0.2b
  2. Copyright (c) 2015 Emanuele Forestieri.All rights reserved.
  3.  
  4. Changelog:
  5. #0.2b [10/07/2015]
  6. -migliorato controllo sull'input della partizione
  7. -aggiunta la scelta per il riavvio
  8. -ottimizzato il codice
  9. -grafica migliorata
  10. #0.1b [19/06/2015]
  11. -release iniziale
  12.  
  13. note:
  14. -compilare con -O3 (facoltativo)
  15. */
  16. #include <iostream>
  17. #include <cstdlib>
  18. #include <unistd.h>
  19. using namespace std;
  20. void part(string& s)
  21. {
  22.         do
  23.         {
  24.                 cout << "INSERISCI PARTIZIONE LINUX=";
  25.                 cin >> s;
  26.                 if (s[0]!='/' || s[4]!='/' || s[8]=='\0' || s.substr(1,3)!="dev" || s.size()>9)
  27.                         cout << "[!]PARTIZIONE NON VALIDA, RE";
  28.         }
  29.         while (s[0]!='/' || s[4]!='/' || s[8]=='\0' || s.substr(1,3)!="dev" || s.size()>9);
  30. }
  31.  
  32. void mount(string f,string s)
  33. {
  34.     cout << "[*] MONTANDO LE PARTIZIONI...";
  35.         f="mount " + s + " /mnt";
  36.         system(f.c_str());
  37.         system("mount --bind /dev /mnt/dev");
  38.         system("mount --bind /dev/pts /mnt/dev/pts");
  39.         system("mount --bind /proc /mnt/proc");
  40.         system("mount --bind /sys /mnt/sys");
  41.         cout << "\n[+] PARTIZIONI MONTATE!";
  42. }
  43. void umount()
  44. {
  45.     cout << "\n[*] SMONTANDO LE PARTIZIONI...";
  46.     system("umount /mnt/dev/pts");
  47.         system("umount /mnt/dev");
  48.         system("umount /mnt/proc");
  49.         system("umount /mnt/sys");
  50.         system("umount /mnt");
  51.         cout << "\n[+] PARTIZIONI SMONTATE!\n";
  52. }
  53. void g_restore()
  54. {
  55.     cout << "\n------------------------------";
  56.     cout << "\n|GRUB_RESTORE 0.2 beta       |";
  57.     cout << "\n|Designed for linux       |";
  58.     cout << "\n|Coded by Emanuele Forestieri|";
  59.     cout << "\n------------------------------\n\n";
  60.     string s;
  61.     part(s);
  62.     string f;
  63.     mount(f,s);
  64.     unsigned char c;
  65.     cout << "\n[*] INSTALLANDO IL GRUB...";
  66.     cout << "\n";
  67.     chroot("/mnt");
  68.     f="grub-install " + s.substr(0,8);
  69.     system(f.c_str());
  70.     system("update-grub");
  71.     cout << "[+] GRUB INSTALLATO!";
  72.     chdir("..");
  73.     chroot(".");
  74.     umount();
  75.     cout << "[!] RIAVVIARE ORA[S/n]?";
  76.     cin >> c;
  77.     if (c=='s' || c=='S')
  78.         system("reboot");
  79.     else
  80.         cout << endl;
  81. }
  82. int main()
  83. {
  84.     g_restore();
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement