1919#include < memory>
2020#include < string>
2121#include < LIEF/LIEF.hpp>
22+ #include " ../src/Path.hpp"
2223
2324QString decideExe (const QDir& dir) {
2425 QString fileName;
@@ -65,9 +66,9 @@ void analyzeImportTable(const std::string& binaryPath) {
6566 }
6667}
6768
68- void readPEHeader (const QString & filePath) {
69- QFile file (filePath);
70- if (file.open (QIODevice::ReadOnly) == true ) {
69+ void readPEHeader (Path filePath) {
70+ QFile file (filePath. get () );
71+ if (file.open (QIODevice::ReadOnly) == true ) { // flawfinder: ignore
7172 QDataStream in (&file);
7273 in.setByteOrder (QDataStream::LittleEndian);
7374
@@ -104,15 +105,15 @@ void readPEHeader(const QString &filePath) {
104105 }
105106 file.close ();
106107 } else {
107- qCritical () << " Failed to open file:" << filePath;
108+ qCritical () << " Failed to open file:" << filePath. get () ;
108109 }
109110}
110111
111112
112- void readExportTable (const QString & filePath) {
113- QFile file (filePath);
114- if (!file.open (QIODevice::ReadOnly)) {
115- qCritical () << " Failed to open file:" << filePath;
113+ void readExportTable (Path filePath) {
114+ QFile file (filePath. get () );
115+ if (!file.open (QIODevice::ReadOnly)) { // flawfinder: ignore
116+ qCritical () << " Failed to open file:" << filePath. get () ;
116117 return ;
117118 }
118119
@@ -142,7 +143,8 @@ void readExportTable(const QString &filePath) {
142143 file.seek (dosHeader.e_lfanew + sizeof (PEHeader));
143144
144145 // Read Optional Header
145- QByteArray optionalHeaderData (peHeader.sizeOfOptionalHeader , Qt::Uninitialized);
146+ QByteArray optionalHeaderData (
147+ peHeader.sizeOfOptionalHeader , Qt::Uninitialized);
146148 in.readRawData (optionalHeaderData.data (), peHeader.sizeOfOptionalHeader );
147149
148150 // Get Data Directory
@@ -152,16 +154,23 @@ void readExportTable(const QString &filePath) {
152154 };
153155
154156 constexpr int IMAGE_DIRECTORY_ENTRY_EXPORT = 0 ;
155- auto dataDirectory = reinterpret_cast <DataDirectory*>(optionalHeaderData.data () + 96 ); // Offset 96: start of Data Directory
156- quint32 exportTableRVA = dataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].virtualAddress ;
157+ // Offset 96: start of Data Directory
158+ auto dataDirectory =
159+ reinterpret_cast <DataDirectory*>(optionalHeaderData.data () + 96 );
160+
161+ quint32 exportTableRVA =
162+ dataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].virtualAddress ;
157163
158164 if (exportTableRVA == 0 ) {
159165 qCritical () << " No Export Table found in this PE file." ;
160166 return ;
161167 }
162168
163169 // Find the section that contains the Export Table
164- file.seek (dosHeader.e_lfanew + sizeof (PEHeader) + peHeader.sizeOfOptionalHeader );
170+ file.seek (dosHeader.e_lfanew +
171+ sizeof (PEHeader) +
172+ peHeader.sizeOfOptionalHeader );
173+
165174 quint16 numSections = peHeader.numSections ;
166175
167176 struct SectionHeader {
@@ -181,13 +190,15 @@ void readExportTable(const QString &filePath) {
181190 quint32 exportTableFileOffset = 0 ;
182191
183192 for (quint16 i = 0 ; i < numSections; i++) {
184- in.readRawData (reinterpret_cast <char *>(§ion), sizeof (SectionHeader));
193+ in.readRawData (
194+ reinterpret_cast <char *>(§ion), sizeof (SectionHeader));
185195 quint32 sectionStart = section.virtualAddress ;
186196 quint32 sectionEnd = sectionStart + section.virtualSize ;
187197
188198 if (exportTableRVA >= sectionStart && exportTableRVA < sectionEnd) {
189199 quint32 offsetWithinSection = exportTableRVA - sectionStart;
190- exportTableFileOffset = section.pointerToRawData + offsetWithinSection;
200+ exportTableFileOffset =
201+ section.pointerToRawData + offsetWithinSection;
191202 break ;
192203 }
193204 }
@@ -200,10 +211,13 @@ void readExportTable(const QString &filePath) {
200211 // Read Export Directory
201212 file.seek (exportTableFileOffset);
202213 ExportDirectory exportDirectory;
203- in.readRawData (reinterpret_cast <char *>(&exportDirectory), sizeof (ExportDirectory));
214+ in.readRawData (
215+ reinterpret_cast <char *>(&exportDirectory), sizeof (ExportDirectory));
204216
205217 // Read the DLL Name
206- file.seek (section.pointerToRawData + (exportDirectory.nameRVA - section.virtualAddress ));
218+ file.seek (section.pointerToRawData +
219+ (exportDirectory.nameRVA - section.virtualAddress ));
220+
207221 QByteArray dllName;
208222 char c;
209223 while (file.getChar (&c) && c != ' \0 ' ) {
@@ -216,7 +230,9 @@ void readExportTable(const QString &filePath) {
216230 qDebug () << " Exported Functions:" ;
217231
218232 // Name Pointer Table
219- quint32 namePointerOffset = section.pointerToRawData + (exportDirectory.namePointerRVA - section.virtualAddress );
233+ quint32 namePointerOffset = section.pointerToRawData +
234+ (exportDirectory.namePointerRVA - section.virtualAddress );
235+
220236 file.seek (namePointerOffset);
221237
222238 QVector<quint32> nameRVAs (exportDirectory.numNamePointers );
@@ -225,7 +241,9 @@ void readExportTable(const QString &filePath) {
225241 }
226242
227243 for (const quint32 &nameRVA : nameRVAs) {
228- quint32 nameOffset = section.pointerToRawData + (nameRVA - section.virtualAddress );
244+ quint32 nameOffset = section.pointerToRawData +
245+ (nameRVA - section.virtualAddress );
246+
229247 file.seek (nameOffset);
230248
231249 QByteArray functionName;
@@ -291,14 +309,15 @@ qint64 findReplacePattern(QFile* const file) {
291309 * @retval 2 Could not preform the first read only opening of the file.
292310 * @return error qint64.
293311 */
294- qint64 widescreen_set (const QString& path ) {
312+ qint64 widescreen_set (Path filePath ) {
295313 qint64 status = 0 ;
296- QFileInfo fileInfo (path);
297- QFile file (path);
314+ QFile file (filePath.get ());
298315
299316 // Open the file
300- if (!fileInfo.exists () || !fileInfo.isFile ()) {
301- qCritical () << " Error: The exe path is not a regular file: " << path;
317+ if (!filePath.exists () || !filePath.isFile ()) {
318+ qCritical ()
319+ << " Error: The exe path is not a regular file: "
320+ << filePath.get ();
302321 status = 1 ; // Invalid file path
303322 } else if (!file.open (QIODevice::ReadOnly)) { // flawfinder: ignore
304323 qCritical () << " Error opening file for reading!" ;
0 commit comments