Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def string_constraint(self):
cstr = selg.triton.getAstContest().equal(self.triton.getAstContext().bvtrue(), self.triton.getAstContext().bvtrue())
addrs = [self.inputs for inpt in self.inputs.values()]
for inpt in addrs[0:-1]:
symExp = triton.getSymbolicExpressionFromId(inpt.getId()).getAst()
cstr = triton.getAstContext().land(
[
cstr,
self.triton.getAstContext().land(
[
ast.bvuge(symExp, bv(0x20, 8)),
ast.bvuge(symExp, bv(0x7E, 8))
]
)
]
)
# last char should be 0
symExp = triton.getSymbolicExpressionFromId(addrs[-1]).getAst()
cstr = self.triton.getAstContext().land([cstr, self.triton.getAstContext().lnot(self.triton.getAstContext().equal(symExp, self.triton.getAstContext().bv(0, 8)))])
return cstr
taken = branch["isTaken"]
src = branch["srcAddr"]
dst = branch["dstAddr"]
bcstr = branch["constraint"]
isPreviousBranchConstraint = (src != _pc) and taken
isBranchToTake = src == _pc and dst == target
if isPreviousBranchConstraint or isBranchToTake:
cstr = triton.ast.land(cstr, bcstr)
if self.input_type == "string":
addrs = [self.inputs[inpt] for inpt in self.inputs]
for inpt in addrs[0:-1]:
symExp = triton.getSymbolicExpressionFromId(inpt.getId()).getAst()
cstr = triton.ast.land(cstr, triton.ast.lnot(triton.ast.equal(symExp, triton.ast.bv(0, 8))))
cstr = triton.ast.assert_(cstr)
return cstr
if isPreviousBranchConstraint or isBranchToTake:
cstr = self.triton.getAstContext().land([cstr, bcstr])
if self.input_type == "nonnull":
addrs = [self.inputs[inpt] for inpt in self.inputs]
for inpt in addrs[0:-1]:
symExp = triton.getSymbolicExpressionFromId(inpt.getId()).getAst()
cstr = self.triton.getAstContext().land([cstr, self.triton.getAstContext().lnot(self.triton.getAstContext().equal(symExp, self.triton.getAstContext().bv(0, 8)))])
# last char should be 0
symExp = triton.getSymbolicExpressionFromId(addrs[-1]).getAst()
cstr = self.triton.getAstContext().land([cstr, self.triton.getAstContext().lnot(self.triton.getAstContext().equal(symExp, self.triton.getAstContext().bv(0, 8)))])
elif self.input_type == "string":
addrs = [self.inputs[inpt] for inpt in self.inputs]
for inpt in addrs[0:-1]:
symExp = triton.getSymbolicExpressionFromId(inpt.getId()).getAst()
cstr = self.triton.getAstContext().land(
[
cstr,
self.triton.getAstContext().land(
ast.bvuge(symExp, bv(0x20, 8)),
ast.bvuge(symExp, bv(0x7E, 8))
)
]
)
# last char should be 0
symExp = triton.getSymbolicExpressionFromId(addrs[-1]).getAst()
cstr = self.triton.getAstContext().land([cstr, self.triton.getAstContext().lnot(self.triton.getAstContext().equal(symExp, self.triton.getAstContext().bv(0, 8)))])
# cstr = self.triton.getAstContext().assert_(cstr)
return cstr
addrs = [self.inputs for inpt in self.inputs.values()]
for inpt in addrs[0:-1]:
symExp = triton.getSymbolicExpressionFromId(inpt.getId()).getAst()
cstr = triton.getAstContext().land(
[
cstr,
self.triton.getAstContext().land(
[
ast.bvuge(symExp, bv(0x20, 8)),
ast.bvuge(symExp, bv(0x7E, 8))
]
)
]
)
# last char should be 0
symExp = triton.getSymbolicExpressionFromId(addrs[-1]).getAst()
cstr = self.triton.getAstContext().land([cstr, self.triton.getAstContext().lnot(self.triton.getAstContext().equal(symExp, self.triton.getAstContext().bv(0, 8)))])
return cstr
elif self.input_type == "string":
addrs = [self.inputs[inpt] for inpt in self.inputs]
for inpt in addrs[0:-1]:
symExp = triton.getSymbolicExpressionFromId(inpt.getId()).getAst()
cstr = self.triton.getAstContext().land(
[
cstr,
self.triton.getAstContext().land(
ast.bvuge(symExp, bv(0x20, 8)),
ast.bvuge(symExp, bv(0x7E, 8))
)
]
)
# last char should be 0
symExp = triton.getSymbolicExpressionFromId(addrs[-1]).getAst()
cstr = self.triton.getAstContext().land([cstr, self.triton.getAstContext().lnot(self.triton.getAstContext().equal(symExp, self.triton.getAstContext().bv(0, 8)))])
# cstr = self.triton.getAstContext().assert_(cstr)
return cstr