8 ms·
Ray tracing in notepad.exe at 30 FPS
- phoe-krk 7y agoSomeone use that technique to hook a WSL bash shell in there. I can't wait for notepad to be my terminal.
- sesuximo 7y agoDo it!
- heinrichhartman 7y agoActually. I just added something similar to my emacs yesterday: (defun sh-line () (interactive) (let ((cmd (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) (end-of-line) (newline) (insert (shell-command-to-string cmd)))) (local-set-key (kbd "M-RET") 'sh-line) With this Alt-RET will evaluate the last line in your shell, and insert the output.
- snazz 7y agoIt is worth mentioning that Emacs is a wee bit easier to script than notepad.exe :)
- TeMPOraL 7y agoSpeaking of Emacs, shells and WSL, I recently had to shell out from Emacs under WSL to git-bash under Windows proper, to run cmake to run MSBuild, and get the generation/compilation output all the way back. Turns out, while regular M-x shell-command would work, M-x async-shell-command (i.e. shell-command with appended &) would not - it wasn't able to communicate with the spawned process. I needed it to be async so that a compile wouldn't block my Emacs. The solution I came up with is a bit lower-level, looks like this: (make-process :name "some_name" :buffer "buffer" :command ("cmd" "to" "run") :connection-type 'pipe :coding 'utf-8-dos) Two key lines are :connection-type 'pipe, which solves the I/O issues, and :coding 'utf-8-dos, which ensures the output streamed to an Emacs buffer isn't polluted by ^M (CR from CRLF line ending). Now, if anyone figured out how to configure a connection to a language server across the WSL boundary, I'm all ears.
- heinrichhartman 7y agoDoes `M-x compile` not work for you on windows? This is what I use to do run build scripts async.
- jsrcout 7y agoThank you! Macintosh MPW had a very similar feature back in the day, it rocked. Haven't seen it since. Added to my .emacs!
- rodiger 7y agoI love how useless this is. Hacking for the sake of hacking. Really cool!
- sesuximo 7y agothis is a great introduction to programming on Windows
- bluedino 7y agoReminds me of stuff like "Advanced Windows 95 Programming" by Jeffrey Richter
- mbreese 7y agoHow common is it to be able to read/write another program’s memory space? It’s not something I’ve ever done before, but it doesn’t seem like it’s a very good idea from a security standpoint. Are there other use cases that I’m missing? Still, this is a really cool hack.
- swinglock 7y agoDebuggers.
- mbreese 7y agoThere we go... that was the obvious use case I was forgetting!
- deleted 7y ago[deleted]
- xxs 7y agoI'd not call it common. Back in the days of old (windows 3.1), I did that to extract dictionary entries - had to control the interface with wm_click too. There was way more encoding than notepad shown in the example, end result was rft. The basic principle is that it was possible to make the process load a DLL.
- simias 7y agoWell shared memory is a non-adversarial and limited way to effectively read and write the memory of an other process. It doesn't have any obvious implications security-wise since obviously if a process can read and write an other processe's memory then obviously you have some amount of trust that it's not going to do that. That's why you generally need certain privileges to do that. The main problem is that messing with a process memory is inherently non-portable and very likely to break if the program changes even slightly. Actually if the system uses address space randomization it may even change between invocations of the program. As such the only programs that usually bother to do that are debuggers and tracers. Before the advent of MMUs and virtual memory everybody shared the same address space and everybody could write everywhere. Fun times. You still have MMU-less system nowadays but it's generally limited to really low power (or really old) microcontrollers.
- anonymfus 7y agoIIRC you can just use WM_SETTEXT message instead. Don't know about FPS, probably in between of the two methods you used.
- mywittyname 7y agoI'm not sure this would work. The "game" is running in a different process than notepad and WM_SETTEXT accepts a memory pointer as input. This pointer would be meaningless because it's coming from a different process.
- netmare 7y agoWindows does automatic parameter marshaling for system messages (0 to WM_USER-1), which WM_SETTEXT is a part of. Since the meaning of the parameters is well-established, the system can allocate memory in the target process and replace the pointers with meaningful values for the target wndproc.
- unnouinceput 7y agoYou can also allocate memory on the hooked process, Notepad in this case, and modify that one then use WM_SETTEXT. I thought about that when I saw his "wait to fill Notepad with WM_CHAR" which took like 10 seconds? Anyway WM_SETTEXT would be faster then 30 FPS he achieved with accessing Notepad's buffer memory since he's doing a lot of extra-work there to achieve the final result.
- simias 7y agoIt's funny how CheatEngine seems to see a lot of use as a legit "professional" dev tool. I personally don't use it because I don't run Windows a whole lot but I've had a few bug reports on github where people would use CheatEngine to investigate bugs even though the code was fully available so you could use any full-featured debugger instead. I suspect that some younger developers simply started tinkering with CheatEngine before they learned proper programming so they feel very comfortable using it instead of a regular debugger. I started programming by tinkering with BASIC game listings so I feel a certain kinship with this approach. Also CheatEngine is probably easier to set up and will work regardless of whether you have access to the source or not. And unlike more advanced tools like IDA you don't have to worry about expensive license or pirating since it's free and open source. That being said if you're reporting bugs on open source projects on GH please try to use more appropriate debugging tools, I don't know what to do when somebody starts posting dumps of the Windows VM address space to show me how something isn't working as it should...
- mhh__ 7y agoIn terms of simply poking around with memory cheatengine's UI is much more direct than (say) GDB or similar
- arsome 7y agoYeah, you could consider going to something like x64dbg for this case, but really for finding data in memory, CheatEngine is king.
- scottmcf 7y agoIt really says a lot that kids are so easily able to use/understand what is going on with Cheat Engine, despite how powerful it is.
- TeMPOraL 7y agoTells you that people with a goal to accomplish don't need to have their tools dumbed down for them, despite what modern UX trends would have you believe.
- mrspeaker 7y agoI remember doing the "use PostMessage to send a WM_CHAR" trick as part of program I made to auto-draw in a FaceBook drawing app. It would read a pixel value from a file, then "click" in the FaceBook app's color textfield, send 7 delete messages to remove the #000000 color, type in the new color value, then "click" at an X/Y position. It did it 10 times a second. It worked great until I accidentally focused another app while it was running: and the 70 delete-messages-per-second got sent to Microsoft Outlook. It took me a while to figure out what was going on as screenfuls of emails evaporated before my eyes.
- stronglikedan 7y agoHopefully it wasn't a shift+delete message! ;-)
- grenoire 7y agoWell, basically the same story but with Auto Hotkey scripts!
- TheSpiceIsLife 7y agoCan get messy real quick! I have: F9:: Reload Return in all my AutoHotKey scripts, so hitting F9 will cause the script to reload and thereby stop anything running. Also handy when doing edits and you want to reload to test.
- numpad0 7y agoIn old Japanese internet that kind of bitmap-to-click tools were called “dot-tre” or “dot tracer” after the name of an app in mid 2000s
- bluedino 7y agoI never got to program for classic Mac OS, but I wonder what a similar program would look like, considering they didn't have memory protection or anything.
- tambourine_man 7y agoA lot of cool hacks where possible because of that. One very useful, was an extension that allowed you to “save” a file even after you‘ve hit “don’t save”
- saagarjha 7y agoOh, Mac OS had oodles of these. Even Mac OS X had a bunch of "Haxies" because it would load plugins into every process for a while. These days you need to turn off a bunch of security features to make it work in general.
- gprasanth 7y agoThis is severely cool. Human endeavour never ceases to amaze me. For me, the most beautiful aspect of being human is the length people go to, to express themselves through their creations.
- polytronic 7y agoThat's awesome! An example of true art in software engineering! Kudos!
- aabajian 7y agoI'm a radiology resident. I did a similar thing with PowerScribe 360, the most popular dictation tool for radiologists. I injected an auto-complete dropdown and an inline spell checker. The Win32 SendMessage APIs are quite powerful if the underlying program is built on top of Win32.
- deleted 7y ago[deleted]
- Scoundreller 7y agoOnly problem is that a lot of apps are being run “in the cloud” over Citrix these days. Suddenly all you have is a streaming image. Sometimes you can work with the x and y coordinates if you resize each screen each time. Sometimes that can be very fast because you can click on the controls before they’re even drawn on your screen.
- folmar 7y agoCitrix often works so poor that _I_ click controls of program I use often before they are drawn.
- unnouinceput 7y agoPostMessage not SendMessage. Latter waits, former doesn't hence why you can end-up with a hang if you mix one with the other. On other hand, if you want sync communication you use SendMessage.
- tomc1985 7y agoI am so glad this demo exists, because it identifies one of the many great things that modern sandbox security is trying to destroy I had a lot of fun as a kid fucking with Windows in Spy++. Oh your shareware program disabled the "Continue" button?? Let me just go in there and reenable it. It was like the DOM inspector but for Windows itself. Later I got to use these skills to port a Firefox addon to Internet Explorer. It was a contraption, and it worked. Ironically that project died because I couldn't get the installer to work right
- z3t4 7y agoYou dont want coolgame app to be able to read and alter sucurebank app. the funny thing with for example snap apps is that most want full privileges...
- colejohnson66 7y agoDoesn’t Windows require Administrative privileges to access another process’ memory? I know it does to get direct access to a hard drive. Granted, it would be nice if one had to explicitly whitelist an app that wanted to read other process’ memory.
- asveikau 7y agoYou don't need admin to do it to yourself, otherwise debuggers wouldn't work. It will fail if you do it for an unrelated user though. Basically the permissions are enforced at OpenProcess(), and these are the permissions you can ask for: https://docs.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights https://docs.microsoft.com/en-us/windows/win32/procthread/pr...
- tomc1985 7y agoUp until recently it was standard to just blindly grant admin to whatever asked for it, because UAC's implementation was so damn naggy. With Windows XP or before there was no UAC and most everyone ran as admin unless you were computer savvy or on a corporate PC.
- 7y ago
- rkagerer 7y agoIt’s not possible to read data in a different process’ address space directly (or at least, I didn’t stumble on how to do it). Instead, I first needed to copy the contents of a page range to the memory scanner’s address space. How about injecting your code into that process? (Either from your own DLL via LoadLibrary and SetWindowsHookEx; or WriteProcessMemory directly into it then CreateRemoteThread) [1] I love that Windows lets you do this kind of stuff. Security nightmare, sure, but it allows use cases the creators couldn't envision (e.g. I believe UltraMon uses it to add and override window functionality). The first time I injected a hook into another app from Visual Basic it felt like I had a new superpower. I was going to add some code to force notepad to use the fonts I wanted (Consolas, 11pt), but for some reason sending WM_SETFONT messages kept messing up how fonts were displaying For this one you could automate the menu dialogs to display the current font. SendKeys should do the trick, then read the control values with the same methodology already used in your project. [1] https://www.codeproject.com/Articles/4610/Three-Ways-to-Inject-Your-Code-into-Another-Proces https://www.codeproject.com/Articles/4610/Three-Ways-to-Inje...
- shadykiller 7y agoI once used the similar strategy to hook into DC++ used for lan file sharing in our school. There was a chatroom game which had contest for unjumbling jumbled words. My app would inject into the DC++ messaging pipeline, read the unjumbled word and type back the correct answers. It infuriated long time players whose score I beat in just a few days. It was fun :) Still have the source code here - https://github.com/shadabahmed/quizroom_hacker https://github.com/shadabahmed/quizroom_hacker
- alpb 7y agoIt seems like the refresh rate of Notepad itself is lower, as one can see half-drawn frames in the GIF. But a really cool experiment nonetheless.
- kaetemi 7y agoCaused by the separate background redraw pass of Win32.
- CivBase 7y agoI'm less interested in how he got Notepad in particular to do this and more interested in how convincingly he managed to represent a 3D object by projecting it onto a grid of ASCII characters. I've seen plenty of ASCII art, but I've never even considered what it might look like animated. I went looking for something similar that was interactive and found ASCIICKER. It's everything I wanted and more. https://asciicker.com/y6/ https://asciicker.com/y6/
- Teknoman117 7y agoThere is also libcaca: http://caca.zoy.org/wiki/libcaca http://caca.zoy.org/wiki/libcaca I remember seeing Chromium Embedded Framework had a caca backend (circa 2015) so you could use the chromium renderer in a text terminal.
- pp19dd 7y agoWhoa, Nelly. I just freaked out after hitting q and e to rotate. I thought it was just a 2d representation and ... it's not. Thanks for finding this.
- KMnO4 7y agoYou can see the developer's progress in the previous versions, eg https://asciicker.com/x8/ https://asciicker.com/x8/ There are a whole bunch linked on the main page: https://asciicker.com/ https://asciicker.com/
- NKCSS 7y agoStuff like this is why I love HN :)
- macca321 7y agoI've got a script somewhere that auto saves notepad. I sometimes wonder if it's marketable
- milesvp 7y agoI did some windows hooking/hijacking years ago when I was working on a poker bot, and found that I couldn't get access to some text output of the poker client. Fun fact. The C++ hooking library I found, Detours, which at the time was the most common (only?) library for hooking windows API calls. It was written by microsoft research for accessibility reasons. There are 2 windows API functions (maybe more) that will render text to the screen basically as a bmp making it impossible to gain access to the text being written. Not sure if this was an oversight by the MS windows group, or it was intentional to allow for developers to obfuscate text output in various ways. Thing is, this breaks screen readers. So microsoft got to create a library that unbreaks their API, which I personally found very amusing at the time. Also you should know, that the library makes it obvious it's being used if the client has enough privileges. I don't remember the details because I never needed to care. But it's some combination of adding a process in task manager, and making an obvious fingerprint in memory. I think this was to appease complaints of use by more nefarious purposes than screen readers. My understanding is that companies like Blizzard know how to find you're using detours, if you don't go out of your way to modify the library before compiling it. https://www.microsoft.com/en-us/research/project/detours/ https://www.microsoft.com/en-us/research/project/detours/
- DHowett 7y agoThis is only tangentially related to your post, but it appears as though Detours is open-source! https://github.com/microsoft/detours https://github.com/microsoft/detours
- ebj73 7y agoThis must be mentioned somewhere in the Book of Revelation, surely.
- saagarjha 7y agoHacks like these are fun; but there's a number of interesting takeaways from something like this. One is that applications supporting accessibility or scripting interfaces are really, really important: they let other apps interact with your program in ways you may have never imagined, "for free". Another is that platforms have been locking down on cross-application access for quite a while, for security reasons. Reading or writing a process's memory is a big no-no these days, since it effectively lets you inherit the privileges of that application, and some operating systems will prevent you from doing it altogether no matter how much privileges you have. The latter operating systems have also begin to lock down the APIs that give programmatic control as well, which is somewhat sad… Finally, when doing things like this try to see if you can find the "highest level" to do such hackery at. Ideally, the app has functionality built-in to do what you want, and if that doesn't work see if the accessibility APIs can help. Then see if you can find functions in the binary to call, and then as a last resort you can touch data structures in memory. This is because using higher-level APIs is more likely to keep things working: you might be changing the string in memory, but some code at a "higher level" might not expect that and misbehave. Perhaps it cached the string's length or thinks it has exclusive access to that memory so it overwrites your modifications. Have fun with your hacks, but be careful!
- nolok 7y agoThe Valorant hack through Raspberry Pi emulated mouse* that has been going around really shows that while you're right, ultimately those kind of things are like DRM in that they fight a fight that they cannot win by design. You can't stop the user (or other application pretending to be him) from accessing the content of something while allowing him to access the content of something, and you can't stop the user (or other application pretending to be him) from interacting with your software while being interactive for him. * actual mouse is plugged into the pi, pi is plugged in the computer in usb and pretend to be a mouse, video output is piped into the pi, software magic running on the pi "fix" the mouse movement to make perfect aim when need be through image analysis https://www.youtube.com/watch?v=d1jz8qbzfIk https://www.youtube.com/watch?v=d1jz8qbzfIk
- Polylactic_acid 7y ago
- gerdesj 7y agoAs soon as I saw: "Sending Key Events To Notepad" I simply thought AutoIt and moved on. There is no denying how cool the end result is but input to any Windows thingie can be scripted with AutoIt in a nice easy way with a very expressive, BASIC style language that has existed for decades. You can get it to churn out a self contained .exe. I don't know why Windows sysadmins piss around with anything less for most tasks on an OS that needs a GUI. You can always call into or out of PS/cmd or whatever as needed.
- 83457 7y agoWould it be efficient enough to render a rotating cube at 30fps?
- unnouinceput 7y agoNo. I doubt it will be even 1 FPS.
- gerdesj 7y agoTools for the job
- 83457 7y agoAnd that is exactly my point.
- gfaure 7y agoThis tweet mentions a trick which uses Notepad as a logging sink. https://twitter.com/steveklabnik/status/1263190719721766918 https://twitter.com/steveklabnik/status/1263190719721766918
- steveklabnik 7y agoHere's a link to the source comment: https://www.reddit.com/r/programming/comments/gnazif/ray_tracing_in_notepadexe_at_30_fps/fr8uy2l/ https://www.reddit.com/r/programming/comments/gnazif/ray_tra...
- augustoproiete 6y agoHere is a Serilog sink for .NET apps that writes directly to the most recent Notepad window opened by the user https://github.com/augustoproiete/serilog-sinks-notepad https://github.com/augustoproiete/serilog-sinks-notepad
- j_z_reeves 7y agoI never heard about cheat engine before. Are there similar tools for other platforms? I know you can hook GDB to any running process, but once you're in the process, discovering what is occurring is often pretty difficult. I'm guessing this is how a lot of the game shark cheats were discovered back in the day.
- hexmiles 7y agofor linux there is scanmem and it's gui gameconqueror, which offer the same core functionality of memory scanning https://github.com/scanmem/scanmem https://github.com/scanmem/scanmem
- imvetri 7y agoNice work!. Thanks for sharing
- ygra 7y agoThat post could have been a lot shorter had they known about UI Automation. Not sure whether it's far enough, but it definitely would have tried that probably before even using WM_CHAR, simply because you can just tell the text box to adopt a new text.
- SakeOfBrevity 7y agoThis is the stuff that keeps me on my toes, thank you bro