Qt 获取usb设备信息 hacking

时间:2023-03-08 22:51:25
Qt 获取usb设备信息 hacking
/**************************************************************************
* Qt 获取usb设备信息 hacking
* 声明:
* 本文主要是为了查看之前朋友留下的Qt获取usb设备信息软件运作机制。
*
* 2015-12-31 深圳 南山平山村 曾剑锋
*************************************************************************/ 一、usbfs 文件系统
需要在Linux内核中打开usbfs选项:
───────────────────────────────────────────────────────────────────────────
┌────────────────────────────── USB support ──────────────────────────────┐
│ Arrow keys navigate the menu. <Enter> selects submenus --->. │
│ Highlighted letters are hotkeys. Pressing <Y> includes, <N> excludes, │
│ <M> modularizes features. Press <Esc><Esc> to exit, <?> for Help, </> │
│ for Search. Legend: [*] built-in [ ] excluded <M> module < > │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ --- USB support │ │
│ │ <*> Support for Host-side USB │ │
│ │ [*] USB verbose debug messages │ │
│ │ [*] USB announce new devices │ │
│ │ *** Miscellaneous USB options *** │ │
│ │ [*] USB device filesystem (DEPRECATED) <----------- these │ │
│ │ [*] USB device class-devices (DEPRECATED) │ │
│ │ [ ] Dynamic USB minor allocation │ │
│ │ [*] USB runtime power management (autosuspend) and wakeup │ │
│ │ [*] OTG support │ │
│ └────v(+)─────────────────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────────────────┤
│ <Select> < Exit > < Help > │
└─────────────────────────────────────────────────────────────────────────┘ 二、cat mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::on_pushButton_clicked()
{
if(myprocess)
delete myprocess; myprocess = new QProcess(this);
connect(myprocess, SIGNAL(readyReadStandardOutput()),this, SLOT(result()));
connect(myprocess, SIGNAL(readyReadStandardError()),this, SLOT(result())); /**
* If you say Y here (and to "/proc file system support" in the "File
* systems" section, above), you will get a file /proc/bus/usb/devices
* which lists the devices currently connected to your USB bus or
* busses, and for every connected device a file named
* "/proc/bus/usb/xxx/yyy", where xxx is the bus number and yyy the
* device number; the latter files can be used by user space programs
* to talk directly to the device. These files are "virtual", meaning
* they are generated on the fly and not stored on the hard drive.
*
* You may need to mount the usbfs file system to see the files, use
* mount -t usbfs none /proc/bus/usb
*
* For the format of the various /proc/bus/usb/ files, please read
* <file:Documentation/usb/proc_usb_info.txt>.
*/
myprocess->start("cat /proc/bus/usb/devices");
ui->result->clear();
}
void MainWindow::result()
{
QString abc = myprocess->readAllStandardOutput();
ui->result->append(abc.trimmed());
QString efg = myprocess->readAllStandardError();
if(efg.length()>)ui->result->append(efg.trimmed());
}