Skip to content

Commit

Permalink
Merge pull request #75 from binarly-io/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
yeggor authored Dec 12, 2022
2 parents d7e0648 + 9fb25ed commit 5d3753c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
46 changes: 26 additions & 20 deletions efiXplorer/efiUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,37 @@ void setTypeAndName(ea_t ea, std::string name, std::string type) {
}
}

//--------------------------------------------------------------------------
// Get file format name (fileformatname)
std::string getFileFormatName() {
char file_format[256] = {0};
get_file_type_name(file_format, 256);
return static_cast<std::string>(file_format);
}

//--------------------------------------------------------------------------
// Get input file type (64-bit, 32-bit image or UEFI firmware)
uint8_t getInputFileType() {
char fileType[256] = {};
get_file_type_name(fileType, 256);
auto fileTypeStr = static_cast<std::string>(fileType);
size_t index = fileTypeStr.find("AMD64");
if (index != std::string::npos) {
// Portable executable for AMD64 (PE)
return X64;
}
index = fileTypeStr.find("80386");
if (index != std::string::npos) {
// Portable executable for 80386 (PE)
return X86;
}
index = fileTypeStr.find("UEFI");
if (index != std::string::npos) {
// UEFI firmware
processor_t &ph = PH;
auto filetype = (filetype_t)inf.filetype;
auto bits = inf_is_64bit() ? 64 : inf_is_32bit_exactly() ? 32 : 16;

// check if input file is UEFI firmware image
if (getFileFormatName().find("UEFI") != std::string::npos) {
return UEFI;
}
index = fileTypeStr.find("ARM64");
if (index != std::string::npos) {
// Portable executable for ARM64 (PE)
return ARM64;

if (filetype == f_PE || filetype == f_ELF) {
if (ph.id == PLFM_386) {
if (bits == 64) // x86 64-bit executable
return X64;
if (bits == 32) // x86 32-bit executable
return X86;
}
if (ph.id == PLFM_ARM) {
if (bits == 64) // ARM 64-bit executable
return AARCH64;
}
}
return UNSUPPORTED_TYPE;
}
Expand Down
8 changes: 4 additions & 4 deletions efiXplorer/efiXplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ bool idaapi run(size_t arg) {

uint8_t arch = getInputFileType();
if (arch == X64) {
msg("[%s] input file is portable executable for AMD64 (PE)\n", plugin_name);
msg("[%s] input file is 64-bit module (x86)\n", plugin_name);
EfiAnalysis::efiAnalyzerMainX64();
} else if (arch == X86) {
msg("[%s] input file is portable executable for 80386 (PE)\n", plugin_name);
msg("[%s] input file is 32-bit module (x86)\n", plugin_name);
EfiAnalysis::efiAnalyzerMainX86();
} else if (arch == UEFI) {
msg("[%s] input file is UEFI firmware\n", plugin_name);
warning("%s: analysis may take some time, please wait for it to complete\n",
plugin_name);
msg("[%s] input file is UEFI firmware\n", plugin_name);
if (get_machine_type() == AARCH64) {
msg("[%s] analyze AARCH64 modules\n", plugin_name);
EfiAnalysis::efiAnalyzerMainArm();
Expand All @@ -117,7 +117,7 @@ bool idaapi run(size_t arg) {
EfiAnalysis::efiAnalyzerMainX64();
}
} else if (arch == ARM64) {
msg("[%s] input file is portable executable for ARM64 (PE)\n", plugin_name);
msg("[%s] input file is 64-bit module (ARM)\n", plugin_name);
EfiAnalysis::efiAnalyzerMainArm();
}

Expand Down
2 changes: 1 addition & 1 deletion efiXplorer/efiXplorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@

#include "efiUtils.h"

#define COPYRIGHT "(c) 2020-2021, Binarly - https://github.com/binarly-io/efiXplorer"
#define COPYRIGHT "(c) 2020-2022, Binarly - https://github.com/binarly-io/efiXplorer"

0 comments on commit 5d3753c

Please sign in to comment.