|
| 1 | +# ------------------------------------------------------------------------------ |
| 2 | +# CodeHawk Binary Analyzer |
| 3 | +# Author: Henny Sipma |
| 4 | +# ------------------------------------------------------------------------------ |
| 5 | +# The MIT License (MIT) |
| 6 | +# |
| 7 | +# Copyright (c) 2025 Aarno Labs LLC |
| 8 | +# |
| 9 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | +# of this software and associated documentation files (the "Software"), to deal |
| 11 | +# in the Software without restriction, including without limitation the rights |
| 12 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | +# copies of the Software, and to permit persons to whom the Software is |
| 14 | +# furnished to do so, subject to the following conditions: |
| 15 | +# |
| 16 | +# The above copyright notice and this permission notice shall be included in all |
| 17 | +# copies or substantial portions of the Software. |
| 18 | +# |
| 19 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | +# SOFTWARE. |
| 26 | +# ------------------------------------------------------------------------------ |
| 27 | +""" |
| 28 | +
|
| 29 | +Based on sideeffect_argument_location in bCHLibTypes: |
| 30 | +
|
| 31 | +type sideeffect_argument_location_t = |
| 32 | +| SEGlobal of doubleword_int (* address of global variable passed *) |
| 33 | +| SEStack of numerical_int (* stack offset (negative for local stack) passed *) |
| 34 | +| SEDescr of string (* unidentified address *) |
| 35 | +""" |
| 36 | + |
| 37 | +from typing import TYPE_CHECKING |
| 38 | + |
| 39 | +from chb.invariants.FnDictionaryRecord import FnVarDictionaryRecord, varregistry |
| 40 | + |
| 41 | +import chb.util.fileutil as UF |
| 42 | +from chb.util.IndexedTable import IndexedTableValue |
| 43 | + |
| 44 | +if TYPE_CHECKING: |
| 45 | + from chb.bctypes.BCTyp import BCTyp |
| 46 | + from chb.invariants.FnVarDictionary import FnVarDictionary |
| 47 | + |
| 48 | + |
| 49 | +class SideeffectArgumentLocation(FnVarDictionaryRecord): |
| 50 | + |
| 51 | + def __init__( |
| 52 | + self, |
| 53 | + vd: "FnVarDictionary", |
| 54 | + ixval: IndexedTableValue) -> None: |
| 55 | + FnVarDictionaryRecord.__init__(self, vd, ixval) |
| 56 | + |
| 57 | + @property |
| 58 | + def is_global_location(self) -> bool: |
| 59 | + return False |
| 60 | + |
| 61 | + @property |
| 62 | + def is_stack_location(self) -> bool: |
| 63 | + return False |
| 64 | + |
| 65 | + @property |
| 66 | + def is_unknown_location(self) -> bool: |
| 67 | + return False |
| 68 | + |
| 69 | + def __str__(self) -> str: |
| 70 | + return "sideeffect-argument-location:" + self.tags[0] |
| 71 | + |
| 72 | + |
| 73 | +@varregistry.register_tag("g", SideeffectArgumentLocation) |
| 74 | +class SideeffectArgumentGlobalLocation(SideeffectArgumentLocation): |
| 75 | + |
| 76 | + def __init__( |
| 77 | + self, |
| 78 | + vd: "FnVarDictionary", |
| 79 | + ixval: IndexedTableValue) -> None: |
| 80 | + SideeffectArgumentLocation.__init__(self, vd, ixval) |
| 81 | + |
| 82 | + @property |
| 83 | + def is_global_location(self) -> bool: |
| 84 | + return True |
| 85 | + |
| 86 | + @property |
| 87 | + def gaddr(self) -> str: |
| 88 | + return self.tags[1] |
| 89 | + |
| 90 | + def __str__(self) -> str: |
| 91 | + return "seglobal:" + self.gaddr |
| 92 | + |
| 93 | + |
| 94 | +@varregistry.register_tag("s", SideeffectArgumentLocation) |
| 95 | +class SideeffectArgumentStackLocation(SideeffectArgumentLocation): |
| 96 | + |
| 97 | + def __init__( |
| 98 | + self, |
| 99 | + vd: "FnVarDictionary", |
| 100 | + ixval: IndexedTableValue) -> None: |
| 101 | + SideeffectArgumentLocation.__init__(self, vd, ixval) |
| 102 | + |
| 103 | + @property |
| 104 | + def is_stack_location(self) -> bool: |
| 105 | + return True |
| 106 | + |
| 107 | + @property |
| 108 | + def offset(self) -> int: |
| 109 | + return int(self.tags[1]) |
| 110 | + |
| 111 | + def __str__(self) -> str: |
| 112 | + return "sestack:" + str(self.offset) |
| 113 | + |
| 114 | + |
| 115 | +@varregistry.register_tag("d", SideeffectArgumentLocation) |
| 116 | +class SideeffectArgumentUnknownLocation(SideeffectArgumentLocation): |
| 117 | + |
| 118 | + def __init__( |
| 119 | + self, |
| 120 | + vd: "FnVarDictionary", |
| 121 | + ixval: IndexedTableValue) -> None: |
| 122 | + SideeffectArgumentLocation.__init__(self, vd, ixval) |
| 123 | + |
| 124 | + @property |
| 125 | + def is_unknown_location(self) -> bool: |
| 126 | + return True |
| 127 | + |
| 128 | + @property |
| 129 | + def description(self) -> str: |
| 130 | + return self.tags[1] |
| 131 | + |
| 132 | + def __str__(self) -> str: |
| 133 | + return "sedescr:" + str(self.description) |
0 commit comments