Remove some exceptions in Mach-O and ELF utils

This commit is contained in:
Romain Thomas 2018-07-23 14:59:07 +02:00
parent 4cb7ba46c7
commit 6b2ac0cc2a
2 changed files with 14 additions and 6 deletions

View File

@ -20,6 +20,7 @@
#include <vector>
#include "LIEF/exception.hpp"
#include "LIEF/logging++.hpp"
#include "LIEF/ELF/utils.hpp"
#include "LIEF/ELF/Structures.hpp"
@ -30,7 +31,8 @@ namespace ELF {
bool is_elf(const std::string& file) {
std::ifstream binary(file, std::ios::in | std::ios::binary);
if (not binary) {
throw bad_file("Unable to open the file");
LOG(ERROR) << "Unable to open the file";
return false;
}
char magic[sizeof(ElfMagic)];

View File

@ -17,6 +17,7 @@
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/exception.hpp"
#include "LIEF/logging++.hpp"
#include <fstream>
#include <iterator>
@ -30,7 +31,8 @@ namespace MachO {
bool is_macho(const std::string& file) {
std::ifstream binary(file, std::ios::in | std::ios::binary);
if (not binary) {
throw LIEF::bad_file("Unable to open the '" + file + "'");
LOG(ERROR) << "Unable to open the '" << file << "'";
return false;
}
MACHO_TYPES magic;
@ -76,13 +78,15 @@ bool is_macho(const std::vector<uint8_t>& raw) {
bool is_fat(const std::string& file) {
if (not is_macho(file)) {
throw LIEF::bad_format("'" + file + "' is not a MachO");
LOG(ERROR) << "'" << file << "' is not a MachO";
return false;
}
std::ifstream binary(file, std::ios::in | std::ios::binary);
if (not binary) {
throw LIEF::bad_file("Unable to open the '" + file + "'");
LOG(ERROR) << "Unable to open the '" << file << "'";
return false;
}
MACHO_TYPES magic;
@ -100,13 +104,15 @@ bool is_fat(const std::string& file) {
bool is_64(const std::string& file) {
if (not is_macho(file)) {
throw LIEF::bad_format("'" + file + "' is not a MachO");
LOG(ERROR) << "'" << file << "' is not a MachO";
return false;
}
std::ifstream binary(file, std::ios::in | std::ios::binary);
if (not binary) {
throw LIEF::bad_file("Unable to open the '" + file + "'");
LOG(ERROR) << "Unable to open the '" << file << "'";
return false;
}
MACHO_TYPES magic;