Skip to content

Commit

Permalink
Merge pull request #702 from Johann-PLW/main
Browse files Browse the repository at this point in the history
Update ileapp.py - Synchronizing numbers of available modules with GUI
  • Loading branch information
Johann-PLW authored Mar 22, 2024
2 parents 290f511 + 1fc1dcb commit 4a65201
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
96 changes: 48 additions & 48 deletions ileapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,70 +43,66 @@ def validate_args(args):
raise argparse.ArgumentError(None, 'Unknown timezone! Run the program again.')


def create_profile(available_plugins, path):
available_parsers = []
for parser_data in available_plugins:
if parser_data.name != 'lastbuild' and parser_data.name != 'iTunesBackupInfo':
available_parsers.append((parser_data.category, parser_data.name))

available_parsers.sort()
parsers_in_profile = {}
def create_profile(plugins, path):
available_modules = [(module_data.category, module_data.name) for module_data in plugins]
available_modules.sort()
modules_in_profile = {}

user_choice = ''
print('--- iLEAPP Profile file creation ---\n')
instructions = 'You can type:\n'
instructions += ' - \'a\' to add or remove parsers in the profile file\n'
instructions += ' - \'l\' to display the list of all available parsers with their number\n'
instructions += ' - \'p\' to display the parsers added into the profile file\n'
instructions += ' - \'a\' to add or remove modules in the profile file\n'
instructions += ' - \'l\' to display the list of all available modules with their number\n'
instructions += ' - \'p\' to display the modules added into the profile file\n'
instructions += ' - \'q\' to quit and save\n'
while not user_choice:
print(instructions)
user_choice = input('Please enter your choice: ').lower()
print()
if user_choice == "l":
print('Available parsers:')
for number, available_plugin in enumerate(available_parsers):
print(number + 1, available_plugin)
print('Available modules:')
for number, available_module in enumerate(available_modules):
print(number + 1, available_module)
print()
user_choice = ''
elif user_choice == "p":
if parsers_in_profile:
for number, parser in parsers_in_profile.items():
print(number, parser)
if modules_in_profile:
for number, module in modules_in_profile.items():
print(number, module)
print()
else:
print('No parser added to the profile file\n')
print('No module added to the profile file\n')
user_choice = ''
elif user_choice == 'a':
parser_numbers = input('Enter the numbers of parsers, seperated by a comma, to add or remove in the profile file: ')
parser_numbers = parser_numbers.split(',')
parser_numbers = [parser_number.strip() for parser_number in parser_numbers]
for parser_number in parser_numbers:
if parser_number.isdigit():
parser_number = int(parser_number)
if parser_number > 0 and parser_number <= len(available_parsers):
if parser_number not in parsers_in_profile:
parser_to_add = available_parsers[parser_number - 1]
parsers_in_profile[parser_number] = parser_to_add
print(f'parser number {parser_number} {parser_to_add} was added')
modules_numbers = input('Enter the numbers of modules, seperated by a comma, to add or remove in the profile file: ')
modules_numbers = modules_numbers.split(',')
modules_numbers = [module_number.strip() for module_number in modules_numbers]
for module_number in modules_numbers:
if module_number.isdigit():
module_number = int(module_number)
if module_number > 0 and module_number <= len(available_modules):
if module_number not in modules_in_profile:
module_to_add = available_modules[module_number - 1]
modules_in_profile[module_number] = module_to_add
print(f'module number {module_number} {module_to_add} was added')
else:
parser_to_remove = parsers_in_profile[parser_number]
print(f'parser number {parser_number} {parser_to_remove} was removed')
del parsers_in_profile[parser_number]
parser_to_remove = modules_in_profile[module_number]
print(f'module number {module_number} {parser_to_remove} was removed')
del modules_in_profile[module_number]
else:
print('Please enter the number of a parser!!!\n')
print('Please enter the number of a module!!!\n')
print()
user_choice = ''
elif user_choice == "q":
if parsers_in_profile:
parsers = [parser_info[1] for parser_info in parsers_in_profile.values()]
if modules_in_profile:
modules = [module_info[1] for module_info in modules_in_profile.values()]
profile_filename = ''
while not profile_filename:
profile_filename = input('Enter the name of the profile: ')
profile_filename += '.ilprofile'
filename = os.path.join(path, profile_filename)
with open(filename, "wt", encoding="utf-8") as profile_file:
json.dump({"leapp": "ileapp", "format_version": 1, "plugins": parsers}, profile_file)
json.dump({"leapp": "ileapp", "format_version": 1, "plugins": modules}, profile_file)
print('\nProfile saved:', filename)
print()
else:
Expand Down Expand Up @@ -163,13 +159,16 @@ def main():
profile_filename = None
casedata = {}

# Move lastbuild plugin to first position
lastbuild_index = next((i for i, selected_plugin in enumerate(available_plugins)
if selected_plugin.name == 'lastbuild'), -1)
if lastbuild_index != -1:
available_plugins.insert(0, available_plugins.pop(lastbuild_index))
plugins = []
plugins_parsed_first = []

for plugin in available_plugins:
if plugin.name == 'lastbuild':
plugins_parsed_first.append(plugin)
elif plugin.name != 'iTunesBackupInfo':
plugins.append(plugin)

selected_plugins = available_plugins.copy()
selected_plugins = plugins.copy()

args = parser.parse_args()

Expand Down Expand Up @@ -208,7 +207,7 @@ def main():
create_choice = input('Please enter your choice: ').lower()
print()
if create_choice == '1':
create_profile(selected_plugins, args.create_profile_casedata)
create_profile(plugins, args.create_profile_casedata)
create_choice = ''
elif create_choice == '2':
create_casedata(args.create_profile_casedata)
Expand Down Expand Up @@ -265,10 +264,9 @@ def main():
print(profile_load_error)
return
else:
print(f'Profile loaded: {profile_filename}')
profile_plugins = set(profile.get("plugins", []))
selected_plugins = [selected_plugin for selected_plugin in available_plugins
if selected_plugin.name in profile_plugins or selected_plugin.name == 'lastbuild']
selected_plugins = [selected_plugin for selected_plugin in plugins
if selected_plugin.name in profile_plugins]
else:
profile_load_error = "File was not a valid profile file: invalid format"
print(profile_load_error)
Expand All @@ -287,8 +285,9 @@ def main():
if output_path[1] == ':': output_path = '\\\\?\\' + output_path.replace('/', '\\')

out_params = OutputParameters(output_path)
print(f"Info: {len(available_plugins)} plugins loaded.")

selected_plugins = plugins_parsed_first + selected_plugins

crunch_artifacts(selected_plugins, extracttype, input_path, out_params, wrap_text, loader, casedata, time_offset, profile_filename)


Expand Down Expand Up @@ -333,9 +332,10 @@ def crunch_artifacts(
return False

# Now ready to run
logfunc(f'Info: {len(loader) - 2} modules loaded.') # excluding lastbuild and iTunesBackupInfo
if profile_filename:
logfunc(f'Loaded profile: {profile_filename}')
logfunc(f'Artifact categories to parse: {len(plugins)}')
logfunc(f'Artifact categories to parse: {len(plugins) - 1}') # excluding lastbuild always executed first
logfunc(f'File/Directory selected: {input_path}')
logfunc('\n--------------------------------------------------------------------------------------')

Expand Down
1 change: 0 additions & 1 deletion ileappGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ def load_case():
v.grid(row=0, column=1, sticky='ns')
mlist_text = tk.Text(mlist_frame, name='tbox', bg=theme_bgcolor, highlightthickness=0,
yscrollcommand=v.set, height=mlist_window_height)
# mlist_text.pack(anchor='w')
mlist_text.grid(row=0, column=0, sticky='we')
v.config(command=mlist_text.yview)
for plugin, enabled in mlist.items():
Expand Down
2 changes: 1 addition & 1 deletion scripts/version_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

ileapp_version = '1.18.12'
ileapp_version = '1.19.1'

# Contributors List
# Format = [ Name, Blog-url, Twitter-handle, Github-url]
Expand Down

0 comments on commit 4a65201

Please sign in to comment.