Skip to content

Commit

Permalink
disasm: Allow LE/LX without MZ header
Browse files Browse the repository at this point in the history
  • Loading branch information
mefistotelis committed Jan 10, 2024
1 parent ed9c2a3 commit 1a24de4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
33 changes: 30 additions & 3 deletions src/le.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class LinearExecutable::Loader
vector<uint32_t> fixup_record_offsets;

protected:
bool load_le_header_offset(void);
bool load_header (void);
bool load_object_table (void);
bool load_object_header (ObjectHeader *hdr);
Expand Down Expand Up @@ -154,7 +155,7 @@ LinearExecutable::Loader::load (istream *is, const std::string &name)
}

bool
LinearExecutable::Loader::load_header (void)
LinearExecutable::Loader::load_le_header_offset(void)
{
char id[2];
uint8_t byte;
Expand All @@ -166,6 +167,13 @@ LinearExecutable::Loader::load_header (void)
if (!is->good ())
return false;

// LE/LX header without MZ stub at start
if ((string (id, 2) == "LE") || (string (id, 2) == "LX"))
{
this->header_offset = 0;
return true;
}

if (string (id, 2) != "MZ")
{
cerr << "Invalid MZ signature\n";
Expand All @@ -186,6 +194,25 @@ LinearExecutable::Loader::load_header (void)
if (!read_le (is, &this->header_offset))
return false;

return true;
}

bool
LinearExecutable::Loader::load_header (void)
{
char id[2];
uint8_t byte;
istream *is = this->is;
LinearExecutable *le = this->le;

is->seekg (0);
is->read (id, 2);
if (!is->good ())
return false;

if (!this->load_le_header_offset())
return false;

#ifdef ENABLE_DEBUG
print_variable (&cerr, 40, "header_offset", this->header_offset);
cerr << "\n";
Expand All @@ -196,9 +223,9 @@ LinearExecutable::Loader::load_header (void)
if (!is->good ())
return false;

if (string (id, 2) != "LE")
if ((string (id, 2) != "LE") && (string (id, 2) != "LX"))
{
cerr << "Invalid LE signature\n";
cerr << "Invalid LE signature at offset 0x" << std::hex << this->header_offset << std::endl;
return false;
}

Expand Down
34 changes: 20 additions & 14 deletions src/le_disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,27 +579,33 @@ main (int argc, char **argv)
return 1;
}

ifs.open (argv[1], std::ios::binary);
if(!ifs.is_open())
{
std::cerr << "Error opening file: " << argv[1];
return 1;
}
try {

ifs.open (argv[1], std::ios::binary);
if(!ifs.is_open())
{
std::cerr << "Error opening file: " << argv[1];
return 1;
}

le = LinearExecutable::load (&ifs, argv[1]);

le = LinearExecutable::load (&ifs, argv[1]);
image = create_image (&ifs, le);

image = create_image (&ifs, le);
anal = Analyser (le, image);

anal = Analyser (le, image);
KnownFile::check(anal, le);
KnownFile::pre_anal_fixups_apply(anal);

KnownFile::check(anal, le);
KnownFile::pre_anal_fixups_apply(anal);
anal.run ();

anal.run ();
KnownFile::post_anal_fixups_apply(anal);

KnownFile::post_anal_fixups_apply(anal);
print_code (le, image, &anal);

print_code (le, image, &anal);
} catch (const std::exception &e) {
std::cerr << std::dec << e.what() << std::endl;
}

delete image;
delete le;
Expand Down

0 comments on commit 1a24de4

Please sign in to comment.