Announcement: Python scripting platform to process file paths

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
vkl
Junior Member
Junior Member
Posts: 4
Joined: 2020-05-05, 15:12 UTC

Announcement: Python scripting platform to process file paths

Post by *vkl »

Hi. I want to introduce my open source Python scripting platform:

https://github.com/vikilpet/Taskopy

than can be used to process file paths from Total Commander.
Example task: Virustotal check and group renaming

Code: Select all

def from_total_commander_demo(
	submenu='demo'
	, hotkey='alt+f12'
	, hotkey_suppress=False
):
	time_sleep('10 ms')
	file_lst = clip_get().split('\r\n')
	ext = file_ext(file_lst[0]).lower()
	if ext in ('exe', 'msi'):
		# This is an executable file(s), so let's
		# calculate its hash and open links on Virustotal:
		for fname in file_lst:
			sha256 = file_hash(fname, 'sha-256')
			file_open(f'https://www.virustotal.com/gui/file/{sha256}')
	elif file_name(file_lst[0]).startswith('IMG_'):
		# This is a photo or video. Let's change the time format
		# and add a description:
		prefix = inputbox('Prefix:')
		if prefix == '': return
		pattern = r'(img|vid)_(\d\d\d\d)(\d\d)(\d\d)_(\d\d)(\d\d)(\d\d)'
		for fname in file_lst:
			new_name = re_replace(file_name(fname), pattern
			, r'_\2.\3.\4_\5-\6-\7')
			file_rename(fname, prefix + new_name)
Video: https://youtu.be/IAkXV_XJyfY
vkl
Junior Member
Junior Member
Posts: 4
Joined: 2020-05-05, 15:12 UTC

Re: Announcement: Python scripting platform to process file paths

Post by *vkl »

Replace your name in TC title with something useful

Code: Select all

def total_commander_title(schedule="every().minute", log=False, menu=False):
	TITLE_FORMAT = 'Total Commander  |  %A, %d %b'
	LOCALE = 'en'
	hwnd = window_get(class_name='TTOTAL_CMD')
	if not hwnd: return
	window_title_set(
		hwnd
		, time_now_str(TITLE_FORMAT, use_locale=LOCALE)
	)
I know, the idea is not new
vkl
Junior Member
Junior Member
Posts: 4
Joined: 2020-05-05, 15:12 UTC

Re: Announcement: Python scripting platform to process file paths

Post by *vkl »

Information from Virustotal via API:

Code: Select all

def virustotal_check(fullpath:str=None, caller:str='', submenu='demo'):
	# You can get a free API key
	# (500 requests per day and a rate of 4 requests per minute):
	# https://developers.virustotal.com/reference
	APIKEY = {'x-apikey':'Your API key'}
	if not fullpath:
		fullpath = file_dialog('Virustotal', wildcard='*.exe;*.msi')
		if not fullpath: return
	sha256 = file_hash(fullpath, 'sha-256')
	status, scan_data = safe(json_element)(
		'https://www.virustotal.com/api/v3/files/' + sha256
		, element=['data']
		, headers=APIKEY
	)
	if not status:
		tprint(scan_data)
		dialog('HTTP error', timeout=3)
		return
	# tdebug(scan_data)
	table = [['Anti-Virus', 'Result']]
	for av in scan_data['attributes']['last_analysis_results'].values():
		if not av['result']: continue
		table.append([ av['engine_name'], av['result'] ])
	if len(table) > 1: table_print(table, use_headers=True)
	last_stats = scan_data['attributes']['last_analysis_stats']
	choice = dialog(
		'Malicious: {}\nSuspicious: {}\nUndetected: {}'.format(
			last_stats['malicious']
			, last_stats['suspicious']
			, last_stats['undetected']
		)
		, buttons=['Open Virustotal', 'Cancel']
		, timeout=5
	)
	if choice == 1000:
		file_open(f'https://www.virustotal.com/gui/file/{sha256}')
Post Reply