Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*[BETA] Grub_restore 0.2b
- Copyright (c) 2015 Emanuele Forestieri.All rights reserved.
- Changelog:
- #0.2b [10/07/2015]
- -migliorato controllo sull'input della partizione
- -aggiunta la scelta per il riavvio
- -ottimizzato il codice
- -grafica migliorata
- #0.1b [19/06/2015]
- -release iniziale
- note:
- -compilare con -O3 (facoltativo)
- */
- #include <iostream>
- #include <cstdlib>
- #include <unistd.h>
- using namespace std;
- void part(string& s)
- {
- do
- {
- cout << "INSERISCI PARTIZIONE LINUX=";
- cin >> s;
- if (s[0]!='/' || s[4]!='/' || s[8]=='\0' || s.substr(1,3)!="dev" || s.size()>9)
- cout << "[!]PARTIZIONE NON VALIDA, RE";
- }
- while (s[0]!='/' || s[4]!='/' || s[8]=='\0' || s.substr(1,3)!="dev" || s.size()>9);
- }
- void mount(string f,string s)
- {
- cout << "[*] MONTANDO LE PARTIZIONI...";
- f="mount " + s + " /mnt";
- system(f.c_str());
- system("mount --bind /dev /mnt/dev");
- system("mount --bind /dev/pts /mnt/dev/pts");
- system("mount --bind /proc /mnt/proc");
- system("mount --bind /sys /mnt/sys");
- cout << "\n[+] PARTIZIONI MONTATE!";
- }
- void umount()
- {
- cout << "\n[*] SMONTANDO LE PARTIZIONI...";
- system("umount /mnt/dev/pts");
- system("umount /mnt/dev");
- system("umount /mnt/proc");
- system("umount /mnt/sys");
- system("umount /mnt");
- cout << "\n[+] PARTIZIONI SMONTATE!\n";
- }
- void g_restore()
- {
- cout << "\n------------------------------";
- cout << "\n|GRUB_RESTORE 0.2 beta |";
- cout << "\n|Designed for linux |";
- cout << "\n|Coded by Emanuele Forestieri|";
- cout << "\n------------------------------\n\n";
- string s;
- part(s);
- string f;
- mount(f,s);
- unsigned char c;
- cout << "\n[*] INSTALLANDO IL GRUB...";
- cout << "\n";
- chroot("/mnt");
- f="grub-install " + s.substr(0,8);
- system(f.c_str());
- system("update-grub");
- cout << "[+] GRUB INSTALLATO!";
- chdir("..");
- chroot(".");
- umount();
- cout << "[!] RIAVVIARE ORA[S/n]?";
- cin >> c;
- if (c=='s' || c=='S')
- system("reboot");
- else
- cout << endl;
- }
- int main()
- {
- g_restore();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement