3

Is there a working way to embed the windows console in disasm code? I tried AllocConsole with GetStdHandle or AttachConsole with PID of an existing console but it didn't work. I have tried printf and putchar with no success. I can make a console and be able to change the title (fancy way to get printf:))) but instead of output I get a black screen. I'm on XP and trying to get the status of I/O ports in an old MFC application. MessageBox is a good alternative, but I/O ports send thousands of messages per second. I will be happy even if x32dbg will have this function for logging registry value somehow but new versions doesn't work on my XP

5
  • 2
    How about using another tool? .. for example learn.microsoft.com/en-us/sysinternals/downloads/portmon Dec 2, 2022 at 7:21
  • @MegaTonnage Thanks, but this tool works on standart ports LPT and COM but I need a specific range IO ports 298-2A5. I builded my own tool based on WinIO driver, but this tool blocks IO ports and stops the program from running normally. Dec 2, 2022 at 8:29
  • 1
    Hi and welcome to RE.SE. This sounds weird. A UM app can hardly do anything with I/O ports. There has to be a driver involved. And then it depends how communication happens. Could be that the driver helps to map the I/O port range into the app and the app gets to directly interact with that. But otherwise you could look for DeviceIoControl calls or ReadFile/WriteFile on some device handle (which you could glean via a tool like Process Hacker or Process Explorer).
    – 0xC0000022L
    Dec 2, 2022 at 9:56
  • @0xC0000022L Hi! This application I'm trying to debug has its own drivers in KM and works with it using the old NTport library. My task was to print what they send to each other Dec 2, 2022 at 10:15
  • 1
    @EvilCracker Wouldn't a classic filter driver be the way to go than? Just catch all those IRPs in flight ...
    – 0xC0000022L
    Dec 2, 2022 at 11:57

1 Answer 1

0

Ok, I got it... In an arbitrary place in the program I put this:

call 0x7C8731B9 // kernel32.AllocConsole()
push 0x21 // '!'
call _putch // this print one char '!'
push 0x00553D91 // some string
call _cputs // this print string

In my case no need to use GetStdHandle after AllocConsole

2
  • Odd, I'd expect you have to open the respective pseudo-devices. At least that's how I had to do it whenever I used consoles for tracing purposes in GUI apps.
    – 0xC0000022L
    Dec 2, 2022 at 9:58
  • @0xC0000022L Windows C functions which starts from _ do magic :) Dec 2, 2022 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.