Qt 소스 오픈 애플릿 - dll, exe 버전 정보 보기
32666 단어 Qt 소스 공유
Qt 소스 오픈 애플릿 – dll,exe 버전 정보 보기
먼저 위의 그림에서 효과를 보십시오.
작업에서 자주 볼 수 있는 파일에 대한 서명, dll,exe에 포함된 정보를 추출하고 검증합니다.그래서 나는 한 종류로 포장해서 나중에 직접 사용해서 매우 편리하다.여러분이 이 종류를 받으면 프로젝트에 직접 사용할 수 있습니다.
여기에 주요 코드를 붙여 놓을게요. 완전한 항목을github 위에 놓을게요./****************************************************************************
**
** Copyright (C) 2018 liushixiong ([email protected])
** All rights reserved.
**
****************************************************************************/
#include "dolproductinfo.h"
#include
#include
#include "..\common\common.h"
#pragma comment(lib, "crypt32.lib")
#define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING)
const int LINE_BUFFER_SIZE = 2048;
dolProductInfo::dolProductInfo(const string &pFilePath, bool pIsInit)
: mFilePath(pFilePath)
{
if (pIsInit) { Init(); }
}
dolProductInfo::~dolProductInfo()
{
}
bool dolProductInfo::Init()
{
DWORD temp;
UINT size;
char tempbuf[LINE_BUFFER_SIZE] = { 0 };
HANDLE hFile = CreateFileA(mFilePath.c_str(), GENERIC_READ,
FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) { return false; }
char szMZHader[0x40];
char szMewHader[0x1000];
DWORD read;
bool result = ReadFile(hFile, szMZHader, 0x40, &read, NULL);
if (! result || read != 0x40) {
return false;
}
DWORD filesize = GetFileSize(hFile, NULL);
FormatDWord(filesize, tempbuf);
mSize = tempbuf;
mSize += " Bytes";
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
FILETIME ftCreation, ftModified;
GetFileTime(hFile, &ftCreation, NULL, &ftModified);
FormatFileTime(ftCreation, tempbuf);
mCreationTime = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
FormatFileTime(ftModified, tempbuf);
mModifiedTime = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
CloseHandle(hFile);
if ((size = GetFileVersionInfoSizeA(mFilePath.c_str(), &temp)) < 0) {
return false;
}
char *buf = new char[size];
char *str;
char szLang1[20];
if (! GetFileVersionInfoA(mFilePath.c_str(), 0, size, buf)) {
delete[] buf;
return false;
}
VS_FIXEDFILEINFO *info;
if (VerQueryValueA((LPVOID)buf, ("\\"), (LPVOID *)&info, &size)) {
string retvalue;
mType = GetFileType(info->dwFileType, retvalue);
sprintf_s(tempbuf, LINE_BUFFER_SIZE, "%d.%d.%d.%d",
(info->dwFileVersionMS >> 16),
(info->dwFileVersionMS & 65535),
(info->dwFileVersionLS >> 16),
info->dwFileVersionLS & 65535);
mFileVersion = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
sprintf_s(tempbuf, LINE_BUFFER_SIZE, "%d.%d.%d.%d",
(info->dwProductVersionMS >> 16),
(info->dwProductVersionMS & 65535),
(info->dwProductVersionLS >> 16),
info->dwProductVersionLS & 65535);
mProductVersion = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (! VerQueryValueA((LPCVOID)buf,
("\\VarFileInfo\\Translation"),
(LPVOID *)&str, &size)) {
// return false;
}
sprintf_s(szLang1, sizeof(szLang1)/sizeof(char),
"%4.4X%4.4X",
*(unsigned short *)str,
*(unsigned short *)(str+2));
// unicode , mult char
result = GetInfoStr(buf, szLang1, "ProductName", tempbuf);
if (! result) {
ZeroMemory(szLang1, 20);
sprintf_s(szLang1, sizeof(szLang1)/sizeof(char),
"%4.4X%4.4X",
*(unsigned short *)str,
0x4E4);
if (GetInfoStr(buf, szLang1, "ProductName", tempbuf)) {
mProductName = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
} else {
mProductName = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (GetInfoStr(buf, szLang1, "FileDescription", tempbuf)) {
mFileDescription = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (GetInfoStr(buf, szLang1, "CompanyName", tempbuf)) {
mCompanyName = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (GetInfoStr(buf, szLang1, "LegalCopyRight", tempbuf)) {
mCopyRight = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (GetInfoStr(buf, szLang1, "OriginalFileName", tempbuf)) {
mOriginName = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
string signstr = QueryDigSignature();
delete[] buf;
return true;
}
string dolProductInfo::GetFileType(DWORD pdwFileType, string &pszFileType)
{
const int count = 7;
KEY_VALUE FilesTypes[count] = {
{ VFT_UNKNOWN, "Unkown" },
{ VFT_APP, "Application" },
{ VFT_DLL, "Dynamic-Link Library" },
{ VFT_DRV, "Device Driver" },
{ VFT_FONT,"Font" },
{ VFT_VXD, "Virtual Device" },
{ VFT_STATIC_LIB, "Static-Link Library" }
};
return KeyValueToStr(FilesTypes, count, pdwFileType, pszFileType);
}
string dolProductInfo::GetFilePath() const
{
return mFilePath;
}
void dolProductInfo::SetFilePath(const string &pFilePath)
{
mFilePath = pFilePath;
}
string dolProductInfo::GetFileDescription() const
{
return mFileDescription;
}
void dolProductInfo::SetFileDescription(const string &pFileDescription)
{
mFileDescription = pFileDescription;
}
string dolProductInfo::GetDigSignature() const
{
return mDigSignature;
}
void dolProductInfo::SetDigSignature(const string &pDigSignature)
{
mDigSignature = pDigSignature;
}
string dolProductInfo::GetType() const
{
return mType;
}
코드를 보니 쓸모가 있다고 느꼈다.github는 start에서 내릴 수 있습니다.위챗 공식 번호에 주목하여 더 많은 원본 코드를 얻으세요.
/****************************************************************************
**
** Copyright (C) 2018 liushixiong ([email protected])
** All rights reserved.
**
****************************************************************************/
#include "dolproductinfo.h"
#include
#include
#include "..\common\common.h"
#pragma comment(lib, "crypt32.lib")
#define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING)
const int LINE_BUFFER_SIZE = 2048;
dolProductInfo::dolProductInfo(const string &pFilePath, bool pIsInit)
: mFilePath(pFilePath)
{
if (pIsInit) { Init(); }
}
dolProductInfo::~dolProductInfo()
{
}
bool dolProductInfo::Init()
{
DWORD temp;
UINT size;
char tempbuf[LINE_BUFFER_SIZE] = { 0 };
HANDLE hFile = CreateFileA(mFilePath.c_str(), GENERIC_READ,
FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) { return false; }
char szMZHader[0x40];
char szMewHader[0x1000];
DWORD read;
bool result = ReadFile(hFile, szMZHader, 0x40, &read, NULL);
if (! result || read != 0x40) {
return false;
}
DWORD filesize = GetFileSize(hFile, NULL);
FormatDWord(filesize, tempbuf);
mSize = tempbuf;
mSize += " Bytes";
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
FILETIME ftCreation, ftModified;
GetFileTime(hFile, &ftCreation, NULL, &ftModified);
FormatFileTime(ftCreation, tempbuf);
mCreationTime = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
FormatFileTime(ftModified, tempbuf);
mModifiedTime = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
CloseHandle(hFile);
if ((size = GetFileVersionInfoSizeA(mFilePath.c_str(), &temp)) < 0) {
return false;
}
char *buf = new char[size];
char *str;
char szLang1[20];
if (! GetFileVersionInfoA(mFilePath.c_str(), 0, size, buf)) {
delete[] buf;
return false;
}
VS_FIXEDFILEINFO *info;
if (VerQueryValueA((LPVOID)buf, ("\\"), (LPVOID *)&info, &size)) {
string retvalue;
mType = GetFileType(info->dwFileType, retvalue);
sprintf_s(tempbuf, LINE_BUFFER_SIZE, "%d.%d.%d.%d",
(info->dwFileVersionMS >> 16),
(info->dwFileVersionMS & 65535),
(info->dwFileVersionLS >> 16),
info->dwFileVersionLS & 65535);
mFileVersion = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
sprintf_s(tempbuf, LINE_BUFFER_SIZE, "%d.%d.%d.%d",
(info->dwProductVersionMS >> 16),
(info->dwProductVersionMS & 65535),
(info->dwProductVersionLS >> 16),
info->dwProductVersionLS & 65535);
mProductVersion = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (! VerQueryValueA((LPCVOID)buf,
("\\VarFileInfo\\Translation"),
(LPVOID *)&str, &size)) {
// return false;
}
sprintf_s(szLang1, sizeof(szLang1)/sizeof(char),
"%4.4X%4.4X",
*(unsigned short *)str,
*(unsigned short *)(str+2));
// unicode , mult char
result = GetInfoStr(buf, szLang1, "ProductName", tempbuf);
if (! result) {
ZeroMemory(szLang1, 20);
sprintf_s(szLang1, sizeof(szLang1)/sizeof(char),
"%4.4X%4.4X",
*(unsigned short *)str,
0x4E4);
if (GetInfoStr(buf, szLang1, "ProductName", tempbuf)) {
mProductName = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
} else {
mProductName = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (GetInfoStr(buf, szLang1, "FileDescription", tempbuf)) {
mFileDescription = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (GetInfoStr(buf, szLang1, "CompanyName", tempbuf)) {
mCompanyName = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (GetInfoStr(buf, szLang1, "LegalCopyRight", tempbuf)) {
mCopyRight = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
if (GetInfoStr(buf, szLang1, "OriginalFileName", tempbuf)) {
mOriginName = tempbuf;
ZeroMemory(tempbuf, LINE_BUFFER_SIZE);
}
string signstr = QueryDigSignature();
delete[] buf;
return true;
}
string dolProductInfo::GetFileType(DWORD pdwFileType, string &pszFileType)
{
const int count = 7;
KEY_VALUE FilesTypes[count] = {
{ VFT_UNKNOWN, "Unkown" },
{ VFT_APP, "Application" },
{ VFT_DLL, "Dynamic-Link Library" },
{ VFT_DRV, "Device Driver" },
{ VFT_FONT,"Font" },
{ VFT_VXD, "Virtual Device" },
{ VFT_STATIC_LIB, "Static-Link Library" }
};
return KeyValueToStr(FilesTypes, count, pdwFileType, pszFileType);
}
string dolProductInfo::GetFilePath() const
{
return mFilePath;
}
void dolProductInfo::SetFilePath(const string &pFilePath)
{
mFilePath = pFilePath;
}
string dolProductInfo::GetFileDescription() const
{
return mFileDescription;
}
void dolProductInfo::SetFileDescription(const string &pFileDescription)
{
mFileDescription = pFileDescription;
}
string dolProductInfo::GetDigSignature() const
{
return mDigSignature;
}
void dolProductInfo::SetDigSignature(const string &pDigSignature)
{
mDigSignature = pDigSignature;
}
string dolProductInfo::GetType() const
{
return mType;
}