Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some unnecessary cases of make_like #567

Merged
merged 1 commit into from
Nov 5, 2024
Merged
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
14 changes: 5 additions & 9 deletions claripy/simplifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ def bv_reverse_simplifier(body):
return first_ast
return first_ast[upper_bound:0]
if all(a.length == 8 for a in body.args):
return body.make_like(body.op, body.args[::-1], simplify=True)
return claripy.Concat(*body.args[::-1])

if body.op == "Concat" and all(a.op == "Reverse" for a in body.args) and all(a.length % 8 == 0 for a in body.args):
return body.make_like(body.op, [a.args[0] for a in reversed(body.args)], simplify=True)
return claripy.Concat(*[a.args[0] for a in reversed(body.args)])

if body.op == "Extract" and body.args[2].op == "Reverse":
# Reverse(Extract(hi, lo, Reverse(x))) ==> Extract(bits-lo-1, bits-hi-1, x)
Expand All @@ -357,7 +357,7 @@ def bv_reverse_simplifier(body):
x = body.args[2].args[0]
new_hi = x.size() - lo - 1
new_lo = x.size() - hi - 1
return body.make_like(body.op, (new_hi, new_lo, x), simplify=True)
return claripy.Extract(new_hi, new_lo, x)
return None
return None

Expand Down Expand Up @@ -770,7 +770,7 @@ def zeroext_simplifier(n, e):

if e.op == "ZeroExt":
# ZeroExt(A, ZeroExt(B, x)) ==> ZeroExt(A + B, x)
return e.make_like(e.op, (n + e.args[0], e.args[1]), length=n + e.size(), simplify=True)
claripy.ZeroExt(n + e.args[0], e.args[1])
return None


Expand Down Expand Up @@ -855,11 +855,7 @@ def extract_simplifier(high, low, val):
return (val.args[2])[new_high:new_low]

if val.op == "Reverse" and val.args[0].op == "Concat" and all(a.length % 8 == 0 for a in val.args[0].args):
val = val.make_like(
"Concat",
tuple(reversed([a.reversed for a in val.args[0].args])),
simplify=True,
)[high:low]
val = claripy.Concat(*reversed([a.reversed for a in val.args[0].args]))[high:low]
if not val.symbolic:
return val

Expand Down