1212from contextlib import suppress
1313from functools import partial
1414from os import path
15- from typing import List , Optional , Protocol
15+ from typing import Any , List , Optional , Protocol
1616
1717from extract_utils .elf import file_needs_lib
1818from extract_utils .file import File
@@ -50,15 +50,21 @@ def __call__(
5050 ctx : BlobFixupCtx ,
5151 file : File ,
5252 file_path : str ,
53- * args ,
53+ * args : Any ,
5454 tmp_dir : Optional [str ] = None ,
55- ** kwargs ,
55+ ** kwargs : Any ,
5656 ): ...
5757
5858
5959class blob_fixup :
6060 def __init__ (self ):
61- self .__functions : List [tuple [blob_fixup_fn_impl_type , tuple , dict ]] = []
61+ self .__functions : List [
62+ tuple [
63+ blob_fixup_fn_impl_type ,
64+ tuple [blob_fixup_fn_impl_type ],
65+ dict [str , blob_fixup_fn_impl_type ],
66+ ]
67+ ] = []
6268 self .__create_tmp_dir = False
6369
6470 self .__patchelf_path = patchelf_version_path_map [
@@ -68,9 +74,9 @@ def __init__(self):
6874 def call (
6975 self ,
7076 fn : blob_fixup_fn_impl_type ,
71- * args ,
72- need_tmp_dir = True ,
73- ** kwargs ,
77+ * args : Any ,
78+ need_tmp_dir : bool = True ,
79+ ** kwargs : Any ,
7480 ) -> blob_fixup :
7581 self .__functions .append ((fn , args , kwargs ))
7682 if need_tmp_dir :
@@ -88,8 +94,8 @@ def replace_needed_impl(
8894 ctx : BlobFixupCtx ,
8995 file : File ,
9096 file_path : str ,
91- * args ,
92- ** kwargs ,
97+ * args : Any ,
98+ ** kwargs : Any ,
9399 ):
94100 run_cmd (
95101 [
@@ -120,8 +126,8 @@ def add_needed_impl(
120126 ctx : BlobFixupCtx ,
121127 file : File ,
122128 file_path : str ,
123- * args ,
124- ** kwargs ,
129+ * args : Any ,
130+ ** kwargs : Any ,
125131 ):
126132 if file_needs_lib (file_path , lib ):
127133 return
@@ -138,8 +144,8 @@ def remove_needed_impl(
138144 ctx : BlobFixupCtx ,
139145 file : File ,
140146 file_path : str ,
141- * args ,
142- ** kwargs ,
147+ * args : Any ,
148+ ** kwargs : Any ,
143149 ):
144150 run_cmd ([self .__patchelf_path , '--remove-needed' , lib , file_path ])
145151
@@ -153,8 +159,8 @@ def clear_symbol_version_impl(
153159 ctx : BlobFixupCtx ,
154160 file : File ,
155161 file_path : str ,
156- * args ,
157- ** kwargs ,
162+ * args : Any ,
163+ ** kwargs : Any ,
158164 ):
159165 run_cmd (
160166 [self .__patchelf_path , '--clear-symbol-version' , symbol , file_path ]
@@ -165,7 +171,12 @@ def clear_symbol_version(self, symbol: str) -> blob_fixup:
165171 return self .call (impl )
166172
167173 def fix_soname_impl (
168- self , ctx : BlobFixupCtx , file : File , file_path : str , * args , ** kwargs
174+ self ,
175+ ctx : BlobFixupCtx ,
176+ file : File ,
177+ file_path : str ,
178+ * args : Any ,
179+ ** kwargs : Any ,
169180 ):
170181 run_cmd (
171182 [self .__patchelf_path , '--set-soname' , file .basename , file_path ]
@@ -182,7 +193,7 @@ def __get_patches(self, ctx: BlobFixupCtx, module_patches_path: str):
182193
183194 assert path .isdir (patches_path )
184195
185- patches = []
196+ patches : List [ str ] = []
186197 for f in os .scandir (patches_path ):
187198 if f .name .endswith ('.patch' ):
188199 patches .append (f .path )
@@ -196,7 +207,7 @@ def __get_patch_affected_files(self, patch: str) -> List[str]:
196207 ['git' , '--work-tree' , os .devnull , 'apply' , '--numstat' , patch ]
197208 )
198209
199- files = []
210+ files : List [ str ] = []
200211 for line in output .strip ().splitlines ():
201212 parts = line .split ('\t ' )
202213 if len (parts ) != 3 :
@@ -208,7 +219,7 @@ def __get_patch_affected_files(self, patch: str) -> List[str]:
208219 return files
209220
210221 def __get_patches_affected_files (self , patches : List [str ]) -> List [str ]:
211- affected_files = []
222+ affected_files : List [ str ] = []
212223 for patch in patches :
213224 affected_files += self .__get_patch_affected_files (patch )
214225 return affected_files
@@ -234,7 +245,7 @@ def __get_apktool_unpack_args(
234245 if affected_file == APKTOOL_ANDROID_MANIFEST_NAME :
235246 decode_manifest = True
236247
237- unpack_args = []
248+ unpack_args : List [ str ] = []
238249 if not decode_res and not decode_manifest :
239250 unpack_args .append (APKTOOL_NO_RES_ARG )
240251
@@ -249,9 +260,9 @@ def patch_impl(
249260 ctx : BlobFixupCtx ,
250261 file : File ,
251262 file_path : str ,
252- * args ,
253- tmp_dir = None ,
254- ** kwargs ,
263+ * args : Any ,
264+ tmp_dir : Optional [ str ] = None ,
265+ ** kwargs : Any ,
255266 ):
256267 patches = self .__get_patches (ctx , patches_path )
257268 assert tmp_dir is not None
@@ -311,9 +322,9 @@ def copy_file_to_tmp_impl(
311322 ctx : BlobFixupCtx ,
312323 file : File ,
313324 file_path : str ,
314- * args ,
315- tmp_dir = None ,
316- ** kwargs ,
325+ * args : Any ,
326+ tmp_dir : Optional [ str ] = None ,
327+ ** kwargs : Any ,
317328 ):
318329 assert tmp_dir is not None
319330 shutil .copy (file_path , tmp_dir )
@@ -326,9 +337,9 @@ def copy_file_from_tmp_impl(
326337 ctx : BlobFixupCtx ,
327338 file : File ,
328339 file_path : str ,
329- * args ,
330- tmp_dir = None ,
331- ** kwargs ,
340+ * args : Any ,
341+ tmp_dir : Optional [ str ] = None ,
342+ ** kwargs : Any ,
332343 ):
333344 assert tmp_dir is not None
334345 tmp_file_path = path .join (tmp_dir , file .basename )
@@ -348,10 +359,10 @@ def apktool_unpack_impl(
348359 ctx : BlobFixupCtx ,
349360 file : File ,
350361 file_path : str ,
351- * args ,
352- tmp_dir = None ,
353- patches_path : Optional [str ] = None ,
354- ** kwargs ,
362+ * args : Any ,
363+ patches_path : str ,
364+ tmp_dir : Optional [str ] = None ,
365+ ** kwargs : Any ,
355366 ):
356367 assert tmp_dir is not None
357368
@@ -373,7 +384,7 @@ def apktool_unpack_impl(
373384
374385 def apktool_unpack (
375386 self ,
376- patches_path : Optional [ str ] = None ,
387+ patches_path : str ,
377388 ) -> blob_fixup :
378389 impl = partial (
379390 self .apktool_unpack_impl ,
@@ -386,9 +397,9 @@ def apktool_pack_impl(
386397 ctx : BlobFixupCtx ,
387398 file : File ,
388399 file_path : str ,
389- * args ,
390- tmp_dir = None ,
391- ** kwargs ,
400+ * args : Any ,
401+ tmp_dir : Optional [ str ] = None ,
402+ ** kwargs : Any ,
392403 ):
393404 assert tmp_dir is not None
394405
@@ -408,7 +419,12 @@ def apktool_pack(self) -> blob_fixup:
408419 return self .call (self .apktool_pack_impl , need_tmp_dir = True )
409420
410421 def stripzip_impl (
411- self , ctx : BlobFixupCtx , file : File , file_path : str , * args , ** kwargs
422+ self ,
423+ ctx : BlobFixupCtx ,
424+ file : File ,
425+ file_path : str ,
426+ * args : Any ,
427+ ** kwargs : Any ,
412428 ):
413429 run_cmd (
414430 [
@@ -420,21 +436,30 @@ def stripzip_impl(
420436 def stripzip (self ):
421437 return self .call (self .stripzip_impl )
422438
423- def apktool_patch (self , patches_path : str , * args ) -> blob_fixup :
439+ def apktool_patch (
440+ self ,
441+ patches_path : str ,
442+ * args : Any ,
443+ ) -> blob_fixup :
424444 if args :
425445 color_print (
426446 'apktool_patch() no longer takes custom arguments' ,
427447 color = Color .YELLOW ,
428448 )
429449
430- self .apktool_unpack (patches_path = patches_path )
450+ self .apktool_unpack (patches_path )
431451 self .patch_dir (patches_path )
432452 self .apktool_pack ()
433453 self .stripzip ()
434454 return self
435455
436456 def strip_debug_sections_impl (
437- self , ctx : BlobFixupCtx , file : File , file_path : str , * args , ** kwargs
457+ self ,
458+ ctx : BlobFixupCtx ,
459+ file : File ,
460+ file_path : str ,
461+ * args : Any ,
462+ ** kwargs : Any ,
438463 ):
439464 run_cmd (
440465 [
@@ -454,8 +479,8 @@ def regex_replace_impl(
454479 ctx : BlobFixupCtx ,
455480 file : File ,
456481 file_path : str ,
457- * args ,
458- ** kwargs ,
482+ * args : Any ,
483+ ** kwargs : Any ,
459484 ):
460485 with open (file_path , 'r' , newline = '' , encoding = 'utf-8' ) as f :
461486 data = f .read ()
@@ -476,8 +501,8 @@ def binary_regex_replace_impl(
476501 ctx : BlobFixupCtx ,
477502 file : File ,
478503 file_path : str ,
479- * args ,
480- ** kwargs ,
504+ * args : Any ,
505+ ** kwargs : Any ,
481506 ):
482507 with open (file_path , 'rb' ) as f :
483508 data = f .read ()
@@ -498,8 +523,8 @@ def sig_replace_impl(
498523 ctx : BlobFixupCtx ,
499524 file : File ,
500525 file_path : str ,
501- * args ,
502- ** kwargs ,
526+ * args : Any ,
527+ ** kwargs : Any ,
503528 ):
504529 with open (file_path , 'rb+' ) as f :
505530 data = f .read ()
@@ -532,8 +557,8 @@ def fix_xml_impl(
532557 ctx : BlobFixupCtx ,
533558 file : File ,
534559 file_path : str ,
535- * args ,
536- ** kwargs ,
560+ * args : Any ,
561+ ** kwargs : Any ,
537562 ):
538563 lines : list [str ] = []
539564 with open (file_path , 'r' , newline = '' , encoding = 'utf-8' ) as f :
@@ -556,8 +581,8 @@ def add_line_if_missing_impl(
556581 ctx : BlobFixupCtx ,
557582 file : File ,
558583 file_path : str ,
559- * args ,
560- ** kwargs ,
584+ * args : Any ,
585+ ** kwargs : Any ,
561586 ):
562587 with open (file_path , 'r+' , newline = '' , encoding = 'utf-8' ) as f :
563588 data = f .read ()
0 commit comments