Exemplo n.º 1
0
bool Autodetection::detect()
{
    m_device = "";
    m_mountpoint = "";
    m_errdev = "";

    detectUsb();

    // Try detection via rockbox.info / rbutil.log
    QStringList mounts = mountpoints();

    for(int i=0; i< mounts.size();i++)
    {
        // do the file checking
        QDir dir(mounts.at(i));
        qDebug() << "[Autodetect] paths to check:" << mounts;
        if(dir.exists())
        {
            // check logfile first.
            if(QFile(mounts.at(i) + "/.rockbox/rbutil.log").exists()) {
                QSettings log(mounts.at(i) + "/.rockbox/rbutil.log",
                              QSettings::IniFormat, this);
                if(!log.value("platform").toString().isEmpty()) {
                    if(m_device.isEmpty())
                        m_device = log.value("platform").toString();
                    m_mountpoint = mounts.at(i);
                    qDebug() << "[Autodetect] rbutil.log detected:" << m_device << m_mountpoint;
                    return true;
                }
            }

            // check rockbox-info.txt afterwards.
            RockboxInfo info(mounts.at(i));
            if(info.success())
            {
                if(m_device.isEmpty())
                {
                    m_device = info.target();
                    // special case for video64mb. This is a workaround, and
                    // should get replaced when autodetection is reworked.
                    if(m_device == "ipodvideo" && info.ram() == 64)
                    {
                        m_device = "ipodvideo64mb";
                    }
                }
                m_mountpoint = mounts.at(i);
                qDebug() << "[Autodetect] rockbox-info.txt detected:"
                         << m_device << m_mountpoint;
                return true;
            }

            // check for some specific files in root folder
            QDir root(mounts.at(i));
            QStringList rootentries = root.entryList(QDir::Files);
            if(rootentries.contains("archos.mod", Qt::CaseInsensitive))
            {
                // archos.mod in root folder -> Archos Player
                m_device = "player";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ONDIOST.BIN", Qt::CaseInsensitive))
            {
                // ONDIOST.BIN in root -> Ondio FM
                m_device = "ondiofm";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ONDIOSP.BIN", Qt::CaseInsensitive))
            {
                // ONDIOSP.BIN in root -> Ondio SP
                m_device = "ondiosp";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ajbrec.ajz", Qt::CaseInsensitive))
            {
                qDebug() << "[Autodetect] ajbrec.ajz found. Trying detectAjbrec()";
                if(detectAjbrec(mounts.at(i))) {
                    m_mountpoint = mounts.at(i);
                    qDebug() << "[Autodetect]" << m_device;
                    return true;
                }
            }
            // detection based on player specific folders
            QStringList rootfolders = root.entryList(QDir::Dirs
                    | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
            if(rootfolders.contains("GBSYSTEM", Qt::CaseInsensitive))
            {
                // GBSYSTEM folder -> Gigabeat
                m_device = "gigabeatf";
                m_mountpoint = mounts.at(i);
                return true;
            }
#if defined(Q_OS_WIN32)
            // on windows, try to detect the drive letter of an Ipod
            if(rootfolders.contains("iPod_Control", Qt::CaseInsensitive))
            {
                // iPod_Control folder -> Ipod found
                // detecting of the Ipod type is done below using ipodpatcher
                m_mountpoint = mounts.at(i);
            }
#endif
        }

    }

    int n;
    // try ipodpatcher
    // initialize sector buffer. Needed.
    ipod_sectorbuf = NULL;
    ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE);
    struct ipod_t ipod;
    n = ipod_scan(&ipod);
    if(n == 1) {
        qDebug() << "[Autodetect] Ipod found:" << ipod.modelstr << "at" << ipod.diskname;
        // if the found ipod is a macpod also notice it as device with problem.
        if(ipod.macpod)
            m_errdev = ipod.targetname;
        m_device = ipod.targetname;
        // since resolveMountPoint is doing exact matches we need to select
        // the correct partition.
        QString mp(ipod.diskname);
#ifdef Q_OS_LINUX
        mp.append("2");
#endif
#ifdef Q_OS_MACX
        mp.append("s2");
#endif
        m_mountpoint = resolveMountPoint(mp);
        return true;
    }
    else {
        qDebug() << "[Autodetect] ipodpatcher: no Ipod found." << n;
    }
    free(ipod_sectorbuf);
    ipod_sectorbuf = NULL;

    // try sansapatcher
    // initialize sector buffer. Needed.
    sansa_sectorbuf = NULL;
    sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE);
    struct sansa_t sansa;
    n = sansa_scan(&sansa);
    if(n == 1) {
        qDebug() << "[Autodetect] Sansa found:" << sansa.targetname << "at" << sansa.diskname;
        m_device = QString("sansa%1").arg(sansa.targetname);
        QString mp(sansa.diskname);
#ifdef Q_OS_LINUX
        mp.append("1");
#endif
#ifdef Q_OS_MACX
        mp.append("s1");
#endif
        m_mountpoint = resolveMountPoint(mp);
        return true;
    }
    else {
        qDebug() << "[Autodetect] sansapatcher: no Sansa found." << n;
    }
    free(sansa_sectorbuf);
    sansa_sectorbuf = NULL;

    if(m_mountpoint.isEmpty() && m_device.isEmpty()
            && m_errdev.isEmpty() && m_incompat.isEmpty())
        return false;
    return true;
}
Exemplo n.º 2
0
Arquivo: main.cpp Projeto: aep/reaver
static int child(void *arg)
{
    context &ctx = *(context*)(arg);

    std::cerr << "[RVR] [RUN] decontaminating test chamber\n";

    //uagh clonens + private ns concept seem to be conflicting or something
    //for now we're just going to assume no one wants this shit
    mount(0, "/", 0, MS_REC | MS_PRIVATE, 0);


    // create my own temp universe
    umount ("/boot");
    mount  (0, "/boot", "tmpfs", 0, 0);

    mkdir  ("/boot/" , S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);



    std::vector<std::string> mountpoints({
        "/",
        "/data",
        "/mnt/tools",
    });


    for (std::vector<std::string>::iterator i = mountpoints.begin(); i != mountpoints.end(); i++) {
        mount(i->c_str(), ("/boot" + *i).c_str(), 0,  MS_BIND, 0);
        mount(0,  ("/boot" + *i).c_str(), 0,  MS_REMOUNT | MS_RDONLY | MS_BIND, 0);
    }

    // do we need sys? its polluted with systemd shit
    std::vector<std::string> rwmountpoints({
        "/dev",
        "/run",
        "/tmp" //rw bind because we share ccache
    });

    for (std::vector<std::string>::iterator i = rwmountpoints.begin(); i != rwmountpoints.end(); i++) {
        mount(i->c_str(), ("/boot" + *i).c_str(), 0,  MS_BIND | MS_REC, 0);
    }

    // new proc
    mount  ("none", "/boot/proc", "proc", 0, 0);



    // rw mount workdir
    char cwd[40000];
    getcwd(cwd, 40000);
    mount (cwd, (std::string("/boot") + cwd).c_str(), 0, MS_BIND | MS_REC,0);

    // chroot
    if (chroot("/boot") != 0)
        throw std::runtime_error("chroot2 failed");

    // dont get stuck in the old cwd with the old mount ns!
    chdir(cwd);


    std::cerr<< "[RVR] [RUN] booting\n";

    execvp(ctx.argv[0], ctx.argv);
    std::cerr<< "[RVR] [RUN] that didn't work :(\n";
    return 3;
}