-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Injected becomes a separate package #9
base: master
Are you sure you want to change the base?
Conversation
Changes: 1) Created a new "injectdll" package 2) Formatted all *.py modules from the package 3) Refactoring CMakeLists.txt (fixed some paths to source files) 4) Created setup.py to generate Wheel on local computer (includes: build cmake for DLL (dotnet, hooks), copy to package directory after build) 5) Fixed license text
Changes: 1) New README 2) Cmake build for 32 and 64-bit platform
description='A set of Python modules to inject DLls into applications for the Microsoft Windows', | ||
keywords="windows gui .net inject testing test desktop dll wpf", | ||
url="https://github.com/pywinauto/injected", | ||
author='Mark Mc Mahon and Contributors', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark didn't participate in injectdll development, but I need to carefully review the code one more time to check if there is some code written by him a long time ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest use "(C) 2018-2023 Vasily Ryabov and NNSU (Lobachevsky University) students" instead current version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for file headers. Of course author
field should omit (C) and years.
raise RuntimeError("Application and Python must be both 32-bit or both 64-bit") | ||
self.h_process = self._get_process_handle(self.pid) | ||
|
||
self.dll_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), | ||
'backends', backend_name, | ||
'bin', 'x{}'.format("64" if is64bitprocess(self.pid) else "86"), | ||
'../libs', backend_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use os.path.dirname(...)
than using ../
which may be platform specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will be fixed in next commits
## Development | ||
|
||
1. Clone repository: <https://github.com/pywinauto/injected.git> | ||
2. Create new features or improve exiting (for the injectdll package) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: exiting -> existing, but I would completely remove all "Development" steps or write "Issues and pull requests are welcome!"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will be fixed in next commits
author='Mark Mc Mahon and Contributors', | ||
author_email='pywinauto@yandex.ru', | ||
long_description=""" | ||
It allows to inject DLls into applications for the Microsoft Windows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DLls -> DLLs, or even suggest this:
This package can inject pre-built dynamic library into the target process and get some data from the application or do some actions (it depends on a used backend/library).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will be fixed in next commits
|
||
## How to use | ||
|
||
python.exe example_injector.py \<Process name\> \<path to dll\> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script example_injector.py
was removed
@@ -0,0 +1,14 @@ | |||
include injectdll/libs/dotnet/x86/bootstrap.dll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also remove *.dll files in this folder: https://github.com/pywinauto/injected/tree/master/backends/dotnet/bin
These files will not be needed after the injectdll wheels is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, It will be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this point. Is this manifest not used for building wheels by setup.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This manifest is OK, I meant that the pre-built DLLs in the bin folders will no longer be needed after merging this PR and having wheels.
@@ -9,7 +9,7 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) | |||
set(CMAKE_CSharp_FLAGS "/platform:x86") | |||
endif() | |||
|
|||
set(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION "v4.0") | |||
set(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION "v4.8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you increase the target .NET version?
In this case a subset of programs built with .NET Framework versions 4.0-4.8 will not be supported by this backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While debugging, I couldn't use .NET Target Framework v4.0 (I already have v 4.8. and .NET doesn't let me roll back the Framework version).
It will be fixed in the next commits.
return self._pipes[pid] | ||
|
||
def _create_pipe(self, pid): | ||
pipe_name = 'process_{}'.format(pid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to change the name of pipe, you also need to change it on the backend side here:
injected/backends/dotnet/src/wpf/Main.cs
Line 16 in a7eee0e
using (NamedPipeServerStream pipeServer = new NamedPipeServerStream(String.Format("pywinauto_{0}", pid), PipeDirection.InOut, 1, PipeTransmissionMode.Message)) |
Note: prefix
pywinauto_
looks better for me, because it is less ambiguous and avoids possible conflicts with other applications (for example, some other process may want to create pipe with name process_{PID}
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vasily-v-ryabov suggested removing all mention of the pywinauto project.
Maybe I should use injectdll_
instead, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I remember, I suggested using 2 PIDs in a pipe name: Python process and target process. Also I'd suggest adding a text param for the part of the name. For example, pywinauto will name this pipe "pywinauto_{py_pid}_{target_pid}"
, other lib or app can assign another text part of the name. It should make the pipe name 100% unique.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most important thing is to specify the same pipe name on the client and server sides, otherwise this code will not work :)
reply = json.loads(reply) | ||
|
||
reply_code = reply['status_code'] | ||
reply_message = reply['message'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message
is optional field of JSON reply, so this code can raise a KeyError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be fixed in the next commits.
subprocess.check_call(['cmake', '-B ' + build_dir, '-S ' + cmake_dir, '-A ' + arch]) | ||
subprocess.check_call(['cmake', '--build', build_dir]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMake build DLLs in Debug mode here. I think it will be better to build it in Release (or RelWithDebInfo?) mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be fixed in the next commits.
Hello Team!
Injected has been redesigned to become a separate PyPi package.
Check out the following changes: