[英]Z3py - do a roll
Is there a recommended way of doing a bitwise roll to either left or right by any amount? 是否有推荐的方式向左或向右滚动任意数量?
For example with a byte - 0x57 rolr 3 = 0xEA
. 例如,一个字节 -
0x57 rolr 3 = 0xEA
。
I have not found any "roll" operation in the Z3py docs. 我没有在Z3py文档中找到任何“滚动”操作。 I was thinking about using a
BitVec
s for each bit but that doesn't seem efficient/probably won't work. 我正在考虑为每个位使用
BitVec
,但这看起来效率不高/可能无效。 Any advice is appreciated, thanks. 任何建议表示赞赏,谢谢。
Edit: Thanks for the answers so far. 编辑:感谢您的答案到目前为止。 This is more of an API question because I suck at it right now.
这更像是一个API问题,因为我现在很尴尬。 Heres what I have as a starting point.
以我所拥有的为出发点。
def roll(bt):
count = BitVecVal(int('0x03', 16), 8)
s.add(bt == (bt << count | bt >> (8 - count)) & 0xFF)
a = BitVec('a', 8)
s = Solver()
roll(a)
s.add(a == BitVecVal(int('0xEA', 16), 8))
s.check()
This prints out nothing and model is not available. 这打印出来没有,模型不可用。
You can do a rotate like this: 你可以像这样做一个旋转:
size = 0x100 # size of the bitvector
rotated = (x << n) | (x >> (size - n)) & (size - 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.