@@ -68,13 +68,8 @@ def group_by_subroutines(
6868 return raw_result
6969
7070
71- def extract_strings_grouped_by_subs (pe_file : BufferedReader ) -> dict [Rva , list [StringCrossReference ]]:
72- pe = lief .PE .parse (pe_file )
73- assert pe is not None
71+ def extract_strings_grouped_by_subs (pe : lief .PE .Binary ) -> dict [SubroutineInfo , list [StringCrossReference ]]:
7472 code_section = pe .sections [0 ]
75-
76- image_base = pe .optional_header .imagebase
77-
7873 strings_with_xrefs = extract_strings_with_xrefs (pe )
7974
8075 subroutines = list (
@@ -89,10 +84,10 @@ def extract_strings_grouped_by_subs(pe_file: BufferedReader) -> dict[Rva, list[S
8984
9085 raw_result = group_by_subroutines (strings_with_xrefs , subroutines )
9186
92- result : dict [Rva , list [StringCrossReference ]] = {}
87+ result : dict [SubroutineInfo , list [StringCrossReference ]] = {}
9388 for subroutine , string_xrefs in sorted (raw_result .items (), key = itemgetter (0 )):
9489 sorted_xrefs = sorted (string_xrefs , key = lambda x : x .cross_reference )
95- result [Rva ( image_base + subroutine . start ) ] = sorted_xrefs
90+ result [subroutine ] = sorted_xrefs
9691
9792 return result
9893
@@ -106,8 +101,12 @@ class ExtractConfig(DictConfig):
106101@with_config (ExtractConfig , ".extract.yaml" )
107102def main (conf : ExtractConfig ) -> None :
108103 with Path (conf .file_name ).open ("rb" ) as pe_file :
109- for subroutine , strings in extract_strings_grouped_by_subs (pe_file ).items ():
110- print (f"[sub_{ subroutine :x} ]" )
104+ pe = lief .PE .parse (pe_file )
105+ assert pe is not None
106+
107+ image_base = pe .optional_header .imagebase
108+ for subroutine , strings in extract_strings_grouped_by_subs (pe ).items ():
109+ print (f"[sub_{ image_base + subroutine .start :x} ]" )
111110 for string in strings :
112111 print (string .string )
113112
0 commit comments