support old compiler shenanigans

This commit is contained in:
xensik 2022-05-24 20:08:54 +02:00
parent 628749631b
commit 0da3653f26
2 changed files with 21 additions and 4 deletions

View File

@ -263,8 +263,16 @@ void decompiler::decompile_instruction(const instruction::ptr& inst, bool last)
break; break;
case opcode::OP_EvalLocalVariableCached: case opcode::OP_EvalLocalVariableCached:
{ {
auto node = std::make_unique<ast::expr_identifier>(loc, locals_.at(std::stoi(inst->data[0]))); try
stack_.push(std::move(node)); {
auto node = std::make_unique<ast::expr_identifier>(loc, locals_.at(std::stoi(inst->data[0])));
stack_.push(std::move(node));
}
catch(const std::exception& e)
{
auto node = std::make_unique<ast::expr_identifier>(loc, "broken_code!!");
stack_.push(std::move(node));
}
} }
break; break;
case opcode::OP_EvalArray: case opcode::OP_EvalArray:
@ -1624,7 +1632,7 @@ void decompiler::decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t
block blk; block blk;
blk.loc_break = last_location_index(stmt, end) ? blocks_.back().loc_end : stmt->list.at(end + 1).loc().label(); blk.loc_break = last_location_index(stmt, end) ? blocks_.back().loc_end : stmt->list.at(end + 1).loc().label();
blk.loc_end = stmt->list.at(end).loc().label(); blk.loc_end = stmt->list.at(end).loc().label();
blk.loc_continue = stmt->list.at(end).loc().label(); blk.loc_continue = stmt->list.at(begin).loc().label();
auto loc = stmt->list.at(begin).loc(); auto loc = stmt->list.at(begin).loc();

View File

@ -81,6 +81,8 @@ void disassembler::disassemble(const std::string& file, std::vector<std::uint8_t
// string list // string list
script_->pos(64); script_->pos(64);
stringlist_.insert({ 0x3E, "" }); // old compiler null string points to header flags
while (script_->pos() < header_.include_offset) while (script_->pos() < header_.include_offset)
{ {
auto pos = script_->pos(); auto pos = script_->pos();
@ -212,7 +214,14 @@ void disassembler::disassemble(const std::string& file, std::vector<std::uint8_t
} }
else else
{ {
entry->size = (header_.cseg_offset + header_.cseg_size) - entry->offset; if (header_.cseg_size == 0) // old compiler fucked!
{
entry->size = (header_.exports_offset) - entry->offset;
}
else
{
entry->size = (header_.cseg_offset + header_.cseg_size) - entry->offset;
}
} }
script_->pos(entry->offset); script_->pos(entry->offset);