Skip to content

Commit

Permalink
Make sure the pos does not change
Browse files Browse the repository at this point in the history
Resolve #1113
  • Loading branch information
romainthomas committed Oct 7, 2024
1 parent 0dc8895 commit 6cdc093
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/ELF/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace ELF {

bool is_elf(BinaryStream& stream) {
using magic_t = std::array<char, sizeof(details::ElfMagic)>;
stream.setpos(0);
if (auto res = stream.peek<magic_t>()) {
ScopedStream scoped(stream, 0);
if (auto res = scoped->peek<magic_t>()) {
const auto magic = *res;
return std::equal(std::begin(magic), std::end(magic),
std::begin(details::ElfMagic));
Expand Down
8 changes: 4 additions & 4 deletions src/PE/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ inline std::string to_lower(std::string str) {

bool is_pe(BinaryStream& stream) {
using signature_t = std::array<char, sizeof(details::PE_Magic)>;
stream.setpos(0);
if (auto dos_header = stream.read<details::pe_dos_header>()) {
ScopedStream scoped(stream, 0);
if (auto dos_header = scoped->read<details::pe_dos_header>()) {
if (dos_header->Magic != /* MZ */0x5a4d) {
return false;
}
stream.setpos(dos_header->AddressOfNewExeHeader);
if (auto res_sig = stream.read<signature_t>()) {
scoped->setpos(dos_header->AddressOfNewExeHeader);
if (auto res_sig = scoped->read<signature_t>()) {
const auto signature = *res_sig;
return std::equal(std::begin(signature), std::end(signature),
std::begin(details::PE_Magic));
Expand Down

0 comments on commit 6cdc093

Please sign in to comment.