def handle(self, *args, **options):
# Need an absolute path for the target in order to simplify
# symlink creation.
target_path = options['target'][0]
target_path = os.path.realpath(target_path)
# Check that the target actually exists
if not os.path.isfile(target_path):
raise CommandError('Target %s does not exist' % target_path)
default_magic = Magic()
magic_checks = [
(Magic(magic_file=CGC_MAGIC), CGC_REGEX, CGCProjectConfiguration, 'i386'),
(default_magic, ELF32_REGEX, LinuxProjectConfiguration, 'i386'),
(default_magic, ELF64_REGEX, LinuxProjectConfiguration, 'x86_64'),
(default_magic, DLL32_REGEX, WindowsDLLProjectConfiguration, 'i386'),
(default_magic, DLL64_REGEX, WindowsDLLProjectConfiguration, 'x86_64'),
(default_magic, PE32_REGEX, WindowsProjectConfiguration, 'i386'),
(default_magic, PE64_REGEX, WindowsProjectConfiguration, 'x86_64'),
(default_magic, MSDOS_REGEX, WindowsProjectConfiguration, 'i386')
]
# Check the target program against the valid file types
for magic_check, regex, proj_config_class, arch in magic_checks:
magic = magic_check.from_file(target_path)
matches = regex.match(magic)
# If we find a match, create that project. The user instructions
# are returned
if matches:
options['target'] = target_path
options['target_arch'] = arch
return call_command(Project(proj_config_class), **options)
# Otherwise no valid file type was found
raise CommandError('%s is not a valid target for S2E analysis' %
target_path)
评论列表
文章目录