Closed jm33-m0 closed 2 years ago
The plan is to use SetWindowPos
syscall to adjust the size of console window automatically, so it matches the terminal size on C2 side.
The main issue here is we don't have an easy/direct way to obtain the window handle of our child process, one possible solution is to use FindWindow
syscall, but it only matches window titles.
If we use CreateProcess
syscall instead of exec.Command
wrapper, StartInfo
can be adjusted as well as initial window size, but it doesn't solve this issue completely as our terminal size may change.
For now you can manually set the terminal size in powershell session, if the window gets too small/large
SetWindowPos
seems working, the shell pane (that pops up when you select an agent) looks normal, I am still not sure why it worked.
As a start, SetConsoleScreenBufferSize
should be the way to go, but I am afraid that it only resizes the console buffer of current process.
If we use SetWindowPos
, it's done in pixels, meaning we might not end up with correct window size (that matches character count)
FFS, I have solved this issue mostly, now the only issue here is that window resizing ignores title bar width and scroll bar width, so you will end up with a few lines short, meaning the resized console window is always a bit smaller than it should be.
But it should be highly usable, at least when compared with previous versions.
Now everything should work, open a new issue if you find any other issues
Overall the shell is working, and you should be able to use Tab and Ctrl in
cmd
andpowershell
sessions.However the terminal size seems wrong, as an example, the when you issue
cls
to clear screen, on-screen text cannot be cleared correctly.