1 // Copyright (c) 2020-2021 hors<horsicq@gmail.com>
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 //
21 #include "formatswidget.h"
22 #include "ui_formatswidget.h"
23 
FormatsWidget(QWidget * pParent)24 FormatsWidget::FormatsWidget(QWidget *pParent) :
25     XShortcutsWidget(pParent),
26     ui(new Ui::FormatsWidget)
27 {
28     ui->setupUi(this);
29 
30 #if QT_VERSION >= 0x050300
31     const QSignalBlocker blocker(ui->comboBoxScanEngine);
32 #else
33     const bool bBlocked1=ui->comboBoxScanEngine->blockSignals(true);
34 #endif
35 
36     ui->comboBoxScanEngine->addItem(QString("Auto"),SE_AUTO);
37     ui->comboBoxScanEngine->addItem(QString("Detect It Easy(DiE)"),SE_DIE);
38     ui->comboBoxScanEngine->addItem(QString("Nauz File Detector(NFD)"),SE_NFD);
39 
40     ui->stackedWidgetMain->setCurrentIndex(TABINFO_BINARY);
41 
42     adjustScanTab(SE_AUTO);
43 
44     connect(ui->pageScanNFD,SIGNAL(scanStarted()),this,SLOT(onScanStarted()));
45     connect(ui->pageScanNFD,SIGNAL(scanFinished()),this,SLOT(onScanFinished()));
46     connect(ui->pageScanDIE,SIGNAL(scanStarted()),this,SLOT(onScanStarted()));
47     connect(ui->pageScanDIE,SIGNAL(scanFinished()),this,SLOT(onScanFinished()));
48 
49     g_options={};
50 
51 #if QT_VERSION < 0x050300
52     ui->comboBoxScanEngine->blockSignals(bBlocked1);
53 #endif
54 }
55 
setFileName(QString sFileName,bool bScan)56 void FormatsWidget::setFileName(QString sFileName, bool bScan)
57 {
58     this->g_sFileName=sFileName;
59     this->g_bScan=bScan;
60 
61     QSet<XBinary::FT> stFileTypes=XBinary::getFileTypes(sFileName,true);
62 
63     XBinary::filterFileTypes(&stFileTypes);
64 
65     QList<XBinary::FT> listFileTypes=XBinary::_getFileTypeListFromSet(stFileTypes);
66 
67     XBinary::FT fileType=XBinary::FT_UNKNOWN;
68 
69     if(listFileTypes.size())
70     {
71         if(listFileTypes.at(0)==XBinary::FT_BINARY)
72         {
73             fileType=XBinary::FT_BINARY;
74         }
75     }
76 
77     XFormats::setFileTypeComboBox(ui->comboBoxFileType,&listFileTypes,fileType);
78 
79     reload();
80 }
81 
setScanEngine(QString sScanEngine)82 void FormatsWidget::setScanEngine(QString sScanEngine)
83 {
84     if(sScanEngine=="die")
85     {
86         ui->comboBoxScanEngine->setCurrentIndex(SE_DIE);
87     }
88     else if(sScanEngine=="nfd")
89     {
90         ui->comboBoxScanEngine->setCurrentIndex(SE_NFD);
91     }
92 }
93 
setOptions(FormatsWidget::OPTIONS options)94 void FormatsWidget::setOptions(FormatsWidget::OPTIONS options)
95 {
96     g_options=options;
97     ui->pageScanDIE->setDatabasePath(options.sDatabasePath);
98     ui->pageScanDIE->setInfoPath(options.sInfoPath);
99 }
100 
~FormatsWidget()101 FormatsWidget::~FormatsWidget()
102 {
103     delete ui;
104 }
105 
on_comboBoxFileType_currentIndexChanged(int nIndex)106 void FormatsWidget::on_comboBoxFileType_currentIndexChanged(int nIndex)
107 {
108     Q_UNUSED(nIndex)
109 
110     reload();
111 }
112 
reload()113 void FormatsWidget::reload()
114 {
115     adjustScanTab(getScanEngine((SE)ui->comboBoxScanEngine->currentIndex()));
116 
117     XBinary::FT fileType=getCurrentFileType();
118 
119     QFile file;
120     file.setFileName(g_sFileName);
121 
122     if(file.open(QIODevice::ReadOnly))
123     {
124         XBinary::_MEMORY_MAP memoryMap=XFormats::getMemoryMap(fileType,&file);
125 
126         XBinary::MODE mode=memoryMap.mode;
127 
128         if((mode==XBinary::MODE_UNKNOWN)||(mode==XBinary::MODE_DATA))
129         {
130             mode=XBinary::getWidthModeFromSize(file.size());
131         }
132 
133         if(mode==XBinary::MODE_8)
134         {
135             ui->lineEditBaseAddress->setValue((quint8)memoryMap.nModuleAddress);
136         }
137         else if(mode==XBinary::MODE_16)
138         {
139             ui->lineEditBaseAddress->setValue((quint16)memoryMap.nModuleAddress);
140         }
141         else if((mode==XBinary::MODE_16SEG)||(mode==XBinary::MODE_32))
142         {
143             ui->lineEditBaseAddress->setValue((quint32)memoryMap.nModuleAddress);
144         }
145         else if(mode==XBinary::MODE_64)
146         {
147             ui->lineEditBaseAddress->setValue((quint64)memoryMap.nModuleAddress);
148         }
149 
150         ui->lineEditEndianness->setText(XBinary::endiannessToString(memoryMap.bIsBigEndian));
151         ui->lineEditArch->setText(memoryMap.sArch);
152         ui->lineEditMode->setText(XBinary::modeIdToString(memoryMap.mode));
153         ui->lineEditType->setText(memoryMap.sType);
154 
155         if(fileType==XBinary::FT_BINARY)
156         {
157             XBinary binary(&file);
158 
159             ui->stackedWidgetMain->setCurrentIndex(TABINFO_BINARY);
160 
161             ui->lineEditEntryPoint->setValue((quint32)binary.getEntryPointAddress());
162         }
163         else if(fileType==XBinary::FT_COM)
164         {
165             ui->stackedWidgetMain->setCurrentIndex(TABINFO_COM);
166 
167             XCOM com(&file);
168 
169             if(com.isValid())
170             {
171                 ui->lineEditEntryPoint->setValue((quint16)com.getEntryPointAddress());
172             }
173         }
174         else if(fileType==XBinary::FT_ZIP)
175         {
176             // TODO Set name on button
177             ui->stackedWidgetMain->setCurrentIndex(TABINFO_ZIP);
178 
179             XZip xzip(&file);
180 
181             if(xzip.isValid())
182             {
183                 ui->lineEditEntryPoint->setValue(xzip.getEntryPointAddress());
184             }
185         }
186         else if(fileType==XBinary::FT_DEX)
187         {
188             ui->stackedWidgetMain->setCurrentIndex(TABINFO_DEX);
189 
190             XDEX dex(&file);
191 
192             if(dex.isValid())
193             {
194                 ui->lineEditEntryPoint->setValue((quint16)dex.getEntryPointAddress());
195             }
196         }
197         else if(fileType==XBinary::FT_MSDOS)
198         {
199             ui->stackedWidgetMain->setCurrentIndex(TABINFO_MSDOS);
200 
201             XMSDOS msdos(&file);
202 
203             if(msdos.isValid())
204             {
205                 ui->lineEditEntryPoint->setValue((quint16)msdos.getEntryPointAddress());
206 
207                 ui->pushButtonMSDOSOverlay->setEnabled(msdos.isOverlayPresent());
208             }
209         }
210         else if(fileType==XBinary::FT_LE)
211         {
212             ui->stackedWidgetMain->setCurrentIndex(TABINFO_LE);
213 
214             XLE le(&file);
215 
216             if(le.isValid())
217             {
218                 ui->lineEditEntryPoint->setValue((quint32)le.getEntryPointAddress());
219             }
220         }
221         else if(fileType==XBinary::FT_NE)
222         {
223             ui->stackedWidgetMain->setCurrentIndex(TABINFO_NE);
224 
225             XNE ne(&file);
226 
227             if(ne.isValid())
228             {
229                 ui->lineEditEntryPoint->setValue((quint32)ne.getEntryPointAddress());
230             }
231         }
232         else if((fileType==XBinary::FT_PE32)||(fileType==XBinary::FT_PE64))
233         {
234             ui->stackedWidgetMain->setCurrentIndex(TABINFO_PE);
235 
236             XPE pe(&file);
237 
238             if(pe.isValid())
239             {
240                 if(pe.is64())
241                 {
242                     ui->lineEditEntryPoint->setValue((quint64)pe.getEntryPointAddress());
243                 }
244                 else
245                 {
246                     ui->lineEditEntryPoint->setValue((quint32)pe.getEntryPointAddress());
247                 }
248 
249                 bool bIsResourcesPresent=pe.isResourcesPresent();
250 
251                 ui->lineEditPESections->setValue(pe.getFileHeader_NumberOfSections());
252                 ui->groupBoxPESections->setEnabled(pe.isSectionsTablePresent());
253 
254                 ui->pushButtonPEExport->setEnabled(pe.isExportPresent());
255                 ui->pushButtonPEImport->setEnabled(pe.isImportPresent());
256                 ui->pushButtonPEResources->setEnabled(bIsResourcesPresent);
257                 ui->pushButtonPENET->setEnabled(pe.isNETPresent());
258                 ui->pushButtonPETLS->setEnabled(pe.isTLSPresent());
259 
260                 ui->groupBoxPEResources->setEnabled(bIsResourcesPresent);
261                 ui->pushButtonPEManifest->setEnabled(pe.isResourceManifestPresent());
262                 ui->pushButtonPEVersion->setEnabled(pe.isResourceVersionPresent());
263 
264                 ui->pushButtonPEOverlay->setEnabled(pe.isOverlayPresent());
265 
266                 ui->lineEditPETimeDateStamp->setText(XBinary::valueToTimeString(pe.getFileHeader_TimeDateStamp(),XBinary::DT_TYPE_POSIX));
267                 ui->lineEditPESizeOfImage->setValue(pe.getOptionalHeader_SizeOfImage());
268             }
269         }
270         else if((fileType==XBinary::FT_ELF32)||(fileType==XBinary::FT_ELF64))
271         {
272             ui->stackedWidgetMain->setCurrentIndex(TABINFO_ELF);
273 
274             XELF elf(&file);
275 
276             if(elf.isValid())
277             {
278                 if(elf.is64())
279                 {
280                     ui->lineEditEntryPoint->setValue((quint64)elf.getEntryPointAddress());
281                 }
282                 else
283                 {
284                     ui->lineEditEntryPoint->setValue((quint32)elf.getEntryPointAddress());
285                 }
286             }
287 
288             ui->lineEditELFPrograms->setEnabled(elf.isProgramsTablePresent());
289             ui->lineEditELFSections->setEnabled(elf.isSectionsTablePresent());
290             ui->lineEditELFPrograms->setValue(elf.getNumberOfPrograms());
291             ui->lineEditELFSections->setValue(elf.getNumberOfSections());
292         }
293         else if((fileType==XBinary::FT_MACHO32)||(fileType==XBinary::FT_MACHO64))
294         {
295             ui->stackedWidgetMain->setCurrentIndex(TABINFO_MACH);
296 
297             XMACH mach(&file);
298 
299             if(mach.isValid())
300             {
301                 if(mach.is64())
302                 {
303                     ui->lineEditEntryPoint->setValue((quint64)mach.getEntryPointAddress());
304                 }
305                 else
306                 {
307                     ui->lineEditEntryPoint->setValue((quint32)mach.getEntryPointAddress());
308                 }
309 
310                 QList<XMACH::COMMAND_RECORD> listCommandRecords=mach.getCommandRecords();
311                 QList<XMACH::SECTION_RECORD> listSectionRecords=mach.getSectionRecords(&listCommandRecords);
312                 QList<XMACH::SEGMENT_RECORD> listSegmentRecords=mach.getSegmentRecords(&listCommandRecords);
313                 QList<XMACH::LIBRARY_RECORD> listLibraryRecords=mach.getLibraryRecords(&listCommandRecords);
314 
315                 ui->lineEditMACHCommands->setEnabled(listCommandRecords.count());
316                 ui->lineEditMACHSections->setEnabled(listSectionRecords.count());
317                 ui->lineEditMACHSegments->setEnabled(listSegmentRecords.count());
318                 ui->lineEditMACHLibraries->setEnabled(listLibraryRecords.count());
319 
320                 ui->lineEditMACHCommands->setValue((quint16)listCommandRecords.count());
321                 ui->lineEditMACHSections->setValue((quint16)listSectionRecords.count());
322                 ui->lineEditMACHSegments->setValue((quint16)listSegmentRecords.count());
323                 ui->lineEditMACHLibraries->setValue((quint16)listLibraryRecords.count());
324             }
325         }
326 
327         file.close();
328 
329         scan();
330     }
331     else
332     {
333         // TODO Error message
334     }
335 }
336 
scan()337 void FormatsWidget::scan()
338 {
339     int nIndex=ui->comboBoxScanEngine->currentIndex();
340 
341     nIndex=getScanEngine((SE)nIndex);
342 
343     adjustScanTab((SE)nIndex);
344 
345     if(g_sFileName!="")
346     {
347         if(nIndex==SE_DIE)
348         {
349             ui->pageScanDIE->setData(g_sFileName,g_bScan,getCurrentFileType());
350         }
351         else if(nIndex==SE_NFD)
352         {
353             ui->pageScanNFD->setData(g_sFileName,g_bScan,getCurrentFileType());
354         }
355     }
356 
357     // TODO YARA
358 }
359 
on_pushButtonDisasm_clicked()360 void FormatsWidget::on_pushButtonDisasm_clicked()
361 {
362     if(g_sFileName!="")
363     {
364         QFile file;
365         file.setFileName(g_sFileName);
366 
367         if(file.open(QIODevice::ReadOnly))
368         {
369             DialogMultiDisasm dialogDisasm(this); // TODO File_Type
370 
371             XMultiDisasmWidget::OPTIONS options={};
372             options.fileType=getCurrentFileType();
373             options.nInitAddress=ui->lineEditEntryPoint->getValue();
374             options.sSignaturesPath=g_options.sSearchSignaturesPath;
375 
376             dialogDisasm.setData(&file,options);
377             dialogDisasm.setShortcuts(getShortcuts());
378 
379             dialogDisasm.exec();
380 
381             file.close();
382         }
383     }
384 }
385 
on_pushButtonHexEntryPoint_clicked()386 void FormatsWidget::on_pushButtonHexEntryPoint_clicked()
387 {
388     if(g_sFileName!="")
389     {
390         QFile file;
391         file.setFileName(g_sFileName);
392 
393         if(XBinary::tryToOpen(&file))
394         {
395             XHexView::OPTIONS hexOptions={};
396     //        hexOptions.sBackupFileName=XBinary::getBackupName(&file);
397             hexOptions.nStartSelectionOffset=XFormats::getEntryPointOffset(getCurrentFileType(),&file);
398 
399             DialogHexView dialogHex(this,&file,hexOptions);
400             dialogHex.setShortcuts(getShortcuts());
401 
402             dialogHex.exec();
403 
404             file.close();
405         }
406     }
407 
408 }
409 
on_pushButtonMemoryMap_clicked()410 void FormatsWidget::on_pushButtonMemoryMap_clicked()
411 {
412     if(g_sFileName!="")
413     {
414         QFile file;
415         file.setFileName(g_sFileName);
416 
417         if(file.open(QIODevice::ReadOnly))
418         {
419             DialogMemoryMap dialogMemoryMap(this,&file,getCurrentFileType(),g_options.sSearchSignaturesPath);
420             dialogMemoryMap.setShortcuts(getShortcuts());
421 
422             dialogMemoryMap.exec();
423 
424             file.close();
425         }
426     }
427 }
428 
on_pushButtonPEExport_clicked()429 void FormatsWidget::on_pushButtonPEExport_clicked()
430 {
431     showPE(SPE::TYPE_EXPORT);
432 }
433 
on_pushButtonPEImport_clicked()434 void FormatsWidget::on_pushButtonPEImport_clicked()
435 {
436     showPE(SPE::TYPE_IMPORT);
437 }
438 
on_pushButtonPEResources_clicked()439 void FormatsWidget::on_pushButtonPEResources_clicked()
440 {
441     showPE(SPE::TYPE_RESOURCES);
442 }
443 
on_pushButtonPEOverlay_clicked()444 void FormatsWidget::on_pushButtonPEOverlay_clicked()
445 {
446     showPE(SPE::TYPE_OVERLAY);
447 }
448 
on_pushButtonPE_clicked()449 void FormatsWidget::on_pushButtonPE_clicked()
450 {
451     showPE(SPE::TYPE_IMAGE_FILE_HEADER);
452 }
453 
on_pushButtonPESections_clicked()454 void FormatsWidget::on_pushButtonPESections_clicked()
455 {
456     showPE(SPE::TYPE_SECTIONS);
457 }
458 
on_pushButtonPEManifest_clicked()459 void FormatsWidget::on_pushButtonPEManifest_clicked()
460 {
461     showPE(SPE::TYPE_RESOURCE_MANIFEST);
462 }
463 
on_pushButtonPEVersion_clicked()464 void FormatsWidget::on_pushButtonPEVersion_clicked()
465 {
466     showPE(SPE::TYPE_RESOURCE_VERSION);
467 }
468 
on_pushButtonPENET_clicked()469 void FormatsWidget::on_pushButtonPENET_clicked()
470 {
471     showPE(SPE::TYPE_NETHEADER);
472 }
473 
on_pushButtonMACH_clicked()474 void FormatsWidget::on_pushButtonMACH_clicked()
475 {
476     showMACH(SMACH::TYPE_mach_header);
477 }
478 
on_pushButtonMACHSegments_clicked()479 void FormatsWidget::on_pushButtonMACHSegments_clicked()
480 {
481     showMACH(SMACH::TYPE_mach_segments);
482 }
483 
on_pushButtonMACHSections_clicked()484 void FormatsWidget::on_pushButtonMACHSections_clicked()
485 {
486     showMACH(SMACH::TYPE_mach_sections);
487 }
488 
on_pushButtonMACHCommands_clicked()489 void FormatsWidget::on_pushButtonMACHCommands_clicked()
490 {
491     showMACH(SMACH::TYPE_mach_commands);
492 }
493 
on_pushButtonMACHLibraries_clicked()494 void FormatsWidget::on_pushButtonMACHLibraries_clicked()
495 {
496     showMACH(SMACH::TYPE_mach_libraries);
497 }
498 
showMSDOS(SMSDOS::TYPE type)499 void FormatsWidget::showMSDOS(SMSDOS::TYPE type)
500 {
501     QFile file;
502     file.setFileName(g_sFileName);
503 
504     if(XBinary::tryToOpen(&file))
505     {
506         FW_DEF::OPTIONS options={};
507 
508         options.bSaveBackup=options.bSaveBackup;
509         options.nStartType=type;
510         options.sSearchSignaturesPath=g_options.sSearchSignaturesPath;
511 
512         DialogMSDOS dialogMSDOS(this);
513 
514         dialogMSDOS.setData(&file,options);
515         dialogMSDOS.setShortcuts(getShortcuts());
516 
517         dialogMSDOS.exec();
518 
519         file.close();
520     }
521 }
522 
showLE(SLE::TYPE type)523 void FormatsWidget::showLE(SLE::TYPE type)
524 {
525     QFile file;
526     file.setFileName(g_sFileName);
527 
528     if(XBinary::tryToOpen(&file))
529     {
530         FW_DEF::OPTIONS options={};
531 
532         options.bSaveBackup=options.bSaveBackup;
533         options.nStartType=type;
534         options.sSearchSignaturesPath=g_options.sSearchSignaturesPath;
535 
536         DialogLE dialogLE(this);
537 
538         dialogLE.setData(&file,options);
539         dialogLE.setShortcuts(getShortcuts());
540 
541         dialogLE.exec();
542 
543         file.close();
544     }
545 }
546 
showNE(SNE::TYPE type)547 void FormatsWidget::showNE(SNE::TYPE type)
548 {
549     QFile file;
550     file.setFileName(g_sFileName);
551 
552     if(XBinary::tryToOpen(&file))
553     {
554         FW_DEF::OPTIONS options={};
555 
556         options.bSaveBackup=options.bSaveBackup;
557         options.nStartType=type;
558         options.sSearchSignaturesPath=g_options.sSearchSignaturesPath;
559 
560         DialogNE dialogNE(this);
561 
562         dialogNE.setData(&file,options);
563         dialogNE.setShortcuts(getShortcuts());
564 
565         dialogNE.exec();
566 
567         file.close();
568     }
569 }
570 
showPE(SPE::TYPE type)571 void FormatsWidget::showPE(SPE::TYPE type)
572 {
573     QFile file;
574     file.setFileName(g_sFileName);
575 
576     if(XBinary::tryToOpen(&file))
577     {
578         FW_DEF::OPTIONS options={};
579 
580         options.bSaveBackup=options.bSaveBackup;
581         options.nStartType=type;
582         options.sSearchSignaturesPath=g_options.sSearchSignaturesPath;
583 
584         DialogPE dialogPE(this);
585 
586         dialogPE.setData(&file,options);
587         dialogPE.setShortcuts(getShortcuts());
588 
589         dialogPE.exec();
590 
591         file.close();
592     }
593 }
594 
showELF(SELF::TYPE type)595 void FormatsWidget::showELF(SELF::TYPE type)
596 {
597     QFile file;
598     file.setFileName(g_sFileName);
599 
600     if(XBinary::tryToOpen(&file))
601     {
602         FW_DEF::OPTIONS options={};
603 
604         options.bSaveBackup=options.bSaveBackup;
605         options.nStartType=type;
606         options.sSearchSignaturesPath=g_options.sSearchSignaturesPath;
607 
608         DialogELF dialogELF(this);
609 
610         dialogELF.setData(&file,options);
611         dialogELF.setShortcuts(getShortcuts());
612 
613         dialogELF.exec();
614 
615         file.close();
616     }
617 }
618 
showMACH(SMACH::TYPE type)619 void FormatsWidget::showMACH(SMACH::TYPE type)
620 {
621     QFile file;
622     file.setFileName(g_sFileName);
623 
624     if(XBinary::tryToOpen(&file))
625     {
626         FW_DEF::OPTIONS options={};
627 
628         options.bSaveBackup=options.bSaveBackup;
629         options.nStartType=type;
630         options.sSearchSignaturesPath=g_options.sSearchSignaturesPath;
631 
632         DialogMACH dialogMACH(this);
633 
634         dialogMACH.setData(&file,options);
635         dialogMACH.setShortcuts(getShortcuts());
636 
637         dialogMACH.exec();
638 
639         file.close();
640     }
641 }
642 
showDEX(SDEX::TYPE type)643 void FormatsWidget::showDEX(SDEX::TYPE type)
644 {
645     QFile file;
646     file.setFileName(g_sFileName);
647 
648     if(XBinary::tryToOpen(&file))
649     {
650         FW_DEF::OPTIONS options={};
651 
652         options.bSaveBackup=options.bSaveBackup;
653         options.nStartType=type;
654         options.sSearchSignaturesPath=g_options.sSearchSignaturesPath;
655 
656         DialogDEX dialogDEX(this);
657 
658         dialogDEX.setData(&file,options);
659         dialogDEX.setShortcuts(getShortcuts());
660 
661         dialogDEX.exec();
662 
663         file.close();
664     }
665 }
666 
getCurrentFileType()667 XBinary::FT FormatsWidget::getCurrentFileType()
668 {
669     XBinary::FT fileType=(XBinary::FT)(ui->comboBoxFileType->currentData().toInt());
670 
671     return fileType;
672 }
673 
on_pushButtonMSDOSOverlay_clicked()674 void FormatsWidget::on_pushButtonMSDOSOverlay_clicked()
675 {
676     showMSDOS(SMSDOS::TYPE_OVERLAY);
677 }
678 
on_pushButtonMSDOS_clicked()679 void FormatsWidget::on_pushButtonMSDOS_clicked()
680 {
681     showMSDOS(SMSDOS::TYPE_DOS_HEADER);
682 }
683 
on_pushButtonPETLS_clicked()684 void FormatsWidget::on_pushButtonPETLS_clicked()
685 {
686     showPE(SPE::TYPE_TLS);
687 }
688 
on_pushButtonELF_clicked()689 void FormatsWidget::on_pushButtonELF_clicked()
690 {
691     showELF(SELF::TYPE_Elf_Ehdr);
692 }
693 
on_pushButtonELFSections_clicked()694 void FormatsWidget::on_pushButtonELFSections_clicked()
695 {
696     showELF(SELF::TYPE_Elf_Shdr);
697 }
698 
on_pushButtonELFPrograms_clicked()699 void FormatsWidget::on_pushButtonELFPrograms_clicked()
700 {
701     showELF(SELF::TYPE_Elf_Phdr);
702 }
703 
on_comboBoxScanEngine_currentIndexChanged(int nIndex)704 void FormatsWidget::on_comboBoxScanEngine_currentIndexChanged(int nIndex)
705 {
706     adjustScanTab(getScanEngine((SE)nIndex));
707 
708     scan();
709 }
710 
on_pushButtonLE_clicked()711 void FormatsWidget::on_pushButtonLE_clicked()
712 {
713     showLE(SLE::TYPE_VXD_HEADER);
714 }
715 
on_pushButtonNE_clicked()716 void FormatsWidget::on_pushButtonNE_clicked()
717 {
718     showNE(SNE::TYPE_OS2_HEADER);
719 }
720 
on_pushButtonDEX_clicked()721 void FormatsWidget::on_pushButtonDEX_clicked()
722 {
723     showDEX(SDEX::TYPE_HEADER);
724 }
725 
on_pushButtonZIP_clicked()726 void FormatsWidget::on_pushButtonZIP_clicked()
727 {
728     DialogArchive dialogArchive(this);
729 
730     FW_DEF::OPTIONS options={};
731 
732     options.bSaveBackup=options.bSaveBackup;;
733 
734     dialogArchive.setFileName(g_sFileName,options,QSet<XBinary::FT>());
735     dialogArchive.setShortcuts(getShortcuts());
736 
737     dialogArchive.exec();
738 }
739 
getScanEngine(FormatsWidget::SE seIndex)740 FormatsWidget::SE FormatsWidget::getScanEngine(FormatsWidget::SE seIndex)
741 {
742     SE tabResult=seIndex;
743 
744     if(seIndex==SE_AUTO)
745     {
746         tabResult=SE_DIE;
747 
748         XBinary::FT fileType=getCurrentFileType();
749 
750         if( (fileType==XBinary::FT_DEX)||
751             (fileType==XBinary::FT_ELF32)||
752             (fileType==XBinary::FT_ELF64)||
753             (fileType==XBinary::FT_MACHO32)||
754             (fileType==XBinary::FT_MACHO64)||
755             (fileType==XBinary::FT_ZIP))
756         {
757             tabResult=SE_NFD;
758         }
759     }
760 
761     return tabResult;
762 }
763 
adjustScanTab(FormatsWidget::SE seIndex)764 void FormatsWidget::adjustScanTab(FormatsWidget::SE seIndex)
765 {
766     if(seIndex==SE_DIE)
767     {
768         ui->stackedWidgetScan->setCurrentIndex(0);
769     }
770     else if(seIndex==SE_NFD)
771     {
772         ui->stackedWidgetScan->setCurrentIndex(1);
773     }
774 }
775 
onScanStarted()776 void FormatsWidget::onScanStarted()
777 {
778     ui->stackedWidgetMain->setEnabled(false);
779     ui->groupBoxFileType->setEnabled(false);
780     ui->groupBoxScanEngine->setEnabled(false);
781     ui->groupBoxEntryPoint->setEnabled(false);
782 }
783 
onScanFinished()784 void FormatsWidget::onScanFinished()
785 {
786     ui->stackedWidgetMain->setEnabled(true);
787     ui->groupBoxFileType->setEnabled(true);
788     ui->groupBoxScanEngine->setEnabled(true);
789     ui->groupBoxEntryPoint->setEnabled(true);
790 }
791 
registerShortcuts(bool bState)792 void FormatsWidget::registerShortcuts(bool bState)
793 {
794     Q_UNUSED(bState)
795 }
796