iw9: opcode reversing

This commit is contained in:
xensik 2022-11-14 16:06:50 +01:00
parent 57ef733af4
commit 17a0b789c4
3 changed files with 177 additions and 177 deletions

View File

@ -83,12 +83,12 @@ void disassembler::dissasemble_function(const function::ptr& func)
void disassembler::dissasemble_instruction(const instruction::ptr& inst) void disassembler::dissasemble_instruction(const instruction::ptr& inst)
{ {
switch (static_cast<opcode>(inst->opcode)) /*switch (static_cast<opcode>(inst->opcode))
{ {
default: default:
throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }*/
} }
void disassembler::disassemble_builtin_call(const instruction::ptr& inst, bool method, bool args) void disassembler::disassemble_builtin_call(const instruction::ptr& inst, bool method, bool args)
@ -261,9 +261,9 @@ void disassembler::resolve_local_functions()
{ {
for (const auto& inst : func->instructions) for (const auto& inst : func->instructions)
{ {
switch (static_cast<opcode>(inst->opcode)) /*switch (static_cast<opcode>(inst->opcode))
{ {
/*case opcode::OP_GetLocalFunction: case opcode::OP_GetLocalFunction:
case opcode::OP_ScriptLocalFunctionCall: case opcode::OP_ScriptLocalFunctionCall:
case opcode::OP_ScriptLocalFunctionCall2: case opcode::OP_ScriptLocalFunctionCall2:
case opcode::OP_ScriptLocalMethodCall: case opcode::OP_ScriptLocalMethodCall:
@ -272,10 +272,10 @@ void disassembler::resolve_local_functions()
case opcode::OP_ScriptLocalMethodThreadCall: case opcode::OP_ScriptLocalMethodThreadCall:
case opcode::OP_ScriptLocalMethodChildThreadCall: case opcode::OP_ScriptLocalMethodChildThreadCall:
inst->data[0] = resolve_function(inst->data[0]); inst->data[0] = resolve_function(inst->data[0]);
break;*/ break;
default: default:
break; break;
} }*/
} }
} }
} }
@ -341,9 +341,9 @@ void disassembler::print_instruction(const instruction::ptr& inst)
{ {
output_->write_string(utils::string::va("\t\t%s", resolver::opcode_name(inst->opcode).data())); output_->write_string(utils::string::va("\t\t%s", resolver::opcode_name(inst->opcode).data()));
switch (static_cast<opcode>(inst->opcode)) /*switch (static_cast<opcode>(inst->opcode))
{ {
/*case opcode::OP_GetLocalFunction: case opcode::OP_GetLocalFunction:
case opcode::OP_ScriptLocalFunctionCall: case opcode::OP_ScriptLocalFunctionCall:
case opcode::OP_ScriptLocalFunctionCall2: case opcode::OP_ScriptLocalFunctionCall2:
case opcode::OP_ScriptLocalMethodCall: case opcode::OP_ScriptLocalMethodCall:
@ -378,14 +378,14 @@ void disassembler::print_instruction(const instruction::ptr& inst)
} }
} }
} }
break;*/ break;
default: default:*/
for (auto& data : inst->data) for (auto& data : inst->data)
{ {
output_->write_string(utils::string::va(" %s", data.data())); output_->write_string(utils::string::va(" %s", data.data()));
} }
break; // break;
} //}
output_->write_string("\n"); output_->write_string("\n");
} }

View File

@ -11,12 +11,12 @@ namespace xsk::gsc::iw9
auto opcode_size(std::uint8_t id) -> std::uint32_t auto opcode_size(std::uint8_t id) -> std::uint32_t
{ {
switch (static_cast<opcode>(id)) /*switch (static_cast<opcode>(id))
{ {
default: default:*/
throw error("couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} // }
} }
} // namespace xsk::gsc::iw9 } // namespace xsk::gsc::iw9

View File

@ -14,177 +14,177 @@
namespace xsk::gsc::iw9 namespace xsk::gsc::iw9
{ {
constexpr std::uint32_t max_string_id = 0x1472F; constexpr std::uint32_t max_string_id = 0;
enum class opcode : std::uint8_t enum class opcode : std::uint8_t
{ {
unk_000 = 0x00, unk_000 = 0x00, // size 1 OP_CastFieldObject
unk_001 = 0x01, unk_001 = 0x01, // size 2 OP_SetLocalVariableFieldCached
unk_002 = 0x02, unk_002 = 0x02, // size 1 OP_plus
unk_003 = 0x03, unk_003 = 0x03, // size 2 OP_RemoveLocalVariables
unk_004 = 0x04, unk_004 = 0x04, // size 9, script 8 (hash?) OP_EvalSelfFieldVariableRef
unk_005 = 0x05, unk_005 = 0x05, // size 6, stack 8 + 8 OP_ScriptFarMethodChildThreadCall
unk_006 = 0x06, unk_006 = 0x06, // size 1 OP_GetGameRef
unk_007 = 0x07, unk_007 = 0x07, // size 9, script 8 (hash?) OP_EvalAnimFieldVariable
unk_008 = 0x08, unk_008 = 0x08, // size 9, script 8 (hash?) OP_EvalLevelFieldVariableRef
unk_009 = 0x09, unk_009 = 0x09, // size 1 OP_GetThisthread
unk_010 = 0x0A, unk_010 = 0x0A, // size 1 OP_greater
unk_011 = 0x0B, unk_011 = 0x0B, // size 3 OP_waittillmatch
unk_012 = 0x0C, unk_012 = 0x0C, // size 1 OP_shift_right
unk_013 = 0x0D, unk_013 = 0x0D, // size 1 OP_dec
unk_014 = 0x0E, unk_014 = 0x0E, // size 3 OP_JumpOnTrue
unk_015 = 0x0F, unk_015 = 0x0F, // size 1 OP_bit_or
unk_016 = 0x10, unk_016 = 0x10, // size 1 OP_equality
unk_017 = 0x11, unk_017 = 0x11, // size 1 OP_ClearLocalVariableFieldCached0
unk_018 = 0x12, unk_018 = 0x12, // size 1 OP_notify
unk_019 = 0x13, unk_019 = 0x13, // size 13 OP_GetVector
unk_020 = 0x14, unk_020 = 0x14, // size 2 OP_ScriptMethodChildThreadCallPointer
unk_021 = 0x15, unk_021 = 0x15, // size 1 OP_PreScriptCall
unk_022 = 0x16, unk_022 = 0x16, // size 2 OP_GetByte
unk_023 = 0x17, unk_023 = 0x17, // size 6, stack 8 + 8 OP_ScriptFarThreadCall
unk_024 = 0x18, unk_024 = 0x18, // size 9, script 8 (hash?) OP_SetSelfFieldVariableField
unk_025 = 0x19, unk_025 = 0x19, // size 3 OP_JumpOnFalseExpr
unk_026 = 0x1A, unk_026 = 0x1A, // size 1 OP_GetUndefined
unk_027 = 0x1B, unk_027 = 0x1B, // size 3 OP_jumpback
unk_028 = 0x1C, unk_028 = 0x1C, // size 3 OP_JumpOnTrueExpr
unk_029 = 0x1D, unk_029 = 0x1D, // size 4, stack string OP_CallBuiltin
unk_030 = 0x1E, unk_030 = 0x1E, // size 1 OP_SetLocalVariableFieldCached0
unk_031 = 0x1F, unk_031 = 0x1F, // size 9, script 8 (hash?) OP_ClearFieldVariable
unk_032 = 0x20, unk_032 = 0x20, // size 1 OP_GetLevel
unk_033 = 0x21, unk_033 = 0x21, // size 1 OP_size
unk_034 = 0x22, unk_034 = 0x22, // size 2 OP_SafeSetWaittillVariableFieldCached
unk_035 = 0x23, unk_035 = 0x23, // size 1 OP_AddArray
unk_036 = 0x24, unk_036 = 0x24, // size 1 OP_endon
unk_037 = 0x25, unk_037 = 0x25, // size 9, script 8 (hash?) OP_EvalFieldVariable
unk_038 = 0x26, unk_038 = 0x26, // size 1 OP_shift_left
unk_039 = 0x27, unk_039 = 0x27, // size 1 OP_EvalLocalArrayRefCached0
unk_040 = 0x28, unk_040 = 0x28, // size 1 OP_Return
unk_041 = 0x29, unk_041 = 0x29, // size 9 OP_CreateLocalVariable
unk_042 = 0x2A, unk_042 = 0x2A, // size 1 OP_SafeSetVariableFieldCached0
unk_043 = 0x2B, unk_043 = 0x2B, // size 3, stack string OP_GetBuiltinFunction
unk_044 = 0x2C, unk_044 = 0x2C, // size 2 OP_CallBuiltinMethodPointer
unk_045 = 0x2D, unk_045 = 0x2D, // size 1 OP_GetSelfObject
unk_046 = 0x2E, unk_046 = 0x2E, // size 1 OP_GetGame
unk_047 = 0x2F, unk_047 = 0x2F, // size 9, script 8 (hash?) OP_SetLevelFieldVariableField
unk_048 = 0x30, unk_048 = 0x30, // size 1 OP_EvalArray
unk_049 = 0x31, unk_049 = 0x31, // size 1 OP_GetSelf
unk_050 = 0x32, unk_050 = 0x32, // size 1 OP_End
unk_051 = 0x33, unk_051 = 0x33, // size 9, script 8 (hash?) OP_EvalSelfFieldVariable
unk_052 = 0x34, unk_052 = 0x34, // size 1 OP_less_equal
unk_053 = 0x35, unk_053 = 0x35, // size 1 OP_EvalLocalVariableCached0
unk_054 = 0x36, unk_054 = 0x36, // size 1 OP_EvalLocalVariableCached1
unk_055 = 0x37, unk_055 = 0x37, // size 1 OP_EvalLocalVariableCached2
unk_056 = 0x38, unk_056 = 0x38, // size 1 OP_EvalLocalVariableCached3
unk_057 = 0x39, unk_057 = 0x39, // size 1 OP_EvalLocalVariableCached4
unk_058 = 0x3A, unk_058 = 0x3A, // size 1 OP_EvalLocalVariableCached5
unk_059 = 0x3B, unk_059 = 0x3B, // size 2 OP_EvalLocalVariableCached
unk_060 = 0x3C, unk_060 = 0x3C, // size 9 OP_EvalNewLocalArrayRefCached0
unk_061 = 0x3D, unk_061 = 0x3D, // size 2 OP_ScriptChildThreadCallPointer
unk_062 = 0x3E, unk_062 = 0x3E, // size 2 OP_EvalLocalVariableObjectCached
unk_063 = 0x3F, unk_063 = 0x3F, // size 5 OP_GetInteger
unk_064 = 0x40, unk_064 = 0x40, // size 1 OP_ScriptMethodCallPointer
unk_065 = 0x41, unk_065 = 0x41, // size 1 OP_checkclearparams
unk_066 = 0x42, unk_066 = 0x42, // size 9, script 8 (hash?) OP_SetAnimFieldVariableField
unk_067 = 0x43, unk_067 = 0x43, // missing OP_waittillmatch2
unk_068 = 0x44, unk_068 = 0x44, // size 1 OP_minus
unk_069 = 0x45, unk_069 = 0x45, // size 3 OP_GetNegUnsignedShort
unk_070 = 0x46, unk_070 = 0x46, // size 2 OP_GetNegByte
unk_071 = 0x47, unk_071 = 0x47, // size 9 OP_SafeCreateVariableFieldCached
unk_072 = 0x48, unk_072 = 0x48, // size 1 OP_greater_equal
unk_073 = 0x49, unk_073 = 0x49, // size 1 OP_vector
unk_074 = 0x4A, unk_074 = 0x4A, // size 3, stack string OP_GetBuiltinMethod
unk_075 = 0x4B, unk_075 = 0x4B, // size 3 + 8 * count, stack strings OP_endswitch
unk_076 = 0x4C, unk_076 = 0x4C, // size 1 OP_ClearArray
unk_077 = 0x4D, unk_077 = 0x4D, // size 1 OP_DecTop
unk_078 = 0x4E, unk_078 = 0x4E, // size 1 OP_CastBool
unk_079 = 0x4F, unk_079 = 0x4F, // size 1 OP_EvalArrayRef
unk_080 = 0x50, unk_080 = 0x50, // size 9 OP_SetNewLocalVariableFieldCached0
unk_081 = 0x51, unk_081 = 0x51, // size 1 OP_GetZero
unk_082 = 0x52, unk_082 = 0x52, // size 1 OP_wait
unk_083 = 0x53, unk_083 = 0x53, // size 1 OP_waittill
unk_084 = 0x54, unk_084 = 0x54, // size 5, stack string OP_GetIString
unk_085 = 0x55, unk_085 = 0x55, // size 5, stack 8 + 8 OP_ScriptFarFunctionCall
unk_086 = 0x56, unk_086 = 0x56, // size 1 OP_GetAnimObject
unk_087 = 0x57, unk_087 = 0x57, // size 2, stack string OP_GetAnimTree
unk_088 = 0x58, unk_088 = 0x58, // size 2 OP_EvalLocalArrayCached
unk_089 = 0x59, unk_089 = 0x59, // size 1 OP_mod
unk_090 = 0x5A, unk_090 = 0x5A, // size 6, stack 8 + 8 OP_ScriptFarMethodThreadCall
unk_091 = 0x5B, unk_091 = 0x5B, // size 3 OP_GetUnsignedShort
unk_092 = 0x5C, unk_092 = 0x5C, // size 1 OP_clearparams
unk_093 = 0x5D, unk_093 = 0x5D, // size 2 OP_ScriptMethodThreadCallPointer
unk_094 = 0x5E, unk_094 = 0x5E, // size 1 OP_ScriptFunctionCallPointer
unk_095 = 0x5F, unk_095 = 0x5F, // size 1 OP_EmptyArray
unk_096 = 0x60, unk_096 = 0x60, // size 2 OP_SafeSetVariableFieldCached
unk_097 = 0x61, unk_097 = 0x61, // missing OP_ClearVariableField
unk_098 = 0x62, unk_098 = 0x62, // size 9, script 8 (hash?) OP_EvalFieldVariableRef
unk_099 = 0x63, unk_099 = 0x63, // missing OP_EvalNewLocalVariableRefCached0
unk_100 = 0x64, unk_100 = 0x64, // size 5 OP_GetFloat
unk_101 = 0x65, unk_101 = 0x65, // size 2 OP_EvalLocalVariableRefCached
unk_102 = 0x66, unk_102 = 0x66, // size 3 OP_JumpOnFalse
unk_103 = 0x67, unk_103 = 0x67, // size 1 OP_BoolComplement
unk_104 = 0x68, unk_104 = 0x68, // size 2 OP_ScriptThreadCallPointer
unk_105 = 0x69, unk_105 = 0x69, // size 1 OP_less
unk_106 = 0x6A, unk_106 = 0x6A, // size 1 OP_BoolNot
unk_107 = 0x6B, unk_107 = 0x6B, // size 1 OP_waittillFrameEnd
unk_108 = 0x6C, unk_108 = 0x6C, // size 1 OP_waitframe
unk_109 = 0x6D, unk_109 = 0x6D, // size 5, stack string OP_GetString
unk_110 = 0x6E, unk_110 = 0x6E, // size 9, script 8 (hash?) OP_EvalLevelFieldVariable
unk_111 = 0x6F, unk_111 = 0x6F, // size 1 OP_GetLevelObject
unk_112 = 0x70, unk_112 = 0x70, // size 1 OP_inc
unk_113 = 0x71, unk_113 = 0x71, // size 4, stack string (hash) OP_CallBuiltinMethod
unk_114 = 0x72, unk_114 = 0x72, // size 1 OP_GetAnim
unk_115 = 0x73, unk_115 = 0x73, // size 5 OP_switch
unk_116 = 0x74, unk_116 = 0x74, // size 1 OP_SetVariableField
unk_117 = 0x75, unk_117 = 0x75, // size 1 OP_divide
unk_118 = 0x76, unk_118 = 0x76, // size 6, stack 8 + 8 OP_ScriptFarChildThreadCall
unk_119 = 0x77, unk_119 = 0x77, // size 1 OP_multiply
unk_120 = 0x78, unk_120 = 0x78, // size 2 OP_ClearLocalVariableFieldCached
unk_121 = 0x79, unk_121 = 0x79, // size 9, script 8 (hash?) OP_EvalAnimFieldVariableRef
unk_122 = 0x7A, unk_122 = 0x7A, // size 2 OP_EvalLocalArrayRefCached
unk_123 = 0x7B, unk_123 = 0x7B, // size 1 OP_EvalLocalVariableRefCached0
unk_124 = 0x7C, unk_124 = 0x7C, // size 1 OP_bit_and
unk_125 = 0x7D, unk_125 = 0x7D, // size ?, stack string * 2 OP_GetAnimation
unk_126 = 0x7E, unk_126 = 0x7E, // size 5, stack 8 + 8 OP_GetFarFunction
unk_127 = 0x7F, unk_127 = 0x7F, // size 2 OP_CallBuiltinPointer
unk_128 = 0x80, unk_128 = 0x80, // size 5 OP_jump
unk_129 = 0x81, unk_129 = 0x81, // size 1 OP_voidCodepos
unk_130 = 0x82, unk_130 = 0x82, // size 5, stack 8 + 8 OP_ScriptFarMethodCall
unk_131 = 0x83, unk_131 = 0x83, // size 1 OP_inequality
unk_132 = 0x84, unk_132 = 0x84, // size 1 OP_bit_ex_or
unk_133 = 0x85, unk_133 = 0x85, // size 9
unk_134 = 0x86, unk_134 = 0x86, // size 5
unk_135 = 0x87, unk_135 = 0x87, // size 9
unk_136 = 0x88, unk_136 = 0x88, // size 9
unk_137 = 0x89, unk_137 = 0x89, // size 5
unk_138 = 0x8A, unk_138 = 0x8A, // size 9
unk_139 = 0x8B, unk_139 = 0x8B,
unk_140 = 0x8C, unk_140 = 0x8C,
unk_141 = 0x8D, unk_141 = 0x8D,
unk_142 = 0x8E, unk_142 = 0x8E,
unk_143 = 0x8F, unk_143 = 0x8F,
unk_144 = 0x90, unk_144 = 0x90,
unk_145 = 0x91, unk_145 = 0x91, // size 6 OP_prof_begin
unk_146 = 0x92, unk_146 = 0x92, // size 2 OP_prof_end
unk_147 = 0x93, unk_147 = 0x93, // OP_breakpoint
unk_148 = 0x94, unk_148 = 0x94, // OP_assignmentBreakpoint
unk_149 = 0x95, unk_149 = 0x95, // OP_manualAndAssignmentBreakpoint
unk_150 = 0x96, unk_150 = 0x96, // size 1 OP_BoolNotAfterAnd
unk_151 = 0x97, unk_151 = 0x97, // size 2 + 8 * count (params?) OP_FormalParams
unk_152 = 0x98, unk_152 = 0x98, // size 1 OP_IsDefined
unk_153 = 0x99, unk_153 = 0x99, // size 1 OP_IsTrue
unk_154 = 0x9A, unk_154 = 0x9A, // size 5, stack 4 OP_NativeGetFarFunction
unk_155 = 0x9B, unk_155 = 0x9B, // size 5, stack 4 OP_NativeFarFunctionCall
unk_156 = 0x9C, unk_156 = 0x9C, // size 5, stack 4 OP_NativeFarMethodCall
unk_157 = 0x9D, unk_157 = 0x9D, // size 6, stack 4 OP_NativeFarFunctionThreadCall
unk_158 = 0x9E, unk_158 = 0x9E, // size 6, stack 4 OP_NativeFarMethodThreadCall
unk_159 = 0x9F, unk_159 = 0x9F, // size 6, stack 4 OP_NativeFarFunctionChildThreadCall
unk_160 = 0xA0, unk_160 = 0xA0, // size 6, stack 4 OP_NativeFarMethodChildThreadCall
unk_161 = 0xA1, unk_161 = 0xA1, // size 9 OP_EvalNewLocalArrayRefCached0_Precompiled
unk_162 = 0xA2, unk_162 = 0xA2, // size 9 OP_SetNewLocalVariableFieldCached0_Precompiled
unk_163 = 0xA3, unk_163 = 0xA3, // size 9 OP_CreateLocalVariable_Precompiled
unk_164 = 0xA4, unk_164 = 0xA4, // size 9 OP_SafeCreateVariableFieldCached_Precompiled
unk_165 = 0xA5, unk_165 = 0xA5, // size 2 + 8 * count (params?) OP_FormalParams_Precompiled
unk_166 = 0xA6, unk_166 = 0xA6, // size 9, stack 8
OP_count = 0xA7, OP_count = 0xA7,
}; };