diff --git a/chb/app/CHVersion.py b/chb/app/CHVersion.py index 4e153622..f099e124 100644 --- a/chb/app/CHVersion.py +++ b/chb/app/CHVersion.py @@ -1 +1 @@ -chbversion: str = "0.3.0-20250804" +chbversion: str = "0.3.0-20250805" diff --git a/chb/mips/opcodes/MIPSTrapIfEqualImmediate.py b/chb/mips/opcodes/MIPSTrapIfEqualImmediate.py new file mode 100644 index 00000000..fd927153 --- /dev/null +++ b/chb/mips/opcodes/MIPSTrapIfEqualImmediate.py @@ -0,0 +1,72 @@ +# ------------------------------------------------------------------------------ +# CodeHawk Binary Analyzer +# Author: Henny Sipma +# ------------------------------------------------------------------------------ +# The MIT License (MIT) +# +# Copyright (c) 2025 Aarno Labs LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# ------------------------------------------------------------------------------ + +from typing import cast, List, Sequence, TYPE_CHECKING + +from chb.app.InstrXData import InstrXData + +from chb.invariants.XXpr import XXpr + +from chb.mips.MIPSDictionaryRecord import mipsregistry +from chb.mips.MIPSOpcode import MIPSOpcode, simplify_result +from chb.mips.MIPSOperand import MIPSOperand + +import chb.util.fileutil as UF + +from chb.util.IndexedTable import IndexedTableValue + +if TYPE_CHECKING: + from chb.mips.MIPSDictionary import MIPSDictionary + + +@mipsregistry.register_tag("teqi", MIPSOpcode) +class MIPSTrapIfEqualImmediate(MIPSOpcode): + """Trap if equal immediate. + + TEQI rs, imm + + args[0]: index of rs in mipsdictionary + args[1]: index of imm in mipsdictionary + """ + + def __init__( + self, + mipsd: "MIPSDictionary", + ixval: IndexedTableValue) -> None: + MIPSOpcode.__init__(self, mipsd, ixval) + + @property + def operands(self) -> Sequence[MIPSOperand]: + return [self.mipsd.mips_operand(i) for i in self.args] + + def annotation(self, xdata: InstrXData) -> str: + rhs1 = str(xdata.xprs[0]) + rhs2 = str(xdata.xprs[1]) + result = xdata.xprs[2] + rresult = xdata.xprs[3] + xresult = simplify_result(xdata.args[2], xdata.args[3], result, rresult) + return 'trap if ' + rhs1 + ' == ' + rhs2 + ' (' + xresult + ')' diff --git a/chb/mips/opcodes/MIPSTrapIfLessThanUnsigned.py b/chb/mips/opcodes/MIPSTrapIfLessThanUnsigned.py new file mode 100644 index 00000000..e7a17122 --- /dev/null +++ b/chb/mips/opcodes/MIPSTrapIfLessThanUnsigned.py @@ -0,0 +1,73 @@ +# ------------------------------------------------------------------------------ +# CodeHawk Binary Analyzer +# Author: Henny Sipma +# ------------------------------------------------------------------------------ +# The MIT License (MIT) +# +# Copyright (c) 2025 Aarno Labs LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# ------------------------------------------------------------------------------ + +from typing import cast, List, Sequence, TYPE_CHECKING + +from chb.app.InstrXData import InstrXData + +from chb.invariants.XXpr import XXpr + +from chb.mips.MIPSDictionaryRecord import mipsregistry +from chb.mips.MIPSOpcode import MIPSOpcode, simplify_result +from chb.mips.MIPSOperand import MIPSOperand + +import chb.util.fileutil as UF + +from chb.util.IndexedTable import IndexedTableValue + +if TYPE_CHECKING: + from chb.mips.MIPSDictionary import MIPSDictionary + + +@mipsregistry.register_tag("tltu", MIPSOpcode) +class MIPSTrapIfLessThanUnsigned(MIPSOpcode): + """Trap if less than unsigned. + + TLTU rs, rt + + args[0]: code field (bits 15:6) + args[1]: index of rs in mipsdictionary + args[2]: index of rt in mipsdictionary + """ + + def __init__( + self, + mipsd: "MIPSDictionary", + ixval: IndexedTableValue) -> None: + MIPSOpcode.__init__(self, mipsd, ixval) + + @property + def operands(self) -> Sequence[MIPSOperand]: + return [self.mipsd.mips_operand(i) for i in self.args[1:]] + + def annotation(self, xdata: InstrXData) -> str: + rhs1 = str(xdata.xprs[0]) + rhs2 = str(xdata.xprs[1]) + result = xdata.xprs[2] + rresult = xdata.xprs[3] + xresult = simplify_result(xdata.args[2], xdata.args[3], result, rresult) + return 'trap if ' + rhs1 + ' < ' + rhs2 + ' (' + xresult + ')' diff --git a/chb/mips/opcodes/MIPSTrapIfNotEqualImmediate.py b/chb/mips/opcodes/MIPSTrapIfNotEqualImmediate.py new file mode 100644 index 00000000..1f49429d --- /dev/null +++ b/chb/mips/opcodes/MIPSTrapIfNotEqualImmediate.py @@ -0,0 +1,72 @@ +# ------------------------------------------------------------------------------ +# CodeHawk Binary Analyzer +# Author: Henny Sipma +# ------------------------------------------------------------------------------ +# The MIT License (MIT) +# +# Copyright (c) 2025 Aarno Labs LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# ------------------------------------------------------------------------------ + +from typing import cast, List, Sequence, TYPE_CHECKING + +from chb.app.InstrXData import InstrXData + +from chb.invariants.XXpr import XXpr + +from chb.mips.MIPSDictionaryRecord import mipsregistry +from chb.mips.MIPSOpcode import MIPSOpcode, simplify_result +from chb.mips.MIPSOperand import MIPSOperand + +import chb.util.fileutil as UF + +from chb.util.IndexedTable import IndexedTableValue + +if TYPE_CHECKING: + from chb.mips.MIPSDictionary import MIPSDictionary + + +@mipsregistry.register_tag("tnei", MIPSOpcode) +class MIPSTrapIfNotEqualImmediate(MIPSOpcode): + """Trap if not equal immediate. + + TNEI rs, imm + + args[0]: index of rs in mipsdictionary + args[1]: index of imm in mipsdictionary + """ + + def __init__( + self, + mipsd: "MIPSDictionary", + ixval: IndexedTableValue) -> None: + MIPSOpcode.__init__(self, mipsd, ixval) + + @property + def operands(self) -> Sequence[MIPSOperand]: + return [self.mipsd.mips_operand(i) for i in self.args] + + def annotation(self, xdata: InstrXData) -> str: + rhs1 = str(xdata.xprs[0]) + rhs2 = str(xdata.xprs[1]) + result = xdata.xprs[2] + rresult = xdata.xprs[3] + xresult = simplify_result(xdata.args[2], xdata.args[3], result, rresult) + return 'trap if ' + rhs1 + ' != ' + rhs2 + ' (' + xresult + ')'