├── .DS_Store
├── .github
└── workflows
│ ├── build.yml
│ └── build.zip
├── .gitignore
├── .idea
├── .gitignore
├── RemoteInput.iml
├── misc.xml
├── modules.xml
└── vcs.xml
├── CMakeLists.txt
├── README.md
├── RemoteInput.cbp
├── RemoteInput.depend
├── RemoteInput.layout
├── RemoteInput.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
│ └── xcuserdata
│ │ └── brandonanthony.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
├── xcshareddata
│ └── xcschemes
│ │ ├── RemoteInputBootstrap.xcscheme
│ │ └── libRemoteInput.xcscheme
└── xcuserdata
│ └── brandonanthony.xcuserdatad
│ └── xcschemes
│ └── xcschememanagement.plist
├── RemoteInput
├── .idea
│ ├── .gitignore
│ ├── RemoteInput.iml
│ ├── misc.xml
│ ├── modules.xml
│ └── vcs.xml
├── DetachedThreadPool.cxx
├── DetachedThreadPool.hxx
├── EIOS.cxx
├── EIOS.hxx
├── EIOSTypes.hxx
├── Echo
│ ├── Atomics.cxx
│ ├── Atomics.hxx
│ ├── Event.cxx
│ ├── Event.hxx
│ ├── MemoryMap.cxx
│ ├── MemoryMap.hxx
│ ├── MemoryMapStream.hxx
│ ├── Module.cxx
│ ├── Module.hxx
│ ├── Mutex.cxx
│ ├── Mutex.hxx
│ ├── Semaphore.cxx
│ ├── Semaphore.hxx
│ ├── Stream.cxx
│ ├── Stream.hxx
│ ├── Synchronization.hxx
│ ├── Time.cxx
│ ├── Time.hxx
│ ├── TypeTraits.hxx
│ ├── TypeTraits_Functional.hxx
│ └── TypeTraits_Functional_Attributes.hxx
├── Hooks
│ ├── ModelRendering.cxx
│ └── ModelRendering.hxx
├── Info.plist
├── Injection
│ ├── Injector.hxx
│ ├── Injector_Arm.cpp
│ ├── Injector_Darwin.cxx
│ ├── Injector_Linux.cpp
│ └── Injector_Windows.cxx
├── JVM.cxx
├── JVM.hxx
├── Java
│ ├── AWTAccessor.cxx
│ ├── AWTAccessor.hxx
│ ├── AWTEvent.cxx
│ ├── AWTEvent.hxx
│ ├── AWTEventAccessor.cxx
│ ├── AWTEventAccessor.hxx
│ ├── Applet.cxx
│ ├── Applet.hxx
│ ├── Component.cxx
│ ├── Component.hxx
│ ├── Container.cxx
│ ├── Container.hxx
│ ├── EventQueue.cxx
│ ├── EventQueue.hxx
│ ├── FocusEvent.cxx
│ ├── FocusEvent.hxx
│ ├── Frame.cxx
│ ├── Frame.hxx
│ ├── InputEvent.cxx
│ ├── InputEvent.hxx
│ ├── JNI_Common.hxx
│ ├── KeyEvent.cxx
│ ├── KeyEvent.hxx
│ ├── MouseEvent.cxx
│ ├── MouseEvent.hxx
│ ├── MouseWheelEvent.cxx
│ ├── MouseWheelEvent.hxx
│ ├── PointerInfo.cxx
│ ├── PointerInfo.hxx
│ ├── RIEventQueue.cxx
│ ├── RIEventQueue.hxx
│ ├── SunToolkit.cxx
│ ├── SunToolkit.hxx
│ ├── Toolkit.cxx
│ ├── Toolkit.hxx
│ ├── Window.cxx
│ ├── Window.hxx
│ ├── WindowEvent.cxx
│ └── WindowEvent.hxx
├── Platform
│ ├── DebugConsole.cxx
│ ├── DebugConsole.hxx
│ ├── JavaInternal.hxx
│ ├── NativeHooks.hxx
│ ├── NativeHooks_Darwin.cxx
│ ├── NativeHooks_Linux.cxx
│ ├── NativeHooks_Windows.cxx
│ ├── Platform.hxx
│ ├── Platform_Darwin.mm
│ ├── Platform_Linux.cxx
│ ├── Platform_Windows.cxx
│ └── RemoteInputBootstrap_Darwin.cxx
├── Plugin
│ ├── ControlCenter.cxx
│ ├── ControlCenter.hxx
│ ├── Graphics.cxx
│ ├── Graphics.hxx
│ ├── ImageData.cxx
│ ├── ImageData.hxx
│ ├── InputOutput.cxx
│ ├── InputOutput.hxx
│ ├── JVM
│ │ ├── JVMCache.cxx
│ │ ├── JVMCache.hxx
│ │ ├── RemoteVM.cxx
│ │ └── RemoteVM.hxx
│ ├── NativePlugin.cxx
│ ├── NativePlugin.hxx
│ ├── Plugin.cxx
│ ├── Plugin.hxx
│ ├── Python
│ │ ├── Python.cxx
│ │ ├── Python.hxx
│ │ ├── PythonCommon.cxx
│ │ ├── PythonCommon.hxx
│ │ ├── PythonCommon_Templates.hxx
│ │ ├── PythonEIOS.cxx
│ │ ├── PythonEIOS.hxx
│ │ ├── PythonJavaArray.cxx
│ │ ├── PythonJavaArray.hxx
│ │ ├── PythonJavaList.cxx
│ │ ├── PythonJavaList.hxx
│ │ ├── PythonJavaObject.cxx
│ │ ├── PythonJavaObject.hxx
│ │ ├── PythonMacros.hxx
│ │ ├── PythonPlugin.cxx
│ │ └── PythonPlugin.hxx
│ ├── Signal.hxx
│ ├── SimbaPlugin.cxx
│ ├── SimbaPlugin.hxx
│ └── TMemoryManager.hxx
├── Random.cxx
├── Random.hxx
├── Reflection.cxx
├── Reflection.hxx
├── ReflectionHook.cxx
├── ReflectionHook.hxx
├── RemoteInput.def
├── RemoteInput.h
├── Thirdparty
│ ├── CMakeLists.txt
│ ├── Hook.cxx
│ ├── Hook.hxx
│ ├── Injector.cxx
│ ├── Injector.hxx
│ ├── kubo_injector
│ │ ├── LICENSE_GPL.txt
│ │ ├── LICENSE_LGPL.txt
│ │ ├── README.md
│ │ ├── include
│ │ │ └── injector.h
│ │ └── src
│ │ │ ├── linux
│ │ │ ├── elf.c
│ │ │ ├── injector.c
│ │ │ ├── injector_internal.h
│ │ │ ├── ptrace.c
│ │ │ ├── remote_call.c
│ │ │ ├── shellcode.S
│ │ │ └── util.c
│ │ │ ├── macos
│ │ │ ├── exc_handler.c
│ │ │ ├── injector.c
│ │ │ ├── injector_internal.h
│ │ │ ├── mach.c
│ │ │ ├── mach_exc.h
│ │ │ ├── mach_excServer.c
│ │ │ ├── ptrace.c
│ │ │ ├── remote_call.c
│ │ │ └── util.c
│ │ │ └── windows
│ │ │ ├── injector.c
│ │ │ └── injector.def
│ ├── linux_detours
│ │ ├── include
│ │ │ ├── detours.h
│ │ │ ├── plthook.h
│ │ │ └── types.h
│ │ └── src
│ │ │ ├── barrier.cpp
│ │ │ ├── detours.cpp
│ │ │ ├── disasm.cpp
│ │ │ ├── plthook_elf.cpp
│ │ │ ├── trampoline_arm.cpp
│ │ │ └── trampoline_x86.cpp
│ ├── min_hook
│ │ ├── include
│ │ │ └── MinHook.h
│ │ └── src
│ │ │ ├── buffer.c
│ │ │ ├── buffer.h
│ │ │ ├── hde
│ │ │ ├── hde32.c
│ │ │ ├── hde32.h
│ │ │ ├── hde64.c
│ │ │ ├── hde64.h
│ │ │ ├── pstdint.h
│ │ │ ├── table32.h
│ │ │ └── table64.h
│ │ │ ├── hook.c
│ │ │ ├── trampoline.c
│ │ │ └── trampoline.h
│ ├── nanobind
│ │ ├── CMakeLists.txt
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── cmake
│ │ │ ├── collect-symbols-pypy.py
│ │ │ ├── collect-symbols.py
│ │ │ ├── darwin-ld-cpython.sym
│ │ │ ├── darwin-ld-pypy.sym
│ │ │ └── nanobind-config.cmake
│ │ ├── ext
│ │ │ └── robin_map
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── LICENSE
│ │ │ │ ├── README.md
│ │ │ │ ├── cmake
│ │ │ │ └── tsl-robin-mapConfig.cmake.in
│ │ │ │ └── include
│ │ │ │ └── tsl
│ │ │ │ ├── robin_growth_policy.h
│ │ │ │ ├── robin_hash.h
│ │ │ │ ├── robin_map.h
│ │ │ │ └── robin_set.h
│ │ ├── include
│ │ │ └── nanobind
│ │ │ │ ├── eigen
│ │ │ │ ├── dense.h
│ │ │ │ └── sparse.h
│ │ │ │ ├── eval.h
│ │ │ │ ├── intrusive
│ │ │ │ ├── counter.h
│ │ │ │ ├── counter.inl
│ │ │ │ └── ref.h
│ │ │ │ ├── make_iterator.h
│ │ │ │ ├── nanobind.h
│ │ │ │ ├── nb_accessor.h
│ │ │ │ ├── nb_attr.h
│ │ │ │ ├── nb_call.h
│ │ │ │ ├── nb_cast.h
│ │ │ │ ├── nb_class.h
│ │ │ │ ├── nb_defs.h
│ │ │ │ ├── nb_descr.h
│ │ │ │ ├── nb_enums.h
│ │ │ │ ├── nb_error.h
│ │ │ │ ├── nb_func.h
│ │ │ │ ├── nb_lib.h
│ │ │ │ ├── nb_misc.h
│ │ │ │ ├── nb_python.h
│ │ │ │ ├── nb_traits.h
│ │ │ │ ├── nb_tuple.h
│ │ │ │ ├── nb_types.h
│ │ │ │ ├── ndarray.h
│ │ │ │ ├── operators.h
│ │ │ │ ├── stl
│ │ │ │ ├── array.h
│ │ │ │ ├── bind_map.h
│ │ │ │ ├── bind_vector.h
│ │ │ │ ├── chrono.h
│ │ │ │ ├── complex.h
│ │ │ │ ├── detail
│ │ │ │ │ ├── chrono.h
│ │ │ │ │ ├── nb_array.h
│ │ │ │ │ ├── nb_dict.h
│ │ │ │ │ ├── nb_list.h
│ │ │ │ │ ├── nb_optional.h
│ │ │ │ │ ├── nb_set.h
│ │ │ │ │ └── traits.h
│ │ │ │ ├── filesystem.h
│ │ │ │ ├── function.h
│ │ │ │ ├── list.h
│ │ │ │ ├── map.h
│ │ │ │ ├── optional.h
│ │ │ │ ├── pair.h
│ │ │ │ ├── set.h
│ │ │ │ ├── shared_ptr.h
│ │ │ │ ├── string.h
│ │ │ │ ├── string_view.h
│ │ │ │ ├── tuple.h
│ │ │ │ ├── unique_ptr.h
│ │ │ │ ├── unordered_map.h
│ │ │ │ ├── unordered_set.h
│ │ │ │ ├── variant.h
│ │ │ │ ├── vector.h
│ │ │ │ └── wstring.h
│ │ │ │ ├── trampoline.h
│ │ │ │ └── typing.h
│ │ └── src
│ │ │ ├── __init__.py
│ │ │ ├── __main__.py
│ │ │ ├── buffer.h
│ │ │ ├── common.cpp
│ │ │ ├── error.cpp
│ │ │ ├── hash.h
│ │ │ ├── implicit.cpp
│ │ │ ├── nb_combined.cpp
│ │ │ ├── nb_enum.cpp
│ │ │ ├── nb_func.cpp
│ │ │ ├── nb_internals.cpp
│ │ │ ├── nb_internals.h
│ │ │ ├── nb_ndarray.cpp
│ │ │ ├── nb_static_property.cpp
│ │ │ ├── nb_type.cpp
│ │ │ ├── stubgen.py
│ │ │ └── trampoline.cpp
│ └── rd_route
│ │ ├── include
│ │ └── rd_route.h
│ │ └── src
│ │ └── rd_route.c
├── ThreadPool.cxx
└── ThreadPool.hxx
└── setup.py
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Brandon-T/RemoteInput/336b88e619bc799a353543592dd2c06691dff804/.DS_Store
--------------------------------------------------------------------------------
/.github/workflows/build.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Brandon-T/RemoteInput/336b88e619bc799a353543592dd2c06691dff804/.github/workflows/build.zip
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 | /cmake-build-*
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/.idea/RemoteInput.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RemoteInput
2 |
3 | 
4 |
5 | Remote input injects into a Java process to allow io operations such as keyboard and mouse input, reading canvas data and drawing on the canvas.
6 |
7 | Binaries are available here:
8 | https://github.com/Brandon-T/Reflection/releases/tag/autobuild
9 |
10 | ---
11 |
12 | > [!NOTE]
13 | > Linux has protection against dll injection, `setcap` can be used on the executable injecting remoteinput.
14 | > `sudo setcap cap_sys_ptrace=eip /path/to/executable`
15 |
--------------------------------------------------------------------------------
/RemoteInput.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/RemoteInput.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/RemoteInput.xcodeproj/project.xcworkspace/xcuserdata/brandonanthony.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Brandon-T/RemoteInput/336b88e619bc799a353543592dd2c06691dff804/RemoteInput.xcodeproj/project.xcworkspace/xcuserdata/brandonanthony.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/RemoteInput.xcodeproj/xcshareddata/xcschemes/RemoteInputBootstrap.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
57 |
58 |
59 |
60 |
62 |
63 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/RemoteInput.xcodeproj/xcshareddata/xcschemes/libRemoteInput.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
57 |
58 |
59 |
60 |
62 |
63 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/RemoteInput.xcodeproj/xcuserdata/brandonanthony.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | RemoteInput.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 | RemoteInputBootstrap.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 1
16 |
17 | libRemoteInput.xcscheme_^#shared#^_
18 |
19 | orderHint
20 | 0
21 |
22 | remoteInput64.xcscheme_^#shared#^_
23 |
24 | orderHint
25 | 1
26 |
27 |
28 | SuppressBuildableAutocreation
29 |
30 | 5E6281EA2421B776006BA298
31 |
32 | primary
33 |
34 |
35 | 5E6B99FB2394C4F200E6720C
36 |
37 | primary
38 |
39 |
40 | 5EC59506232D956B00922111
41 |
42 | primary
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/RemoteInput/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
3 |
4 |
--------------------------------------------------------------------------------
/RemoteInput/.idea/RemoteInput.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/RemoteInput/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/RemoteInput/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/RemoteInput/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/RemoteInput/DetachedThreadPool.cxx:
--------------------------------------------------------------------------------
1 | #include "DetachedThreadPool.hxx"
2 |
3 | DetachedThreadPool::DetachedThreadPool() noexcept : DetachedThreadPool(std::thread::hardware_concurrency())
4 | {
5 | }
6 |
7 | DetachedThreadPool::DetachedThreadPool(std::size_t max_threads) noexcept : mutex(std::make_shared()), condition(std::make_shared()), tasks(std::make_shared>>()), threads(), stop(std::make_shared(false)), max_threads(max_threads)
8 | {
9 | this->create_threads();
10 | }
11 |
12 | DetachedThreadPool::DetachedThreadPool(DetachedThreadPool&& other) noexcept : mutex(std::move(other.mutex)), condition(std::move(other.condition)), tasks(std::move(other.tasks)), threads(std::move(other.threads)), stop(std::move(other.stop)), max_threads(other.max_threads)
13 | {
14 | other.max_threads = 0;
15 | }
16 |
17 | DetachedThreadPool::~DetachedThreadPool() noexcept
18 | {
19 | if (max_threads == 0)
20 | {
21 | return;
22 | }
23 |
24 | this->terminate();
25 | }
26 |
27 | void DetachedThreadPool::create_threads() noexcept
28 | {
29 | if (max_threads == 0)
30 | {
31 | return;
32 | }
33 |
34 | if (threads.size() != max_threads)
35 | {
36 | threads.reserve(max_threads);
37 |
38 | for (std::size_t i = 0; i < max_threads; ++i)
39 | {
40 | threads.emplace_back([mutex = this->mutex, condition = this->condition, tasks = this->tasks, stop = this->stop] {
41 | while(true)
42 | {
43 | std::unique_lock lock(*mutex);
44 | condition->wait(lock, [tasks, stop] {
45 | return !tasks->empty() || !stop || *stop;
46 | });
47 |
48 | if (!stop || *stop) //&& tasks->empty()
49 | {
50 | lock.unlock();
51 | break;
52 | }
53 |
54 | auto task = std::move(tasks->front());
55 | tasks->pop();
56 |
57 | lock.unlock();
58 |
59 | task(*stop.get());
60 | }
61 | });
62 |
63 | this->threads[i].detach();
64 | }
65 | }
66 | }
67 |
68 | void DetachedThreadPool::terminate() noexcept
69 | {
70 | if (stop && !*stop)
71 | {
72 | std::unique_lock lock(*mutex);
73 | *stop = true;
74 | lock.unlock();
75 | condition->notify_all();
76 | std::vector().swap(this->threads);
77 | }
78 | }
79 |
80 | void DetachedThreadPool::add_task(std::function &&task)
81 | {
82 | if (stop && !*stop)
83 | {
84 | std::unique_lock lock(*mutex);
85 | tasks->emplace(task);
86 | lock.unlock();
87 | condition->notify_one();
88 | }
89 | else
90 | {
91 | throw std::runtime_error("DetachedThreadPool is currently shutting down. Cannot enqueue more tasks.");
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/RemoteInput/DetachedThreadPool.hxx:
--------------------------------------------------------------------------------
1 | #ifndef DETACHEDTHREADPOOL_HXX_INCLUDED
2 | #define DETACHEDTHREADPOOL_HXX_INCLUDED
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | class DetachedThreadPool final
15 | {
16 | private:
17 | std::shared_ptr mutex;
18 | std::shared_ptr condition;
19 | std::shared_ptr>> tasks;
20 | std::vector threads;
21 | std::shared_ptr stop;
22 | std::size_t max_threads;
23 | void create_threads() noexcept;
24 |
25 | public:
26 | DetachedThreadPool() noexcept;
27 | DetachedThreadPool(std::size_t max_threads) noexcept;
28 | DetachedThreadPool(const DetachedThreadPool&) = delete;
29 | DetachedThreadPool(DetachedThreadPool&& other) noexcept;
30 | ~DetachedThreadPool() noexcept;
31 |
32 |
33 | DetachedThreadPool& operator = (const DetachedThreadPool&) = delete;
34 | DetachedThreadPool& operator = (DetachedThreadPool&&) = delete;
35 |
36 | void terminate() noexcept;
37 |
38 | void add_task(std::function &&task);
39 |
40 | template
41 | auto enqueue(Task &&task, Args&&... args) noexcept -> std::future>;
42 | };
43 |
44 | template
45 | auto DetachedThreadPool::enqueue(Task &&task, Args&&... args) noexcept -> std::future>
46 | {
47 | auto packaged_task = std::make_shared(Args&&...)>>(
48 | std::bind(std::forward(task), std::forward(args)...)
49 | );
50 |
51 | std::future> result = packaged_task->get_future();
52 | std::unique_lock lock(*mutex);
53 | if (*stop)
54 | {
55 | throw std::runtime_error("DetachedThreadPool is currently shutting down. Cannot enqueue more tasks.");
56 | }
57 |
58 | tasks->emplace([packaged_task](std::atomic_bool &stopped) {
59 | (*packaged_task)(stopped);
60 | }, std::ref(stop));
61 |
62 | condition->notify_one();
63 | return result;
64 | }
65 |
66 | #endif // DETACHEDTHREADPOOL_HXX_INCLUDED
67 |
--------------------------------------------------------------------------------
/RemoteInput/EIOSTypes.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2023-03-28.
3 | //
4 |
5 | #ifndef EIOSTYPES_HXX_INCLUDED
6 | #define EIOSTYPES_HXX_INCLUDED
7 |
8 | #include
9 |
10 | enum class ImageFormat: std::uint32_t
11 | {
12 | BGR_BGRA, // Compatibility for Simba's Black pixels representing Transparency. Simba should really fix this.
13 | BGRA,
14 | RGBA,
15 | ARGB,
16 | ABGR
17 | };
18 |
19 | enum class EIOSCommand: std::uint32_t
20 | {
21 | COMMAND_NONE,
22 | KILL_APPLICATION,
23 |
24 | GET_IMAGE_DIMENSIONS,
25 | GET_TARGET_DIMENSIONS,
26 | HAS_FOCUS,
27 | GAIN_FOCUS,
28 | LOSE_FOCUS,
29 | IS_KEYBOARD_INPUT_ENABLED,
30 | SET_KEYBOARD_INPUT_ENABLED,
31 | IS_MOUSE_INPUT_ENABLED,
32 | SET_MOUSE_INPUT_ENABLED,
33 | GET_MOUSE,
34 | GET_REAL_MOUSE,
35 | MOVE_MOUSE,
36 | HOLD_MOUSE,
37 | RELEASE_MOUSE,
38 | SCROLL_MOUSE,
39 | IS_MOUSE_HELD,
40 | SEND_STRING,
41 | SEND_KEY,
42 | KEY_SEND,
43 | HOLD_KEY,
44 | RELEASE_KEY,
45 | IS_KEY_HELD,
46 |
47 | GET_KEYBOARD_SPEED,
48 | SET_KEYBOARD_SPEED,
49 | GET_KEYBOARD_REPEAT_DELAY,
50 | SET_KEYBOARD_REPEAT_DELAY,
51 | STOP_ALL_PROCESSING,
52 |
53 | GET_UI_SCALING,
54 | SET_UI_SCALING,
55 |
56 | REFLECT_OBJECT,
57 | REFLECT_COMPARE_OBJECTS,
58 | REFLECT_INSTANCE_OF,
59 | REFLECT_RELEASE_OBJECT,
60 | REFLECT_RELEASE_OBJECTS,
61 | REFLECT_CHAR,
62 | REFLECT_BYTE,
63 | REFLECT_BOOLEAN,
64 | REFLECT_SHORT,
65 | REFLECT_INT,
66 | REFLECT_LONG,
67 | REFLECT_FLOAT,
68 | REFLECT_DOUBLE,
69 | REFLECT_STRING,
70 | REFLECT_ARRAY,
71 | REFLECT_ARRAY_SIZE,
72 | REFLECT_ARRAY_WITH_SIZE,
73 |
74 | REFLECT_ARRAY_ALL,
75 | REFLECT_ARRAY_WITH_INDEX_SIZE,
76 | REFLECT_ARRAY_INDICES,
77 |
78 | REFLECT_CLASS_NAME,
79 | REFLECT_CLASS_TYPE,
80 | REFLECT_CLASS_LOADER,
81 |
82 | REMOTE_VM_INSTRUCTION
83 | };
84 |
85 | typedef struct EIOSData
86 | {
87 | std::int32_t parent_process_id;
88 | std::int32_t parent_thread_id;
89 | std::int32_t image_width;
90 | std::int32_t image_height;
91 | std::int32_t target_width;
92 | std::int32_t target_height;
93 | bool debug_graphics;
94 | bool ui_scaling;
95 | ImageFormat image_format;
96 | EIOSCommand command;
97 | std::uint8_t data[100000 * 8];
98 | } EIOSData;
99 |
100 | #endif /* EIOSTYPES_HXX_INCLUDED */
101 |
--------------------------------------------------------------------------------
/RemoteInput/Echo/Event.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2023-12-30.
3 | //
4 |
5 | #ifndef EVENT_HXX_INCLUDED
6 | #define EVENT_HXX_INCLUDED
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #if defined(_WIN32) || defined(_WIN64)
15 | #include
16 | #endif
17 |
18 | #include "MemoryMap.hxx"
19 |
20 | class Event
21 | {
22 | private:
23 | #if defined(_WIN32) || defined(_WIN64)
24 | HANDLE hEvent;
25 | #else
26 | std::atomic_flag* flag;
27 | std::int32_t* ref;
28 | std::unique_ptr mem_map;
29 | #endif
30 |
31 | bool timed_wait(std::uint64_t nanoseconds) const noexcept;
32 |
33 | public:
34 | Event();
35 | Event(std::string name);
36 | ~Event();
37 |
38 | bool is_signalled() const noexcept;
39 |
40 | void wait() const noexcept;
41 | void signal() const noexcept;
42 |
43 | bool try_wait() const noexcept;
44 |
45 | template
46 | bool try_wait_for(const std::chrono::duration& relative_time) const noexcept
47 | {
48 | auto nano_seconds = std::chrono::duration_cast(relative_time);
49 | if (nano_seconds == std::chrono::duration::zero())
50 | {
51 | return try_wait();
52 | }
53 |
54 | return timed_wait(nano_seconds.count());
55 | }
56 |
57 | template
58 | bool try_wait_until(const std::chrono::time_point& absolute_time) const noexcept
59 | {
60 | const auto current = Clock::now();
61 | if (current >= absolute_time)
62 | {
63 | return try_wait();
64 | }
65 | else
66 | {
67 | return try_wait_for(absolute_time - current);
68 | }
69 | }
70 | };
71 |
72 | #endif //EVENT_HXX_INCLUDED
73 |
--------------------------------------------------------------------------------
/RemoteInput/Echo/Module.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Module.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2019-09-14.
6 | // Copyright © 2019 XIO. All rights reserved.
7 | //
8 |
9 | #include "Module.hxx"
10 |
11 | #if defined _WIN32 || defined _WIN64
12 | Module::Module(const char* path) noexcept : module(static_cast(LoadLibraryA(path))) {}
13 | Module::Module(const wchar_t* path) noexcept : module(static_cast(LoadLibraryW(path))) {}
14 |
15 | Module::~Module() noexcept {FreeLibrary(static_cast(module));}
16 | #else
17 | Module::Module(const char* path) noexcept : module(dlopen(path, RTLD_LAZY | RTLD_GLOBAL)) {}
18 | Module::Module(const wchar_t* path) noexcept : module(nullptr)
19 | {
20 | std::string utf8 = std::wstring_convert>().to_bytes(path);
21 | module = dlopen(utf8.c_str(), RTLD_LAZY | RTLD_GLOBAL);
22 | }
23 |
24 | Module::~Module() noexcept {dlclose(module);}
25 | #endif
26 |
--------------------------------------------------------------------------------
/RemoteInput/Echo/Mutex.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Mutex.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2019-09-14.
6 | // Copyright © 2019 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef MUTEX_HXX_INCLUDED
10 | #define MUTEX_HXX_INCLUDED
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #if defined(_WIN32) || defined(_WIN64)
20 | #include
21 | #endif
22 |
23 | #if defined(__APPLE__)
24 | #include
25 | #endif
26 |
27 | #if !defined(_WIN32) && !defined(_WIN64)
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #endif
37 |
38 | #include "MemoryMap.hxx"
39 |
40 | class Mutex
41 | {
42 | private:
43 | #if defined(_WIN32) || defined(_WIN64)
44 | HANDLE hMutex;
45 | #else
46 | pthread_mutex_t* mutex;
47 | std::int32_t* ref;
48 | std::unique_ptr mem_map;
49 | #endif
50 |
51 | bool timed_lock(std::uint64_t nanoseconds) const noexcept;
52 |
53 | public:
54 | Mutex();
55 | Mutex(const std::string &name);
56 | ~Mutex();
57 |
58 | Mutex(const Mutex &other) = delete;
59 | Mutex& operator = (const Mutex &other) = delete;
60 |
61 | void lock() const;
62 | void unlock() const;
63 |
64 | bool try_lock() const noexcept;
65 |
66 | template
67 | bool try_lock_for(const std::chrono::duration& duration) const noexcept
68 | {
69 | if (duration == std::chrono::duration::zero())
70 | {
71 | return try_lock();
72 | }
73 |
74 | return timed_lock(std::chrono::duration_cast(duration));
75 | }
76 |
77 | template
78 | bool try_lock_until(const std::chrono::time_point& absolute_time) const noexcept
79 | {
80 | auto const current = Clock::now();
81 | if (current >= absolute_time)
82 | {
83 | return try_lock();
84 | }
85 |
86 | return try_lock_for(absolute_time - current);
87 | }
88 | };
89 |
90 | #endif /* MUTEX_HXX_INCLUDED */
91 |
--------------------------------------------------------------------------------
/RemoteInput/Echo/Semaphore.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Semaphore.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2019-09-14.
6 | // Copyright © 2019 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef SEMAPHORE_HXX_INCLUDED
10 | #define SEMAPHORE_HXX_INCLUDED
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #if defined(_WIN32) || defined(_WIN64)
20 | #include
21 | #endif
22 |
23 | #if defined(__APPLE__)
24 | #include
25 | #endif
26 |
27 | #if !defined(_WIN32) && !defined(_WIN64)
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #endif
37 |
38 | #include "MemoryMap.hxx"
39 |
40 | class Semaphore
41 | {
42 | private:
43 | #if defined(_WIN32) || defined(_WIN64)
44 | HANDLE hSemaphore;
45 | #else
46 | bool shared;
47 | bool owned;
48 | void* hSem;
49 | std::string name;
50 | #endif
51 |
52 | bool timed_acquire(std::uint64_t nanoseconds) const noexcept;
53 |
54 | public:
55 | Semaphore(std::int32_t count = 0);
56 | Semaphore(const std::string &name, std::int32_t count = 0);
57 | ~Semaphore();
58 |
59 | Semaphore(const Semaphore &other) = delete;
60 | Semaphore& operator = (const Semaphore &other) = delete;
61 |
62 | void acquire() const;
63 | void release() const;
64 |
65 | bool try_acquire() const noexcept;
66 |
67 | template
68 | bool try_acquire_for(const std::chrono::duration& duration) const noexcept
69 | {
70 | if (duration == std::chrono::duration::zero())
71 | {
72 | return try_acquire();
73 | }
74 |
75 | return timed_acquire(std::chrono::duration_cast(duration));
76 | }
77 |
78 | template
79 | bool try_acquire_until(const std::chrono::time_point& absolute_time) const noexcept
80 | {
81 | auto const current = Clock::now();
82 | if (current >= absolute_time)
83 | {
84 | return try_acquire();
85 | }
86 |
87 | return try_acquire_for(absolute_time - current);
88 | }
89 | };
90 |
91 | #endif //SEMAPHORE_HXX_INCLUDED
92 |
--------------------------------------------------------------------------------
/RemoteInput/Echo/Stream.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2020-12-12.
3 | //
4 |
5 | #include "Stream.hxx"
6 |
7 | void Stream::read(void* value, std::size_t size)
8 | {
9 | DirectStream::read(reinterpret_cast(value), size);
10 | }
11 |
12 | void Stream::write(const void* value, std::size_t size)
13 | {
14 | DirectStream::write(reinterpret_cast(value), size);
15 | }
16 |
17 | std::streampos Stream::tellg()
18 | {
19 | return DirectStream::tellg();
20 | }
21 |
22 | std::streampos Stream::tellp()
23 | {
24 | return DirectStream::tellp();
25 | }
26 |
27 | Stream& Stream::seekg(std::streamoff off, std::ios_base::seekdir dir)
28 | {
29 | DirectStream::seekg(off, dir);
30 | return *this;
31 | }
32 |
33 | Stream& Stream::seekp(std::streamoff off, std::ios_base::seekdir dir)
34 | {
35 | DirectStream::seekp(off, dir);
36 | return *this;
37 | }
38 |
39 | Stream& Stream::operator << (const char* value)
40 | {
41 | write(value);
42 | return *this;
43 | }
44 |
45 | Stream& Stream::operator >> (char* value)
46 | {
47 | read(value);
48 | return *this;
49 | }
--------------------------------------------------------------------------------
/RemoteInput/Echo/Time.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Time.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2019-09-14.
6 | // Copyright © 2019 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef TIME_HXX_INCLUDED
10 | #define TIME_HXX_INCLUDED
11 |
12 | #if defined(_WIN32) || defined(_WIN64)
13 | #include
14 | #else
15 | #include
16 | #endif
17 |
18 | #include
19 | #include
20 |
21 |
22 | void timeval_to_timespec(struct timeval* tv, struct timespec* ts) noexcept;
23 | void timespec_to_timeval(struct timespec* ts, struct timeval* tv) noexcept;
24 | struct timespec add_timespec(struct timespec* a, struct timespec* b) noexcept;
25 | struct timespec sub_timespec(struct timespec* a, struct timespec* b) noexcept;
26 |
27 | struct timeval filetime_to_timeval(uint64_t filetime) noexcept;
28 | uint64_t timeval_to_filetime(struct timeval* tp) noexcept;
29 |
30 | uint64_t get_file_time() noexcept;
31 | uint64_t get_adjusted_file_time() noexcept;
32 | inline uint64_t time_since_epoch(uint64_t time) noexcept {return time - 116444736000000000ULL;}
33 |
34 | #endif // TIME_HXX_INCLUDED
35 |
--------------------------------------------------------------------------------
/RemoteInput/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSHumanReadableCopyright
22 | Copyright © 2019 XIO. All rights reserved.
23 |
24 |
25 |
--------------------------------------------------------------------------------
/RemoteInput/Injection/Injector.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2020-05-02.
3 | //
4 |
5 | #ifndef REMOTEINPUT_INJECTOR_HXX
6 | #define REMOTEINPUT_INJECTOR_HXX
7 |
8 | #include
9 | #include
10 |
11 | class Injector
12 | {
13 | public:
14 | static bool Inject(std::string module_path, std::int32_t pid, void* bootstrap) noexcept;
15 | };
16 |
17 | #endif //REMOTEINPUT_INJECTOR_HXX
18 |
--------------------------------------------------------------------------------
/RemoteInput/Injection/Injector_Windows.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2020-05-02.
3 | //
4 |
5 | #include "Injector.hxx"
6 |
7 | #if defined(_WIN32) || defined(_WIN64)
8 | #include
9 | #endif
10 |
11 | #if defined(_WIN32) || defined(_WIN64)
12 | auto IsProcessAlive = [](std::int32_t pid) -> bool {
13 | HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid);
14 | if (process)
15 | {
16 | DWORD ret = WaitForSingleObject(process, 0);
17 | CloseHandle(process);
18 | return ret == WAIT_TIMEOUT;
19 | }
20 | return false;
21 | };
22 |
23 | bool Injector::Inject(std::string module_path, std::int32_t pid, void* bootstrap) noexcept
24 | {
25 | if (IsProcessAlive(pid))
26 | {
27 | HMODULE hKernel32 = nullptr;
28 | void* RemoteAddress = nullptr;
29 | HANDLE ProcessHandle, hThread = nullptr;
30 | LPTHREAD_START_ROUTINE LoadLibraryHandle = nullptr;
31 |
32 | if ((ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, pid)))
33 | {
34 | if ((hKernel32 = GetModuleHandle("Kernel32.dll")))
35 | {
36 | LoadLibraryHandle = reinterpret_cast(GetProcAddress(hKernel32, "LoadLibraryA"));
37 | if (LoadLibraryHandle)
38 | {
39 | RemoteAddress = VirtualAllocEx(ProcessHandle, nullptr, module_path.size() * sizeof(char), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
40 | if (RemoteAddress)
41 | {
42 | if (WriteProcessMemory(ProcessHandle, RemoteAddress, &module_path[0], module_path.size() * sizeof(char), nullptr))
43 | {
44 | hThread = CreateRemoteThread(ProcessHandle, nullptr, 0, LoadLibraryHandle, RemoteAddress, 0, nullptr);
45 | if (hThread)
46 | {
47 | //More than enough time to wait for a proccess to create a thread..
48 | WaitForSingleObject(hThread, 5000);
49 | CloseHandle(hThread);
50 |
51 | VirtualFreeEx(ProcessHandle, RemoteAddress, module_path.size() * sizeof(char), MEM_RELEASE);
52 | CloseHandle(ProcessHandle);
53 | return true;
54 | }
55 | }
56 |
57 | VirtualFreeEx(ProcessHandle, RemoteAddress, module_path.size() * sizeof(char), MEM_RELEASE);
58 | }
59 | }
60 | }
61 | CloseHandle(ProcessHandle);
62 | }
63 | }
64 | return false;
65 | }
66 | #endif
--------------------------------------------------------------------------------
/RemoteInput/JVM.hxx:
--------------------------------------------------------------------------------
1 | #ifndef JVM_HXX_INCLUDED
2 | #define JVM_HXX_INCLUDED
3 |
4 | #if defined(_WIN32) || defined(_WIN64)
5 | #include
6 | #else
7 | #include
8 | #endif // defined
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | #include "JNI_Common.hxx"
15 |
16 | class JVM
17 | {
18 | private:
19 | JavaVM* vm;
20 | bool createdVM;
21 | bool loadedJNI;
22 | #if defined(_WIN32) || defined(_WIN64)
23 | HMODULE module;
24 | #else
25 | void* module;
26 | #endif // defined
27 |
28 | bool Init(int argc, const char* argv[]) noexcept;
29 | jint JNI_GetDefaultJavaVMInitArgs(void *args) const noexcept;
30 | jint JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args) const noexcept;
31 | jint JNI_GetCreatedJavaVMs(JavaVM **, jsize, jsize *) const noexcept;
32 |
33 |
34 | public:
35 | JVM() noexcept;
36 | JVM(JNIEnv* env) noexcept;
37 | JVM(int argc, const char* argv[]) noexcept;
38 | ~JVM() noexcept;
39 |
40 | operator bool() const noexcept;
41 | JavaVM* getVM() const noexcept;
42 |
43 |
44 | jint AttachCurrentThread(JNIEnv** env) noexcept;
45 | jint AttachCurrentThreadAsDaemon(JNIEnv** env) noexcept;
46 | jint DetachCurrentThread() noexcept;
47 | };
48 |
49 | #endif // JVM_HXX_INCLUDED
50 |
--------------------------------------------------------------------------------
/RemoteInput/Java/AWTAccessor.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // AWTAccessor.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "AWTAccessor.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | AWTAccessor::AWTAccessor(JNIEnv* env, jclass cls, jobject accessor) noexcept : env(env), cls(cls), accessor(accessor)
15 | {
16 | if (!this->cls)
17 | {
18 | this->cls = env->GetObjectClass(accessor);
19 | }
20 |
21 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
22 | env->DeleteLocalRef(std::exchange(this->accessor, env->NewGlobalRef(this->accessor)));
23 | }
24 |
25 | AWTAccessor::~AWTAccessor() noexcept
26 | {
27 | if (cls)
28 | {
29 | env->DeleteGlobalRef(cls);
30 | }
31 |
32 | if (accessor)
33 | {
34 | env->DeleteGlobalRef(accessor);
35 | }
36 | }
37 |
38 | AWTAccessor::AWTAccessor(AWTAccessor&& other) noexcept : env(other.env), cls(other.cls), accessor(other.accessor)
39 | {
40 | other.env = nullptr;
41 | other.cls = nullptr;
42 | other.accessor = nullptr;
43 | }
44 |
45 | AWTAccessor& AWTAccessor::operator = (AWTAccessor&& other) noexcept
46 | {
47 | this->env = other.env;
48 | this->cls = other.cls;
49 | this->accessor = other.accessor;
50 | other.env = nullptr;
51 | other.cls = nullptr;
52 | other.accessor = nullptr;
53 | return *this;
54 | }
55 |
56 | AWTEventAccessor AWTAccessor::getAWTEventAccessor(JNIEnv* env) noexcept
57 | {
58 | jclass cls = env->FindClass("sun/awt/AWTEventAccessor");
59 | static jmethodID methodId = env->GetStaticMethodID(cls, "getAWTEventAccessor", "()Lsun/awt/AWTEventAccessor;");
60 | jobject accessor = env->CallStaticObjectMethod(cls, methodId);
61 | return AWTEventAccessor{env, cls, accessor};
62 | }
63 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/AWTAccessor.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // AWTAccessor.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef AWTAccessor_HXX_INCLUDED
10 | #define AWTAccessor_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "AWTEventAccessor.hxx"
14 |
15 | namespace java
16 | {
17 | class AWTAccessor
18 | {
19 | private:
20 | JNIEnv* env;
21 | jclass cls;
22 | jobject accessor;
23 |
24 | AWTAccessor(JNIEnv* env, jclass cls, jobject accessor) noexcept;
25 |
26 | public:
27 | AWTAccessor(AWTAccessor&& other) noexcept;
28 | AWTAccessor(const AWTAccessor& other) = delete;
29 | ~AWTAccessor() noexcept;
30 |
31 | AWTAccessor& operator = (AWTAccessor&& other) noexcept;
32 | AWTAccessor& operator = (const AWTAccessor& other) = delete;
33 |
34 | static AWTEventAccessor getAWTEventAccessor(JNIEnv* env) noexcept;
35 | };
36 | }
37 |
38 | #endif /* AWTAccessor_HXX_INCLUDED */
39 |
--------------------------------------------------------------------------------
/RemoteInput/Java/AWTEvent.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // AWTEvent.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef AWTEvent_HXX_INCLUDED
10 | #define AWTEvent_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 |
14 | namespace java
15 | {
16 | class AWTEvent
17 | {
18 | protected:
19 | jobject self;
20 | static void SetSystemGenerated(JNIEnv* env, jobject event, bool is_system_generated);
21 | static void Post(JNIEnv* env, jobject event, bool is_system_generated);
22 |
23 | public:
24 | AWTEvent() noexcept;
25 | AWTEvent(jobject self) noexcept;
26 | AWTEvent(AWTEvent&& other) noexcept;
27 | AWTEvent(const AWTEvent& other) = delete;
28 | virtual ~AWTEvent() noexcept;
29 |
30 | AWTEvent& operator = (AWTEvent&& other) noexcept;
31 | AWTEvent& operator = (const AWTEvent& other) = delete;
32 |
33 | virtual jobject get() const noexcept;
34 | virtual jobject getSource(JNIEnv* env) const noexcept;
35 | };
36 | }
37 |
38 | #endif /* AWTEvent_HXX_INCLUDED */
39 |
--------------------------------------------------------------------------------
/RemoteInput/Java/AWTEventAccessor.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // AWTEventAccessor.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "AWTEventAccessor.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | AWTEventAccessor::AWTEventAccessor(JNIEnv* env, jclass cls, jobject accessor) noexcept : env(env), cls(cls), accessor(accessor)
15 | {
16 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
17 | env->DeleteLocalRef(std::exchange(this->accessor, env->NewGlobalRef(this->accessor)));
18 | }
19 |
20 | AWTEventAccessor::~AWTEventAccessor() noexcept
21 | {
22 | if (cls)
23 | {
24 | env->DeleteGlobalRef(cls);
25 | }
26 |
27 | if (accessor)
28 | {
29 | env->DeleteGlobalRef(accessor);
30 | }
31 | }
32 |
33 | AWTEventAccessor::AWTEventAccessor(AWTEventAccessor&& other) noexcept : env(other.env), cls(other.cls), accessor(other.accessor)
34 | {
35 | other.env = nullptr;
36 | other.cls = nullptr;
37 | other.accessor = nullptr;
38 | }
39 |
40 | AWTEventAccessor& AWTEventAccessor::operator = (AWTEventAccessor&& other) noexcept
41 | {
42 | this->env = other.env;
43 | this->cls = other.cls;
44 | this->accessor = other.accessor;
45 | other.env = nullptr;
46 | other.cls = nullptr;
47 | other.accessor = nullptr;
48 | return *this;
49 | }
50 |
51 | void AWTEventAccessor::setSystemGenerated(AWTEvent* event) const noexcept
52 | {
53 | static jmethodID methodId = env->GetMethodID(cls, "setSystemGenerated", "(Ljava/awt/AWTEvent;)V");
54 | env->CallVoidMethod(accessor, methodId, event->get());
55 | }
56 |
57 | void AWTEventAccessor::setPosted(AWTEvent* event) const noexcept
58 | {
59 | static jmethodID methodId = env->GetMethodID(cls, "setPosted", "(Ljava/awt/AWTEvent;)V");
60 | env->CallVoidMethod(accessor, methodId, event->get());
61 | }
62 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/AWTEventAccessor.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // AWTEventAccessor.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef AWTEventAccessor_HXX_INCLUDED
10 | #define AWTEventAccessor_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "AWTEvent.hxx"
14 |
15 | namespace java
16 | {
17 | class AWTEventAccessor
18 | {
19 | private:
20 | JNIEnv* env;
21 | jclass cls;
22 | jobject accessor;
23 |
24 | public:
25 | AWTEventAccessor(JNIEnv* env, jclass cls, jobject accessor) noexcept;
26 | AWTEventAccessor(AWTEventAccessor&& other) noexcept;
27 | AWTEventAccessor(const AWTEventAccessor& other) = delete;
28 | ~AWTEventAccessor() noexcept;
29 |
30 | AWTEventAccessor& operator = (AWTEventAccessor&& other) noexcept;
31 | AWTEventAccessor& operator = (const AWTEventAccessor& other) = delete;
32 |
33 | void setSystemGenerated(AWTEvent* event) const noexcept;
34 | void setPosted(AWTEvent* event) const noexcept;
35 | };
36 | }
37 |
38 | #endif /* AWTEventAccessor_HXX_INCLUDED */
39 |
--------------------------------------------------------------------------------
/RemoteInput/Java/Applet.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Applet.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "Applet.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | Applet::Applet(JNIEnv* env, jobject applet, bool canDelete) noexcept : Window(env, nullptr, applet, canDelete)
15 | {
16 | this->cls = applet ? env->GetObjectClass(applet) : env->FindClass("java/awt/Applet");
17 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/RemoteInput/Java/Applet.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Applet.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef APPLET_HXX_INCLUDED
10 | #define APPLET_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "Window.hxx"
14 |
15 | namespace java
16 | {
17 | class Applet final : public Window
18 | {
19 | public:
20 | Applet(JNIEnv* env, jobject applet, bool canDelete = true) noexcept;
21 | };
22 | }
23 |
24 | #endif /* APPLET_HXX_INCLUDED */
25 |
--------------------------------------------------------------------------------
/RemoteInput/Java/Component.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Component.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef COMPONENT_HXX_INCLUDED
10 | #define COMPONENT_HXX_INCLUDED
11 |
12 | #include
13 | #include
14 | #include "JNI_Common.hxx"
15 | #include "AWTEvent.hxx"
16 |
17 | namespace java
18 | {
19 | class Container;
20 |
21 | class Component
22 | {
23 | protected:
24 | JNIEnv* env;
25 | jclass cls;
26 | jobject component;
27 | bool canDelete;
28 |
29 | public:
30 | Component(JNIEnv* env, jobject component, bool canDelete = true) noexcept;
31 | Component(JNIEnv* env, jclass cls, jobject component, bool canDelete = true) noexcept;
32 | Component(Component&& other) noexcept;
33 | Component(const Component& other) = delete;
34 | virtual ~Component() noexcept;
35 |
36 |
37 | Component& operator = (Component&& other) noexcept;
38 | Component& operator = (const Component& other) = delete;
39 |
40 | JNIEnv* getEnv() const noexcept;
41 | jobject get() const noexcept;
42 |
43 | void getLocationOnScreen(std::int32_t &x, std::int32_t &y) const noexcept;
44 | void getMousePosition(std::int32_t &x, std::int32_t &y) const noexcept;
45 | void getLocation(std::int32_t &x, std::int32_t &y) const noexcept;
46 | void getSize(std::size_t &width, std::size_t &height) const noexcept;
47 | Component getComponentAt(std::int32_t x, std::int32_t y) const noexcept;
48 | Container getParent() const noexcept;
49 | void dispatchEvent(AWTEvent* event) const noexcept;
50 | void dispatchEvent(jobject event) const noexcept;
51 |
52 |
53 | bool isVisible() const noexcept;
54 | bool isValid() const noexcept;
55 | bool isEnabled() const noexcept;
56 | void setEnabled(bool enabled) const noexcept;
57 |
58 | bool hasFocus() const noexcept;
59 | bool requestFocusInWindow() const noexcept;
60 | void requestFocus() const noexcept;
61 | };
62 | }
63 |
64 | #endif /* COMPONENT_HXX_INCLUDED */
65 |
--------------------------------------------------------------------------------
/RemoteInput/Java/Container.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-21.
3 | //
4 |
5 | #include "Container.hxx"
6 | #include
7 |
8 | namespace java
9 | {
10 | Container::Container(JNIEnv* env, jobject container, bool canDelete) noexcept : Component(env, nullptr, container, canDelete)
11 | {
12 | this->cls = container ? env->GetObjectClass(container) : env->FindClass("java/awt/Container");
13 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
14 | }
15 |
16 | Container::Container(JNIEnv* env, jclass cls, jobject container, bool canDelete) noexcept : Component(env, cls, container, canDelete)
17 | {
18 | }
19 |
20 | Component Container::getComponent(std::int32_t index) const noexcept
21 | {
22 | jclass containerClass = env->FindClass("java/awt/Container");
23 | static jmethodID methodId = env->GetMethodID(containerClass, "getComponent", "(I)Ljava/awt/Component;");
24 | env->DeleteLocalRef(containerClass);
25 |
26 | jobject object = env->CallObjectMethod(this->component, methodId, index);
27 | if (object)
28 | {
29 | env->DeleteLocalRef(std::exchange(object, env->NewGlobalRef(object)));
30 | return {env, object};
31 | }
32 | return {env, nullptr};
33 | }
34 |
35 | int Container::getComponentCount() const noexcept
36 | {
37 | jclass containerClass = env->FindClass("java/awt/Container");
38 | static jmethodID methodId = env->GetMethodID(containerClass, "getComponentCount", "()I");
39 | env->DeleteLocalRef(containerClass);
40 |
41 | return env->CallIntMethod(component, methodId);
42 | }
43 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/Container.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-21.
3 | //
4 |
5 | #ifndef REMOTEINPUT_CONTAINER_HXX
6 | #define REMOTEINPUT_CONTAINER_HXX
7 |
8 | #include "JNI_Common.hxx"
9 | #include "Component.hxx"
10 |
11 | namespace java
12 | {
13 | class Container : public Component
14 | {
15 | public:
16 | Container(JNIEnv* env, jobject container, bool canDelete = true) noexcept;
17 | Container(JNIEnv* env, jclass cls, jobject container, bool canDelete = true) noexcept;
18 |
19 | Component getComponent(std::int32_t index) const noexcept;
20 | int getComponentCount() const noexcept;
21 | };
22 | }
23 |
24 |
25 | #endif //REMOTEINPUT_CONTAINER_HXX
26 |
--------------------------------------------------------------------------------
/RemoteInput/Java/EventQueue.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // EventQueue.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "EventQueue.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | EventQueue::EventQueue(JNIEnv* env) noexcept : env(env), cls(nullptr), queue(nullptr)
15 | {
16 | }
17 |
18 | EventQueue::EventQueue(JNIEnv* env, jclass cls, jobject queue) noexcept : env(env), cls(cls), queue(queue)
19 | {
20 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
21 | env->DeleteLocalRef(std::exchange(this->queue, env->NewGlobalRef(this->queue)));
22 | }
23 |
24 | EventQueue::~EventQueue() noexcept
25 | {
26 | if (cls)
27 | {
28 | env->DeleteGlobalRef(cls);
29 | }
30 |
31 | // In Java 6, the system deletes the queue.
32 | // If we attempt to delete it, it will crash!
33 | /*if (queue)
34 | {
35 | env->DeleteGlobalRef(queue);
36 | }*/
37 | }
38 |
39 | EventQueue::EventQueue(EventQueue&& other) noexcept : env(other.env), cls(other.cls), queue(other.queue)
40 | {
41 | other.env = nullptr;
42 | other.cls = nullptr;
43 | other.queue = nullptr;
44 | }
45 |
46 | EventQueue& EventQueue::operator = (EventQueue&& other) noexcept
47 | {
48 | this->env = other.env;
49 | this->cls = other.cls;
50 | this->queue = other.queue;
51 | other.env = nullptr;
52 | other.cls = nullptr;
53 | other.queue = nullptr;
54 | return *this;
55 | }
56 |
57 | void EventQueue::push(EventQueue* queue) const noexcept
58 | {
59 | static jmethodID methodId = env->GetMethodID(cls, "push", "(Ljava/awt/EventQueue;)V");
60 | env->CallVoidMethod(this->queue, methodId, queue->queue);
61 | }
62 |
63 | void EventQueue::postEvent(AWTEvent* event) const noexcept
64 | {
65 | static jmethodID methodId = env->GetMethodID(cls, "postEvent", "(Ljava/awt/AWTEvent;)V");
66 | env->CallVoidMethod(queue, methodId, event->get());
67 | }
68 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/EventQueue.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // EventQueue.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef EventQueue_HXX_INCLUDED
10 | #define EventQueue_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "AWTEvent.hxx"
14 |
15 | namespace java
16 | {
17 | class EventQueue
18 | {
19 | protected:
20 | JNIEnv* env;
21 | jclass cls;
22 | jobject queue;
23 |
24 | EventQueue(JNIEnv* env) noexcept;
25 |
26 | public:
27 | EventQueue(JNIEnv* env, jclass cls, jobject queue) noexcept;
28 | EventQueue(EventQueue&& other) noexcept;
29 | EventQueue(const EventQueue& other) = delete;
30 | virtual ~EventQueue() noexcept;
31 |
32 | EventQueue& operator = (EventQueue&& other) noexcept;
33 | EventQueue& operator = (const EventQueue& other) = delete;
34 |
35 | virtual void push(EventQueue* queue) const noexcept;
36 | virtual void postEvent(AWTEvent* event) const noexcept;
37 | };
38 | }
39 |
40 | #endif /* EventQueue_HXX_INCLUDED */
41 |
--------------------------------------------------------------------------------
/RemoteInput/Java/FocusEvent.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // FocusEvent.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef FocusEvent_HXX_INCLUDED
10 | #define FocusEvent_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "AWTEvent.hxx"
14 | #include "Component.hxx"
15 |
16 | namespace java
17 | {
18 | class FocusEvent final : public AWTEvent
19 | {
20 | public:
21 | enum class Cause : std::uint32_t;
22 |
23 | private:
24 | JNIEnv* env;
25 | jclass cls;
26 | static jobject GetCauseDescription(JNIEnv* env, Cause cause) noexcept;
27 |
28 | public:
29 | FocusEvent(JNIEnv* env, Component* receiver, std::int32_t id, bool temporary, Cause cause) noexcept;
30 | virtual ~FocusEvent() noexcept;
31 |
32 | static void Dispatch(JNIEnv* env, Component* receiver, std::int32_t id, bool temporary, Cause cause, bool is_system_generated = false) noexcept;
33 | static void Post(JNIEnv* env, Component* receiver, std::int32_t id, bool temporary, Cause cause, bool is_system_generated = false) noexcept;
34 |
35 | #if !defined(_MSC_VER)
36 | #warning "WINDOWS BS"
37 | #endif
38 |
39 | #if defined(MOUSE_EVENT) && (defined(_WIN32) || defined(_WIN64))
40 | #undef MOUSE_EVENT
41 | #endif
42 |
43 | enum class Cause : std::uint32_t
44 | {
45 | UNKNOWN,
46 | MOUSE_EVENT,
47 | TRAVERSAL,
48 | TRAVERSAL_UP,
49 | TRAVERSAL_DOWN,
50 | TRAVERSAL_FORWARD,
51 | TRAVERSAL_BACKWARD,
52 | ROLLBACK,
53 | UNEXPECTED,
54 | ACTIVATION,
55 | CLEAR_GLOBAL_FOCUS_OWNER
56 | };
57 |
58 | enum FocusCodes : std::int32_t
59 | {
60 | FOCUS_GAINED = 1004,
61 | FOCUS_LOST = 1005
62 | };
63 | };
64 | }
65 |
66 | #endif /* FocusEvent_HXX_INCLUDED */
67 |
--------------------------------------------------------------------------------
/RemoteInput/Java/Frame.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Frame.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "Frame.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | Frame::Frame(JNIEnv* env, jobject frame, bool canDelete) noexcept : Window(env, nullptr, frame, canDelete)
15 | {
16 | this->cls = frame ? env->GetObjectClass(frame) : env->FindClass("java/awt/JFrame");
17 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
18 | }
19 |
20 | Component Frame::getContentPane() const noexcept
21 | {
22 | static jmethodID methodId = env->GetMethodID(cls, "getContentPane", "()Ljava/awt/Component;");
23 | jobject object = env->CallObjectMethod(component, methodId);
24 | if (object)
25 | {
26 | env->DeleteLocalRef(std::exchange(object, env->NewGlobalRef(object)));
27 | return {env, object};
28 | }
29 | return {env, nullptr};
30 | }
31 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/Frame.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Frame.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef FRAME_HXX_INCLUDED
10 | #define FRAME_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "Window.hxx"
14 |
15 | namespace java
16 | {
17 | class Frame final : public Window
18 | {
19 | public:
20 | Frame(JNIEnv* env, jobject frame, bool canDelete = true) noexcept;
21 |
22 | Component getContentPane() const noexcept;
23 | };
24 | }
25 |
26 | #endif /* FRAME_HXX_INCLUDED */
27 |
--------------------------------------------------------------------------------
/RemoteInput/Java/InputEvent.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // InputEvent.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2019-12-27.
6 | // Copyright © 2019 XIO. All rights reserved.
7 | //
8 |
9 | #include "InputEvent.hxx"
10 |
11 | namespace java
12 | {
13 | std::int32_t InputEvent::GetDownMaskForButton(std::int32_t button) noexcept
14 | {
15 | static const std::int32_t masks[] = {
16 | InputEventMasks::BUTTON1_DOWN_MASK,
17 | InputEventMasks::BUTTON2_DOWN_MASK,
18 | InputEventMasks::BUTTON3_DOWN_MASK,
19 | 1 << 14, //4th physical button (this is not a wheel!)
20 | 1 << 15, //(this is not a wheel!)
21 | 1 << 16,
22 | 1 << 17,
23 | 1 << 18,
24 | 1 << 19,
25 | 1 << 20,
26 | 1 << 21,
27 | 1 << 22,
28 | 1 << 23,
29 | 1 << 24,
30 | 1 << 25,
31 | 1 << 26,
32 | 1 << 27,
33 | 1 << 28,
34 | 1 << 29,
35 | 1 << 30
36 | };
37 |
38 | return masks[button - 1];
39 | }
40 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/InputEvent.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // InputEvent.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2019-12-27.
6 | // Copyright © 2019 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef InputEvent_HXX_INCLUDED
10 | #define InputEvent_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include
14 |
15 | namespace java
16 | {
17 | struct InputEvent
18 | {
19 | enum InputEventMasks : std::uint32_t
20 | {
21 | SHIFT_DOWN_MASK = 1 << 6,
22 | CTRL_DOWN_MASK = 1 << 7,
23 | META_DOWN_MASK = 1 << 8,
24 | ALT_DOWN_MASK = 1 << 9,
25 | BUTTON1_DOWN_MASK = 1 << 10,
26 | BUTTON2_DOWN_MASK = 1 << 11,
27 | BUTTON3_DOWN_MASK = 1 << 12,
28 | ALT_GRAPH_DOWN_MASK = 1 << 13
29 | };
30 |
31 | static std::int32_t GetDownMaskForButton(std::int32_t button) noexcept;
32 | };
33 | }
34 |
35 | #endif /* InputEvent_HXX_INCLUDED */
36 |
--------------------------------------------------------------------------------
/RemoteInput/Java/JNI_Common.hxx:
--------------------------------------------------------------------------------
1 | // JNI_Common.hxx
2 | // RemoteInput
3 | //
4 | // Created by Brandon on 2022-12-02.
5 | // Copyright © 2022 XIO. All rights reserved.
6 | //
7 |
8 | #ifndef JNI_COMMON_HXX_INCLUDED
9 | #define JNI_COMMON_HXX_INCLUDED
10 |
11 | #if defined(__clang__)
12 | #pragma clang diagnostic push
13 | #pragma clang diagnostic ignored "-Wignored-attributes"
14 | #endif
15 |
16 | #include
17 |
18 | #if defined(__clang__)
19 | #pragma clang diagnostic pop
20 | #endif
21 |
22 | #endif //JNI_COMMON_HXX_INCLUDED
23 |
--------------------------------------------------------------------------------
/RemoteInput/Java/KeyEvent.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // KeyEvent.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "KeyEvent.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | KeyEvent::KeyEvent(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t keyCode, jchar keyChar, std::int32_t keyLocation) noexcept : AWTEvent(), env(env), cls(nullptr)
15 | {
16 | this->cls = env->FindClass("java/awt/event/KeyEvent");
17 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
18 |
19 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIICI)V");
20 | self = env->NewObject(cls, methodId, source->get(), id, when, modifiers, keyCode, keyChar, keyLocation);
21 | env->DeleteLocalRef(std::exchange(self, static_cast(env->NewGlobalRef(self))));
22 | }
23 |
24 | KeyEvent::~KeyEvent() noexcept
25 | {
26 | env->DeleteGlobalRef(cls);
27 | env->DeleteGlobalRef(self);
28 | }
29 |
30 | void KeyEvent::Dispatch(JNIEnv* env, Component* receiver, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t keyCode, jchar keyChar, std::int32_t keyLocation, bool is_system_generated) noexcept
31 | {
32 | jclass cls = env->FindClass("java/awt/event/KeyEvent");
33 | if (cls)
34 | {
35 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIICI)V");
36 | jobject event = env->NewObject(cls, methodId, source->get(), id, when, modifiers, keyCode, keyChar, keyLocation);
37 | if (event)
38 | {
39 | AWTEvent::SetSystemGenerated(env, event, is_system_generated);
40 | receiver->dispatchEvent(event);
41 | env->DeleteLocalRef(event);
42 | }
43 |
44 | env->DeleteLocalRef(cls);
45 | }
46 | }
47 |
48 | void KeyEvent::Post(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t keyCode, jchar keyChar, std::int32_t keyLocation, bool is_system_generated) noexcept
49 | {
50 | jclass cls = env->FindClass("java/awt/event/KeyEvent");
51 | if (cls)
52 | {
53 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIICI)V");
54 | jobject event = env->NewObject(cls, methodId, source->get(), id, when, modifiers, keyCode, keyChar, keyLocation);
55 | if (event)
56 | {
57 | AWTEvent::Post(env, event, is_system_generated);
58 | env->DeleteLocalRef(event);
59 | }
60 | env->DeleteLocalRef(cls);
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/KeyEvent.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // KeyEvent.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef KeyEvent_HXX_INCLUDED
10 | #define KeyEvent_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "AWTEvent.hxx"
14 | #include "Component.hxx"
15 |
16 | namespace java
17 | {
18 | class KeyEvent final : public AWTEvent
19 | {
20 | private:
21 | JNIEnv* env;
22 | jclass cls;
23 |
24 | public:
25 | KeyEvent(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t keyCode, jchar keyChar, std::int32_t keyLocation) noexcept;
26 | virtual ~KeyEvent() noexcept;
27 |
28 | static void Dispatch(JNIEnv* env, Component* receiver, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t keyCode, jchar keyChar, std::int32_t keyLocation, bool is_system_generated = false) noexcept;
29 |
30 | static void Post(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t keyCode, jchar keyChar, std::int32_t keyLocation, bool is_system_generated = false) noexcept;
31 |
32 | enum KeyCodes : std::int32_t
33 | {
34 | KEY_TYPED = 400,
35 | KEY_PRESSED = 401,
36 | KEY_RELEASED = 402,
37 |
38 | VK_UNDEFINED = 0x0,
39 | CHAR_UNDEFINED = 0xFF,
40 | KEY_LOCATION_UNKNOWN = 0x0,
41 | KEY_LOCATION_STANDARD = 0x1,
42 | KEY_LOCATION_LEFT = 0x2,
43 | KEY_LOCATION_RIGHT = 0x3,
44 | KEY_LOCATION_NUMPAD = 0x4
45 | };
46 | };
47 | }
48 |
49 | #endif /* KeyEvent_HXX_INCLUDED */
50 |
--------------------------------------------------------------------------------
/RemoteInput/Java/MouseEvent.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // MouseEvent.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "MouseEvent.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | MouseEvent::MouseEvent(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t clickCount, bool popupTrigger, std::int32_t button) noexcept : AWTEvent(), env(env), cls(nullptr)
15 | {
16 | this->cls = env->FindClass("java/awt/event/MouseEvent");
17 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
18 |
19 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIIIIZI)V");
20 | self = env->NewObject(cls, methodId, source->get(), id, when, modifiers, x, y, clickCount, popupTrigger, button);
21 | env->DeleteLocalRef(std::exchange(self, static_cast(env->NewGlobalRef(self))));
22 | }
23 |
24 | MouseEvent::~MouseEvent() noexcept
25 | {
26 | env->DeleteGlobalRef(cls);
27 | env->DeleteGlobalRef(self);
28 | }
29 |
30 | void MouseEvent::Dispatch(JNIEnv* env, Component* receiver, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t clickCount, bool popupTrigger, std::int32_t button, bool is_system_generated) noexcept
31 | {
32 | jclass cls = env->FindClass("java/awt/event/MouseEvent");
33 | if (cls)
34 | {
35 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIIIIZI)V");
36 | jobject event = env->NewObject(cls, methodId, source->get(), id, when, modifiers, x, y, clickCount, popupTrigger, button);
37 | if (event)
38 | {
39 | AWTEvent::SetSystemGenerated(env, event, is_system_generated);
40 | receiver->dispatchEvent(event);
41 | env->DeleteLocalRef(event);
42 | }
43 |
44 | env->DeleteLocalRef(cls);
45 | }
46 | }
47 |
48 | void MouseEvent::Post(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t clickCount, bool popupTrigger, std::int32_t button, bool is_system_generated) noexcept
49 | {
50 | jclass cls = env->FindClass("java/awt/event/MouseEvent");
51 | if (cls)
52 | {
53 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIIIIZI)V");
54 | jobject event = env->NewObject(cls, methodId, source->get(), id, when, modifiers, x, y, clickCount, popupTrigger, button);
55 | if (event)
56 | {
57 | AWTEvent::Post(env, event, is_system_generated);
58 | env->DeleteLocalRef(event);
59 | }
60 | env->DeleteLocalRef(cls);
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/MouseEvent.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // MouseEvent.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef MouseEvent_HXX_INCLUDED
10 | #define MouseEvent_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "AWTEvent.hxx"
14 | #include "Component.hxx"
15 |
16 | namespace java
17 | {
18 | class MouseEvent final : public AWTEvent
19 | {
20 | private:
21 | JNIEnv* env;
22 | jclass cls;
23 |
24 | public:
25 | MouseEvent(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t clickCount, bool popupTrigger, std::int32_t button) noexcept;
26 | virtual ~MouseEvent() noexcept;
27 |
28 | static void Dispatch(JNIEnv* env, Component* receiver, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t clickCount, bool popupTrigger, std::int32_t button, bool is_system_generated = false) noexcept;
29 |
30 | static void Post(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t clickCount, bool popupTrigger, std::int32_t button, bool is_system_generated = false) noexcept;
31 |
32 | #if !defined(_MSC_VER)
33 | #warning "WINDOWS BS"
34 | #endif
35 |
36 | #if defined(MOUSE_MOVED) && (defined(_WIN32) || defined(_WIN64))
37 | #undef MOUSE_MOVED
38 | #endif // MOUSE_MOVED
39 |
40 | enum MouseEventCodes : std::uint32_t
41 | {
42 | MOUSE_CLICKED = 500,
43 | MOUSE_PRESSED = 501,
44 | MOUSE_RELEASED = 502,
45 | MOUSE_MOVED = 503,
46 | MOUSE_ENTERED = 504,
47 | MOUSE_EXITED = 505,
48 | MOUSE_DRAGGED = 506,
49 | MOUSE_WHEEL = 507,
50 |
51 | NOBUTTON = 0,
52 | BUTTON1 = 1,
53 | BUTTON2 = 2,
54 | BUTTON3 = 3,
55 | };
56 | };
57 | }
58 |
59 | #endif /* MouseEvent_HXX_INCLUDED */
60 |
--------------------------------------------------------------------------------
/RemoteInput/Java/MouseWheelEvent.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // MouseWheelEvent.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-10.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "MouseWheelEvent.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | MouseWheelEvent::MouseWheelEvent(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t xAbs, std::int32_t yAbs, std::int32_t clickCount, bool popupTrigger, std::int32_t scrollType, std::int32_t scrollAmount, std::int32_t wheelRotation, double preciseWheelRotation) noexcept : AWTEvent(), env(env), cls(nullptr)
15 | {
16 | this->cls = env->FindClass("java/awt/event/MouseWheelEvent");
17 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
18 |
19 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIIIIIIZIIID)V");
20 | self = env->NewObject(cls, methodId, source->get(), id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger, scrollType, scrollAmount, wheelRotation, preciseWheelRotation);
21 | env->DeleteLocalRef(std::exchange(self, static_cast(env->NewGlobalRef(self))));
22 | }
23 |
24 | MouseWheelEvent::~MouseWheelEvent() noexcept
25 | {
26 | env->DeleteGlobalRef(cls);
27 | env->DeleteGlobalRef(self);
28 | }
29 |
30 | void MouseWheelEvent::Dispatch(JNIEnv* env, Component* receiver, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t xAbs, std::int32_t yAbs, std::int32_t clickCount, bool popupTrigger, std::int32_t scrollType, std::int32_t scrollAmount, std::int32_t wheelRotation, double preciseWheelRotation, bool is_system_generated) noexcept
31 | {
32 | jclass cls = env->FindClass("java/awt/event/MouseWheelEvent");
33 | if (cls)
34 | {
35 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIIIIIIZIIID)V");
36 | jobject event = env->NewObject(cls, methodId, source->get(), id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger, scrollType, scrollAmount, wheelRotation, preciseWheelRotation);
37 | if (event)
38 | {
39 | AWTEvent::SetSystemGenerated(env, event, is_system_generated);
40 | receiver->dispatchEvent(event);
41 | env->DeleteLocalRef(event);
42 | }
43 |
44 | env->DeleteLocalRef(cls);
45 | }
46 | }
47 |
48 | void MouseWheelEvent::Post(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t xAbs, std::int32_t yAbs, std::int32_t clickCount, bool popupTrigger, std::int32_t scrollType, std::int32_t scrollAmount, std::int32_t wheelRotation, double preciseWheelRotation, bool is_system_generated) noexcept
49 | {
50 | jclass cls = env->FindClass("java/awt/event/MouseWheelEvent");
51 | if (cls)
52 | {
53 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;IJIIIIIIZIIID)V");
54 | jobject event = env->NewObject(cls, methodId, source->get(), id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger, scrollType, scrollAmount, wheelRotation, preciseWheelRotation);
55 | if (event)
56 | {
57 | AWTEvent::Post(env, event, is_system_generated);
58 | env->DeleteLocalRef(event);
59 | }
60 | env->DeleteLocalRef(cls);
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/MouseWheelEvent.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // MouseWheelEvent.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-10.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef MouseWheelEvent_HXX_INCLUDED
10 | #define MouseWheelEvent_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "AWTEvent.hxx"
14 | #include "Component.hxx"
15 |
16 | namespace java
17 | {
18 | class MouseWheelEvent final : public AWTEvent
19 | {
20 | private:
21 | JNIEnv* env;
22 | jclass cls;
23 |
24 | public:
25 | MouseWheelEvent(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t xAbs, std::int32_t yAbs, std::int32_t clickCount, bool popupTrigger, std::int32_t scrollType, std::int32_t scrollAmount, std::int32_t wheelRotation, double preciseWheelRotation) noexcept;
26 | virtual ~MouseWheelEvent() noexcept;
27 |
28 | static void Dispatch(JNIEnv* env, Component* receiver, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t xAbs, std::int32_t yAbs, std::int32_t clickCount, bool popupTrigger, std::int32_t scrollType, std::int32_t scrollAmount, std::int32_t wheelRotation, double preciseWheelRotation, bool is_system_generated = false) noexcept;
29 |
30 | static void Post(JNIEnv* env, Component* source, std::int32_t id, std::int64_t when, std::int32_t modifiers, std::int32_t x, std::int32_t y, std::int32_t xAbs, std::int32_t yAbs, std::int32_t clickCount, bool popupTrigger, std::int32_t scrollType, std::int32_t scrollAmount, std::int32_t wheelRotation, double preciseWheelRotation, bool is_system_generated = false) noexcept;
31 |
32 | enum MouseWheelEventCodes : std::uint32_t
33 | {
34 | WHEEL_UNIT_SCROLL = 0,
35 | WHEEL_BLOCK_SCROLL = 1
36 | };
37 | };
38 | }
39 |
40 | #endif /* MouseWheelEvent_HXX_INCLUDED */
41 |
--------------------------------------------------------------------------------
/RemoteInput/Java/PointerInfo.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // PointerInfo.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-03-16.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef PointerInfo_HXX_INCLUDED
10 | #define PointerInfo_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "Component.hxx"
14 |
15 | namespace java
16 | {
17 | class PointerInfo
18 | {
19 | private:
20 | JNIEnv* env;
21 | jclass cls;
22 | jobject pointerInfo;
23 |
24 | PointerInfo(JNIEnv* env, jclass cls, jobject pointerInfo) noexcept;
25 |
26 | public:
27 | PointerInfo(PointerInfo&& other) noexcept;
28 | PointerInfo(const PointerInfo& other) = delete;
29 | ~PointerInfo() noexcept;
30 |
31 | PointerInfo& operator = (PointerInfo&& other) noexcept;
32 | PointerInfo& operator = (const PointerInfo& other) = delete;
33 |
34 | static PointerInfo getPointerInfo(JNIEnv* env) noexcept;
35 |
36 | void getLocation(std::int32_t &x, std::int32_t &y) const noexcept;
37 |
38 | static void PointToScreen(JNIEnv* env, std::int32_t &x, std::int32_t &y, Component* component) noexcept;
39 | };
40 | }
41 |
42 | #endif /* PointerInfo_HXX_INCLUDED */
43 |
--------------------------------------------------------------------------------
/RemoteInput/Java/RIEventQueue.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-17.
3 | //
4 |
5 | #ifndef RIEVENTQUEUE_HXX
6 | #define RIEVENTQUEUE_HXX
7 |
8 | #include "JNI_Common.hxx"
9 | #include "EventQueue.hxx"
10 | #include "AWTEvent.hxx"
11 | #include
12 |
13 | namespace java
14 | {
15 | class RIEvent final: public AWTEvent
16 | {
17 | private:
18 | JNIEnv* env;
19 | static jobject Wrap(JNIEnv* env, jobject original) noexcept;
20 | public:
21 | RIEvent(JNIEnv* env, AWTEvent* original) noexcept;
22 | RIEvent(JNIEnv* env, jobject original) noexcept;
23 | RIEvent(RIEvent&& other) noexcept;
24 | virtual ~RIEvent() noexcept final;
25 |
26 | RIEvent& operator = (RIEvent&& other) noexcept;
27 | };
28 |
29 | class RIEventQueue: public EventQueue
30 | {
31 | private:
32 | bool is_blocking_keyboard_events;
33 | bool is_blocking_mouse_events;
34 |
35 | void DefineClass();
36 | static void DispatchEvent(JNIEnv* env, jobject thiz, jobject event);
37 |
38 | public:
39 | RIEventQueue(JNIEnv* env) noexcept;
40 |
41 | bool is_keyboard_input_enabled() const noexcept;
42 | void set_keyboard_input_enabled(bool enabled) noexcept;
43 |
44 | bool is_mouse_input_enabled() const noexcept;
45 | void set_mouse_input_enabled(bool enabled) noexcept;
46 | };
47 | }
48 |
49 | #endif /* RIEVENTQUEUE_HXX */
50 |
--------------------------------------------------------------------------------
/RemoteInput/Java/SunToolkit.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-21.
3 | //
4 |
5 | #include "SunToolkit.hxx"
6 | #include
7 |
8 | namespace java
9 | {
10 | Window SunToolkit::getContainingWindow(Component* component)
11 | {
12 | JNIEnv* env = component->getEnv();
13 | jclass cls = env->FindClass("sun/awt/SunToolkit");
14 | if (cls)
15 | {
16 | static jmethodID methodId = env->GetStaticMethodID(cls, "getContainingWindow", "(Ljava/awt/Component;)Ljava/awt/Window;");
17 | if (methodId)
18 | {
19 | jobject containing_window = env->CallStaticObjectMethod(cls, methodId, component->get());
20 | env->DeleteLocalRef(cls);
21 | env->DeleteLocalRef(std::exchange(containing_window, env->NewGlobalRef(containing_window)));
22 | return {env, containing_window};
23 | }
24 | env->DeleteLocalRef(cls);
25 | }
26 |
27 | cls = env->FindClass("java/awt/Window");
28 | if (cls)
29 | {
30 | jobject comp = env->NewGlobalRef(component->get());
31 | while(comp && !env->IsInstanceOf(comp, cls))
32 | {
33 | comp = env->NewGlobalRef(Component(env, comp).getParent().get());
34 | }
35 |
36 | env->DeleteLocalRef(cls);
37 | return {env, comp};
38 | }
39 |
40 | return {env, nullptr};
41 | }
42 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/SunToolkit.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-21.
3 | //
4 |
5 | #ifndef REMOTEINPUT_SUNTOOLKIT_HXX
6 | #define REMOTEINPUT_SUNTOOLKIT_HXX
7 |
8 | #include "Toolkit.hxx"
9 | #include "Window.hxx"
10 |
11 | namespace java
12 | {
13 | class SunToolkit : public Toolkit
14 | {
15 | public:
16 | static Window getContainingWindow(Component* component);
17 | };
18 | }
19 |
20 | #endif //REMOTEINPUT_SUNTOOLKIT_HXX
21 |
--------------------------------------------------------------------------------
/RemoteInput/Java/Toolkit.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Toolkit.cxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #include "Toolkit.hxx"
10 | #include
11 |
12 | namespace java
13 | {
14 | Toolkit::Toolkit(JNIEnv* env, jclass cls, jobject toolkit) noexcept : env(env), cls(cls), toolkit(toolkit)
15 | {
16 | if (!this->cls)
17 | {
18 | this->cls = env->GetObjectClass(toolkit);
19 | }
20 |
21 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
22 | env->DeleteLocalRef(std::exchange(this->toolkit, env->NewGlobalRef(this->toolkit)));
23 | }
24 |
25 | Toolkit::~Toolkit() noexcept
26 | {
27 | if (cls)
28 | {
29 | env->DeleteGlobalRef(cls);
30 | }
31 |
32 | if (toolkit)
33 | {
34 | env->DeleteGlobalRef(toolkit);
35 | }
36 | }
37 |
38 | Toolkit::Toolkit(Toolkit&& other) noexcept : env(other.env), cls(other.cls), toolkit(other.toolkit)
39 | {
40 | other.env = nullptr;
41 | other.cls = nullptr;
42 | other.toolkit = nullptr;
43 | }
44 |
45 | Toolkit& Toolkit::operator = (Toolkit&& other) noexcept
46 | {
47 | this->env = other.env;
48 | this->cls = other.cls;
49 | this->toolkit = other.toolkit;
50 | other.env = nullptr;
51 | other.cls = nullptr;
52 | other.toolkit = nullptr;
53 | return *this;
54 | }
55 |
56 | Toolkit Toolkit::getDefaultToolkit(JNIEnv* env) noexcept
57 | {
58 | jclass cls = env->FindClass("java/awt/Toolkit");
59 | static jmethodID methodId = env->GetStaticMethodID(cls, "getDefaultToolkit", "()Ljava/awt/Toolkit;");
60 | jobject toolkit = env->CallStaticObjectMethod(cls, methodId);
61 | return Toolkit{env, cls, toolkit};
62 | }
63 |
64 | EventQueue Toolkit::getSystemEventQueue() const noexcept
65 | {
66 | static jmethodID methodId = env->GetMethodID(cls, "getSystemEventQueue", "()Ljava/awt/EventQueue;");
67 | jobject queue = env->CallObjectMethod(toolkit, methodId);
68 | return EventQueue(env, env->FindClass("java/awt/EventQueue"), queue);
69 | }
70 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/Toolkit.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Toolkit.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-01-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef Toolkit_HXX_INCLUDED
10 | #define Toolkit_HXX_INCLUDED
11 |
12 | #include "JNI_Common.hxx"
13 | #include "EventQueue.hxx"
14 |
15 | namespace java
16 | {
17 | class Toolkit
18 | {
19 | private:
20 | JNIEnv* env;
21 | jclass cls;
22 | jobject toolkit;
23 |
24 | protected:
25 | Toolkit(JNIEnv* env, jclass cls, jobject toolkit) noexcept;
26 |
27 | public:
28 | Toolkit(Toolkit&& other) noexcept;
29 | Toolkit(const Toolkit& other) = delete;
30 | virtual ~Toolkit() noexcept;
31 |
32 | Toolkit& operator = (Toolkit&& other) noexcept;
33 | Toolkit& operator = (const Toolkit& other) = delete;
34 |
35 | static Toolkit getDefaultToolkit(JNIEnv* env) noexcept;
36 |
37 | EventQueue getSystemEventQueue() const noexcept;
38 | };
39 | }
40 |
41 | #endif /* Toolkit_HXX_INCLUDED */
42 |
--------------------------------------------------------------------------------
/RemoteInput/Java/Window.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-21.
3 | //
4 |
5 | #include "Window.hxx"
6 | #include
7 |
8 | namespace java
9 | {
10 | Window::Window(JNIEnv* env, jobject window, bool canDelete) noexcept : Container(env, nullptr, window, canDelete)
11 | {
12 | this->cls = window ? env->GetObjectClass(window) : env->FindClass("java/awt/Window");
13 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
14 | }
15 |
16 | Window::Window(JNIEnv* env, jclass cls, jobject window, bool canDelete) noexcept : Container(env, cls, window, canDelete)
17 | {
18 | }
19 |
20 | void Window::pack() const noexcept
21 | {
22 | static jmethodID methodId = env->GetMethodID(cls, "pack", "()V");
23 | env->CallVoidMethod(component, methodId);
24 | }
25 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/Window.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-21.
3 | //
4 |
5 | #ifndef REMOTEINPUT_WINDOW_HXX
6 | #define REMOTEINPUT_WINDOW_HXX
7 |
8 |
9 | #include "JNI_Common.hxx"
10 | #include "Container.hxx"
11 |
12 | namespace java
13 | {
14 | class Window : public Container
15 | {
16 | public:
17 | Window(JNIEnv* env, jobject window, bool canDelete = true) noexcept;
18 | Window(JNIEnv* env, jclass cls, jobject window, bool canDelete = true) noexcept;
19 | void pack() const noexcept;
20 | };
21 | }
22 |
23 | #endif //REMOTEINPUT_WINDOW_HXX
24 |
--------------------------------------------------------------------------------
/RemoteInput/Java/WindowEvent.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-21.
3 | //
4 |
5 | #include "WindowEvent.hxx"
6 | #include
7 |
8 | namespace java
9 | {
10 | WindowEvent::WindowEvent(JNIEnv* env, Component* receiver, std::int32_t id, std::int32_t old_state, std::int32_t new_state) noexcept : AWTEvent(), env(env), cls(nullptr)
11 | {
12 | this->cls = env->FindClass("java/awt/event/WindowEvent");
13 | env->DeleteLocalRef(std::exchange(this->cls, static_cast(env->NewGlobalRef(this->cls))));
14 |
15 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Component;III)V");
16 | self = env->NewObject(cls, methodId, receiver->get(), id, old_state, new_state);
17 | env->DeleteLocalRef(std::exchange(self, static_cast(env->NewGlobalRef(self))));
18 | }
19 |
20 | WindowEvent::~WindowEvent() noexcept
21 | {
22 | env->DeleteGlobalRef(cls);
23 | env->DeleteGlobalRef(self);
24 | }
25 |
26 | void WindowEvent::Dispatch(JNIEnv* env, Component* receiver, std::int32_t id, std::int32_t old_state, std::int32_t new_state, bool is_system_generated) noexcept
27 | {
28 | jclass cls = env->FindClass("java/awt/event/WindowEvent");
29 | if (cls)
30 | {
31 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Window;III)V");
32 | jobject event = env->NewObject(cls, methodId, receiver->get(), id, old_state, new_state);
33 |
34 | if (event)
35 | {
36 | AWTEvent::SetSystemGenerated(env, event, is_system_generated);
37 | receiver->dispatchEvent(event);
38 | env->DeleteLocalRef(event);
39 | }
40 |
41 | env->DeleteLocalRef(cls);
42 | }
43 | }
44 |
45 | void WindowEvent::Post(JNIEnv* env, Component* receiver, std::int32_t id, std::int32_t old_state, std::int32_t new_state, bool is_system_generated) noexcept
46 | {
47 | jclass cls = env->FindClass("java/awt/event/WindowEvent");
48 | if (cls)
49 | {
50 | static jmethodID methodId = env->GetMethodID(cls, "", "(Ljava/awt/Window;III)V");
51 | jobject event = env->NewObject(cls, methodId, receiver->get(), id, old_state, new_state);
52 | if (event)
53 | {
54 | AWTEvent::Post(env, event, is_system_generated);
55 | env->DeleteLocalRef(event);
56 | }
57 | env->DeleteLocalRef(cls);
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/RemoteInput/Java/WindowEvent.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2021-10-21.
3 | //
4 |
5 | #ifndef REMOTEINPUT_WINDOWEVENT_HXX
6 | #define REMOTEINPUT_WINDOWEVENT_HXX
7 |
8 | #include "JNI_Common.hxx"
9 | #include "AWTEvent.hxx"
10 | #include "Component.hxx"
11 |
12 | namespace java
13 | {
14 | class WindowEvent final : public AWTEvent
15 | {
16 | private:
17 | JNIEnv* env;
18 | jclass cls;
19 |
20 | public:
21 | WindowEvent(JNIEnv* env, Component* receiver, std::int32_t id, std::int32_t old_state, std::int32_t new_state) noexcept;
22 | virtual ~WindowEvent() noexcept;
23 |
24 | static void Dispatch(JNIEnv* env, Component* receiver, std::int32_t id, std::int32_t old_state, std::int32_t new_state, bool is_system_generated = false) noexcept;
25 | static void Post(JNIEnv* env, Component* receiver, std::int32_t id, std::int32_t old_state, std::int32_t new_state, bool is_system_generated = false) noexcept;
26 |
27 | enum WindowEventCodes : std::int32_t
28 | {
29 | WINDOW_ICONIFIED = 203,
30 | WINDOW_DEICONIFIED = 204,
31 | WINDOW_ACTIVATED = 205,
32 | WINDOW_DEACTIVATED = 206,
33 | WINDOW_GAINED_FOCUS = 207,
34 | WINDOW_LOST_FOCUS = 208,
35 | WINDOW_STATE_CHANGED = 209
36 | };
37 | };
38 | }
39 |
40 | #endif //REMOTEINPUT_WINDOWEVENT_HXX
41 |
--------------------------------------------------------------------------------
/RemoteInput/Platform/DebugConsole.cxx:
--------------------------------------------------------------------------------
1 | #include "DebugConsole.hxx"
2 | #include
3 |
4 | DebugConsole::DebugConsole() noexcept : input(nullptr), error(nullptr), output(nullptr), allocated_console(false)
5 | {
6 | #if defined(_WIN32) || defined(_WIN64)
7 | allocated_console = AllocConsole();
8 | #if defined(__STDC_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1
9 | freopen_s(&input, "CONIN$", "r", stdin);
10 | freopen_s(&error, "CONOUT$", "w", stderr);
11 | freopen_s(&output, "CONOUT$", "w", stdout);
12 | #else
13 | input = std::freopen("CONIN$", "r", stdin);
14 | error = std::freopen("CONOUT$", "w", stderr);
15 | output = std::freopen("CONOUT$", "w", stdout);
16 | #endif
17 | #else
18 |
19 | #endif
20 | }
21 |
22 | DebugConsole::DebugConsole(DebugConsole&& other) : input(other.input), error(other.error), output(other.output), allocated_console(other.allocated_console)
23 | {
24 | other.input = nullptr;
25 | other.error = nullptr;
26 | other.output = nullptr;
27 | other.allocated_console = false;
28 | }
29 |
30 | DebugConsole::~DebugConsole() noexcept
31 | {
32 | #if defined(_WIN32) || defined(_WIN64)
33 | if (allocated_console)
34 | {
35 | FreeConsole();
36 | }
37 | #endif
38 |
39 | std::fclose(input);
40 | std::fclose(error);
41 | std::fclose(output);
42 | }
43 |
44 | DebugConsole& DebugConsole::operator=(DebugConsole &&other)
45 | {
46 | std::fclose(input);
47 | std::fclose(error);
48 | std::fclose(output);
49 | input = other.input;
50 | error = other.error;
51 | output = other.output;
52 | allocated_console = other.allocated_console;
53 | other.input = nullptr;
54 | other.error = nullptr;
55 | other.output = nullptr;
56 | other.allocated_console = false;
57 | return *this;
58 | }
--------------------------------------------------------------------------------
/RemoteInput/Platform/DebugConsole.hxx:
--------------------------------------------------------------------------------
1 | #ifndef DEBUGCONSOLE_HXX_INCLUDED
2 | #define DEBUGCONSOLE_HXX_INCLUDED
3 |
4 | #if defined(_WIN32) || defined(_WIN64)
5 | #include
6 | #endif
7 |
8 | #include
9 |
10 | class DebugConsole final
11 | {
12 | private:
13 | FILE* input;
14 | FILE* error;
15 | FILE* output;
16 | bool allocated_console;
17 |
18 | public:
19 | DebugConsole() noexcept;
20 | DebugConsole(DebugConsole&& other);
21 | DebugConsole(const DebugConsole& other) = delete;
22 | ~DebugConsole() noexcept;
23 |
24 | DebugConsole& operator = (const DebugConsole& other) = delete;
25 | DebugConsole& operator = (DebugConsole&& other);
26 | };
27 |
28 | #endif // DEBUGCONSOLE_HXX_INCLUDED
29 |
--------------------------------------------------------------------------------
/RemoteInput/Platform/NativeHooks.hxx:
--------------------------------------------------------------------------------
1 | #ifndef NATIVEHOOKS_HXX_INCLUDED
2 | #define NATIVEHOOKS_HXX_INCLUDED
3 |
4 | void StartHook() noexcept;
5 |
6 | #endif // NATIVEHOOKS_HXX_INCLUDED
7 |
--------------------------------------------------------------------------------
/RemoteInput/Platform/Platform.hxx:
--------------------------------------------------------------------------------
1 | #ifndef PLATFORM_HXX_INCLUDED
2 | #define PLATFORM_HXX_INCLUDED
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include "Reflection.hxx"
10 |
11 | void GetDesktopResolution(int &width, int &height) noexcept;
12 | std::unique_ptr GetNativeReflector() noexcept;
13 |
14 | std::int32_t GetCurrentThreadID() noexcept;
15 |
16 | bool IsProcessAlive(std::int32_t pid) noexcept;
17 | bool IsThreadAlive(std::int32_t tid) noexcept;
18 | std::vector get_pids() noexcept;
19 | std::vector get_pids(const char* process_name) noexcept;
20 | std::int32_t InjectProcess(std::int32_t) noexcept;
21 | std::vector InjectProcesses(const char* process_name) noexcept;
22 | std::int32_t PIDFromWindow(void* window) noexcept;
23 |
24 | std::vector GetLoadedModuleNames(const char* partial_module_name) noexcept;
25 |
26 | #if !defined(_WIN32) && !defined(_WIN64)
27 | void* GetModuleHandle(const char* module_name) noexcept;
28 | #endif
29 |
30 | template
31 | void yield_thread(std::chrono::duration time) noexcept
32 | {
33 | /*auto start = std::chrono::high_resolution_clock::now();
34 | auto end = start + time;
35 | do {
36 | //std::this_thread::yield();
37 | std::this_thread::sleep_for(std::chrono::nanoseconds(1));
38 | } while (std::chrono::high_resolution_clock::now() < end);*/
39 | std::this_thread::sleep_for(time);
40 | }
41 |
42 | template
43 | std::int64_t elapsed_time(std::chrono::high_resolution_clock::time_point start) noexcept
44 | {
45 | auto end = std::chrono::high_resolution_clock::now();
46 | return std::chrono::duration_cast(end - start).count();
47 | }
48 |
49 | #endif // PLATFORM_HXX_INCLUDED
50 |
--------------------------------------------------------------------------------
/RemoteInput/Platform/RemoteInputBootstrap_Darwin.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // RemoteInputBootstrap_Darwin.cpp
3 | // RemoteInputBootstrap
4 | //
5 | // Created by Brandon on 2020-03-17.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #if defined(MACH_INJECT)
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #define EXPORT [[gnu::visibility("default")]]
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | void _pthread_set_self(void*);
33 | EXPORT void LoadLibrary(ptrdiff_t offset, void *param, size_t psize, void *dummy);
34 |
35 | #ifdef __cplusplus
36 | }
37 | #endif
38 |
39 | void LoadLibrary(ptrdiff_t offset, void* param, size_t psize, void* userp)
40 | {
41 | _pthread_set_self(userp);
42 |
43 | int policy = 0;
44 | pthread_attr_t attr = {};
45 | pthread_t thread = nullptr;
46 | struct sched_param sched = {};
47 |
48 | pthread_attr_init(&attr);
49 | pthread_attr_getschedpolicy(&attr, &policy);
50 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
51 | pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
52 |
53 | sched.sched_priority = sched_get_priority_max(policy);
54 | pthread_attr_setschedparam(&attr, &sched);
55 |
56 | pthread_create(&thread, &attr, [](void* param) -> void* {
57 | void* lib = dlopen(static_cast(param), RTLD_NOW | RTLD_NOLOAD);
58 | if (lib)
59 | {
60 | dlclose(lib);
61 | return nullptr;
62 | }
63 |
64 | lib = dlopen(static_cast(param), RTLD_NOW);
65 | if (!lib)
66 | {
67 | fprintf(stderr, "Could not load module: %s\n", dlerror());
68 | }
69 | return nullptr;
70 | }, param);
71 |
72 | pthread_attr_destroy(&attr);
73 | thread_suspend(mach_thread_self());
74 | }
75 | #endif
--------------------------------------------------------------------------------
/RemoteInput/Plugin/ImageData.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2023-03-22.
3 | //
4 |
5 | #ifndef IMAGEDATA_HXX_INCLUDED
6 | #define IMAGEDATA_HXX_INCLUDED
7 |
8 | #include
9 | #include "EIOSTypes.hxx"
10 | #include "Stream.hxx"
11 |
12 | struct EIOSData;
13 | enum class EIOSCommand: std::uint32_t;
14 |
15 | class ImageData
16 | {
17 | private:
18 | std::unique_ptr stream;
19 | std::unique_ptr image_data;
20 |
21 | public:
22 | ImageData(void* buffer, std::size_t size);
23 | ~ImageData();
24 |
25 | void prepare_for_read() const;
26 | void prepare_for_write() const;
27 |
28 | std::int32_t parent_process_id() const;
29 | std::int32_t parent_thread_id() const;
30 | std::int32_t image_width() const;
31 | std::int32_t image_height() const;
32 | std::int32_t target_width() const;
33 | std::int32_t target_height() const;
34 | bool debug_graphics() const;
35 | bool ui_scaling() const;
36 | ImageFormat image_format() const;
37 | EIOSCommand command() const;
38 |
39 | void set_parent_process_id(std::int32_t pid);
40 | void set_parent_thread_id(std::int32_t tid);
41 | void set_image_width(std::int32_t width);
42 | void set_image_height(std::int32_t height);
43 | void set_target_width(std::int32_t width);
44 | void set_target_height(std::int32_t height);
45 | void set_debug_graphics(bool debug_graphics);
46 | void set_ui_scaling(bool ui_scaling);
47 | void set_image_format(ImageFormat format);
48 | void set_command(EIOSCommand command);
49 |
50 | void* data_buffer(std::ios_base::openmode mode) const noexcept;
51 |
52 | std::uint8_t* image_buffer() const noexcept;
53 | std::uint8_t* debug_image_buffer() const noexcept;
54 | Stream& data_stream() const noexcept;
55 | };
56 |
57 | #endif /* IMAGEDATA_HXX_INCLUDED */
58 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/JVM/JVMCache.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2023-03-25.
3 | //
4 |
5 | #ifndef REMOTEINPUT_JVMCACHE_HXX
6 | #define REMOTEINPUT_JVMCACHE_HXX
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include "ReflectionHook.hxx"
14 | #include "JVM.hxx"
15 | #include "TypeTraits.hxx"
16 |
17 | class JVMCache
18 | {
19 | public:
20 | JVMCache(JNIEnv* env, jobject class_loader);
21 | JVMCache(const JVMCache&) = delete;
22 | JVMCache(JVMCache&&);
23 | ~JVMCache();
24 |
25 | JVMCache& operator = (const JVMCache&) = delete;
26 | JVMCache& operator = (JVMCache&&);
27 |
28 | jclass GetClass(JNIEnv* env, std::string_view name) noexcept;
29 | jfieldID GetFieldID(JNIEnv* env, jclass clazz, std::string_view name, std::string_view sig, bool is_static) noexcept;
30 |
31 | void clear();
32 |
33 | private:
34 | jobject class_loader;
35 | jmethodID load_class_method;
36 |
37 | std::unordered_map::type, std::function>, string_hash, std::equal_to<>> class_cache;
38 | std::unordered_map field_cache;
39 |
40 |
41 | static std::size_t field_hash(jclass clazz, std::string_view field_name, std::string_view signature) noexcept;
42 | };
43 |
44 |
45 | #endif //REMOTEINPUT_JVMCACHE_HXX
46 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/NativePlugin.cxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2022-09-21.
3 | //
4 |
5 | #include "NativePlugin.hxx"
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include "Platform.hxx"
12 | #include "ControlCenter.hxx"
13 |
14 | // MARK: - EXPORTS
15 |
16 | void EIOS_Inject(const char* process_name) noexcept
17 | {
18 | if (process_name)
19 | {
20 | std::vector pids = InjectProcesses(process_name);
21 | for (std::int32_t pid : pids)
22 | {
23 | if (pid != -1)
24 | {
25 | ControlCenter::wait_for_sync(pid);
26 | }
27 | }
28 | }
29 | }
30 |
31 | void EIOS_Inject_PID(std::int32_t pid) noexcept
32 | {
33 | if (pid != -1)
34 | {
35 | if (InjectProcess(pid) == pid)
36 | {
37 | ControlCenter::wait_for_sync(pid);
38 | }
39 | }
40 | }
41 |
42 | EIOS* EIOS_From_PID(std::int32_t pid) noexcept
43 | {
44 | extern std::unordered_map clients;
45 | if (clients.count(pid))
46 | {
47 | return clients[pid];
48 | }
49 | return nullptr;
50 | }
51 |
52 | void Reflect_Release_Object(EIOS* eios, jobject object) noexcept
53 | {
54 | if (eios)
55 | {
56 | //Make sure we're not freeing null objects..
57 | if (object)
58 | {
59 | eios->control_center->reflect_release_object(object);
60 | }
61 | }
62 | }
63 |
64 | void Reflect_Release_Objects(EIOS* eios, jobject* objects, std::size_t amount) noexcept
65 | {
66 | if (eios)
67 | {
68 | //Make sure we're not freeing null objects..
69 | if (objects && amount > 0)
70 | {
71 | //This is the fastest possible way to remove duplicates..
72 | //Do NOT use `unordered_set` constructor instead of the for-loop.
73 | //It is slower than emplace/insert.
74 | std::unordered_set set;
75 | for (std::size_t i = 0; i < amount; ++i)
76 | {
77 | set.insert(objects[i]);
78 | }
79 |
80 | //Remove null objects
81 | set.erase(nullptr);
82 |
83 | //Create a contiguous array of objects for the client.
84 | std::vector objects;
85 | objects.assign(set.begin(), set.end());
86 |
87 | //Make sure we're not freeing null objects..
88 | if (objects.size())
89 | {
90 | eios->control_center->reflect_release_objects(objects.data(), objects.size());
91 | }
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/RemoteInput/Plugin/NativePlugin.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2022-09-21.
3 | //
4 |
5 | #ifndef REMOTEINPUT_NATIVEPLUGIN_HXX
6 | #define REMOTEINPUT_NATIVEPLUGIN_HXX
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | #include "EIOS.hxx"
13 |
14 | #ifdef __cplusplus
15 | extern "C"
16 | {
17 | #endif
18 |
19 | EXPORT void EIOS_Inject(const char* process_name) noexcept;
20 | EXPORT void EIOS_Inject_PID(std::int32_t pid) noexcept;
21 | EXPORT EIOS* EIOS_From_PID(std::int32_t pid) noexcept;
22 | EXPORT void Reflect_Release_Object(EIOS* eios, jobject object) noexcept;
23 | EXPORT void Reflect_Release_Objects(EIOS* eios, jobject* objects, std::size_t amount) noexcept;
24 |
25 | #ifdef __cplusplus
26 | }
27 | #endif
28 |
29 | #endif //REMOTEINPUT_NATIVEPLUGIN_HXX
30 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/Plugin.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Plugin.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2019-12-21.
6 | // Copyright © 2019 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef PLUGIN_HXX_INCLUDED
10 | #define PLUGIN_HXX_INCLUDED
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | #if defined(_WIN32) || defined(_WIN64)
17 | #include
18 | extern HMODULE module;
19 | #endif
20 |
21 | #endif /* PLUGIN_HXX_INCLUDED */
22 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/Python/PythonJavaArray.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2023-12-10.
3 | //
4 |
5 | #ifndef REMOTEINPUT_PYTHONJAVAARRAY_HXX
6 | #define REMOTEINPUT_PYTHONJAVAARRAY_HXX
7 |
8 | #include "PythonCommon.hxx"
9 |
10 | #if defined(USE_PYBIND11)
11 | void declare_python_java_array(nanobind::module_ &module);
12 | #else
13 | PyObject* Python_JavaArray_GetLength(PyJavaArray* self, PyObject* args[], Py_ssize_t args_length) noexcept;
14 | PyObject* Python_JavaArray_Get1D(PyJavaArray* self, PyObject* args[], Py_ssize_t args_length, PyObject* kwnames) noexcept;
15 | PyObject* Python_JavaArray_Get2D(PyJavaArray* self, PyObject* args[], Py_ssize_t args_length, PyObject* kwnames) noexcept;
16 | PyObject* Python_JavaArray_Get3D(PyJavaArray* self, PyObject* args[], Py_ssize_t args_length, PyObject* kwnames) noexcept;
17 | PyObject* Python_JavaArray_Get4D(PyJavaArray* self, PyObject* args[], Py_ssize_t args_length, PyObject* kwnames) noexcept;
18 | PyObject* Python_JavaArray_Release_Object(PyJavaArray* self, PyObject* args[], Py_ssize_t args_length) noexcept;
19 | #endif
20 |
21 | #endif //REMOTEINPUT_PYTHONJAVAARRAY_HXX
22 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/Python/PythonJavaList.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2023-12-18.
3 | //
4 |
5 | #ifndef REMOTEINPUT_PYTHONJAVALIST_HXX
6 | #define REMOTEINPUT_PYTHONJAVALIST_HXX
7 |
8 | #include "PythonCommon.hxx"
9 |
10 | PyObject* create_java_list(Py_ssize_t length);
11 |
12 | #endif //REMOTEINPUT_PYTHONJAVALIST_HXX
13 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/Python/PythonJavaObject.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2022-09-21.
3 | //
4 |
5 | #ifndef REMOTEINPUT_PYTHONJAVAOBJECT_HXX
6 | #define REMOTEINPUT_PYTHONJAVAOBJECT_HXX
7 |
8 | #include "PythonCommon.hxx"
9 |
10 | #if defined(USE_PYBIND11)
11 | void declare_python_java_object(nanobind::module_ &module);
12 | #else
13 | PyObject* Python_Reflect_Object(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
14 | PyObject* Python_Reflect_IsSame_Object(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
15 | PyObject* Python_Reflect_InstanceOf(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
16 | PyObject* Python_Reflect_Bool(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
17 | PyObject* Python_Reflect_Char(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
18 | PyObject* Python_Reflect_Byte(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
19 | PyObject* Python_Reflect_Short(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
20 | PyObject* Python_Reflect_Int(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
21 | PyObject* Python_Reflect_Long(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
22 | PyObject* Python_Reflect_Float(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
23 | PyObject* Python_Reflect_Double(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
24 | PyObject* Python_Reflect_String(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
25 | PyObject* Python_Reflect_Array(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
26 | PyObject* Python_JavaObject_Release_Object(PyJavaObject* self, PyObject* args[], Py_ssize_t args_length) noexcept;
27 | #endif
28 |
29 | #endif //REMOTEINPUT_PYTHONJAVAOBJECT_HXX
30 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/Python/PythonMacros.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Brandon on 2024-09-17.
3 | //
4 |
5 | #ifndef REMOTEINPUT_PYTHONMACROS_HXX
6 | #define REMOTEINPUT_PYTHONMACROS_HXX
7 |
8 | #if !defined(USE_PYBIND11)
9 | // On Windows, Python is really badly implemented,
10 | // so we must include `math.h` and not `cmath` to get the _hpyot symbol
11 | #include
12 | #include
13 | #include
14 | #include "object.h"
15 |
16 | #if defined(_WIN32) || defined(_WIN64)
17 | #include "structmember.h"
18 | #elif defined(__linux__) && (defined(__x86_64__) || defined(__i386__))
19 | #include "structmember.h"
20 | #elif defined(__APPLE__)
21 | #if __has_include()
22 | #include /* Python.framework */
23 | #else
24 | #include "structmember.h"
25 | #endif
26 | #elif defined(__aarch64__) || defined(__arm__)
27 | #include "structmember.h"
28 | #endif
29 |
30 | #if defined(_WIN32) || defined(_WIN64)
31 | #include
32 | #else
33 | #include
34 | #endif // defined
35 |
36 | #if defined(Py_LIMITED_API)
37 | #ifndef HAS_PYTHON_VERSION
38 | #define HAS_PYTHON_VERSION(MIN_VERSION) ((Py_LIMITED_API >= MIN_VERSION) && (PY_VERSION_HEX >= MIN_VERSION))
39 | #endif
40 | #else
41 | #ifndef HAS_PYTHON_VERSION
42 | #define HAS_PYTHON_VERSION(MIN_VERSION) (PY_VERSION_HEX >= MIN_VERSION)
43 | #endif
44 | #endif
45 |
46 | #if HAS_PYTHON_VERSION(0x03070000)
47 | #ifndef METH_FASTCALL
48 | #define METH_FASTCALL 0x0080 // Python 3.7 incorrectly labels this as Py_LIMITED_API
49 | #endif
50 | #endif
51 | #endif
52 |
53 | #endif //REMOTEINPUT_PYTHONMACROS_HXX
54 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/Python/PythonPlugin.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // PythonPlugin.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2020-11-09.
6 | // Copyright © 2020 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef REMOTEINPUT_PYTHONPLUGIN_HXX
10 | #define REMOTEINPUT_PYTHONPLUGIN_HXX
11 |
12 | #include "Plugin.hxx"
13 |
14 | #ifndef USE_PYBIND11
15 |
16 | //On Windows, Python is really badly implemented, so we must include `math.h` and not `cmath` to get the _hpyot symbol
17 | #include
18 | #include
19 |
20 | #if defined(_WIN32) || defined (_WIN64)
21 | #define EXPORT __declspec(dllexport)
22 | #else
23 | #define EXPORT [[gnu::visibility("default")]]
24 | #endif
25 |
26 | #if PY_MAJOR_VERSION < 3
27 | #define MODINIT(name) init##name
28 | #else
29 | #define MODINIT(name) PyInit_##name
30 | #endif
31 |
32 | extern "C"
33 | {
34 | //PyMODINIT_FUNC MODINIT(remote_input)();
35 | EXPORT PyObject* PyInit_remote_input();
36 | }
37 |
38 | #endif
39 |
40 | #endif //REMOTEINPUT_PYTHONPLUGIN_HXX
41 |
--------------------------------------------------------------------------------
/RemoteInput/Plugin/Signal.hxx:
--------------------------------------------------------------------------------
1 | //
2 | // Signal.hxx
3 | // RemoteInput
4 | //
5 | // Created by Brandon on 2019-12-15.
6 | // Copyright © 2019 XIO. All rights reserved.
7 | //
8 |
9 | #ifndef SIGNAL_HXX_INCLUDED
10 | #define SIGNAL_HXX_INCLUDED
11 |
12 | #include "Synchronization.hxx"
13 |
14 | template
15 | class Signal
16 | {
17 | private:
18 | T primitive;
19 |
20 | public:
21 | Signal() noexcept requires synchronization::lockable || synchronization::acquirable;
22 | Signal(std::string name) noexcept requires synchronization::lockable || synchronization::acquirable;
23 | ~Signal() = default;
24 |
25 | Signal(const Signal &other) = delete;
26 | Signal& operator = (const Signal &other) = delete;
27 |
28 | void signal() noexcept;
29 | void wait() noexcept;
30 |
31 | bool try_wait() noexcept;
32 |
33 | template
34 | bool try_wait_for(const std::chrono::duration& relative_time) noexcept;
35 |
36 | template
37 | bool try_wait_until(const std::chrono::time_point& absolute_time) noexcept;
38 | };
39 |
40 | template
41 | Signal::Signal() noexcept requires synchronization::lockable || synchronization::acquirable
42 | : primitive()
43 | {
44 | }
45 |
46 | template
47 | Signal::Signal(std::string name) noexcept requires synchronization::lockable || synchronization::acquirable
48 | : primitive(name)
49 | {
50 | }
51 |
52 | template
53 | void Signal::signal() noexcept
54 | {
55 | if constexpr(synchronization::lockable)
56 | {
57 | primitive.unlock();
58 | }
59 | else
60 | {
61 | primitive.release();
62 | }
63 | }
64 |
65 | template
66 | void Signal::wait() noexcept
67 | {
68 | if constexpr(synchronization::lockable)
69 | {
70 | primitive.lock();
71 | }
72 | else
73 | {
74 | primitive.acquire();
75 | }
76 | }
77 |
78 | template
79 | bool Signal::try_wait() noexcept
80 | {
81 | if constexpr(synchronization::lockable)
82 | {
83 | return primitive.try_lock();
84 | }
85 | else
86 | {
87 | return primitive.try_acquire();
88 | }
89 | }
90 |
91 |
92 | template
93 | template
94 | bool Signal::try_wait_for(const std::chrono::duration& relative_time) noexcept
95 | {
96 | if constexpr(synchronization::lockable