Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chb/app/CHVersion.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
chbversion: str = "0.3.0-20250804"
chbversion: str = "0.3.0-20250805"
72 changes: 72 additions & 0 deletions chb/mips/opcodes/MIPSTrapIfEqualImmediate.py
Original file line number Diff line number Diff line change
@@ -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 + ')'
73 changes: 73 additions & 0 deletions chb/mips/opcodes/MIPSTrapIfLessThanUnsigned.py
Original file line number Diff line number Diff line change
@@ -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 + ')'
72 changes: 72 additions & 0 deletions chb/mips/opcodes/MIPSTrapIfNotEqualImmediate.py
Original file line number Diff line number Diff line change
@@ -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 + ')'