srounet / Pymem

A python library for windows, providing the needed functions to start working on your own with memory editing.
MIT License
303 stars 45 forks source link

Fixed issue with inject_dll function failing when injecting DLLs with non-ANSI characters in path #139

Closed dream2333 closed 1 week ago

dream2333 commented 2 weeks ago

The inject_dll_from_path function allows injecting a DLL into an opened process using the Unicode version of LoadLibrary (LoadLibraryW). This function supports paths containing non-ASCII characters and provides better compatibility with the latest version of the library.

The new function replaces the inject_dll function, which used the ANSI version of LoadLibrary (LoadLibraryA). The LoadLibraryA function's handling of path names is tied to the system's ANSI code page, making it unreliable for paths with non-English characters due to dependency on the current ANSI code page settings. This can result in failure to load DLLs if the path contains non-English characters.

Changing the system's locale to adjust the ANSI code page for non-English character support is possible but not recommended, as it impacts the entire system and could negatively affect other non-Unicode applications.

The optimal approach is to use LoadLibraryW, which supports UTF-16 encoded strings, ensuring compatibility with all Unicode characters.