+ print ("INFO : Eval Express [%s] : %s" % (Expr, Result))\r
+ return Result\r
+\r
+ def ValueToByteArray (self, ValueStr, Length):\r
+ Match = re.match("\{\s*FILE:(.+)\}", ValueStr)\r
+ if Match:\r
+ FileList = Match.group(1).split(',')\r
+ Result = bytearray()\r
+ for File in FileList:\r
+ File = File.strip()\r
+ BinPath = os.path.join(os.path.dirname(self._DscFile), File)\r
+ Result.extend(bytearray(open(BinPath, 'rb').read()))\r
+ else:\r
+ try:\r
+ Result = bytearray(self.ValueToList(ValueStr, Length))\r
+ except ValueError as e:\r
+ raise Exception ("Bytes in '%s' must be in range 0~255 !" % ValueStr)\r
+ if len(Result) < Length:\r
+ Result.extend(b'\x00' * (Length - len(Result)))\r
+ elif len(Result) > Length:\r
+ raise Exception ("Value '%s' is too big to fit into %d bytes !" % (ValueStr, Length))\r
+\r
+ return Result[:Length]\r
+\r
+ def ValueToList (self, ValueStr, Length):\r
+ if ValueStr[0] == '{':\r
+ Result = []\r
+ BinList = ValueStr[1:-1].split(',')\r
+ InBitField = False\r
+ LastInBitField = False\r
+ Value = 0\r
+ BitLen = 0\r
+ for Element in BinList:\r
+ InBitField = False\r
+ Each = Element.strip()\r
+ if len(Each) == 0:\r
+ pass\r
+ else:\r
+ if Each[0] in ['"', "'"]:\r
+ Result.extend(list(bytearray(Each[1:-1], 'utf-8')))\r
+ elif ':' in Each:\r
+ Match = re.match("(.+):(\d+)b", Each)\r
+ if Match is None:\r
+ raise Exception("Invald value list format '%s' !" % Each)\r
+ InBitField = True\r
+ CurrentBitLen = int(Match.group(2))\r
+ CurrentValue = ((self.EvaluateExpress(Match.group(1)) & (1<<CurrentBitLen) - 1)) << BitLen\r
+ else:\r
+ Result.append(self.EvaluateExpress(Each.strip()))\r
+ if InBitField:\r
+ Value += CurrentValue\r
+ BitLen += CurrentBitLen\r
+ if LastInBitField and ((not InBitField) or (Element == BinList[-1])):\r
+ if BitLen % 8 != 0:\r
+ raise Exception("Invald bit field length!")\r
+ Result.extend(Val2Bytes(Value, BitLen // 8))\r
+ Value = 0\r
+ BitLen = 0\r
+ LastInBitField = InBitField\r
+ elif ValueStr.startswith("'") and ValueStr.endswith("'"):\r
+ Result = Str2Bytes (ValueStr, Length)\r
+ elif ValueStr.startswith('"') and ValueStr.endswith('"'):\r
+ Result = Str2Bytes (ValueStr, Length)\r
+ else:\r
+ Result = Val2Bytes (self.EvaluateExpress(ValueStr), Length)\r