0

I've actually already asked questions regarding my problem. To prevent people asking for irrelevant details over again, I'll post this background info you can skip:

I'm making a automation application. This application does some tasks for the user over time for specific window. When these taks are required to be made, window flashes in taskbar and sometimes even steals focus to get the user to do the task. Once the automation is here, this is no longer wanted - the user will only focus the window when he wants to check how well is the automation doing it's job.

I discovered this focus and flash disable dll project thanks to this superuser post about applications stealing focus.

My automation application is in Java. So while I can open a DLL injection application and disable flashing manually, I'd like to integrate it in the java applicaton - for example as a setting option. When user selects to disable flashing and stealing focus, the dll will be injected.

Of course, this requires Java to be able to inject my .dll file. I've found this project: dotnet-dll-injector but it only deals with .NET dll files.

Q: Is there a way, in Java, to pick a .dll file and inject it into process? Which libraries would lead to this if the solution isn't straightforward?

I've noticed CreateRemoteThread is somehow related to the DLL injection. Maybe JNA library supports that?

Community
  • 1
  • 1
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • If you call C code via JNI you can do whatever you want. – Radiodef Mar 04 '15 at 19:25
  • Might be simplistic, but what about plain ol' `System.load();`? – user489041 Mar 04 '15 at 19:47
  • @Radiodef sure, I could make another DLL to call that would inject my DLL's. But that's getting quite complicated and my user's might not like how non-transparent my program is. – Tomáš Zato Mar 04 '15 at 22:28
  • @user489041 No, that function is designed to load java libraries into Java program. I want to load binary DL library into "binary" process. – Tomáš Zato Mar 04 '15 at 22:29
  • Expanding on my idea, have a C wrapper that you load using System.load() that exposes the api you need. – user489041 Mar 05 '15 at 03:48
  • I already took a look if there's a DLL injector C/C++ opensource project I could compile as dll. Unfortunatelly, I've found nothing. However your solution seems like the right one - only have the necessary native code in dll, do the rest in java. – Tomáš Zato Mar 05 '15 at 07:08

1 Answers1

1

I don't know of a way to do it natively in Java.

Since you've found a working solution in .NET and your task is Windows-specific, I suggest the following:

Build dotnet-dll-injector as a DLL and call it from your Java app. How to call into .NET dll from Java

Edit: easier to build it as a console app and use Runtime.getRuntime().exec("...");

Or if you're still early in the development process and you have no immediate plan to go cross-platform, just do everything in C# and save some headache.

Community
  • 1
  • 1
Neal Ehardt
  • 10,334
  • 9
  • 41
  • 51
  • From my understanding, dotnet-dll-injector is Java software developped to inject `.NET` dll's. That means it cannot probably inject normal binary DLL files. Using `Runtime.getRuntime().exec` I could bundle this [DLL injector tool](http://securityxploded.com/remote-dll-injector.php) with the project. But I didn't want to distribute 3rd party binary file - the DLL I'm using is suspicious enough. I want my project to be transparent as much as possible - I'm distributing in gaming environment where keyloggers and viruses are everywhere and people are rightfully paranoid. – Tomáš Zato Mar 04 '15 at 22:27