@@ -759,13 +759,11 @@ def inject(self, interest=None, nosleepskip=False):
759
759
bin_name = LOADER64_NAME
760
760
dll = CAPEMON64_NAME
761
761
bit_str = "64-bit"
762
- side_dll = SIDELOADER64_NAME
763
762
else :
764
763
ttd_name = TTD32_NAME
765
764
bin_name = LOADER32_NAME
766
765
dll = CAPEMON32_NAME
767
766
bit_str = "32-bit"
768
- side_dll = SIDELOADER32_NAME
769
767
770
768
bin_name = os .path .join (Path .cwd (), bin_name )
771
769
dll = os .path .join (Path .cwd (), dll )
@@ -790,15 +788,8 @@ def inject(self, interest=None, nosleepskip=False):
790
788
791
789
path = os .path .dirname (nt_path_to_dos_path_ansi (self .get_filepath ()))
792
790
793
- if self .detect_dll_sideloading (path ):
794
- try :
795
- copy (dll , os .path .join (path , "capemon.dll" ))
796
- copy (side_dll , os .path .join (path , "version.dll" ))
797
- copy (os .path .join (Path .cwd (), "dll" , f"{ self .pid } .ini" ), os .path .join (path , "config.ini" ))
798
- except OSError as e :
799
- log .error ("Failed to copy DLL: %s" , e )
800
- return False
801
- log .info ("%s DLL to sideload is %s, sideloader %s" , bit_str , os .path .join (path , "capemon.dll" ), os .path .join (path , "version.dll" ))
791
+ if self .detect_dll_sideloading (path ) and self .has_msimg32 (path ):
792
+ self .deploy_version_proxy (path )
802
793
return True
803
794
804
795
log .info ("%s DLL to inject is %s, loader %s" , bit_str , dll , bin_name )
@@ -865,3 +856,41 @@ def __str__(self):
865
856
"""Get a string representation of this process."""
866
857
image_name = self .get_image_name () or "???"
867
858
return f"<{ self .__class__ .__name__ } { self .pid } { image_name } >"
859
+
860
+ def has_msimg32 (self , directory_path : str ) -> bool :
861
+ """Check if msimg32.dll exists in directory"""
862
+ try :
863
+ return any (
864
+ f .name .lower () == "msimg32.dll"
865
+ for f in Path (directory_path ).glob ("*" )
866
+ if f .is_file ()
867
+ )
868
+ except (OSError , PermissionError ):
869
+ return False
870
+
871
+ def deploy_version_proxy (self , directory_path : str ):
872
+ """Deploy version.dll proxy loader"""
873
+ if self .is_64bit ():
874
+ dll = CAPEMON64_NAME
875
+ side_dll = SIDELOADER64_NAME
876
+ bit_str = "64-bit"
877
+ else :
878
+ dll = CAPEMON32_NAME
879
+ side_dll = SIDELOADER32_NAME
880
+ bit_str = "32-bit"
881
+
882
+ dll = os .path .join (Path .cwd (), dll )
883
+
884
+ if not os .path .exists (dll ):
885
+ log .warning ("invalid path %s for monitor DLL to be sideloaded in %s, sideloading aborted" , dll , self )
886
+ return
887
+
888
+ try :
889
+ copy (dll , os .path .join (directory_path , "capemon.dll" ))
890
+ copy (side_dll , os .path .join (directory_path , "version.dll" ))
891
+ copy (os .path .join (Path .cwd (), "dll" , f"{ self .pid } .ini" ), os .path .join (directory_path , "config.ini" ))
892
+ except OSError as e :
893
+ log .error ("Failed to copy DLL: %s" , e )
894
+ return
895
+ log .info ("%s DLL to sideload is %s, sideloader %s" , bit_str , os .path .join (directory_path , "capemon.dll" ), os .path .join (directory_path , "version.dll" ))
896
+ return
0 commit comments