@@ -7029,3 +7029,84 @@ def render_jinja_template(data_set):
70297029 except Exception :
70307030 # Handle exceptions
70317031 return CommonUtil .Exception_Handler (sys .exc_info ())
7032+
7033+
7034+ @logger
7035+ def download_chrome_extension (data_set ):
7036+ """
7037+ This function downloads a Chrome extension CRX file using the extension ID
7038+
7039+ Args:
7040+ data_set:
7041+ ------------------------------------------------------------------------------
7042+ extension id | input parameter | jhbgaabkbcfjgjldjeddmofchgpjlhnj
7043+ download directory | input parameter | C:/Downloads
7044+ download chrome extension | common action | result
7045+ ------------------------------------------------------------------------------
7046+
7047+ Return:
7048+ `passed` if success
7049+ `zeuz_failed` if fails
7050+ """
7051+ sModuleInfo = inspect .currentframe ().f_code .co_name + " : " + MODULE_NAME
7052+
7053+ try :
7054+ extension_id = None
7055+ download_dir = None
7056+
7057+ for left , mid , right in data_set :
7058+ left = left .strip ().lower ()
7059+ if "extension id" == left :
7060+ extension_id = right .strip ()
7061+ if "download directory" == left :
7062+ download_dir = CommonUtil .path_parser (right .strip ())
7063+
7064+ if extension_id is None :
7065+ CommonUtil .ExecLog (sModuleInfo , "Please provide the extension ID" , 3 )
7066+ return "zeuz_failed"
7067+
7068+ if download_dir is None :
7069+ download_dir = sr .Get_Shared_Variables ("zeuz_download_folder" )
7070+ CommonUtil .ExecLog (sModuleInfo , f"Using default download directory: { download_dir } " , 1 )
7071+
7072+ # Make sure the download directory exists
7073+ os .makedirs (download_dir , exist_ok = True )
7074+
7075+ # Get the CRX download link
7076+ url = "https://www.crx4chrome.com/crx-url.php"
7077+ headers = {
7078+ "Referer" : f"https://www.crx4chrome.com/crx-downloader/{ extension_id } " ,
7079+ }
7080+ data = {"id" : extension_id }
7081+
7082+ CommonUtil .ExecLog (sModuleInfo , f"Requesting download link for extension ID: { extension_id } " , 1 )
7083+ response = requests .post (url , headers = headers , data = data , verify = False )
7084+
7085+ if response .status_code != 200 :
7086+ CommonUtil .ExecLog (sModuleInfo , f"Failed to get download link. Status code: { response .status_code } " , 3 )
7087+ return "zeuz_failed"
7088+
7089+ match = re .search (r'href="(https://clients2\.googleusercontent\.com/crx/blobs/[^\"]+\.crx)"' , response .text )
7090+ if not match or not match .group (1 ).startswith ("http" ):
7091+ CommonUtil .ExecLog (sModuleInfo , f"Invalid download link received: { match .group (1 )} " , 3 )
7092+ return "zeuz_failed"
7093+
7094+ download_link = match .group (1 )
7095+
7096+ # Download the CRX file
7097+ CommonUtil .ExecLog (sModuleInfo , f"Downloading extension from: { download_link } " , 1 )
7098+ crx_filename = f"{ extension_id } .crx"
7099+ crx_path = os .path .join (download_dir , crx_filename )
7100+
7101+ with requests .get (download_link , stream = True , verify = False ) as r :
7102+ r .raise_for_status ()
7103+ with open (crx_path , 'wb' ) as f :
7104+ for chunk in r .iter_content (chunk_size = 8192 ):
7105+ f .write (chunk )
7106+
7107+ CommonUtil .ExecLog (sModuleInfo , f"Extension downloaded successfully to: { crx_path } " , 1 )
7108+ return "passed"
7109+
7110+ except Exception :
7111+ return CommonUtil .Exception_Handler (sys .exc_info ())
7112+
0 commit comments