├── .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 | 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 | ![example workflow](https://github.com/Brandon-T/RemoteInput/actions/workflows/build.yml/badge.svg) 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 | 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) 97 | { 98 | return primitive.try_lock_for(relative_time); 99 | } 100 | else 101 | { 102 | return primitive.try_acquire_for(relative_time); 103 | } 104 | } 105 | 106 | template 107 | template 108 | bool Signal::try_wait_until(const std::chrono::time_point& absolute_time) noexcept 109 | { 110 | if constexpr(synchronization::lockable) 111 | { 112 | return primitive.try_lock_until(absolute_time); 113 | } 114 | else 115 | { 116 | return primitive.try_acquire_until(absolute_time); 117 | } 118 | } 119 | 120 | #endif /* SIGNAL_HXX_INCLUDED */ 121 | -------------------------------------------------------------------------------- /RemoteInput/Random.cxx: -------------------------------------------------------------------------------- 1 | // 2 | // Random.cxx 3 | // RemoteInput 4 | // 5 | // Created by Brandon on 2019-12-29. 6 | // Copyright © 2019 XIO. All rights reserved. 7 | // 8 | 9 | #include "Random.hxx" 10 | 11 | std::shared_ptr Random::instance() noexcept 12 | { 13 | thread_local std::shared_ptr instance{new Random()}; 14 | return instance; 15 | } 16 | 17 | std::int64_t Random::generate_random_int(std::int64_t min, std::int64_t max) noexcept 18 | { 19 | thread_local std::uniform_int_distribution dist{min, max}; 20 | return dist(rng, decltype(dist)::param_type(min, max)); 21 | } 22 | 23 | float Random::generate_random_float(float min, float max) noexcept 24 | { 25 | thread_local std::uniform_real_distribution<> dist{min, std::nextafter(max, std::numeric_limits::max())}; 26 | return dist(rng, decltype(dist)::param_type(min, std::nextafter(max, std::numeric_limits::max()))); 27 | } 28 | 29 | double Random::generate_random_double(double min, double max) noexcept 30 | { 31 | thread_local std::uniform_real_distribution<> dist{min, std::nextafter(max, std::numeric_limits::max())}; 32 | return dist(rng, decltype(dist)::param_type(min, std::nextafter(max, std::numeric_limits::max()))); 33 | } 34 | -------------------------------------------------------------------------------- /RemoteInput/Random.hxx: -------------------------------------------------------------------------------- 1 | // 2 | // Random.hxx 3 | // RemoteInput 4 | // 5 | // Created by Brandon on 2019-12-29. 6 | // Copyright © 2019 XIO. All rights reserved. 7 | // 8 | 9 | #ifndef RANDOM_HXX_INCLUDED 10 | #define RANDOM_HXX_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | class Random 17 | { 18 | private: 19 | Random() {} 20 | 21 | #if defined(__x86_64__) 22 | std::mt19937_64 rng{std::random_device()()}; 23 | #else 24 | std::mt19937 rng{std::random_device()()}; 25 | #endif 26 | 27 | public: 28 | Random(Random const&) = delete; 29 | Random& operator = (Random const&) = delete; 30 | 31 | static std::shared_ptr instance() noexcept; 32 | 33 | std::int64_t generate_random_int(std::int64_t min, std::int64_t max) noexcept; 34 | float generate_random_float(float min, float max) noexcept; 35 | double generate_random_double(double min, double max) noexcept; 36 | }; 37 | 38 | #endif /* RANDOM_HXX_INCLUDED */ 39 | -------------------------------------------------------------------------------- /RemoteInput/ReflectionHook.cxx: -------------------------------------------------------------------------------- 1 | // 2 | // ReflectionHook.cxx 3 | // RemoteInput 4 | // 5 | // Created by Brandon on 2019-12-01. 6 | // Copyright © 2019 XIO. All rights reserved. 7 | // 8 | 9 | #include "ReflectionHook.hxx" 10 | 11 | ReflectionHook::ReflectionHook(jobject object, std::string cls, std::string field, std::string desc) noexcept : object(object), cls(cls), field(field), desc(desc) 12 | {} 13 | 14 | Stream& operator << (Stream& stream, const ReflectionHook &hook) 15 | { 16 | return stream << hook.object << hook.cls << hook.field << hook.desc; 17 | } 18 | 19 | Stream& operator >> (Stream& stream, ReflectionHook &hook) 20 | { 21 | return stream >> hook.object >> hook.cls >> hook.field >> hook.desc; 22 | } -------------------------------------------------------------------------------- /RemoteInput/ReflectionHook.hxx: -------------------------------------------------------------------------------- 1 | // 2 | // ReflectionHook.hxx 3 | // RemoteInput 4 | // 5 | // Created by Brandon on 2019-12-01. 6 | // Copyright © 2019 XIO. All rights reserved. 7 | // 8 | 9 | #ifndef ReflectionHook_HXX_INCLUDED 10 | #define ReflectionHook_HXX_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | #include "JNI_Common.hxx" 16 | #include "Stream.hxx" 17 | #include "TypeTraits.hxx" 18 | 19 | struct ReflectionHook 20 | { 21 | jobject object; 22 | std::string cls; 23 | std::string field; 24 | std::string desc; 25 | 26 | ReflectionHook(jobject object = nullptr, std::string cls = "", std::string field = "", std::string desc = "") noexcept; 27 | }; 28 | 29 | Stream& operator << (Stream& stream, const ReflectionHook &hook); 30 | Stream& operator >> (Stream& stream, ReflectionHook &hook); 31 | 32 | template<> 33 | struct std::hash 34 | { 35 | std::size_t operator()(const ReflectionHook& hook) const noexcept 36 | { 37 | std::size_t hash = 0; 38 | hash_combine(hash, hook.cls); 39 | hash_combine(hash, hook.field); 40 | hash_combine(hash, hook.desc); 41 | return hash; 42 | } 43 | }; 44 | 45 | #endif /* ReflectionHook_HXX_INCLUDED */ 46 | -------------------------------------------------------------------------------- /RemoteInput/RemoteInput.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | EIOS_GetImageBuffer=EIOS_GetImageBuffer@4 3 | EIOS_GetDebugImageBuffer=EIOS_GetDebugImageBuffer@4 4 | EIOS_GetMousePosition=EIOS_GetMousePosition@12 5 | EIOS_GetTargetDimensions=EIOS_GetTargetDimensions@12 6 | EIOS_HoldKey=EIOS_HoldKey@8 7 | EIOS_HoldMouse=EIOS_HoldMouse@16 8 | EIOS_IsKeyHeld=EIOS_IsKeyHeld@8 9 | EIOS_IsMouseHeld=EIOS_IsMouseHeld@8 10 | EIOS_MoveMouse=EIOS_MoveMouse@12 11 | EIOS_ReleaseKey=EIOS_ReleaseKey@8 12 | EIOS_ReleaseMouse=EIOS_ReleaseMouse@16 13 | EIOS_ReleaseTarget=EIOS_ReleaseTarget@4 14 | EIOS_RequestTarget=EIOS_RequestTarget@4 15 | EIOS_ScrollMouse=EIOS_ScrollMouse@16 16 | EIOS_SendString=EIOS_SendString@16 17 | EIOS_UpdateImageBuffer=EIOS_UpdateImageBuffer@4 18 | GetFunctionCount 19 | GetFunctionInfo 20 | GetPluginABIVersion 21 | GetTypeCount 22 | GetTypeInfo 23 | OnAttach 24 | OnDetach 25 | SetPluginMemManager 26 | SetPluginSimbaMethods 27 | SetPluginSimbaMemoryAllocators 28 | RegisterSimbaPlugin 29 | -------------------------------------------------------------------------------- /RemoteInput/RemoteInput.h: -------------------------------------------------------------------------------- 1 | // 2 | // RemoteInput.h 3 | // RemoteInput 4 | // 5 | // Created by Brandon on 2019-09-14. 6 | // Copyright © 2019 XIO. All rights reserved. 7 | // 8 | 9 | #if defined(__APPLE__) 10 | #import 11 | 12 | //! Project version number for RemoteInput. 13 | FOUNDATION_EXPORT double RemoteInputVersionNumber; 14 | 15 | //! Project version string for RemoteInput. 16 | FOUNDATION_EXPORT const unsigned char RemoteInputVersionString[]; 17 | #endif 18 | 19 | // In this header, you should import all the public headers of your framework using statements like #import 20 | 21 | 22 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/Hook.hxx: -------------------------------------------------------------------------------- 1 | // 2 | // Created by brandon on 2020-04-06. 3 | // 4 | 5 | #ifndef HOOK_HXX 6 | #define HOOK_HXX 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class Hook 13 | { 14 | private: 15 | void* original; 16 | void* detour; 17 | void* trampoline; 18 | std::uint8_t data[32]; 19 | 20 | public: 21 | Hook(void* original, void* detour); 22 | Hook(const Hook& other) = delete; 23 | Hook(Hook&& other) noexcept; 24 | ~Hook(); 25 | 26 | Hook& operator = (const Hook& other) = delete; 27 | Hook& operator = (Hook&& other) = delete; 28 | 29 | void apply(); 30 | void remove(); 31 | 32 | template 33 | R call(Args... args); 34 | }; 35 | 36 | template 37 | R Hook::call( Args... args) 38 | { 39 | #if defined(_WIN32) || defined(_WIN64) 40 | return reinterpret_cast(trampoline ? trampoline : original)(std::forward(args)...); 41 | #elif defined(__APPLE__) 42 | return reinterpret_cast(trampoline ? trampoline : original)(std::forward(args)...); 43 | #else 44 | return reinterpret_cast(original)(std::forward(args)...); 45 | #endif 46 | } 47 | 48 | #endif //HOOK_HXX 49 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/Injector.cxx: -------------------------------------------------------------------------------- 1 | // 2 | // Created by brandon on 04/11/24. 3 | // 4 | 5 | #include "Injector.hxx" 6 | #include "kubo_injector/include/injector.h" 7 | 8 | Injector::Injector(std::int32_t pid) : pid(pid), injector(nullptr), handle(nullptr) 9 | { 10 | if (injector_attach(reinterpret_cast(&injector), pid) != 0) 11 | { 12 | injector = nullptr; 13 | } 14 | } 15 | 16 | Injector::~Injector() 17 | { 18 | if (injector) 19 | { 20 | injector_detach(reinterpret_cast(injector)); 21 | } 22 | 23 | handle = nullptr; 24 | injector = nullptr; 25 | } 26 | 27 | bool Injector::Inject(std::string module_path) noexcept 28 | { 29 | if (injector && !handle) 30 | { 31 | return injector_inject(static_cast(injector), module_path.c_str(), &handle) == 0; 32 | } 33 | return false; 34 | } 35 | 36 | bool Injector::UnInject() noexcept 37 | { 38 | if (injector && handle) 39 | { 40 | if (injector_uninject(static_cast(injector), handle) == 0) 41 | { 42 | handle = nullptr; 43 | return true; 44 | } 45 | } 46 | return false; 47 | } 48 | 49 | std::int32_t Injector::get_pid() const noexcept 50 | { 51 | return pid; 52 | } 53 | 54 | bool Injector::is_injected() const noexcept 55 | { 56 | return injector && handle; 57 | } -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/Injector.hxx: -------------------------------------------------------------------------------- 1 | // 2 | // Created by brandon on 04/11/24. 3 | // 4 | 5 | #ifndef INJECTOR_HXX 6 | #define INJECTOR_HXX 7 | 8 | #include 9 | #include 10 | 11 | class Injector 12 | { 13 | private: 14 | std::int32_t pid; 15 | void* injector; 16 | void* handle; 17 | 18 | public: 19 | Injector(std::int32_t pid); 20 | ~Injector(); 21 | 22 | bool Inject(std::string module_path) noexcept; 23 | bool UnInject() noexcept; 24 | 25 | std::int32_t get_pid() const noexcept; 26 | bool is_injected() const noexcept; 27 | }; 28 | 29 | 30 | 31 | #endif //INJECTOR_HXX 32 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/kubo_injector/src/linux/shellcode.S: -------------------------------------------------------------------------------- 1 | #if defined(__x86_64__) 2 | #define handle_offset 0 3 | #define dlopen_addr_offset 8 4 | #define dlerror_addr_offset 16 5 | #define dlflags_offset 24 6 | #define file_path_offset 28 7 | #define page_size 4096 8 | .text 9 | .global injector_shellcode 10 | .hidden injector_shellcode 11 | .type injector_shellcode, @function 12 | // void *injector_shellcode(injector_shellcode_arg_t *arg) { 13 | injector_shellcode: 14 | // // prolog 15 | pushq %rbx 16 | movq %rdi, %rbx 17 | // int dlflags = arg->dlflags; 18 | movl dlflags_offset(%rbx), %esi 19 | // const char *file_path = arg->file_path; 20 | leaq file_path_offset(%rbx), %rdi 21 | // void *handle = dlopen(file_path, dlflags); 22 | call *dlopen_addr_offset(%rbx) 23 | // arg->handle = handle; 24 | movq %rax, handle_offset(%rbx) 25 | // arg->file_path[0] = '\0'; 26 | movb $0, file_path_offset(%rbx) 27 | // if (handle != NULL) return; 28 | test %rax, %rax 29 | jnz .exit 30 | // if (arg->dlerror_addr == 0) return; 31 | cmpq $0, dlerror_addr_offset(%rbx) 32 | je .exit 33 | // char *errmsg = dlerror(); 34 | call *dlerror_addr_offset(%rbx) 35 | // if (errmsg == NULL) return; 36 | test %rax, %rax 37 | jz .exit 38 | // char *dest = arg->file_path 39 | leaq file_path_offset(%rbx), %rdi 40 | // char *end = (char*)arg + page_size; 41 | leaq page_size(%rbx), %rcx 42 | .loop: 43 | // char c = *(errmsg++); 44 | movb (%rax), %dl 45 | addq $1, %rax 46 | // *(dest++) = c; 47 | movb %dl, (%rdi) 48 | addq $1, %rdi 49 | // if (c == 0) return; 50 | testb %dl, %dl 51 | jz .exit 52 | // if (dest < end) goto loop; 53 | cmpq %rdi, %rcx 54 | ja .loop 55 | .exit: 56 | // // epilog 57 | popq %rbx 58 | ret 59 | // } 60 | .size injector_shellcode, . - injector_shellcode 61 | 62 | .balign 4 63 | .global injector_shellcode_size 64 | .hidden injector_shellcode_size 65 | .type injector_shellcode_size, @object 66 | .size injector_shellcode_size, 4 67 | injector_shellcode_size: 68 | // distance from injector_shellcode to current. 69 | .int . - injector_shellcode 70 | #endif 71 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/kubo_injector/src/linux/util.c: -------------------------------------------------------------------------------- 1 | /* -*- indent-tabs-mode: nil -*- 2 | * 3 | * injector - Library for injecting a shared library into a Linux process 4 | * 5 | * URL: https://github.com/kubo/injector 6 | * 7 | * ------------------------------------------------------ 8 | * 9 | * Copyright (C) 2018 Kubo Takehiro 10 | * 11 | * This library is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU Lesser General Public 13 | * License as published by the Free Software Foundation; either 14 | * version 2.1 of the License, or (at your option) any later version. 15 | * 16 | * This library is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | * Lesser General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU Lesser General Public 22 | * License along with this library; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | #include 26 | #include 27 | #include "injector_internal.h" 28 | 29 | char injector__errmsg[512]; 30 | char injector__errmsg_is_set; 31 | 32 | void injector__set_errmsg(const char *format, ...) 33 | { 34 | va_list ap; 35 | int rv; 36 | 37 | /* prevent the error message from being overwritten. */ 38 | if (injector__errmsg_is_set) { 39 | return; 40 | } 41 | injector__errmsg_is_set = 1; 42 | 43 | va_start(ap, format); 44 | rv = vsnprintf(injector__errmsg, sizeof(injector__errmsg), format, ap); 45 | va_end(ap); 46 | if (rv == -1 || rv >= sizeof(injector__errmsg)) { 47 | injector__errmsg[sizeof(injector__errmsg) - 1] = '\0'; 48 | } 49 | } 50 | 51 | const char *injector__arch2name(arch_t arch) 52 | { 53 | switch (arch) { 54 | case ARCH_X86_64: 55 | return "x86_64"; 56 | case ARCH_X86_64_X32: 57 | return "x86_64 x32-ABI"; 58 | case ARCH_I386: 59 | return "i386"; 60 | case ARCH_ARM64: 61 | return "ARM64"; 62 | case ARCH_ARM_EABI_THUMB: 63 | return "ARM EABI thumb"; 64 | case ARCH_ARM_EABI: 65 | return "ARM EABI"; 66 | case ARCH_MIPS_64: 67 | return "MIPS 64"; 68 | case ARCH_MIPS_N32: 69 | return "MIPS N32 ABI"; 70 | case ARCH_MIPS_O32: 71 | return "MIPS O32 ABI"; 72 | case ARCH_POWERPC_64: 73 | return "PowerPC 64-bit"; 74 | case ARCH_POWERPC: 75 | return "PowerPC"; 76 | case ARCH_RISCV_64: 77 | return "RISC-V 64"; 78 | case ARCH_RISCV_32: 79 | return "RISC-V 32"; 80 | } 81 | return "?"; 82 | } 83 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/kubo_injector/src/macos/ptrace.c: -------------------------------------------------------------------------------- 1 | /* -*- indent-tabs-mode: nil -*- 2 | * 3 | * injector - Library for injecting a shared library into a Linux process 4 | * 5 | * URL: https://github.com/kubo/injector 6 | * 7 | * ------------------------------------------------------ 8 | * 9 | * Copyright (C) 2022 TheOiseth 10 | * 11 | * This library is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU Lesser General Public 13 | * License as published by the Free Software Foundation; either 14 | * version 2.1 of the License, or (at your option) any later version. 15 | * 16 | * This library is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | * Lesser General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU Lesser General Public 22 | * License along with this library; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | #include "injector_internal.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | #define PTRACE_OR_RETURN(request, injector, addr, data) do { \ 31 | int rv = injector__ptrace(request, injector->pid, addr, data, #request); \ 32 | if (rv != 0) { \ 33 | return rv; \ 34 | } \ 35 | } while (0) 36 | static int set_ptrace_error(const char *request_name) 37 | { 38 | int err = errno; 39 | injector__set_errmsg("%s error : %s", request_name, strerror(errno)); 40 | switch (err) { 41 | case EFAULT: 42 | return INJERR_INVALID_MEMORY_AREA; 43 | case EPERM: 44 | return INJERR_PERMISSION; 45 | case ESRCH: 46 | return INJERR_NO_PROCESS; 47 | } 48 | return INJERR_OTHER; 49 | } 50 | 51 | int injector__ptrace(int request, pid_t pid, long addr, long data, const char *request_name) 52 | { 53 | if (ptrace(request, pid, (caddr_t)addr, data) != 0) { 54 | return set_ptrace_error(request_name); 55 | } 56 | return 0; 57 | } 58 | 59 | int injector__ptrace_attach(const injector_t *injector) 60 | { 61 | PTRACE_OR_RETURN(PT_ATTACHEXC, injector, 0, 0); 62 | return 0; 63 | } 64 | 65 | int injector__ptrace_detach(const injector_t *injector) 66 | { 67 | PTRACE_OR_RETURN(PT_DETACH, injector, 0, 0); 68 | return 0; 69 | } 70 | 71 | int injector__ptrace_continue(const injector_t *injector) 72 | { 73 | PTRACE_OR_RETURN(PT_CONTINUE, injector, 1, 0); 74 | return 0; 75 | } 76 | 77 | int injector__ptrace_update(const injector_t *injector, long thread_port) 78 | { 79 | PTRACE_OR_RETURN(PT_THUPDATE, injector, thread_port, 0); 80 | return 0; 81 | } -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/kubo_injector/src/windows/injector.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | injector_attach 3 | injector_inject 4 | injector_detach 5 | injector_error 6 | injector_inject_w 7 | injector_remote_func_addr 8 | injector_remote_call 9 | injector_remote_vcall 10 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/linux_detours/include/plthook.h: -------------------------------------------------------------------------------- 1 | /* -*- indent-tabs-mode: nil -*- 2 | * 3 | * plthook.h -- the header file of plthook 4 | * 5 | * URL: https://github.com/kubo/plthook 6 | * 7 | * ------------------------------------------------------ 8 | * 9 | * Copyright 2013-2014 Kubo Takehiro 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, are 12 | * permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, this list of 15 | * conditions and the following disclaimer. 16 | * 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 18 | * of conditions and the following disclaimer in the documentation and/or other materials 19 | * provided with the distribution. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS OR IMPLIED 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 23 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * The views and conclusions contained in the software and documentation are those of the 32 | * authors and should not be interpreted as representing official policies, either expressed 33 | * or implied, of the authors. 34 | * 35 | */ 36 | #ifndef PLTHOOK_H 37 | #define PLTHOOK_H 1 38 | 39 | #define PLTHOOK_SUCCESS 0 40 | #define PLTHOOK_FILE_NOT_FOUND 1 41 | #define PLTHOOK_INVALID_FILE_FORMAT 2 42 | #define PLTHOOK_FUNCTION_NOT_FOUND 3 43 | #define PLTHOOK_INVALID_ARGUMENT 4 44 | #define PLTHOOK_OUT_OF_MEMORY 5 45 | #define PLTHOOK_INTERNAL_ERROR 6 46 | #define PLTHOOK_NOT_IMPLEMENTED 7 47 | 48 | typedef struct plthook plthook_t; 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | int plthook_open(plthook_t **plthook_out, const char *filename); 55 | int plthook_open_by_handle(plthook_t **plthook_out, void *handle); 56 | int plthook_open_by_address(plthook_t **plthook_out, void *address); 57 | int plthook_enum(plthook_t *plthook, unsigned int *pos, const char **name_out, void ***addr_out); 58 | int plthook_replace(plthook_t *plthook, const char *funcname, void *funcaddr, void **oldfunc); 59 | void plthook_close(plthook_t *plthook); 60 | const char *plthook_error(void); 61 | 62 | #ifdef __cplusplus 63 | }; /* extern "C" */ 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/min_hook/src/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | // Size of each memory slot. 32 | #if defined(_M_X64) || defined(__x86_64__) 33 | #define MEMORY_SLOT_SIZE 64 34 | #else 35 | #define MEMORY_SLOT_SIZE 32 36 | #endif 37 | 38 | VOID InitializeBuffer(VOID); 39 | VOID UninitializeBuffer(VOID); 40 | LPVOID AllocateBuffer(LPVOID pOrigin); 41 | VOID FreeBuffer(LPVOID pBuffer); 42 | BOOL IsExecutableAddress(LPVOID pAddress); 43 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/min_hook/src/hde/hde32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 3 | * Copyright (c) 2006-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde32.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE32_H_ 11 | #define _HDE32_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_DISP8 0x00000020 30 | #define F_DISP16 0x00000040 31 | #define F_DISP32 0x00000080 32 | #define F_RELATIVE 0x00000100 33 | #define F_2IMM16 0x00000800 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_ANY 0x3f000000 47 | 48 | #define PREFIX_SEGMENT_CS 0x2e 49 | #define PREFIX_SEGMENT_SS 0x36 50 | #define PREFIX_SEGMENT_DS 0x3e 51 | #define PREFIX_SEGMENT_ES 0x26 52 | #define PREFIX_SEGMENT_FS 0x64 53 | #define PREFIX_SEGMENT_GS 0x65 54 | #define PREFIX_LOCK 0xf0 55 | #define PREFIX_REPNZ 0xf2 56 | #define PREFIX_REPX 0xf3 57 | #define PREFIX_OPERAND_SIZE 0x66 58 | #define PREFIX_ADDRESS_SIZE 0x67 59 | 60 | #pragma pack(push,1) 61 | 62 | typedef struct { 63 | uint8_t len; 64 | uint8_t p_rep; 65 | uint8_t p_lock; 66 | uint8_t p_seg; 67 | uint8_t p_66; 68 | uint8_t p_67; 69 | uint8_t opcode; 70 | uint8_t opcode2; 71 | uint8_t modrm; 72 | uint8_t modrm_mod; 73 | uint8_t modrm_reg; 74 | uint8_t modrm_rm; 75 | uint8_t sib; 76 | uint8_t sib_scale; 77 | uint8_t sib_index; 78 | uint8_t sib_base; 79 | union { 80 | uint8_t imm8; 81 | uint16_t imm16; 82 | uint32_t imm32; 83 | } imm; 84 | union { 85 | uint8_t disp8; 86 | uint16_t disp16; 87 | uint32_t disp32; 88 | } disp; 89 | uint32_t flags; 90 | } hde32s; 91 | 92 | #pragma pack(pop) 93 | 94 | #ifdef __cplusplus 95 | extern "C" { 96 | #endif 97 | 98 | /* __cdecl */ 99 | unsigned int hde32_disasm(const void *code, hde32s *hs); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* _HDE32_H_ */ 106 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/min_hook/src/hde/hde64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_IMM64 0x00000020 30 | #define F_DISP8 0x00000040 31 | #define F_DISP16 0x00000080 32 | #define F_DISP32 0x00000100 33 | #define F_RELATIVE 0x00000200 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_REX 0x40000000 47 | #define F_PREFIX_ANY 0x7f000000 48 | 49 | #define PREFIX_SEGMENT_CS 0x2e 50 | #define PREFIX_SEGMENT_SS 0x36 51 | #define PREFIX_SEGMENT_DS 0x3e 52 | #define PREFIX_SEGMENT_ES 0x26 53 | #define PREFIX_SEGMENT_FS 0x64 54 | #define PREFIX_SEGMENT_GS 0x65 55 | #define PREFIX_LOCK 0xf0 56 | #define PREFIX_REPNZ 0xf2 57 | #define PREFIX_REPX 0xf3 58 | #define PREFIX_OPERAND_SIZE 0x66 59 | #define PREFIX_ADDRESS_SIZE 0x67 60 | 61 | #pragma pack(push,1) 62 | 63 | typedef struct { 64 | uint8_t len; 65 | uint8_t p_rep; 66 | uint8_t p_lock; 67 | uint8_t p_seg; 68 | uint8_t p_66; 69 | uint8_t p_67; 70 | uint8_t rex; 71 | uint8_t rex_w; 72 | uint8_t rex_r; 73 | uint8_t rex_x; 74 | uint8_t rex_b; 75 | uint8_t opcode; 76 | uint8_t opcode2; 77 | uint8_t modrm; 78 | uint8_t modrm_mod; 79 | uint8_t modrm_reg; 80 | uint8_t modrm_rm; 81 | uint8_t sib; 82 | uint8_t sib_scale; 83 | uint8_t sib_index; 84 | uint8_t sib_base; 85 | union { 86 | uint8_t imm8; 87 | uint16_t imm16; 88 | uint32_t imm32; 89 | uint64_t imm64; 90 | } imm; 91 | union { 92 | uint8_t disp8; 93 | uint16_t disp16; 94 | uint32_t disp32; 95 | } disp; 96 | uint32_t flags; 97 | } hde64s; 98 | 99 | #pragma pack(pop) 100 | 101 | #ifdef __cplusplus 102 | extern "C" { 103 | #endif 104 | 105 | /* __cdecl */ 106 | unsigned int hde64_disasm(const void *code, hde64s *hs); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* _HDE64_H_ */ 113 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/min_hook/src/hde/pstdint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | // Integer types for HDE. 32 | typedef INT8 int8_t; 33 | typedef INT16 int16_t; 34 | typedef INT32 int32_t; 35 | typedef INT64 int64_t; 36 | typedef UINT8 uint8_t; 37 | typedef UINT16 uint16_t; 38 | typedef UINT32 uint32_t; 39 | typedef UINT64 uint64_t; 40 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Wenzel Jakob , All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/README.md: -------------------------------------------------------------------------------- 1 | # nanobind: tiny and efficient C++/Python bindings 2 | 3 | [![Documentation](https://img.shields.io/readthedocs/nanobind/latest)](https://nanobind.readthedocs.io/en/latest/) 4 | [![Continuous Integration](https://img.shields.io/github/actions/workflow/status/wjakob/nanobind/ci.yml?label=tests)](https://github.com/wjakob/nanobind/actions/workflows/ci.yml) 5 | [![](https://img.shields.io/pypi/v/nanobind.svg?color=brightgreen)](https://pypi.org/pypi/nanobind/) 6 | ![](https://img.shields.io/pypi/l/nanobind.svg?color=brightgreen) 7 | [![](https://img.shields.io/badge/Example-Link-brightgreen)](https://github.com/wjakob/nanobind_example) 8 | [![](https://img.shields.io/badge/Changelog-Link-brightgreen)](https://nanobind.readthedocs.io/en/latest/changelog.html) 9 | 10 |

11 | 12 | 13 | 14 | nanobind logo 15 | 16 |

17 | 18 | _nanobind_ is a small binding library that exposes C++ types in Python and vice 19 | versa. It is reminiscent of 20 | [Boost.Python](https://www.boost.org/doc/libs/1_64_0/libs/python/doc/html) and 21 | [pybind11](https://github.com/pybind/pybind11) and uses near-identical syntax. 22 | In contrast to these existing tools, nanobind is more efficient: bindings 23 | compile in a shorter amount of time, produce smaller binaries, and have better 24 | runtime performance. 25 | 26 | More concretely, 27 | [benchmarks](https://nanobind.readthedocs.io/en/latest/benchmark.html) show up 28 | to **~4× faster** compile time, **~5× smaller** binaries, and **~10× lower** 29 | runtime overheads compared to pybind11. nanobind also outperforms Cython in 30 | important metrics (**3-12×** binary size reduction, **1.6-4×** compilation time 31 | reduction, similar runtime performance). 32 | 33 | ## Documentation 34 | 35 | Please see the following links for tutorial and reference documentation in 36 | [HTML](https://nanobind.readthedocs.io/en/latest/) and 37 | [PDF](https://nanobind.readthedocs.io/_/downloads/en/latest/pdf/) formats. 38 | 39 | ## License and attribution 40 | 41 | All material in this repository is licensed under a three-clause [BSD 42 | license](LICENSE). 43 | 44 | Please use the following BibTeX template to cite nanobind in scientific 45 | discourse: 46 | 47 | ```bibtex 48 | @misc{nanobind, 49 | author = {Wenzel Jakob}, 50 | year = {2022}, 51 | note = {https://github.com/wjakob/nanobind}, 52 | title = {nanobind: tiny and efficient C++/Python bindings} 53 | } 54 | ``` 55 | 56 | The nanobind logo was designed by [AndoTwin Studio](https://andotwinstudio.com) 57 | (high-resolution download: 58 | [light](https://rgl.s3.eu-central-1.amazonaws.com/media/uploads/wjakob/2023/03/27/nanobind_logo.jpg), 59 | [dark](https://rgl.s3.eu-central-1.amazonaws.com/media/uploads/wjakob/2023/03/28/nanobind_logo_dark_1.png)). 60 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/cmake/collect-symbols-pypy.py: -------------------------------------------------------------------------------- 1 | from urllib.request import urlopen 2 | import tarfile 3 | import subprocess 4 | 5 | funcs: "set[str]" = set() 6 | 7 | files = [ 8 | ('https://downloads.python.org/pypy/pypy3.9-v7.3.11-macos_arm64.tar.bz2', 'pypy3.9-v7.3.11-macos_arm64/bin/libpypy3.9-c.dylib') 9 | ] 10 | 11 | for f in files: 12 | fs = urlopen(f[0]) 13 | ft = tarfile.open(fileobj=fs, mode="r|bz2") 14 | success = False 15 | for member in ft: # move to the next file each loop 16 | if member.name == f[1]: 17 | ft.extract(member, path='tmp') 18 | success = True 19 | assert success 20 | 21 | out = subprocess.check_output(['nm', '-gjU', 'tmp/' + f[1]]) 22 | for line in out.decode().split('\n'): 23 | if line.startswith('_Py') or line.startswith('__Py'): 24 | funcs.add(line) 25 | 26 | with open("darwin-ld-pypy.sym", "w") as f: 27 | for func in sorted(list(funcs)): 28 | f.write(f'-U _{func}\n') 29 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/cmake/collect-symbols.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # This script collects a list of symbols that are considered to be part of the 4 | # CPython API. The result is used to inform the macOS linker that it's fine for 5 | # those symbols to be undefined when an extension module is linked, as they 6 | # will be provided when the extension module is loaded into the interpreter. 7 | 8 | from urllib.request import urlopen 9 | import re 10 | 11 | funcs: "set[str]" = set() 12 | 13 | for ver in ['3.7', '3.8', '3.9']: 14 | url = f'https://raw.githubusercontent.com/python/cpython/{ver}/PC/python3.def' 15 | output = urlopen(url).read().decode('utf-8') 16 | for match in re.findall(r" (.*)=.*", output): 17 | funcs.add(match) 18 | 19 | for ver in ['3.10', '3.11', 'main']: 20 | url = f'https://raw.githubusercontent.com/python/cpython/{ver}/PC/python3dll.c' 21 | output = urlopen(url).read().decode('utf-8') 22 | for match in re.findall(r"EXPORT_FUNC\((.*)\)", output): 23 | funcs.add(match) 24 | 25 | funcs.remove('name') 26 | 27 | # Add a few more functions that nanobind uses and which aren't in the above list 28 | funcs |= { 29 | 'PyFrame_GetBack', 30 | 'PyGILState_Check', 31 | 'PyObject_LengthHint', 32 | 'Py_CompileStringExFlags', 33 | '_PyInterpreterState_Get', 34 | '_PyObject_MakeTpCall', 35 | '_PyObject_NextNotImplemented', 36 | '_Py_CheckFunctionResult', 37 | '_Py_RefTotal' 38 | } 39 | 40 | with open("darwin-ld-cpython.sym", "w") as f: 41 | for func in sorted(list(funcs)): 42 | f.write(f'-U _{func}\n') 43 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/ext/robin_map/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Thibaut Goetghebuer-Planchon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/ext/robin_map/cmake/tsl-robin-mapConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # This module sets the following variables: 2 | # * tsl-robin-map_FOUND - true if tsl-robin-map found on the system 3 | # * tsl-robin-map_INCLUDE_DIRS - the directory containing tsl-robin-map headers 4 | @PACKAGE_INIT@ 5 | 6 | if(NOT TARGET tsl::robin_map) 7 | include("${CMAKE_CURRENT_LIST_DIR}/tsl-robin-mapTargets.cmake") 8 | get_target_property(tsl-robin-map_INCLUDE_DIRS tsl::robin_map INTERFACE_INCLUDE_DIRECTORIES) 9 | endif() 10 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/eval.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/eval.h: Support for evaluating Python expressions and 3 | statements from strings 4 | 5 | Adapted by Nico Schlömer from pybind11's eval.h. 6 | 7 | All rights reserved. Use of this source code is governed by a 8 | BSD-style license that can be found in the LICENSE file. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | 17 | enum eval_mode { 18 | // Evaluate a string containing an isolated expression 19 | eval_expr = Py_eval_input, 20 | 21 | // Evaluate a string containing a single statement. Returns \c none 22 | eval_single_statement = Py_single_input, 23 | 24 | // Evaluate a string containing a sequence of statement. Returns \c none 25 | eval_statements = Py_file_input 26 | }; 27 | 28 | template 29 | object eval(const str &expr, handle global = handle(), handle local = handle()) { 30 | if (!local.is_valid()) 31 | local = global; 32 | 33 | // This used to be PyRun_String, but that function isn't in the stable ABI. 34 | object codeobj = steal(Py_CompileString(expr.c_str(), "", start)); 35 | if (!codeobj.is_valid()) 36 | raise_python_error(); 37 | 38 | PyObject *result = PyEval_EvalCode(codeobj.ptr(), global.ptr(), local.ptr()); 39 | if (!result) 40 | raise_python_error(); 41 | 42 | return steal(result); 43 | } 44 | 45 | template 46 | object eval(const char (&s)[N], handle global = handle(), handle local = handle()) { 47 | // Support raw string literals by removing common leading whitespace 48 | str expr = (s[0] == '\n') ? str(module_::import_("textwrap").attr("dedent")(s)) : str(s); 49 | return eval(expr, global, local); 50 | } 51 | 52 | inline void exec(const str &expr, handle global = handle(), handle local = handle()) { 53 | eval(expr, global, local); 54 | } 55 | 56 | template 57 | void exec(const char (&s)[N], handle global = handle(), handle local = handle()) { 58 | eval(s, global, local); 59 | } 60 | 61 | NAMESPACE_END(NB_NAMESPACE) 62 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/nanobind.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/nanobind.h: Main include file for core nanobind components 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #if __cplusplus < 201703L && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L) 13 | # error The nanobind library requires C++17! 14 | #endif 15 | 16 | #if defined(_MSC_VER) 17 | # pragma warning(push) 18 | # pragma warning(disable: 4702) // unreachable code (e.g. when binding a noreturn function) 19 | // The next two lines disable warnings that are "just noise" according to Stephan T. Lavavej (a MSFT STL maintainer) 20 | # pragma warning(disable: 4275) // non dll-interface class 'std::exception' used as base for dll-interface class [..] 21 | # pragma warning(disable: 4251) // [..] needs to have a dll-interface to be used by clients of class [..] 22 | #endif 23 | 24 | #define NB_VERSION_MAJOR 2 25 | #define NB_VERSION_MINOR 2 26 | #define NB_VERSION_PATCH 0 27 | #define NB_VERSION_DEV 1 // A value > 0 indicates a development release 28 | 29 | // Core C++ headers that nanobind depends on 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | // Implementation. The nb_*.h files should only be included through nanobind.h 39 | #include "nb_python.h" 40 | #include "nb_defs.h" 41 | #include "nb_enums.h" 42 | #include "nb_traits.h" 43 | #include "nb_tuple.h" 44 | #include "nb_lib.h" 45 | #include "nb_descr.h" 46 | #include "nb_types.h" 47 | #include "nb_accessor.h" 48 | #include "nb_error.h" 49 | #include "nb_attr.h" 50 | #include "nb_cast.h" 51 | #include "nb_misc.h" 52 | #include "nb_call.h" 53 | #include "nb_func.h" 54 | #include "nb_class.h" 55 | 56 | #if defined(_MSC_VER) 57 | # pragma warning(pop) 58 | #endif 59 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/nb_enums.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/nb_enums.h: enumerations used in nanobind (just rv_policy atm.) 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | NAMESPACE_BEGIN(NB_NAMESPACE) 11 | 12 | // Approach used to cast a previously unknown C++ instance into a Python object 13 | enum class rv_policy { 14 | automatic, 15 | automatic_reference, 16 | take_ownership, 17 | copy, 18 | move, 19 | reference, 20 | reference_internal, 21 | none 22 | /* Note to self: nb_func.h assumes that this value fits into 3 bits, 23 | hence no further policies can be added. */ 24 | }; 25 | 26 | NAMESPACE_END(NB_NAMESPACE) 27 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/nb_misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/nb_misc.h: Miscellaneous bits (GIL, etc.) 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | NAMESPACE_BEGIN(NB_NAMESPACE) 11 | 12 | struct gil_scoped_acquire { 13 | public: 14 | NB_NONCOPYABLE(gil_scoped_acquire) 15 | gil_scoped_acquire() noexcept : state(PyGILState_Ensure()) { } 16 | ~gil_scoped_acquire() { PyGILState_Release(state); } 17 | 18 | private: 19 | const PyGILState_STATE state; 20 | }; 21 | 22 | struct gil_scoped_release { 23 | public: 24 | NB_NONCOPYABLE(gil_scoped_release) 25 | gil_scoped_release() noexcept : state(PyEval_SaveThread()) { } 26 | ~gil_scoped_release() { PyEval_RestoreThread(state); } 27 | 28 | private: 29 | PyThreadState *state; 30 | }; 31 | 32 | struct ft_mutex { 33 | public: 34 | NB_NONCOPYABLE(ft_mutex) 35 | ft_mutex() = default; 36 | 37 | #if !defined(NB_FREE_THREADED) 38 | void lock() { } 39 | void unlock() { } 40 | #else 41 | void lock() { PyMutex_Lock(&mutex); } 42 | void unlock() { PyMutex_Unlock(&mutex); } 43 | private: 44 | PyMutex mutex { 0 }; 45 | #endif 46 | }; 47 | 48 | struct ft_lock_guard { 49 | public: 50 | NB_NONCOPYABLE(ft_lock_guard) 51 | ft_lock_guard(ft_mutex &m) : m(m) { m.lock(); } 52 | ~ft_lock_guard() { m.unlock(); } 53 | private: 54 | ft_mutex &m; 55 | }; 56 | 57 | 58 | struct ft_object_guard { 59 | public: 60 | NB_NONCOPYABLE(ft_object_guard) 61 | #if !defined(NB_FREE_THREADED) 62 | ft_object_guard(handle) { } 63 | #else 64 | ft_object_guard(handle h) { PyCriticalSection_Begin(&cs, h.ptr()); } 65 | ~ft_object_guard() { PyCriticalSection_End(&cs); } 66 | private: 67 | PyCriticalSection cs; 68 | #endif 69 | }; 70 | 71 | struct ft_object2_guard { 72 | public: 73 | NB_NONCOPYABLE(ft_object2_guard) 74 | #if !defined(NB_FREE_THREADED) 75 | ft_object2_guard(handle, handle) { } 76 | #else 77 | ft_object2_guard(handle h1, handle h2) { PyCriticalSection2_Begin(&cs, h1.ptr(), h2.ptr()); } 78 | ~ft_object2_guard() { PyCriticalSection2_End(&cs); } 79 | private: 80 | PyCriticalSection2 cs; 81 | #endif 82 | }; 83 | 84 | inline bool leak_warnings() noexcept { 85 | return detail::leak_warnings(); 86 | } 87 | 88 | inline bool implicit_cast_warnings() noexcept { 89 | return detail::implicit_cast_warnings(); 90 | } 91 | 92 | inline void set_leak_warnings(bool value) noexcept { 93 | detail::set_leak_warnings(value); 94 | } 95 | 96 | inline void set_implicit_cast_warnings(bool value) noexcept { 97 | detail::set_implicit_cast_warnings(value); 98 | } 99 | 100 | inline dict globals() { 101 | PyObject *p = PyEval_GetGlobals(); 102 | if (!p) 103 | raise("nanobind::globals(): no frame is currently executing!"); 104 | return borrow(p); 105 | } 106 | 107 | inline Py_hash_t hash(handle h) { 108 | Py_hash_t rv = PyObject_Hash(h.ptr()); 109 | if (rv == -1 && PyErr_Occurred()) 110 | nanobind::raise_python_error(); 111 | return rv; 112 | } 113 | 114 | inline bool is_alive() noexcept { 115 | return detail::is_alive(); 116 | } 117 | 118 | NAMESPACE_END(NB_NAMESPACE) 119 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/nb_python.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/nb_python.h: Include CPython headers while temporarily disabling 3 | certain warnings. Also, disable dangerous preprocessor definitions. 4 | 5 | Copyright (c) 2022 Wenzel Jakob 6 | 7 | All rights reserved. Use of this source code is governed by a 8 | BSD-style license that can be found in the LICENSE file. 9 | */ 10 | 11 | /// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode 12 | 13 | #if defined(_MSC_VER) 14 | # pragma warning(push) 15 | # if defined(_DEBUG) && !defined(Py_DEBUG) 16 | # define NB_DEBUG_MARKER 17 | # undef _DEBUG 18 | # endif 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | /* Python #defines overrides on all sorts of core functions, which 27 | tends to weak havok in C++ codebases that expect these to work 28 | like regular functions (potentially with several overloads) */ 29 | #if defined(isalnum) 30 | # undef isalnum 31 | # undef isalpha 32 | # undef islower 33 | # undef isspace 34 | # undef isupper 35 | # undef tolower 36 | # undef toupper 37 | #endif 38 | 39 | #if defined(copysign) 40 | # undef copysign 41 | #endif 42 | 43 | #if defined(setter) 44 | # undef setter 45 | #endif 46 | 47 | #if defined(getter) 48 | # undef getter 49 | #endif 50 | 51 | #if defined(_MSC_VER) 52 | # if defined(NB_DEBUG_MARKER) 53 | # define _DEBUG 54 | # undef NB_DEBUG_MARKER 55 | # endif 56 | # pragma warning(pop) 57 | #endif 58 | 59 | #if PY_VERSION_HEX < 0x03080000 60 | # error The nanobind library requires Python 3.8 (or newer) 61 | #endif 62 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/nb_tuple.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/nb_tuple.h: tiny self-contained tuple class 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | NAMESPACE_BEGIN(NB_NAMESPACE) 11 | NAMESPACE_BEGIN(detail) 12 | 13 | /** 14 | * \brief nanobind::tuple<...>: a tiny recursive tuple class 15 | * 16 | * std::tuple<...> is one of those STL types that just seems unnecessarily 17 | * complex for typical usage. It pulls in a large amount of headers (22K LOC, 18 | * 530 KiB with Clang/libc++) and goes through elaborate contortions to avoid a 19 | * recursive definition. This is helpful when dealing with very large tuples 20 | * (e.g. efficient compilation of std::get<1000>() in a tuple with 10K entries). 21 | * When working with small tuples used to pass around a few arguments, a simple 22 | * recursive definition compiles faster (generated code is identical). 23 | */ 24 | 25 | template struct tuple; 26 | template <> struct tuple<> { 27 | template using type = void; 28 | }; 29 | 30 | template struct tuple : tuple { 31 | using Base = tuple; 32 | 33 | tuple() = default; 34 | tuple(const tuple &) = default; 35 | tuple(tuple &&) = default; 36 | tuple& operator=(tuple &&) = default; 37 | tuple& operator=(const tuple &) = default; 38 | 39 | template 40 | NB_INLINE tuple(A &&a, As &&...as) 41 | : Base((detail::forward_t) as...), value((detail::forward_t) a) {} 42 | 43 | template NB_INLINE auto& get() { 44 | if constexpr (I == 0) 45 | return value; 46 | else 47 | return Base::template get(); 48 | } 49 | 50 | template NB_INLINE const auto& get() const { 51 | if constexpr (I == 0) 52 | return value; 53 | else 54 | return Base::template get(); 55 | } 56 | 57 | template 58 | using type = 59 | std::conditional_t>; 60 | 61 | private: 62 | T value; 63 | }; 64 | 65 | template tuple(Ts &&...) -> tuple...>; 66 | 67 | NAMESPACE_END(detail) 68 | NAMESPACE_END(NB_NAMESPACE) 69 | 70 | // Support for C++17 structured bindings 71 | template 72 | struct std::tuple_size> 73 | : std::integral_constant { }; 74 | 75 | template 76 | struct std::tuple_element> { 77 | using type = typename nanobind::detail::tuple::template type; 78 | }; 79 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/array.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/array.h: type caster for std::array<...> 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/nb_array.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template struct type_caster> 19 | : array_caster, Type, Size> { }; 20 | 21 | NAMESPACE_END(detail) 22 | NAMESPACE_END(NB_NAMESPACE) 23 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/complex.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/complex.h: type caster for std::complex<...> 3 | 4 | Copyright (c) 2023 Degottex Gilles and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template struct type_caster> { 19 | NB_TYPE_CASTER(std::complex, const_name("complex")) 20 | 21 | template 22 | bool from_python(handle src, uint8_t flags, 23 | cleanup_list *cleanup) noexcept { 24 | (void) flags; 25 | (void) cleanup; 26 | 27 | if (PyComplex_Check(src.ptr())) { 28 | value = std::complex( 29 | (T) PyComplex_RealAsDouble(src.ptr()), 30 | (T) PyComplex_ImagAsDouble(src.ptr()) 31 | ); 32 | return true; 33 | } 34 | 35 | if constexpr (Recursive) { 36 | if (!PyFloat_CheckExact(src.ptr()) && 37 | !PyLong_CheckExact(src.ptr()) && 38 | PyObject_HasAttrString(src.ptr(), "imag")) { 39 | try { 40 | object tmp = handle(&PyComplex_Type)(src); 41 | return from_python(tmp, flags, cleanup); 42 | } catch (...) { 43 | return false; 44 | } 45 | } 46 | } 47 | 48 | make_caster caster; 49 | if (caster.from_python(src, flags, cleanup)) { 50 | value = std::complex(caster.operator cast_t()); 51 | return true; 52 | } 53 | 54 | return false; 55 | } 56 | 57 | template 58 | static handle from_cpp(T2 &&value, rv_policy policy, 59 | cleanup_list *cleanup) noexcept { 60 | (void) policy; 61 | (void) cleanup; 62 | 63 | return PyComplex_FromDoubles((double) value.real(), 64 | (double) value.imag()); 65 | } 66 | }; 67 | 68 | NAMESPACE_END(detail) 69 | NAMESPACE_END(NB_NAMESPACE) 70 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/detail/nb_array.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | NAMESPACE_BEGIN(NB_NAMESPACE) 6 | NAMESPACE_BEGIN(detail) 7 | 8 | template struct array_caster { 9 | NB_TYPE_CASTER(Array, io_name(NB_TYPING_SEQUENCE, NB_TYPING_LIST) + 10 | const_name("[") + make_caster::Name + 11 | const_name("]")) 12 | 13 | using Caster = make_caster; 14 | 15 | bool from_python(handle src, uint8_t flags, cleanup_list *cleanup) noexcept { 16 | PyObject *temp; 17 | 18 | /* Will initialize 'temp' (NULL in the case of a failure.) */ 19 | PyObject **o = seq_get_with_size(src.ptr(), Size, &temp); 20 | 21 | Caster caster; 22 | bool success = o != nullptr; 23 | 24 | flags = flags_for_local_caster(flags); 25 | 26 | if (success) { 27 | for (size_t i = 0; i < Size; ++i) { 28 | if (!caster.from_python(o[i], flags, cleanup) || 29 | !caster.template can_cast()) { 30 | success = false; 31 | break; 32 | } 33 | 34 | value[i] = caster.operator cast_t(); 35 | } 36 | 37 | Py_XDECREF(temp); 38 | } 39 | 40 | return success; 41 | } 42 | 43 | template 44 | static handle from_cpp(T &&src, rv_policy policy, cleanup_list *cleanup) { 45 | object ret = steal(PyList_New(Size)); 46 | 47 | if (ret.is_valid()) { 48 | Py_ssize_t index = 0; 49 | 50 | for (auto &value : src) { 51 | handle h = Caster::from_cpp(forward_like_(value), policy, cleanup); 52 | 53 | if (!h.is_valid()) { 54 | ret.reset(); 55 | break; 56 | } 57 | 58 | NB_LIST_SET_ITEM(ret.ptr(), index++, h.ptr()); 59 | } 60 | } 61 | 62 | return ret.release(); 63 | } 64 | }; 65 | 66 | NAMESPACE_END(detail) 67 | NAMESPACE_END(NB_NAMESPACE) 68 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/detail/nb_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/detail/nb_list.h: base class of list casters 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | NAMESPACE_BEGIN(NB_NAMESPACE) 15 | NAMESPACE_BEGIN(detail) 16 | 17 | template struct list_caster { 18 | NB_TYPE_CASTER(List, io_name(NB_TYPING_SEQUENCE, NB_TYPING_LIST) + 19 | const_name("[") + make_caster::Name + 20 | const_name("]")) 21 | 22 | using Caster = make_caster; 23 | 24 | template using has_reserve = decltype(std::declval().reserve(0)); 25 | 26 | bool from_python(handle src, uint8_t flags, cleanup_list *cleanup) noexcept { 27 | size_t size; 28 | PyObject *temp; 29 | 30 | /* Will initialize 'size' and 'temp'. All return values and 31 | return parameters are zero/NULL in the case of a failure. */ 32 | PyObject **o = seq_get(src.ptr(), &size, &temp); 33 | 34 | value.clear(); 35 | 36 | if constexpr (is_detected_v) 37 | value.reserve(size); 38 | 39 | Caster caster; 40 | bool success = o != nullptr; 41 | 42 | flags = flags_for_local_caster(flags); 43 | 44 | for (size_t i = 0; i < size; ++i) { 45 | if (!caster.from_python(o[i], flags, cleanup) || 46 | !caster.template can_cast()) { 47 | success = false; 48 | break; 49 | } 50 | 51 | value.push_back(caster.operator cast_t()); 52 | } 53 | 54 | Py_XDECREF(temp); 55 | 56 | return success; 57 | } 58 | 59 | template 60 | static handle from_cpp(T &&src, rv_policy policy, cleanup_list *cleanup) { 61 | object ret = steal(PyList_New(src.size())); 62 | 63 | if (ret.is_valid()) { 64 | Py_ssize_t index = 0; 65 | 66 | for (auto &&value : src) { 67 | handle h = Caster::from_cpp(forward_like_(value), policy, cleanup); 68 | 69 | if (!h.is_valid()) { 70 | ret.reset(); 71 | break; 72 | } 73 | 74 | NB_LIST_SET_ITEM(ret.ptr(), index++, h.ptr()); 75 | } 76 | } 77 | 78 | return ret.release(); 79 | } 80 | }; 81 | 82 | NAMESPACE_END(detail) 83 | NAMESPACE_END(NB_NAMESPACE) 84 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/detail/nb_optional.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/optional.h: type caster for std::optional<...> 3 | 4 | Copyright (c) 2022 Yoshiki Matsuda and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | NAMESPACE_BEGIN(NB_NAMESPACE) 15 | NAMESPACE_BEGIN(detail) 16 | 17 | template 18 | struct optional_caster { 19 | using Caster = make_caster; 20 | 21 | NB_TYPE_CASTER(Optional, optional_name(Caster::Name)) 22 | 23 | bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept { 24 | if (src.is_none()) 25 | // default-constructed value is already empty 26 | return true; 27 | 28 | Caster caster; 29 | if (!caster.from_python(src, flags_for_local_caster(flags), cleanup) || 30 | !caster.template can_cast()) 31 | return false; 32 | 33 | value.emplace(caster.operator cast_t()); 34 | 35 | return true; 36 | } 37 | 38 | template 39 | static handle from_cpp(T_ &&value, rv_policy policy, cleanup_list *cleanup) noexcept { 40 | if (!value) 41 | return none().release(); 42 | 43 | return Caster::from_cpp(forward_like_(*value), policy, cleanup); 44 | } 45 | }; 46 | 47 | NAMESPACE_END(detail) 48 | NAMESPACE_END(NB_NAMESPACE) 49 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/detail/nb_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/detail/nb_set.h: base class of set casters 3 | 4 | Copyright (c) 2022 Raymond Yun Fei and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | NAMESPACE_BEGIN(NB_NAMESPACE) 15 | NAMESPACE_BEGIN(detail) 16 | 17 | template struct set_caster { 18 | NB_TYPE_CASTER(Set, io_name(NB_TYPING_ABSTRACT_SET, NB_TYPING_SET) + 19 | const_name("[") + make_caster::Name + 20 | const_name("]")) 21 | 22 | using Caster = make_caster; 23 | 24 | bool from_python(handle src, uint8_t flags, cleanup_list *cleanup) noexcept { 25 | value.clear(); 26 | 27 | PyObject* iter = obj_iter(src.ptr()); 28 | if (!iter) { 29 | PyErr_Clear(); 30 | return false; 31 | } 32 | 33 | bool success = true; 34 | Caster key_caster; 35 | PyObject *key; 36 | 37 | flags = flags_for_local_caster(flags); 38 | 39 | while ((key = PyIter_Next(iter)) != nullptr) { 40 | success &= (key_caster.from_python(key, flags, cleanup) && 41 | key_caster.template can_cast()); 42 | Py_DECREF(key); 43 | 44 | if (!success) 45 | break; 46 | 47 | value.emplace(key_caster.operator cast_t()); 48 | } 49 | 50 | if (PyErr_Occurred()) { 51 | PyErr_Clear(); 52 | success = false; 53 | } 54 | 55 | Py_DECREF(iter); 56 | 57 | return success; 58 | } 59 | 60 | template 61 | static handle from_cpp(T &&src, rv_policy policy, cleanup_list *cleanup) { 62 | object ret = steal(PySet_New(nullptr)); 63 | 64 | if (ret.is_valid()) { 65 | for (auto& key : src) { 66 | object k = steal( 67 | Caster::from_cpp(forward_like_(key), policy, cleanup)); 68 | 69 | if (!k.is_valid() || PySet_Add(ret.ptr(), k.ptr()) != 0) { 70 | ret.reset(); 71 | break; 72 | } 73 | } 74 | } 75 | 76 | return ret.release(); 77 | } 78 | }; 79 | 80 | NAMESPACE_END(detail) 81 | NAMESPACE_END(NB_NAMESPACE) 82 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/filesystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/filesystem.h: type caster for std::filesystem 3 | 4 | Copyright (c) 2023 Qingnan Zhou and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | NAMESPACE_BEGIN(NB_NAMESPACE) 17 | NAMESPACE_BEGIN(detail) 18 | 19 | template <> 20 | struct type_caster { 21 | 22 | static handle from_cpp(const std::filesystem::path &path, rv_policy, 23 | cleanup_list *) noexcept { 24 | str py_str = to_py_str(path.native()); 25 | if (py_str.is_valid()) { 26 | try { 27 | return module_::import_("pathlib") 28 | .attr("Path")(py_str) 29 | .release(); 30 | } catch (python_error &e) { 31 | e.restore(); 32 | } 33 | } 34 | return handle(); 35 | } 36 | 37 | template 38 | bool from_python(handle src, uint8_t, cleanup_list *) noexcept { 39 | bool success = false; 40 | 41 | /* PyUnicode_FSConverter and PyUnicode_FSDecoder normally take care of 42 | calling PyOS_FSPath themselves, but that's broken on PyPy (see PyPy 43 | issue #3168) so we do it ourselves instead. */ 44 | PyObject *buf = PyOS_FSPath(src.ptr()); 45 | if (buf) { 46 | PyObject *native = nullptr; 47 | if constexpr (std::is_same_v) { 48 | if (PyUnicode_FSConverter(buf, &native)) { 49 | if (char* s = PyBytes_AsString(native)) { 50 | value = s; // Points to internal buffer, no need to free 51 | success = true; 52 | } 53 | } 54 | } else { 55 | if (PyUnicode_FSDecoder(buf, &native)) { 56 | if (wchar_t *s = PyUnicode_AsWideCharString(native, nullptr)) { 57 | value = s; 58 | PyMem_Free(s); // New string, must free 59 | success = true; 60 | } 61 | } 62 | } 63 | 64 | Py_DECREF(buf); 65 | Py_XDECREF(native); 66 | } 67 | 68 | if (!success) 69 | PyErr_Clear(); 70 | 71 | return success; 72 | } 73 | 74 | #if PY_VERSION_HEX < 0x03090000 75 | NB_TYPE_CASTER(std::filesystem::path, io_name("typing.Union[str, os.PathLike]", "pathlib.Path")) 76 | #else 77 | NB_TYPE_CASTER(std::filesystem::path, io_name("str | os.PathLike", "pathlib.Path")) 78 | #endif 79 | 80 | private: 81 | static str to_py_str(const std::string &s) { 82 | return steal( 83 | PyUnicode_DecodeFSDefaultAndSize(s.c_str(), (Py_ssize_t) s.size())); 84 | } 85 | 86 | static str to_py_str(const std::wstring &s) { 87 | return steal( 88 | PyUnicode_FromWideChar(s.c_str(), (Py_ssize_t) s.size())); 89 | } 90 | }; 91 | 92 | NAMESPACE_END(detail) 93 | NAMESPACE_END(NB_NAMESPACE) 94 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/function.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/function.h: type caster for std::function<...> 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | struct pyfunc_wrapper { 19 | PyObject *f; 20 | 21 | explicit pyfunc_wrapper(PyObject *f) : f(f) { 22 | Py_INCREF(f); 23 | } 24 | 25 | pyfunc_wrapper(pyfunc_wrapper &&w) noexcept : f(w.f) { 26 | w.f = nullptr; 27 | } 28 | 29 | pyfunc_wrapper(const pyfunc_wrapper &w) : f(w.f) { 30 | if (f) { 31 | gil_scoped_acquire acq; 32 | Py_INCREF(f); 33 | } 34 | } 35 | 36 | ~pyfunc_wrapper() { 37 | if (f) { 38 | gil_scoped_acquire acq; 39 | Py_DECREF(f); 40 | } 41 | } 42 | 43 | pyfunc_wrapper &operator=(const pyfunc_wrapper) = delete; 44 | pyfunc_wrapper &operator=(pyfunc_wrapper &&) = delete; 45 | }; 46 | 47 | template 48 | struct type_caster> { 49 | using ReturnCaster = make_caster< 50 | std::conditional_t, void_type, Return>>; 51 | 52 | NB_TYPE_CASTER(std::function , 53 | const_name(NB_TYPING_CALLABLE "[[") + 54 | concat(make_caster::Name...) + const_name("], ") + 55 | ReturnCaster::Name + const_name("]")) 56 | 57 | struct pyfunc_wrapper_t : pyfunc_wrapper { 58 | using pyfunc_wrapper::pyfunc_wrapper; 59 | 60 | Return operator()(Args... args) const { 61 | gil_scoped_acquire acq; 62 | return cast(handle(f)((forward_t) args...)); 63 | } 64 | }; 65 | 66 | bool from_python(handle src, uint8_t flags, cleanup_list *) noexcept { 67 | if (src.is_none()) 68 | return flags & cast_flags::convert; 69 | 70 | if (!PyCallable_Check(src.ptr())) 71 | return false; 72 | 73 | value = pyfunc_wrapper_t(src.ptr()); 74 | 75 | return true; 76 | } 77 | 78 | static handle from_cpp(const Value &value, rv_policy rvp, 79 | cleanup_list *) noexcept { 80 | const pyfunc_wrapper_t *wrapper = value.template target(); 81 | if (wrapper) 82 | return handle(wrapper->f).inc_ref(); 83 | 84 | if (rvp == rv_policy::none) 85 | return handle(); 86 | 87 | if (!value) 88 | return none().release(); 89 | 90 | return cpp_function(value).release(); 91 | } 92 | }; 93 | 94 | NAMESPACE_END(detail) 95 | NAMESPACE_END(NB_NAMESPACE) 96 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/list.h: type caster for std::list<...> 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/nb_list.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template struct type_caster> 19 | : list_caster, Type> { }; 20 | 21 | NAMESPACE_END(detail) 22 | NAMESPACE_END(NB_NAMESPACE) 23 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/map.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/map.h: type caster for std::map<...> 3 | 4 | Copyright (c) 2022 Matej Ferencevic and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/nb_dict.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template 19 | struct type_caster> 20 | : dict_caster, Key, T> { }; 21 | 22 | NAMESPACE_END(detail) 23 | NAMESPACE_END(NB_NAMESPACE) 24 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/optional.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/optional.h: type caster for std::optional<...> 3 | 4 | Copyright (c) 2022 Yoshiki Matsuda and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/nb_optional.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template struct remove_opt_mono> 19 | : remove_opt_mono { }; 20 | 21 | template 22 | struct type_caster> : optional_caster> {}; 23 | 24 | template <> struct type_caster : none_caster { }; 25 | 26 | NAMESPACE_END(detail) 27 | NAMESPACE_END(NB_NAMESPACE) 28 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/pair.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/pair.h: type caster for std::pair<...> 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template struct type_caster> { 19 | using Value = std::pair; 20 | 21 | // Sub type casters 22 | using Caster1 = make_caster; 23 | using Caster2 = make_caster; 24 | 25 | /// This caster constructs instances on the fly (otherwise it would not be 26 | /// able to handle pairs containing references). Because of this, only the 27 | /// `operator Value()` cast operator is implemented below, and the type 28 | /// alias below informs users of this class of this fact. 29 | template using Cast = Value; 30 | 31 | // Value name for docstring generation 32 | static constexpr auto Name = 33 | const_name(NB_TYPING_TUPLE "[") + concat(Caster1::Name, Caster2::Name) + const_name("]"); 34 | 35 | /// Python -> C++ caster, populates `caster1` and `caster2` upon success 36 | bool from_python(handle src, uint8_t flags, 37 | cleanup_list *cleanup) noexcept { 38 | PyObject *temp; // always initialized by the following line 39 | PyObject **o = seq_get_with_size(src.ptr(), 2, &temp); 40 | 41 | bool success = o && 42 | caster1.from_python(o[0], flags, cleanup) && 43 | caster2.from_python(o[1], flags, cleanup); 44 | 45 | Py_XDECREF(temp); 46 | 47 | return success; 48 | } 49 | 50 | template 51 | static handle from_cpp(T *value, rv_policy policy, cleanup_list *cleanup) { 52 | if (!value) 53 | return none().release(); 54 | return from_cpp(*value, policy, cleanup); 55 | } 56 | 57 | template 58 | static handle from_cpp(T &&value, rv_policy policy, 59 | cleanup_list *cleanup) noexcept { 60 | object o1 = steal( 61 | Caster1::from_cpp(forward_like_(value.first), policy, cleanup)); 62 | if (!o1.is_valid()) 63 | return {}; 64 | 65 | object o2 = steal( 66 | Caster2::from_cpp(forward_like_(value.second), policy, cleanup)); 67 | if (!o2.is_valid()) 68 | return {}; 69 | 70 | PyObject *r = PyTuple_New(2); 71 | NB_TUPLE_SET_ITEM(r, 0, o1.release().ptr()); 72 | NB_TUPLE_SET_ITEM(r, 1, o2.release().ptr()); 73 | return r; 74 | } 75 | 76 | template 77 | bool can_cast() const noexcept { 78 | return caster1.template can_cast() && caster2.template can_cast(); 79 | } 80 | 81 | /// Return the constructed tuple by copying from the sub-casters 82 | explicit operator Value() { 83 | return Value(caster1.operator cast_t(), 84 | caster2.operator cast_t()); 85 | } 86 | 87 | Caster1 caster1; 88 | Caster2 caster2; 89 | }; 90 | 91 | NAMESPACE_END(detail) 92 | NAMESPACE_END(NB_NAMESPACE) 93 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/set.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/set.h: type caster for std::set<...> 3 | 4 | Copyright (c) 2022 Raymond Yun Fei and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/nb_set.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template 19 | struct type_caster> 20 | : set_caster, Key> { 21 | }; 22 | 23 | NAMESPACE_END(detail) 24 | NAMESPACE_END(NB_NAMESPACE) 25 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/string.h: type caster for std::string 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template <> struct type_caster { 19 | NB_TYPE_CASTER(std::string, const_name("str")) 20 | 21 | bool from_python(handle src, uint8_t, cleanup_list *) noexcept { 22 | Py_ssize_t size; 23 | const char *str = PyUnicode_AsUTF8AndSize(src.ptr(), &size); 24 | if (!str) { 25 | PyErr_Clear(); 26 | return false; 27 | } 28 | value = std::string(str, (size_t) size); 29 | return true; 30 | } 31 | 32 | static handle from_cpp(const std::string &value, rv_policy, 33 | cleanup_list *) noexcept { 34 | return PyUnicode_FromStringAndSize(value.c_str(), value.size()); 35 | } 36 | }; 37 | 38 | NAMESPACE_END(detail) 39 | NAMESPACE_END(NB_NAMESPACE) 40 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/string_view.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/string_view.h: type caster for std::string_view 3 | 4 | Copyright (c) 2022 Qingnan Zhou and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template <> struct type_caster { 19 | NB_TYPE_CASTER(std::string_view, const_name("str")) 20 | 21 | bool from_python(handle src, uint8_t, cleanup_list *) noexcept { 22 | Py_ssize_t size; 23 | const char *str = PyUnicode_AsUTF8AndSize(src.ptr(), &size); 24 | if (!str) { 25 | PyErr_Clear(); 26 | return false; 27 | } 28 | value = std::string_view(str, (size_t) size); 29 | return true; 30 | } 31 | 32 | static handle from_cpp(std::string_view value, rv_policy, 33 | cleanup_list *) noexcept { 34 | return PyUnicode_FromStringAndSize(value.data(), value.size()); 35 | } 36 | }; 37 | 38 | NAMESPACE_END(detail) 39 | NAMESPACE_END(NB_NAMESPACE) 40 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/unordered_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/unordered_map.h: type caster for std::unordered_map<...> 3 | 4 | Copyright (c) 2022 Matej Ferencevic and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/nb_dict.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template 19 | struct type_caster> 20 | : dict_caster, Key, T> { }; 21 | 22 | NAMESPACE_END(detail) 23 | NAMESPACE_END(NB_NAMESPACE) 24 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/unordered_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/unordered_set.h: type caster for std::unordered_set<...> 3 | 4 | Copyright (c) 2022 Raymond Yun Fei and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/nb_set.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template 19 | struct type_caster> 20 | : set_caster, Key> { 21 | }; 22 | 23 | NAMESPACE_END(detail) 24 | NAMESPACE_END(NB_NAMESPACE) 25 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/variant.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/variant.h: type caster for std::variant<...> 3 | 4 | Copyright (c) 2022 Yoshiki Matsuda and Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template 19 | struct concat_variant { using type = T; }; 20 | template 21 | struct concat_variant, std::variant, Ts3...> 22 | : concat_variant, Ts3...> {}; 23 | 24 | template struct remove_opt_mono> 25 | : concat_variant, std::variant<>, std::variant>>...> {}; 26 | 27 | template <> struct type_caster : none_caster { }; 28 | 29 | template struct type_caster> { 30 | NB_TYPE_CASTER(std::variant, union_name(make_caster::Name...)) 31 | 32 | template 33 | bool try_variant(const handle &src, uint8_t flags, cleanup_list *cleanup) { 34 | using CasterT = make_caster; 35 | 36 | CasterT caster; 37 | 38 | if (!caster.from_python(src, flags_for_local_caster(flags), cleanup) || 39 | !caster.template can_cast()) 40 | return false; 41 | 42 | value = caster.operator cast_t(); 43 | 44 | return true; 45 | } 46 | 47 | bool from_python(handle src, uint8_t flags, cleanup_list *cleanup) noexcept { 48 | return (try_variant(src, flags, cleanup) || ...); 49 | } 50 | 51 | template 52 | static handle from_cpp(T &&value, rv_policy policy, cleanup_list *cleanup) noexcept { 53 | return std::visit( 54 | [&](auto &&v) { 55 | return make_caster::from_cpp( 56 | std::forward(v), policy, cleanup); 57 | }, 58 | std::forward(value)); 59 | } 60 | }; 61 | 62 | NAMESPACE_END(detail) 63 | NAMESPACE_END(NB_NAMESPACE) 64 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/vector.h: type caster for std::vector<...> 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/nb_list.h" 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template struct type_caster> 19 | : list_caster, Type> { }; 20 | 21 | NAMESPACE_END(detail) 22 | NAMESPACE_END(NB_NAMESPACE) 23 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/stl/wstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/stl/string.h: type caster for std::string 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | template <> struct type_caster { 19 | NB_TYPE_CASTER(std::wstring, const_name("str")) 20 | 21 | bool from_python(handle src, uint8_t, cleanup_list *) noexcept { 22 | Py_ssize_t size; 23 | const wchar_t *str = PyUnicode_AsWideCharString(src.ptr(), &size); 24 | if (!str) { 25 | PyErr_Clear(); 26 | return false; 27 | } 28 | value = std::wstring(str, (size_t) size); 29 | return true; 30 | } 31 | 32 | static handle from_cpp(const std::wstring &value, rv_policy, 33 | cleanup_list *) noexcept { 34 | return PyUnicode_FromWideChar(value.c_str(), value.size()); 35 | } 36 | }; 37 | 38 | NAMESPACE_END(detail) 39 | NAMESPACE_END(NB_NAMESPACE) 40 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/trampoline.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/trampoline.h: functionality for overriding C++ virtual 3 | functions from within Python 4 | 5 | Copyright (c) 2022 Wenzel Jakob 6 | 7 | All rights reserved. Use of this source code is governed by a 8 | BSD-style license that can be found in the LICENSE file. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | NAMESPACE_BEGIN(NB_NAMESPACE) 16 | NAMESPACE_BEGIN(detail) 17 | 18 | struct ticket; 19 | 20 | NB_CORE void trampoline_new(void **data, size_t size, void *ptr) noexcept; 21 | NB_CORE void trampoline_release(void **data, size_t size) noexcept; 22 | NB_CORE void trampoline_enter(void **data, size_t size, const char *name, 23 | bool pure, ticket *ticket); 24 | NB_CORE void trampoline_leave(ticket *ticket) noexcept; 25 | 26 | template struct trampoline { 27 | mutable void *data[2 * Size + 1]; 28 | 29 | NB_INLINE trampoline(void *ptr) { trampoline_new(data, Size, ptr); } 30 | NB_INLINE ~trampoline() { trampoline_release(data, Size); } 31 | 32 | NB_INLINE handle base() const { return (PyObject *) data[0]; } 33 | }; 34 | 35 | struct ticket { 36 | handle self; 37 | handle key; 38 | ticket *prev{}; 39 | PyGILState_STATE state{}; 40 | 41 | template 42 | NB_INLINE ticket(const trampoline &t, const char *name, bool pure) { 43 | trampoline_enter(t.data, Size, name, pure, this); 44 | } 45 | 46 | NB_INLINE ~ticket() noexcept { trampoline_leave(this); } 47 | }; 48 | 49 | #define NB_TRAMPOLINE(base, size) \ 50 | using NBBase = base; \ 51 | using NBBase::NBBase; \ 52 | nanobind::detail::trampoline nb_trampoline{ this } 53 | 54 | #define NB_OVERRIDE_NAME(name, func, ...) \ 55 | using nb_ret_type = decltype(NBBase::func(__VA_ARGS__)); \ 56 | nanobind::detail::ticket nb_ticket(nb_trampoline, name, false); \ 57 | if (nb_ticket.key.is_valid()) { \ 58 | return nanobind::cast( \ 59 | nb_trampoline.base().attr(nb_ticket.key)(__VA_ARGS__)); \ 60 | } else \ 61 | return NBBase::func(__VA_ARGS__) 62 | 63 | #define NB_OVERRIDE_PURE_NAME(name, func, ...) \ 64 | using nb_ret_type = decltype(NBBase::func(__VA_ARGS__)); \ 65 | nanobind::detail::ticket nb_ticket(nb_trampoline, name, true); \ 66 | return nanobind::cast( \ 67 | nb_trampoline.base().attr(nb_ticket.key)(__VA_ARGS__)) 68 | 69 | #define NB_OVERRIDE(func, ...) \ 70 | NB_OVERRIDE_NAME(#func, func, __VA_ARGS__) 71 | 72 | #define NB_OVERRIDE_PURE(func, ...) \ 73 | NB_OVERRIDE_PURE_NAME(#func, func, __VA_ARGS__) 74 | 75 | NAMESPACE_END(detail) 76 | NAMESPACE_END(NB_NAMESPACE) 77 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/include/nanobind/typing.h: -------------------------------------------------------------------------------- 1 | /* 2 | nanobind/typing.h: Optional typing-related functionality 3 | 4 | Copyright (c) 2024 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | NAMESPACE_BEGIN(NB_NAMESPACE) 13 | 14 | inline module_ typing() { return module_::import_("typing"); } 15 | 16 | template 17 | object any_type() { return typing().attr("Any"); } 18 | 19 | template 20 | object type_var(Args&&... args) { 21 | return typing().attr("TypeVar")((detail::forward_t) args...); 22 | } 23 | 24 | template 25 | object type_var_tuple(Args&&... args) { 26 | return typing().attr("TypeVarTuple")((detail::forward_t) args...); 27 | } 28 | 29 | NAMESPACE_END(NB_NAMESPACE) 30 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/src/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | if sys.version_info < (3, 8): 5 | raise ImportError("nanobind does not support Python < 3.8.") 6 | 7 | def include_dir() -> str: 8 | "Return the path to the nanobind include directory" 9 | return os.path.join(os.path.abspath(os.path.dirname(__file__)), "include") 10 | 11 | def cmake_dir() -> str: 12 | "Return the path to the nanobind CMake module directory." 13 | return os.path.join(os.path.abspath(os.path.dirname(__file__)), "cmake") 14 | 15 | __version__ = "2.2.0dev1" 16 | 17 | __all__ = ( 18 | "__version__", 19 | "include_dir", 20 | "cmake_dir", 21 | ) 22 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/src/__main__.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import sys 3 | import sysconfig # type: ignore 4 | 5 | from . import __version__, include_dir, cmake_dir 6 | 7 | 8 | def main() -> None: 9 | parser = argparse.ArgumentParser() 10 | parser.add_argument( 11 | "--version", 12 | action="version", 13 | version=__version__, 14 | help="Print the version number.", 15 | ) 16 | parser.add_argument( 17 | "--include_dir", 18 | action="store_true", 19 | help="Print the path to the nanobind C++ header directory." 20 | ) 21 | parser.add_argument( 22 | "--cmake_dir", 23 | action="store_true", 24 | help="Print the path to the nanobind CMake module directory." 25 | ) 26 | args = parser.parse_args() 27 | if not sys.argv[1:]: 28 | parser.print_help() 29 | if args.include_dir: 30 | print(include_dir()) 31 | if args.cmake_dir: 32 | print(cmake_dir()) 33 | 34 | 35 | if __name__ == "__main__": 36 | main() 37 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/src/hash.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // Slightly adapted version of the MurmurHash3 codebase (originally by Austin 3 | // Appleby, in the public domain) 4 | // 5 | // The changes are as follows: 6 | // 7 | // - fmix32 and fmix64 are exported to other compilation units, since they 8 | // are useful has a hash function for 32/64 bit integers and pointers 9 | // 10 | // - The MurmurHash3_x64_64() function is a variant of the original 11 | // MurmurHash3_x64_128() that only returns the low 64 bit of the hash 12 | // value. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | 20 | inline uint32_t fmix32(uint32_t h) { 21 | h ^= h >> 16; 22 | h *= 0x85ebca6b; 23 | h ^= h >> 13; 24 | h *= 0xc2b2ae35; 25 | h ^= h >> 16; 26 | 27 | return h; 28 | } 29 | 30 | inline uint64_t fmix64(uint64_t k) { 31 | k ^= k >> 33; 32 | k *= (uint64_t) 0xff51afd7ed558ccdull; 33 | k ^= k >> 33; 34 | k *= (uint64_t) 0xc4ceb9fe1a85ec53ull; 35 | k ^= k >> 33; 36 | return k; 37 | } 38 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/src/implicit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | src/implicit.cpp: functions for registering implicit conversions 3 | 4 | Copyright (c) 2022 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include "nb_internals.h" 12 | 13 | NAMESPACE_BEGIN(NB_NAMESPACE) 14 | NAMESPACE_BEGIN(detail) 15 | 16 | void implicitly_convertible(const std::type_info *src, 17 | const std::type_info *dst) noexcept { 18 | nb_internals *internals_ = internals; 19 | type_data *t = nb_type_c2p(internals_, dst); 20 | check(t, "nanobind::detail::implicitly_convertible(src=%s, dst=%s): " 21 | "destination type unknown!", type_name(src), type_name(dst)); 22 | 23 | lock_internals guard(internals_); 24 | size_t size = 0; 25 | 26 | if (t->flags & (uint32_t) type_flags::has_implicit_conversions) { 27 | while (t->implicit.cpp && t->implicit.cpp[size]) 28 | size++; 29 | } else { 30 | t->implicit.cpp = nullptr; 31 | t->implicit.py = nullptr; 32 | t->flags |= (uint32_t) type_flags::has_implicit_conversions; 33 | } 34 | 35 | void **data = (void **) PyMem_Malloc(sizeof(void *) * (size + 2)); 36 | 37 | if (size) 38 | memcpy(data, t->implicit.cpp, size * sizeof(void *)); 39 | data[size] = (void *) src; 40 | data[size + 1] = nullptr; 41 | PyMem_Free(t->implicit.cpp); 42 | t->implicit.cpp = (decltype(t->implicit.cpp)) data; 43 | } 44 | 45 | void implicitly_convertible(bool (*predicate)(PyTypeObject *, PyObject *, 46 | cleanup_list *), 47 | const std::type_info *dst) noexcept { 48 | nb_internals *internals_ = internals; 49 | type_data *t = nb_type_c2p(internals_, dst); 50 | check(t, "nanobind::detail::implicitly_convertible(src=, dst=%s): " 51 | "destination type unknown!", type_name(dst)); 52 | 53 | lock_internals guard(internals_); 54 | size_t size = 0; 55 | 56 | if (t->flags & (uint32_t) type_flags::has_implicit_conversions) { 57 | while (t->implicit.py && t->implicit.py[size]) 58 | size++; 59 | } else { 60 | t->implicit.cpp = nullptr; 61 | t->implicit.py = nullptr; 62 | t->flags |= (uint32_t) type_flags::has_implicit_conversions; 63 | } 64 | 65 | void **data = (void **) PyMem_Malloc(sizeof(void *) * (size + 2)); 66 | if (size) 67 | memcpy(data, t->implicit.py, size * sizeof(void *)); 68 | data[size] = (void *) predicate; 69 | data[size + 1] = nullptr; 70 | PyMem_Free(t->implicit.py); 71 | t->implicit.py = (decltype(t->implicit.py)) data; 72 | } 73 | 74 | NAMESPACE_END(detail) 75 | NAMESPACE_END(NB_NAMESPACE) 76 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/nanobind/src/nb_static_property.cpp: -------------------------------------------------------------------------------- 1 | #include "nb_internals.h" 2 | 3 | NAMESPACE_BEGIN(NB_NAMESPACE) 4 | NAMESPACE_BEGIN(detail) 5 | 6 | /// `nb_static_property.__get__()`: Always pass the class instead of the instance. 7 | static PyObject *nb_static_property_descr_get(PyObject *self, PyObject *, PyObject *cls) { 8 | 9 | // Flag to avoid infinite recursion during static attribute assignment 10 | bool static_property_disabled; 11 | #if defined(NB_FREE_THREADED) 12 | static_property_disabled = (bool) PyThread_tss_get(internals->nb_static_property_disabled); 13 | #else 14 | static_property_disabled = internals->nb_static_property_disabled; 15 | #endif 16 | 17 | if (!static_property_disabled) { 18 | return NB_SLOT(PyProperty_Type, tp_descr_get)(self, cls, cls); 19 | } else { 20 | Py_INCREF(self); 21 | return self; 22 | } 23 | } 24 | 25 | /// `nb_static_property.__set__()`: Just like the above `__get__()`. 26 | static int nb_static_property_descr_set(PyObject *self, PyObject *obj, PyObject *value) { 27 | PyObject *cls = PyType_Check(obj) ? obj : (PyObject *) Py_TYPE(obj); 28 | return NB_SLOT(PyProperty_Type, tp_descr_set)(self, cls, value); 29 | } 30 | 31 | PyTypeObject *nb_static_property_tp() noexcept { 32 | nb_internals *internals_ = internals; 33 | PyTypeObject *tp = internals_->nb_static_property; 34 | 35 | if (NB_UNLIKELY(!tp)) { 36 | lock_internals guard(internals_); 37 | 38 | tp = internals_->nb_static_property; 39 | if (tp) 40 | return tp; 41 | 42 | PyMemberDef *members; 43 | 44 | #if defined(Py_LIMITED_API) 45 | members = (PyMemberDef *) PyType_GetSlot(&PyProperty_Type, Py_tp_members); 46 | #else 47 | members = PyProperty_Type.tp_members; 48 | #endif 49 | 50 | PyType_Slot slots[] = { 51 | { Py_tp_base, &PyProperty_Type }, 52 | { Py_tp_descr_get, (void *) nb_static_property_descr_get }, 53 | { Py_tp_members, members }, 54 | { 0, nullptr } 55 | }; 56 | 57 | PyType_Spec spec = { 58 | /* .name = */ "nanobind.nb_static_property", 59 | /* .basicsize = */ 0, 60 | /* .itemsize = */ 0, 61 | /* .flags = */ Py_TPFLAGS_DEFAULT, 62 | /* .slots = */ slots 63 | }; 64 | 65 | tp = (PyTypeObject *) PyType_FromSpec(&spec); 66 | check(tp, "nb_static_property type creation failed!"); 67 | 68 | internals_->nb_static_property = tp; 69 | internals_->nb_static_property_descr_set = nb_static_property_descr_set; 70 | } 71 | 72 | return tp; 73 | } 74 | 75 | NAMESPACE_END(detail) 76 | NAMESPACE_END(NB_NAMESPACE) 77 | -------------------------------------------------------------------------------- /RemoteInput/Thirdparty/rd_route/include/rd_route.h: -------------------------------------------------------------------------------- 1 | // rd_route.h 2 | // Copyright (c) 2014-2015 Dmitry Rodionov 3 | // 4 | // This software may be modified and distributed under the terms 5 | // of the MIT license. See the LICENSE file for details. 6 | 7 | #ifndef RD_ROUTE 8 | #define RD_ROUTE 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /** 15 | * Override `function` to jump directly into `replacement` location. Caller can later 16 | * access an original function's implementation via `original_ptr` (if passed). 17 | * Note that `original_ptr` won't be equal to `function` due to remapping the latter 18 | * into a different memory space. 19 | * 20 | * @param function pointer to a function to override; 21 | * @param replacement pointer to new implementation; 22 | * @param original will be set to an address of the original implementation's copy; 23 | * 24 | * @return KERN_SUCCESS if succeeded, or other value if failed 25 | */ 26 | int rd_route(void *function, void *replacement, void **original); 27 | 28 | /** 29 | * The same as rd_route(), but the target function is defined with its name, not its symbol pointer. 30 | * If the `image_name` provided, rd_route_byname() looks for the function within it. 31 | * Otherwise it iterates all images loaded into the current process' address space and, if there is more 32 | * than one image containing a function with the specifed name, it will choose the first one. 33 | * 34 | * @param function_name name of a function to override; 35 | * @param image_name name of a mach-o image containing the function. It may be NULL, a full file path or 36 | * just a file name (e.g. "CoreFoundation"); 37 | * @param replacement pointer to new implementation of the function; 38 | * @param original will be set to an address of the original implementation's copy; 39 | * 40 | * @return see rd_route() for the list of possible return values 41 | */ 42 | int rd_route_byname(const char *function_name, const char *image_name, void *replacement, void **original); 43 | 44 | /** 45 | * Copy `function` implementation into another (first available) memory region. 46 | * @param function pointer to a function to override; 47 | * @param duplicate will be set to an address of the function's implementation copy 48 | * 49 | * @return KERN_SUCCESS if succeeded, or other value if failed 50 | */ 51 | int rd_duplicate_function(void *function, void **duplicate); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif /* RD_ROUTE */ 58 | -------------------------------------------------------------------------------- /RemoteInput/ThreadPool.cxx: -------------------------------------------------------------------------------- 1 | #include "ThreadPool.hxx" 2 | 3 | ThreadPool::ThreadPool() noexcept : ThreadPool(std::thread::hardware_concurrency()) 4 | { 5 | } 6 | 7 | ThreadPool::ThreadPool(std::size_t max_threads) noexcept : mutex(), condition(), tasks(), threads(), stop(false) 8 | { 9 | this->threads.reserve(max_threads); 10 | 11 | for (std::size_t i = 0; i < max_threads; ++i) 12 | { 13 | this->threads.emplace_back([this] { 14 | while(true) 15 | { 16 | std::unique_lock lock(this->mutex); 17 | condition.wait(lock, [this] { 18 | return !this->tasks.empty() || this->stop; 19 | }); 20 | 21 | if (this->stop) //&& this->tasks.empty() 22 | { 23 | lock.unlock(); 24 | break; 25 | } 26 | 27 | auto task = std::move(this->tasks.front()); 28 | this->tasks.pop(); 29 | 30 | lock.unlock(); 31 | task(this->stop); 32 | } 33 | }); 34 | } 35 | } 36 | 37 | ThreadPool::~ThreadPool() noexcept 38 | { 39 | if (!this->stop) 40 | { 41 | std::unique_lock lock(this->mutex); 42 | this->stop = true; 43 | lock.unlock(); 44 | this->condition.notify_all(); 45 | 46 | for (auto&& thread : this->threads) 47 | { 48 | thread.join(); 49 | } 50 | 51 | std::vector().swap(this->threads); 52 | } 53 | } 54 | 55 | void ThreadPool::terminate() noexcept 56 | { 57 | if (!this->stop) 58 | { 59 | std::unique_lock lock(this->mutex); 60 | this->stop = true; 61 | lock.unlock(); 62 | this->condition.notify_all(); 63 | 64 | for (auto&& thread : this->threads) 65 | { 66 | thread.detach(); 67 | } 68 | 69 | std::vector().swap(this->threads); 70 | } 71 | } 72 | 73 | void ThreadPool::add_task(std::function &&task) 74 | { 75 | if (!stop) 76 | { 77 | std::unique_lock lock(this->mutex); 78 | this->tasks.emplace(task); 79 | lock.unlock(); 80 | this->condition.notify_one(); 81 | } 82 | else 83 | { 84 | throw std::runtime_error("ThreadPool is currently shutting down. Cannot enqueue more tasks."); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /RemoteInput/ThreadPool.hxx: -------------------------------------------------------------------------------- 1 | #ifndef THREADPOOL_HXX_INCLUDED 2 | #define THREADPOOL_HXX_INCLUDED 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class ThreadPool final 15 | { 16 | private: 17 | std::mutex mutex; 18 | std::condition_variable condition; 19 | std::queue> tasks; 20 | std::vector threads; 21 | std::atomic_bool stop; 22 | 23 | public: 24 | ThreadPool() noexcept; 25 | ThreadPool(std::size_t max_threads) noexcept; 26 | ~ThreadPool() noexcept; 27 | ThreadPool(const ThreadPool&) = delete; 28 | ThreadPool& operator = (const ThreadPool&) = delete; 29 | 30 | void terminate() noexcept; 31 | 32 | void add_task(std::function &&task); 33 | 34 | template 35 | auto enqueue(Task &&task, Args&&... args) noexcept -> std::future>; 36 | }; 37 | 38 | template 39 | auto ThreadPool::enqueue(Task &&task, Args&&... args) noexcept -> std::future> 40 | { 41 | auto packaged_task = std::make_shared(Args&&...)>>( 42 | std::bind(std::forward(task), std::forward(args)...) 43 | ); 44 | 45 | std::future> result = packaged_task->get_future(); 46 | std::unique_lock lock(this->mutex); 47 | if (this->stop) 48 | { 49 | throw std::runtime_error("ThreadPool is currently shutting down. Cannot enqueue more tasks."); 50 | } 51 | 52 | this->tasks.emplace([packaged_task] { 53 | (*packaged_task)(); 54 | }); 55 | 56 | condition.notify_one(); 57 | return result; 58 | } 59 | 60 | #endif // THREADPOOL_HXX_INCLUDED 61 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import subprocess 4 | from setuptools import setup, Extension 5 | from setuptools.command.build_ext import build_ext 6 | from setuptools import find_packages 7 | 8 | class CMakeBuild(build_ext): 9 | def run(self): 10 | try: 11 | subprocess.check_output(['cmake', '--version']) 12 | except OSError: 13 | raise RuntimeError('CMake must be installed to build RemoteInput') 14 | 15 | for extension in self.extensions: 16 | self.build_extension(extension) 17 | 18 | def build_extension(self, extension): 19 | extension_dir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(extension.name))) 20 | cmake_args = [ 21 | f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extension_dir}', 22 | f'-DPYTHON_EXECUTABLE={sys.executable}', 23 | '-DPYTHON_BINDINGS=ON', 24 | '-DUSE_PYBIND11=ON' 25 | ] 26 | 27 | build_type = 'Debug' if self.debug else 'Release' 28 | build_args = ['--config', build_type] 29 | 30 | if sys.platform.startswith('win'): 31 | cmake_args += [ 32 | f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{build_type.upper()}={extension_dir}', 33 | '-A', 'x64' if sys.maxsize > 2**32 else 'Win32' 34 | ] 35 | build_args += ['--', '/m'] 36 | else: 37 | cmake_args += [f'-DCMAKE_BUILD_TYPE={build_type}'] 38 | build_args += ['--', '-j2'] 39 | 40 | build_temp = self.build_temp 41 | if not os.path.exists(build_temp): 42 | os.makedirs(build_temp) 43 | 44 | subprocess.check_call(['cmake', extension.sourcedir] + cmake_args, cwd=build_temp) 45 | subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=build_temp) 46 | 47 | class CMakeExtension(Extension): 48 | def __init__(self, name, sourcedir=''): 49 | super().__init__(name, sources=[]) 50 | self.sourcedir = os.path.abspath(sourcedir) 51 | 52 | # Setup function 53 | setup( 54 | name='RemoteInput', 55 | version='1.0.0', 56 | description='Remote Input', 57 | packages=find_packages(), 58 | ext_modules=[CMakeExtension('RemoteInput', sourcedir='.')], 59 | cmdclass={'build_ext': CMakeBuild}, 60 | zip_safe=False, 61 | ) --------------------------------------------------------------------------------