Beispiel #1
0
def json_to_simval(d: Dict[str, Any]) -> SV.SimValue:
    id = d["i"]

    # SimValue (generic, covers all cases with jsonval implementation)
    if id == "x":
        return SSV.SimSymbolicValue(0, defined=False)

    # SimByteValue
    elif id == "b":
        if "d" in d:
            data = d["d"]
            v: int = data.get("v", 0)
            defined: bool = data.get("d", True)
            return SV.SimByteValue(v, defined)
        else:
            return SV.SimByteValue(0)

    # SimDoubleWordValue
    elif id == "d":
        if "d" in d:
            data = d["d"]
            v = data.get("v", 0)
            defined = data.get("d", True)
            b1defined: bool = data.get("db1", True)
            b2defined: bool = data.get("db2", True)
            b3defined: bool = data.get("db3", True)
            b4defined: bool = data.get("db4", True)
            return SV.SimDoubleWordValue(v,
                                         defined=defined,
                                         b1defined=b1defined,
                                         b2defined=b2defined,
                                         b3defined=b3defined,
                                         b4defined=b4defined)
        else:
            return SV.SimDoubleWordValue(0)

    # SimGlobalAddress
    elif id == "sga":
        data = d["d"]
        modulename: str = data.get("m", "?")
        offset = cast(SV.SimDoubleWordValue, json_to_simval(data["o"]))
        return SSV.SimGlobalAddress(modulename, offset)

    # SimReturnAddress
    elif id == "sra":
        data = d["d"]
        modulename = data.get("m", "?")
        functionaddr: str = data["f"]
        offset = cast(SV.SimDoubleWordValue, json_to_simval(data["o"]))
        return SSV.SimReturnAddress(modulename, functionaddr, offset)

    # SimMemoryByteLink
    elif id == "bl":
        data = d["d"]
        linkedto = cast(SSV.SimSymbolicValue, json_to_simval(data["l"]))
        position: int = cast(int, data["p"])
        return SimMemoryByteLink(linkedto, position)

    else:
        raise UF.CHBError("No deserialization implemented yet for id = " + id)
 def mk_address(self, offset: int) -> SSV.SimAddress:
     addr = cast(SV.SimDoubleWordValue, SV.mk_simvalue(offset, size=4))
     if self.name.startswith("global"):
         names = self.name.split(":")
         if len(names) == 2:
             image = names[1]
         else:
             image = "mainx"
         return SSV.SimGlobalAddress(image, addr)
     elif self.name == "stack":
         return SSV.SimStackAddress(addr)
     else:
         return SSV.SimBaseAddress(self.name, addr)