def create_img(self, base_img_path, img_path):
cmd = ["qemu-img create",
"-b {}".format(base_img_path),
"-f qcow2",
"{}".format(img_path)]
#cprint("["+self.__host_name+"][QEMU]: creating VM image.", self.__output_color)
#print(" ".join(cmd))
return cmd
python类cprint()的实例源码
def checkpoint_vm(self):
cprint("["+self.__host_name+"][QEMU]: checkpointing VM.", self.__output_color)
self.__pexpect_child.expect('(qemu)')
sendline('savevm bee_saved')
def restore_vm(self):
cprint("["+self.__host_name+"][QEMU]: restoringing VM.", self.__output_color)
self.__pexpect_child.expect('(qemu)')
sendline('loadvm bee_saved')
def print_f_score(output, target):
"""returns:
p<recision>,
r<ecall>,
f<-score>,
{"TP", "p", "TP_plus_FP"} """
p, r, TP, TP_plus_FN, TP_plus_FP = precision_recall(output, target)
f = F_score(p, r)
# cprint("Label: " + c((" " + str(10))[-5:], 'red') +
# "\tPrec: " + c(" {:.1f}".format(0.335448 * 100)[-5:], 'green') + '%' +
# " ({:d}/{:d})".format(1025, 1254).ljust(14) +
# "Recall: " + c(" {:.1f}".format(0.964 * 100)[-5:], 'green') + "%" +
# " ({:d}/{:d})".format(15, 154).ljust(14) +
# "F-Score: " + (c(" {:.1f}".format(0.5 * 100)[-5:], "green") + "%")
# )
for label in f.keys():
cprint("Label: " + c((" " + str(label))[-5:], 'red') +
"\tPrec: " + c(" {:.1f}".format(p[label] * 100)[-5:], 'green') + '%' +
" ({:d}/{:d})".format((TP[label] if label in TP else 0), TP_plus_FP[label]).ljust(14) +
"Recall: " + c(" {:.1f}".format((r[label] if label in r else 0) * 100)[-5:], 'green') + "%" +
" ({:d}/{:d})".format((TP[label] if label in TP else 0), TP_plus_FN[label]).ljust(14) +
"F-Score: " + (" N/A" if f[label] is None else (c(" {:.1f}".format(f[label] * 100)[-5:], "green") + "%"))
)
# return p, r, f, _
def generate(self):
"""Generate Project."""
logger.debug("Starting generating project...")
start = time.time()
# Config
self._config()
# Extensions
self._extensions()
# App
self._app()
# Manage
self._manage()
# License
self._license()
# Readme
self._readme()
# Fabfile
self._fabfile()
# Uwsgi
self._uwsgi()
# Conf files Nginx Supervidor
self._config_files()
# Std. Modules
self.module.ger_std_modules()
end = time.time() - start
cprint("=" * 55, "green", attrs=["bold"])
logger.info("[ \u0231 ] Finishing: %f sec." % end)
def emulate(self, pc):
while pc:
# Fetch opcodes
opcode = TritonContext.getConcreteMemoryAreaValue(pc, 16)
# Create the Triton instruction
instruction = Instruction()
instruction.setOpcode(opcode)
instruction.setAddress(pc)
# Process
if (not TritonContext.processing(instruction)):
print("Current opcode is not supported.")
self.log(instruction)
if TritonContext.isRegisterSymbolized(Arch().triton_pc_reg):
pc_expr = TritonContext.getSymbolicExpressionFromId(
TritonContext.getSymbolicRegisterId(Arch().triton_pc_reg))
pc_ast = astCtxt.extract(Arch().reg_bits - 1, 0,
pc_expr.getAst())
# Define constraint
cstr = astCtxt.equal(pc_ast,
astCtxt.bv(self.target_address,
Arch().reg_bits))
model = TritonContext.getModel(cstr)
if model:
cprint('Got answer!!!', 'green')
for sym_id, sym_model in model.items():
value = sym_model.getValue()
TritonContext.setConcreteSymbolicVariableValue(
TritonContext.getSymbolicVariableFromId(sym_id),
value)
cprint('Symbolic variable %02d = %02x (%c)' %
(sym_id, value, chr(value)), 'green')
if click.confirm('Inject back to gdb?', default=True):
self.inject_to_gdb()
return True
# Next
pc = TritonContext.buildSymbolicRegister(
Arch().triton_pc_reg).evaluate()
def check_auth_bucket(bucket_name):
# Let's check S3 static web site hosting status
try:
website_status =s3.get_bucket_website(Bucket=bucket_name)
bucket_status_code = "S3WebSite!"
return bucket_status_code
except ClientError as ex:
bucket_status_code = ex.response['Error']['Code']
# Let's try to get bucket ACL and Policy
# ACL
try:
bucket_acl = s3.get_bucket_acl(Bucket=bucket_name)
for grant in bucket_acl["Grants"]:
if grant["Grantee"]["Type"] == "Group" and "AllUsers" in grant["Grantee"].get("URI"):
bucket_status_code = "AllUsersAccess"
return bucket_status_code
elif grant["Grantee"]["Type"] == "Group" and "AuthenticatedUsers" in grant["Grantee"].get("URI"):
bucket_status_code = "AllAuthUsersAccess"
return bucket_status_code
except ClientError as ex:
if ex.response['Error']['Code'] == "AccessDenied":
bucket_status_code = "AccessDenied2ACL"
else:
bucket_status_code ="Can'tVerify"
# cprint ("Weird"+ str(ex.response['Error']), "red")
#Policy
try:
bucket_policy = s3.get_bucket_policy(Bucket=bucket_name)
bucket_policy_j = json.loads(bucket_policy["Policy"])
for statement in bucket_policy_j["Statement"]:
if (statement.get("Condition") is None and
statement["Effect"] == "Allow" and
("'*'" in str(statement["Principal"]) or statement["Principal"] == "*")):
bucket_status_code = str(statement["Action"])
return bucket_status_code
# Policy exists but not allow public access
bucket_status_code = "NoPublicAccess"
except ClientError as ex:
if ex.response['Error']['Code'] == "NoSuchBucketPolicy":
bucket_status_code = "NoSuchBucketPolicy"
elif ex.response['Error']['Code'] == "AccessDenied":
bucket_status_code = "AccessDenied2Policy"
else:
bucket_status_code ="Can'tVerify"
# cprint("Weird"+ str(ex.response['Error']), "red")
# return status code
return bucket_status_code