fix debug,dump and double check log output

This commit is contained in:
xwings
2020-04-01 11:03:35 +08:00
parent 510bcd32e7
commit a27a0da685
6 changed files with 33 additions and 15 deletions
+2 -1
View File
@@ -35,7 +35,8 @@ import sys
from qiling import *
def my_sandbox(path, rootfs):
ql = Qiling(path, rootfs, output="debug", log_file = 'logfile', log_split= True, log_console = True)
ql = Qiling(path, rootfs, output="debug", log_file = 'logfile', log_console = True)
ql.log_split= True,
ql.root = False
ql.add_fs_mapper('/proc', '/proc')
ql.run()
+1 -1
View File
@@ -30,11 +30,11 @@ def my_netgear(path, rootfs):
rootfs,
output = "debug",
log_dir = "qlog",
log_split = True,
log_console = True,
mmap_start = 0x7ffee000 - 0x800000,
)
ql.log_split = True,
ql.root = False
ql.bindtolocalhost = True
ql.multithread = False
+12 -9
View File
@@ -52,7 +52,6 @@ class Qiling:
verbose=0,
log_console=True,
log_dir=None,
log_split=False,
mmap_start=0,
stack_address=0,
stack_size=0,
@@ -72,7 +71,6 @@ class Qiling:
self.libcache = libcache
self.log_console = log_console
self.log_dir = log_dir
self.log_split = log_split
self.mmap_start = mmap_start
self.stack_address = stack_address
self.stack_size = stack_size
@@ -122,7 +120,8 @@ class Qiling:
# Bind to localhost
self.bindtolocalhost = False
# required root permission
self.root = True
self.root = True
self.log_split = False
if self.ostype and type(self.ostype) == str:
self.ostype = self.ostype.lower()
@@ -287,14 +286,18 @@ class Qiling:
raise QlErrorOutput("[!] Verbose muse be int")
if type(self.verbose) != int or self.verbose > 99 or (self.verbose > 0 and self.output not in (QL_OUT_DEBUG, QL_OUT_DUMP)):
raise QlErrorOutput("[!] Verbose > 1 must use with QL_OUT_DEBUG, QL_OUT_DUMP or else ql.verbose must be 0")
raise QlErrorOutput("[!] Verbose > 1 must use with QL_OUT_DEBUG or else ql.verbose must be 0")
if int(self.verbose) >= level:
if self.output == QL_OUT_DEBUG:
if self.output == QL_OUT_DUMP:
self.verbose = 99
#self.nprint(*args, **kw)
#msg = str(args[0]) + "\n"
#self.log_file_fd.debug(msg, **kw)
if int(self.verbose) >= level and self.output in (QL_OUT_DEBUG, QL_OUT_DUMP):
#self.nprint(*args, **kw)
self.log_file_fd.debug(*args, **kw)
elif self.output == QL_OUT_DUMP:
msg = str(args[0]) + "\n"
self.log_file_fd.debug(msg, **kw)
def addr_to_str(self, addr, short=False, endian="big"):
return ql_addr_to_str(self, addr, short, endian)
+1 -1
View File
@@ -207,7 +207,7 @@ def ql_hook_code_disasm(ql, address, size):
# FIXME: Need to name each reg
for reg in ql.reg_table:
REG_NAME = uc.reg_read(reg)
ql.dprint(3, "[-] 0x%x" % (REG_NAME))
ql.dprint(3, "[-] 0x%x\n" % (REG_NAME))
#ql.nprint("[-] %s= 0x%x %s= 0x%x %s= 0x%x %s= 0x%x %s= 0x%x %s= 0x%x %s= 0x%x\n" % \
#(syscall_num[1], syscall_num[0], arg_0[1], arg_0[0], arg_1[1], arg_1[0], arg_2[1], arg_2[0], arg_3[1],
+1 -1
View File
@@ -328,7 +328,7 @@ def ql_setup_logging_stream(ql_mode, logger=None):
def ql_setup_logging_file(ql_mode, log_file_path, logger=None):
# Create the file and directories if they do not exists
if not exists(log_file_path):
if not exists(log_file_path) and log_file_path.endswith(".qlog"):
open(log_file_path, "a").close()
# setup FileHandler for logging to disk file
+16 -2
View File
@@ -175,6 +175,9 @@ if __name__ == '__main__':
run_parser.add_argument('-g', '--gdb', required=False, help='enable gdb server')
run_parser.add_argument('-m','--multithread', action='store_true', default=False, dest='multithread', help='Run in multithread mode')
run_parser.add_argument('--strace', action='store_true', default=False, dest='strace', help='Run in strace mode')
run_parser.add_argument('--console', required=False, default=True, dest='console', help='display in console')
run_parser.add_argument('--log_dir', required=False, default=None, dest='log_dir', help='log file dir')
run_parser.add_argument('--log_split', action='store_true', default=False, dest='log_split', help='split log file')
run_parser.add_argument('--trace', action='store_true', default=False, dest='trace', help='Run in strace mode')
run_parser.add_argument('--debug_stop', action='store_true', default=False, dest='debug_stop', help='Stop running while encounter any error (only use it with debug mode)')
run_parser.add_argument('--en_root', action='store_true', default=False, dest='en_root', help='Enable sudo required mode')
@@ -210,6 +213,12 @@ if __name__ == '__main__':
elif options.debug:
options.output = "debug"
if options.console == "False":
options.console = False
if options.log_split:
options.console = True
if type(options.verbose) != int and options.output not in ("debug", "dump"):
print("ERROR: verbose mode, must be int and use with --debug or --dump")
usage()
@@ -221,9 +230,11 @@ if __name__ == '__main__':
exit(1)
if options.filename != '' and options.run_args == []:
ql = Qiling(filename=[options.filename] + options.args, rootfs=options.rootfs, output=options.output)
ql = Qiling(filename=[options.filename] + options.args, rootfs=options.rootfs,
output=options.output, log_console=options.console, log_dir=options.log_dir)
elif options.filename == '' and options.args == [] and options.run_args != []:
ql = Qiling(filename=options.run_args, rootfs=options.rootfs, output=options.output)
ql = Qiling(filename=options.run_args, rootfs=options.rootfs, output=options.output,
log_console=options.console, log_dir=options.log_dir)
else:
print("ERROR: Command error!")
usage()
@@ -238,6 +249,9 @@ if __name__ == '__main__':
if options.en_root:
ql.root = True
if options.log_split:
ql.log_split = True
if options.multithread:
ql.multithread = True