How to disable an hooking to my process? - c#

Is there any debug/prepossessing param or any option under Windows 7 and visual studio to prevent from other processes hooking to my process?
I am writing a game for Windows, under Visual Studio, and was wondering if there is a way to disable user to hook to the game's process?

No, that's not possible. Even if you could somehow disable hooking, the user could still attach a debugger to your process and do anything they wanted. That's by design, of course: it's how you debug the problem when you write it.
Once a user has installed a program on their machine, assuming they have sufficient privileges, they have full control over that program. Trying to limit it programmatically is a fool's errand.
The solution to this program is not to be found with code. You need to investigate the built-in Windows security model, like creating limited user accounts; ask more questions about that on Server Fault.

The short answer is no.
On a Windows machine (like most other machines) a user with sufficient privileges will always have the ability to inspect and or modify the contents of your game process's address space.
That said, what sort of user(s) and or attack(s) are you looking to defend against? What assets are you looking to protect? Once you've identified these, you can start thinking about how to design your application such that attackers would have a more difficult time getting at what they want.
I'd start with reading up on Threat Modeling. Good luck!

Disabling is not possible. What you want to do is detecting byte patches, hooks or even just reading in the games memory region. But you better give up, because its not worth the time.

Related

How do I determine why our application crashes for some people, but not others?

This is a tough problem, which I'm not sure how to solve. (Hence my asking here, :) ) I'm on a team of about a half dozen developers working on a WPF app. At this stage we've got a working application. Not all of the features are in it yet, but we're making progress. Everyone on the team can run the app, except for our boss who has a problem running it. When the app first starts it brings up a start screen/landing page with some buttons. All of the rest of us when we run the app we can easily click on any of the buttons. One of these buttons is labels "Orders" and takes the user to another screen where they can work on the orders. When our boss runs it, the app always crashes. However it doesn't do this at all for me, nor any of the other developers. This makes it really hard to figure out what's wrong because I can't duplicate it. I've got to admit that the problem might not be with WPF, but might instead be with the .NET framework, but at this point I don't know. I've got to start somewhere.
So ultimately the question is this, how do I determine what's failing on a different machine than my own? One that I don't have access to?
We're working with VS 2015, .NET Framework 4.5.2.
Diagnostics and logging.
Add as much diagnostic code as you can think of (and then add some more) to the code and log it to a file or the event log or a remote database or where ever. This would include call stacks, parameter values, system information etc. Then when the application crashes you can examine these logs and determine what's different between your machine and the customer's.
Without this information you're just guessing.
Quick check before you do anything else: right after a crash run Event Viewer and go to Windows Logs -> Application. You should see a number of messages related to the app and the crash including exception information that often sheds light on exactly what's going wrong.
You can put some crash report controls,
Find similar question hear exception-reporting-from-a-wpf-application
or try something from hear : CrashReporterdotNet
,
Crash nuget
This is a long shot, but easy enough to research. Your problem may have its root cause in hardware. Compare the video cards of your peers and boss. Your boss may have a card that's not within the Microsoft recommended guidelines. In WPF, there are ways to manage rendering based on the hardware.

SystemSounds.Beep.Play not making any sound

I am having trouble with System.SystemSounds.Beep.Play() not making any sound for a particular user. It seems to be working for everyone else (a fairly large user base with generally 24/7 use) but simply does not make any sound for a particular user.
What I would like to know is if this method has any particular idiosyncrasies that I should be aware of, particularly if they could cause this issue (but really even if they couldn't too)? Has anyone else run into something like this that might point to this being a non-programming issue?
Some extra info that might help: (or might be more confusing)
It does not appear to be a corrupt .NET install because it appears for a particular user across machines.
The user is using the same Active Directory profile for all these machines when they have the issue
Another user can log into the machine and use the exact same executables to get sound successfully
The particular location where the user is has Windows XP machines, though not all users do (some use Windows 7)
You may want to check this link:
http://www.howtogeek.com/howto/windows/turn-off-the-annoying-windows-xp-system-beeps/
make sure that the beep sound is not disabled for the user.
Are the system beeps still on his computer? check C:\Windows\Media, because Beep.Play(); should work fine.
Some other possible problems just to be sure:
The speaker volume isn't at 0%?
The speakers are installed correctly?
Check Windows Control Panel - Sound
Sound event reference must to be set.
For example:
default beep -> Windows Background.wav

How can I know if the user has made a screenshot?

I'm writing a small c# program, I don't want the final user to take screenshots while using my program, is it possible? Or even if he takes one, how can I know it?
Thanks in advance and sorry if this is a poor-content question due to my lack of experience in c# coding.
You can create a system-wide keyboard hook using the low-level keyboard filter and cancel any printscreen keyboard combination. But if someone has also installed a helper application (like Gadwin or something) it'll become a lot more difficult because you won't know beforehand what keyboard shortcut you should catch (most tools allow to specify your own hooks).
Here's an article on using hooks in C#
and here's a ready-made keyboard hook library for .net that uses global mouse and keyboard hooks (use Google to find more freeware and commercial libraries and tools).
On a side note: it's generally not preferred to change the system behavior. Screenshots are system behavior and serve a distinguished purpose for trouble shooting. If you prevent this, users will not be able to show you a screenshot of something wrong. But if you must do it, you can do it.
EDIT: on a deeper level, you can install an API hook. All screenshot applications use API calls to get the content of a (part of) the screen. But API hooks are hard to get right. A more trivial way is probably by writing a user-level driver. While you can prevent all this, it is really worth all the trouble?
You might want a keyboard hook. But it'll tell you if the user pressed the "print screen" key, not if someone programmatically take a screenshot using some GDI function.
I doubt it's possible to prevent all the ways of taking a screenshot.
General answer: No. It's not possible to detect this - especially from C#. There are dozens of ways to take screenshot and even applications written in C++/WinAPI can only detect some of them, but not all.
Also consider - what if user is running your app in virtual machine? He'll be able to take screenshots at host machine and you can do absolutely nothing to detect (not even prevent) this.

Make program instantly start up when login. c#

I have previously posted a question about this but I did not get an answer that suited my needs, so maybe I need to be more specific?
I am trying to make my program instantly start up when the person logs in. It is a computer locking device so I need it to start as soon as possible. I know this is possible because anti-virus programs do this. Such as ESET or Avira.
I currently have my program entering a key into the registry to enable it to start up when the user logs in. But I need it to be much more efficient to maximise security.
Any help would be appreciated,
Thanks.
Actually, most anti-virus programs run as a windows service. If you need instant on then that's the only way to go.
The part you see starting after log in is simply the UI for those services.

Making a Background Service Somewhat Like Apple's Spotlight in VIsual Studio C#

I am about to start working on an application that runs in the background waiting for a certain user input somewhat like apple's spotlight.
Basically the user will give the service a certain key combination that will bring it up (i.e. CTRL + Space or CTRL + p) and the application main GUI will be brought up.
Now my questions:
First, I want this application to have a very small footprint and not draw on many system resources, and not interfere with the operation of other applications.
I also would like to write this application in C#. So far the best idea I have had would be to write a service that listened for key strokes and threw away stroke that were not either the control or following a control key.
This does not seem optimal is there a better way, anyone know how spotlight works?
Second, I am concerned that this kind of service might be identified as mall ware.
What steps might I take to ensure that my software is not targeted by applications such as Avast and Spysweeper?
Would I need to contact all of the manufacturers of these software packages and explain the purpose of my application?
Finally, if anyone could link to resources about how to set up such a service I would greatly appreciate it.
Services are not supposed to interact with the desktop user, as such they aren't supposed to be able to hook and watch for keystrokes. This may work on XP but you will likely have many problems on Vista/7 and later OS's.
You really need a userspace program that runs at user startup to do this that runs as the same user as the logged in user.
Also, if you are concerned about minimal footprint and resource usage, you don't want to be using .NET because it needs to load a fairly large runtime library and creates a fairly big working set. Usually this isn't a problem, but for something like a watcher program, it's best to write it in low footprint C using a low footbring minimal CRT startup.
My suggestion would be to create a winforms application, add the system tray icon using NotificationIcon to the main form of the application. Then hide the main form. The application can receive key strokes, particularly if you set the FormsPreview property to true. You might also need to hook into the windows api keypress events.
You should be safe from Malware scanners.
You may want to take a look at this link for setting up a system tray/win forms app.
How can I make a .NET Windows Forms application that only runs in the System Tray?

Categories