Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

qzmech
Copy link

@qzmech qzmech commented May 15, 2023

Hello Team!

Injected has been redesigned to become a separate PyPi package.

Check out the following changes:

  1. Added cmake assembly for 32 and 64-bit platforms.
  2. Added copying DLLs to package root before creating PyPi wheel.
  3. Package name for PyPi: injectdll
  4. Redesigned code to meet PEP requirements
  5. New README (draft)
  6. License text updated

qzmech added 3 commits May 12, 2023 13:04
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
@qzmech qzmech requested a review from vasily-v-ryabov May 15, 2023 00:40
backends/dotnet/CMakeLists.txt Outdated Show resolved Hide resolved
backends/hook/CMakeLists.txt Outdated Show resolved Hide resolved
injectdll/api.py Show resolved Hide resolved
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',
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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!"

Copy link
Author

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.
Copy link
Contributor

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).

Copy link
Author

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\>
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Contributor

@eltimen eltimen May 29, 2023

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")
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

@eltimen eltimen May 28, 2023

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:

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})

Copy link
Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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']
Copy link
Contributor

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

Copy link
Author

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.

Comment on lines +59 to +60
subprocess.check_call(['cmake', '-B ' + build_dir, '-S ' + cmake_dir, '-A ' + arch])
subprocess.check_call(['cmake', '--build', build_dir])
Copy link
Contributor

@eltimen eltimen May 28, 2023

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.

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants