iw8 compiler encrypted strings support
This commit is contained in:
parent
06a30ddd99
commit
b52ce98b6d
@ -147,7 +147,7 @@ void assembler::assemble_function(const function::ptr& func)
|
||||
|
||||
if (func->id == 0)
|
||||
{
|
||||
stack_->write_c_string(func->name);
|
||||
stack_->write_c_string(encrypt_string(func->name));
|
||||
}
|
||||
|
||||
for (const auto& inst : func->instructions)
|
||||
@ -272,19 +272,19 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
|
||||
case opcode::OP_GetIString:
|
||||
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
|
||||
script_->write<std::uint32_t>(0);
|
||||
stack_->write_c_string(inst->data[0]);
|
||||
stack_->write_c_string(encrypt_string(inst->data[0]));
|
||||
break;
|
||||
case opcode::OP_GetAnimation:
|
||||
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
|
||||
script_->write<std::uint32_t>(0);
|
||||
script_->write<std::uint32_t>(0);
|
||||
stack_->write_c_string(inst->data[0]);
|
||||
stack_->write_c_string(inst->data[1]);
|
||||
stack_->write_c_string(encrypt_string(inst->data[0]));
|
||||
stack_->write_c_string(encrypt_string(inst->data[1]));
|
||||
break;
|
||||
case opcode::OP_GetAnimTree:
|
||||
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
|
||||
script_->write<std::uint8_t>(0);
|
||||
stack_->write_c_string(inst->data[0]);
|
||||
stack_->write_c_string(encrypt_string(inst->data[0]));
|
||||
break;
|
||||
case opcode::OP_waittillmatch:
|
||||
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
|
||||
@ -487,9 +487,9 @@ void assembler::assemble_far_call(const instruction::ptr& inst, bool thread)
|
||||
const auto func_id = resolver::token_id(inst->data[1]);
|
||||
|
||||
stack_->write<std::uint32_t>(file_id);
|
||||
if (file_id == 0) stack_->write_c_string(inst->data[0]);
|
||||
if (file_id == 0) stack_->write_c_string(encrypt_string(inst->data[0]));
|
||||
stack_->write<std::uint32_t>(func_id);
|
||||
if (func_id == 0) stack_->write_c_string(inst->data[1]);
|
||||
if (func_id == 0) stack_->write_c_string(encrypt_string(inst->data[1]));
|
||||
}
|
||||
|
||||
void assembler::assemble_switch(const instruction::ptr& inst)
|
||||
@ -522,7 +522,7 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
|
||||
else
|
||||
{
|
||||
script_->write<uint32_t>(i + 1);
|
||||
stack_->write_c_string(inst->data[1 + (3 * i) + 1]);
|
||||
stack_->write_c_string(encrypt_string(inst->data[1 + (3 * i) + 1]));
|
||||
}
|
||||
|
||||
index += 4;
|
||||
@ -566,7 +566,7 @@ void assembler::assemble_field_variable(const instruction::ptr& inst)
|
||||
if (id > max_string_id)
|
||||
{
|
||||
stack_->write<std::uint32_t>(0);
|
||||
stack_->write_c_string(inst->data[0]);
|
||||
stack_->write_c_string(encrypt_string(inst->data[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -643,4 +643,21 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
|
||||
throw asm_error("couldn't resolve label address of '" + name + "'!");
|
||||
}
|
||||
|
||||
auto assembler::encrypt_string(const std::string& str) -> std::string
|
||||
{
|
||||
if (str.starts_with("_encstr_") && str.size() % 2 == 0)
|
||||
{
|
||||
std::string data{};
|
||||
|
||||
for (auto i = 8u; i < str.size(); i += 2)
|
||||
{
|
||||
data += static_cast<char>(std::stoul(str.substr(i, 2), 0, 16));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
} // namespace xsk::gsc::iw8
|
||||
|
@ -36,6 +36,7 @@ private:
|
||||
void assemble_offset(std::int32_t offset);
|
||||
auto resolve_function(const std::string& name) -> std::int32_t;
|
||||
auto resolve_label(const std::string& name) -> std::int32_t;
|
||||
auto encrypt_string(const std::string& str) -> std::string;
|
||||
};
|
||||
|
||||
} // namespace xsk::gsc::iw8
|
||||
|
@ -51,7 +51,7 @@ void disassembler::disassemble(const std::string& file, std::vector<std::uint8_t
|
||||
func->index = static_cast<std::uint32_t>(script_->pos());
|
||||
func->size = stack_->read<std::uint32_t>();
|
||||
func->id = stack_->read<std::uint32_t>();
|
||||
func->name = func->id == 0 ? patch_enc_string(stack_->read_c_string()) : resolver::token_name(func->id);
|
||||
func->name = func->id == 0 ? decrypt_string(stack_->read_c_string()) : resolver::token_name(func->id);
|
||||
|
||||
dissasemble_function(func);
|
||||
|
||||
@ -190,16 +190,16 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
|
||||
case opcode::OP_GetString:
|
||||
case opcode::OP_GetIString:
|
||||
script_->seek(4);
|
||||
inst->data.push_back(utils::string::to_literal(patch_enc_string(stack_->read_c_string())));
|
||||
inst->data.push_back(utils::string::to_literal(decrypt_string(stack_->read_c_string())));
|
||||
break;
|
||||
case opcode::OP_GetAnimation:
|
||||
script_->seek(8);
|
||||
inst->data.push_back(utils::string::quote(patch_enc_string(stack_->read_c_string()), false));
|
||||
inst->data.push_back(utils::string::quote(patch_enc_string(stack_->read_c_string()), false));
|
||||
inst->data.push_back(utils::string::quote(decrypt_string(stack_->read_c_string()), false));
|
||||
inst->data.push_back(utils::string::quote(decrypt_string(stack_->read_c_string()), false));
|
||||
break;
|
||||
case opcode::OP_GetAnimTree:
|
||||
script_->seek(1);
|
||||
inst->data.push_back(utils::string::quote(patch_enc_string(stack_->read_c_string()), false));
|
||||
inst->data.push_back(utils::string::quote(decrypt_string(stack_->read_c_string()), false));
|
||||
break;
|
||||
case opcode::OP_waittillmatch:
|
||||
inst->data.push_back(utils::string::va("%i", script_->read<std::uint8_t>()));
|
||||
@ -387,9 +387,9 @@ void disassembler::disassemble_far_call(const instruction::ptr& inst, bool threa
|
||||
}
|
||||
|
||||
const auto file_id = stack_->read<std::uint32_t>();
|
||||
const auto file_name = file_id == 0 ? patch_enc_string(stack_->read_c_string()) : resolver::file_name(file_id);
|
||||
const auto file_name = file_id == 0 ? decrypt_string(stack_->read_c_string()) : resolver::file_name(file_id);
|
||||
const auto func_id = stack_->read<std::uint32_t>();
|
||||
const auto func_name = func_id == 0 ? patch_enc_string(stack_->read_c_string()) : resolver::token_name(func_id);
|
||||
const auto func_name = func_id == 0 ? decrypt_string(stack_->read_c_string()) : resolver::token_name(func_id);
|
||||
|
||||
inst->data.emplace(inst->data.begin(), func_name);
|
||||
inst->data.emplace(inst->data.begin(), file_name);
|
||||
@ -420,7 +420,7 @@ void disassembler::disassemble_end_switch(const instruction::ptr& inst)
|
||||
if (value < 0x100000 && value > 0)
|
||||
{
|
||||
inst->data.push_back("case");
|
||||
inst->data.push_back(utils::string::quote(patch_enc_string(stack_->read_c_string()), false));
|
||||
inst->data.push_back(utils::string::quote(decrypt_string(stack_->read_c_string()), false));
|
||||
}
|
||||
else if (value == 0)
|
||||
{
|
||||
@ -455,7 +455,7 @@ void disassembler::disassemble_field_variable(const instruction::ptr& inst)
|
||||
if (id > max_string_id)
|
||||
{
|
||||
auto temp = stack_->read<std::uint32_t>();
|
||||
name = temp == 0 ? patch_enc_string(stack_->read_c_string()) : std::to_string(temp);
|
||||
name = temp == 0 ? decrypt_string(stack_->read_c_string()) : std::to_string(temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -562,7 +562,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
|
||||
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));
|
||||
}
|
||||
|
||||
auto disassembler::patch_enc_string(const std::string& str) -> std::string
|
||||
auto disassembler::decrypt_string(const std::string& str) -> std::string
|
||||
{
|
||||
if (str.size() > 0 && ((static_cast<std::uint8_t>(str[0]) & 0xC0) == 0x80))
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
auto disassemble_offset() -> std::int32_t;
|
||||
void resolve_local_functions();
|
||||
auto resolve_function(const std::string& index) -> std::string;
|
||||
auto patch_enc_string(const std::string& str) -> std::string;
|
||||
auto decrypt_string(const std::string& str) -> std::string;
|
||||
void print_function(const function::ptr& func);
|
||||
void print_instruction(const instruction::ptr& inst);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user