flat assembler
Message board for the users of flat assembler.

Index > Windows > [Closed] How to manipulate keybord stuff.

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
I recently started my third semester at university, during which, we will be focusing a lot on assembly (FASM). We will probably have to submit a project at the end of it and I want to get started on it ASAP.

Basically I want to create a program which "switches" or "replaces" two keys on the keyboard. Specifically, the Ctrl and S keys. Consider the examples below to help you understand.

1) If you wish to save your work in Microsoft Word, you have to press S + Ctrl instead of Ctrl + S.
2) To type "fasm" in google you have to press the following keys in ascending order: F, A, Ctrl, M.
3) To open taskbar you have to press S + Alt + Delete instead of Ctrl + Alt + Delete
4) You have to press Shift + Ctrl to type capital "S". Pressing Ctrl with the Caps Lock on also does the same.

As a low-level language, I think Assembly can go deep enough to do this. I have to figure out what information is sent when a key is pressed, where is it received and how is it manipulated.

Obviously I am gonna have to do a lot of research. But I look at the documentation for FASM and it contains so many words I don't understand. So I was hoping someone here can point me in the right direction. These can be YouTube videos, articles, etc. Anything to help me at least get started. I AM NOT ASKING FOR CODE TO COPY AND PASTE.

Looking forward to your responses. Thanks in advance.


Last edited by codeHacker101 on 09 Nov 2020, 06:30; edited 1 time in total
Post 08 Nov 2020, 22:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17849
Location: In your JS exploiting you and your system
revolution
You will have to replace the keyboard driver in the kernel.

And depending upon your Windows version you might need to have it signed for Windows to accept it.
Post 08 Nov 2020, 22:23
View user's profile Send private message Visit poster's website Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
You have been a big help in a previous question I asked, so am pleasantly surprised to see its you again.


Last edited by codeHacker101 on 08 Nov 2020, 22:33; edited 1 time in total
Post 08 Nov 2020, 22:26
View user's profile Send private message Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
"replace the keyboard driver" sounds like a very permanent change. I was hoping for an exe that will make this happen when I double-click on it to run it and things would go back to normal when I close the program/terminate the process. It that possible?
Post 08 Nov 2020, 22:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17849
Location: In your JS exploiting you and your system
revolution
Not possible from user mode.

That would break the security of Windows and allow anyone to log keystrokes.
Post 08 Nov 2020, 22:33
View user's profile Send private message Visit poster's website Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
I intend to run the program as admin
Post 08 Nov 2020, 22:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17849
Location: In your JS exploiting you and your system
revolution
Admin is still user mode.

You need to do this from the kernel.
Post 08 Nov 2020, 22:35
View user's profile Send private message Visit poster's website Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
Do I have to create my own driver or something?
Post 08 Nov 2020, 22:36
View user's profile Send private message Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
Sounds pretty impossible for a uni student who started assembly a few weeks ago.
Post 08 Nov 2020, 22:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17849
Location: In your JS exploiting you and your system
revolution
codeHacker101 wrote:
Do I have to create my own driver or something?
Yes.
codeHacker101 wrote:
Sounds pretty impossible for a uni student who started assembly a few weeks ago.
The hardest part will be getting it signed.
Post 08 Nov 2020, 22:38
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17849
Location: In your JS exploiting you and your system
revolution
Or use a different OS.

DOS would make this trivial.
Post 08 Nov 2020, 22:39
View user's profile Send private message Visit poster's website Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
You said "kernal" and I found this https://www.educative.io/edpresso/what-is-windows-kernel. Don't even know what DOS is. Maybe I can disable a key, still detect it somehow and programatically send a different keypress. I think you can send keypress in C++. Maybe also assembly.
Post 08 Nov 2020, 22:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17849
Location: In your JS exploiting you and your system
revolution
You can't use a user-mode program to override any kernel driver.

You can send fake keypresses to other applications. But that isn't what you described in the first post. It would just add more keys into the queue of the application.
Post 08 Nov 2020, 22:48
View user's profile Send private message Visit poster's website Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
So I may be able to
1) disable both keys
2) still somehow detect when either gets pressed
3) enable temperarily, send keystroke, disable again

Sort of like pseudo replacement instead of real. What do you think?
Post 08 Nov 2020, 22:57
View user's profile Send private message Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
Are 1 and 2 possible in user mode?
Post 08 Nov 2020, 22:59
View user's profile Send private message Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
Its after 4am here right now and I don't want to take too much of your time either because an ameture like me can turn this into an endless debate and still get nowhere.

But when you said "kernal" it helped me because I googled "windows kernal" and it increased me in knowledge. Maybe thats the best I can do right now. GOOGLE different relevant terminologies to help figure out a way forward.

So if you are willing please tell me more such words and phrases so I can start learning. If not, thank you a lot for bothering to respond to my silly question anyways.
Post 08 Nov 2020, 23:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17849
Location: In your JS exploiting you and your system
revolution
From user mode you can't disable keystrokes in the kernel driver.

You can't prevent the driver from doing its job unless you have your own kernel driver.

The only thing you can do from user mode is wait for the OS to tell you which keys are pressed. If another application has the focus then that app will get the keystrokes, not you, and you can't prevent that.
Post 09 Nov 2020, 03:11
View user's profile Send private message Visit poster's website Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 430
Ali.Z
as rev said, you cannot switch/replace keycode unless you alter the device driver or implement yours.

so what you want to achieve isnt easily doable, and make no sense to swap to keys;
1. no you cant
2. yes
3. im not sure what do you mean

as for 2, you can attach to thread input as every virtual thread have its own input queue/stack (regardless of the subsystem)

but to be more subsystem specific, i.e. gui subsystem then you can make a small dll and inject it into foreground window, the windows who have current focus and hook their window procedure and specifically listen to keydown messages.

_________________
Asm For Wise Humans
Post 09 Nov 2020, 03:49
View user's profile Send private message Reply with quote
codeHacker101



Joined: 02 Nov 2020
Posts: 22
codeHacker101
Sorry I wasted both of your time @revolution and @Ali.Z. This is clearly not doable in a way I was thinking. I was getting far ahead of myself. I have added [Closed] to the title (had to make it shorter because of the word limit). Thank you both for your assistance.
Post 09 Nov 2020, 06:37
View user's profile Send private message Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 116
Location: i@grompe.org.ru
Grom PE
To swap keys around, you don't even need a running program, all you need is a custom keyboard layout.

For more complicated keyboard manipulation, might want to look into WH_KEYBOARD_LL.
Post 10 Nov 2020, 03:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.