-
UID:140458
-
- 注册时间2013-01-17
- 最后登录2015-08-30
- 在线时间109小时
-
- 发帖146
- 搜Ta的帖子
- 精华0
- 金钱1461
- 威望157
- 贡献值1
- 好评度147
-
访问TA的空间加好友用道具
|
获取机器的硬件信息 mac 地址 主板id 等等, 我前几天也弄过,不过没有解决好 后来也就放弃了 因为项目的这个功能不是很着急 给你贴一段代码,供你参考,希望可以帮到你 如果这个问题你解决后,可以分享一份代码给我吗。发私信给我也可以的哦 嘿嘿 - #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <windows.h> //DWORD
- #include <QCryptographicHash>
- #include <QDebug>
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- ui->textEdit1->setText("");
- qDebug()<<"start";
- qDebug()<<"getCPUManID:"<<this->getCPUManID();//通过调用汇编语言获取CPU制造商信息
- qDebug()<<"getCpuInfo:"<<this->getCpuInfo();//处理器信息
- qDebug()<<"GetCPUID:"<<this->GetCPUID();//
- qDebug()<<"GetHarddiskNum:"<<this->GetHarddiskNum();//硬盘序列号
- QString text1="";
- text1.append("getCPUManID:"+this->getCPUManID()+"\n");
- text1.append("getCpuInfo:"+this->getCpuInfo()+"\n");
- text1.append("GetCPUID:"+this->GetCPUID()+"\n");
- text1.append("GetHarddiskNum:"+this->GetHarddiskNum()+"\n");
- ui->textEdit1->setText(text1);
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_pushButton_clicked()
- {
- QString temp1;
- temp1.append("getCPUManID:"+this->getCPUManID()+"*");
- temp1.append("getCpuInfo:"+this->getCpuInfo()+"*");
- temp1.append("GetCPUID:"+this->GetCPUID()+"*");
- temp1.append("GetHarddiskNum:"+this->GetHarddiskNum()+"*");
- qDebug()<<this->jiami(temp1);
- }
- QString MainWindow::getCPUManID()
- //通过调用汇编语言获取CPU制造商信息
- {
- //用来存储信息
- DWORD deax;
- DWORD debx;
- DWORD decx;
- DWORD dedx;
- char ID[25];//存储制造商信息
- memset(ID,0,sizeof(ID));//先清空数组 ID
- //gcc中应该是 __asm__
- __asm
- {
- mov eax,0
- cpuid
- mov deax,eax
- mov debx,ebx
- mov decx,ecx
- mov dedx,edx
- }
- memcpy(ID+0,&debx,4);//制造商信息前四个字符复制到数组
- memcpy(ID+4,&dedx,4);//中间四个
- memcpy(ID+8,&decx,4);//最后四个
- //如果返回 char * ,会出现乱码;故返回 string 值
- //qDebug()<<"manufacture id is "<<QString::fromLocal8Bit(ID);
- return QString::fromLocal8Bit(ID);
- }
- QString MainWindow::getCpuInfo()
- //get cpu info
- {
- SYSTEM_INFO info;
- GetSystemInfo(&info);
- return QString::number(info.dwNumberOfProcessors,16).toUpper()+QString::number(info.dwProcessorType,16).toUpper();
- }
- QString MainWindow::GetCPUID()
- // get cpu id
- {
- DWORD dwId1, dwId2, dwId3, dwId4;
- char szCompany[13];
- //PCHAR pCompany = szCompany;
- //DWORD dwCPU;
- szCompany[12]=0;
- _asm
- {
- pushfd
- pushad
- //取得CPU的ID号
- mov eax,1 //功能号
- _emit 0x0f
- _emit 0xa2
- mov dwId1,eax
- mov dwId2,ebx
- mov dwId3,ecx
- mov dwId4,edx
- // //取得CPU的制造公司名称
- // mov edi,pCompany //功能号
- // mov eax,0
- // _emit 0x0f
- // _emit 0xa2
- // mov eax,ebx
- // stosd
- // mov eax,edx
- // stosd
- // mov eax,ecx
- // stosd
- popad
- popfd
- }
- DWORD dwResult = 0;
- DWORD dwTemp1 = dwId1 << 12;
- DWORD dwTemp2 = dwId2 << 8 ;
- DWORD dwTemp3 = dwId3 << 4;
- dwResult = dwTemp1 + dwTemp2 + dwTemp3 + dwId4;
- return QString::number(dwResult,16).toUpper();
- }
- QString MainWindow::GetHarddiskNum()
- //硬盘序列号
- {
- char cVolume[256]; //
- char cFileSysName[256];
- DWORD dwSerialNum; //硬盘序列号
- DWORD dwFileNameLength;
- DWORD dwFileSysFlag;
- GetVolumeInformationA( "C://", cVolume, 256, &dwSerialNum, &dwFileNameLength,
- &dwFileSysFlag, cFileSysName, 256);
- return QString::number(dwSerialNum,16).toUpper();
- }
- QString MainWindow::jiami(const QString text){
- qDebug()<<text;
- QByteArray byte_array;
- byte_array.append(text);
- QByteArray hash_byte_array = QCryptographicHash::hash(byte_array, QCryptographicHash::Sha3_512);
- QString Sha512 = hash_byte_array.toHex();
- return Sha512;
- }
|