77
88from htpclient .config import Config
99from htpclient .download import Download
10+ from htpclient .helpers import retrieve_binary
1011from htpclient .initialize import Initialize
1112from htpclient .jsonRequest import JsonRequest
1213from htpclient .dicts import *
@@ -63,7 +64,7 @@ def check_client_version(self):
6364
6465 def __check_utils (self ):
6566 path = '7zr' + Initialize .get_os_extension ()
66- if not os . path . isfile (path ):
67+ if not retrieve_binary (path ):
6768 query = copy_and_set_token (dict_downloadBinary , self .config .get_value ('token' ))
6869 query ['type' ] = '7zr'
6970 req = JsonRequest (query )
@@ -80,7 +81,7 @@ def __check_utils(self):
8081 Download .download (ans ['executable' ], path )
8182 os .chmod (path , os .stat (path ).st_mode | stat .S_IEXEC )
8283 path = 'uftpd' + Initialize .get_os_extension ()
83- if not os . path . isfile (path ) and self .config .get_value ('multicast' ):
84+ if not retrieve_binary (path ) and self .config .get_value ('multicast' ):
8485 query = copy_and_set_token (dict_downloadBinary , self .config .get_value ('token' ))
8586 query ['type' ] = 'uftpd'
8687 req = JsonRequest (query )
@@ -121,10 +122,11 @@ def check_prince(self):
121122 logging .error ("Download of prince failed!" )
122123 sleep (5 )
123124 return False
124- if Initialize .get_os () == 1 :
125- os .system ("7zr" + Initialize .get_os_extension () + " x -otemp prince.7z" )
126- else :
127- os .system ("./7zr" + Initialize .get_os_extension () + " x -otemp prince.7z" )
125+ zr_bin = retrieve_binary ("7zr" + Initialize .get_os_extension ())
126+ if not zr_bin :
127+ logging .error ("7zr not found, cannot extract archive" )
128+ return False
129+ os .system (zr_bin + " x -otemp prince.7z" )
128130 for name in os .listdir ("temp" ): # this part needs to be done because it is compressed with the main subfolder of prince
129131 if os .path .isdir ("temp/" + name ):
130132 os .rename ("temp/" + name , "prince" )
@@ -160,10 +162,11 @@ def check_preprocessor(self, task):
160162 logging .error ("Download of preprocessor failed!" )
161163 sleep (5 )
162164 return False
163- if Initialize .get_os () == 1 :
164- os .system (f"7zr{ Initialize .get_os_extension ()} x -otemp temp.7z" )
165- else :
166- os .system (f"./7zr{ Initialize .get_os_extension ()} x -otemp temp.7z" )
165+ zr_bin = retrieve_binary ("7zr" + Initialize .get_os_extension ())
166+ if not zr_bin :
167+ logging .error ("7zr not found, cannot extract archive" )
168+ return False
169+ os .system (f"{ zr_bin } x -otemp temp.7z" )
167170 for name in os .listdir ("temp" ): # this part needs to be done because it is compressed with the main subfolder of prince
168171 if os .path .isdir (Path ('temp' , name )):
169172 os .rename (Path ('temp' , name ), path )
@@ -200,13 +203,12 @@ def check_version(self, cracker_id):
200203 # we need to extract the 7zip
201204 temp_folder = Path (self .config .get_value ('crackers-path' ), 'temp' )
202205 zip_file = Path (self .config .get_value ('crackers-path' ), f'{ cracker_id } .7z' )
203-
204- if Initialize .get_os () == 1 :
205- # Windows
206- cmd = f'7zr{ Initialize .get_os_extension ()} x -o"{ temp_folder } " "{ zip_file } "'
207- else :
208- # Linux
209- cmd = f"./7zr{ Initialize .get_os_extension ()} x -o'{ temp_folder } ' '{ zip_file } '"
206+ zr_bin = retrieve_binary ("7zr" + Initialize .get_os_extension ())
207+ if not zr_bin :
208+ logging .error ("7zr not found, cannot extract archive" )
209+ sleep (5 )
210+ return False
211+ cmd = f'{ zr_bin } x -o"{ temp_folder } " "{ zip_file } "'
210212 os .system (cmd )
211213
212214 # Clean up 7zip
0 commit comments