Giter VIP home page Giter VIP logo

Comments (4)

susam avatar susam commented on May 28, 2024 2

The fix for this issue is now available in Uncap 0.3.0.

Closing this issue now.

from uncap.

navhaxs avatar navhaxs commented on May 28, 2024 1

I just came across this issue today. It appears to be due to 'ConEmu' running on the system when starting uncap. I might have a look at the source, could be an easy fix.

from uncap.

susam avatar susam commented on May 28, 2024

Thank you, Peter (@peterjuras), for reporting this issue.

Thank you, Jeremy (@navhaxs), for creating pull request #7 to resolve this.

As I have explained in the pull request page, the root cause of the issue here is that in the presence of Cmder, the FindWindow("ConsoleWindowClass", NULL) call gets a handle to another window (not the window in which Uncap is running), so the ShowWindow(h, SW_HIDE) call later attempts to hide the wrong window.

For now, I have merged this pull request #7 as is, so that it remains in the commit history of this project. Your pull request resolves the issue by working around the issue with the FreeConsole() call that detaches Uncap from the console regardless of which handle we got with the FindWindow() call.

I will be pushing another commit soon that addresses the root cause of the issue.

Update: I have pushed commit 0bbf27e that addresses the root cause of the issue. See next comment for more details on the root cause of the issue.

from uncap.

susam avatar susam commented on May 28, 2024

Root Cause Demonstration Code

As I mentioned in my previous comment, the root cause of the issue is that the FindWindow("ConsoleWindowClass", NULL) call gets a handle to another window, not the one in which Uncap is running.

Here is an example code that demonstrates the root cause of the issue:

#include <stdio.h>
#include <windows.h>

void printWindowDetails(HWND h)
{
    char buffer[256];
    WINDOWINFO info;
    int ret;

    if (h == NULL) {
        printf("  - window handle is NULL; error %lu\n", GetLastError());
    }

    ret = GetWindowText(h, buffer, 255);
    if (ret > 0) {
        printf("  - window text: %s\n", buffer);
    } else {
        printf("  - cannot get window text; error %lu\n", GetLastError());
    }

    ret = GetWindowModuleFileName(h, buffer, 255);
    if (ret > 0) {
        printf("  - window module file name: %s\n", buffer);
    } else {
        printf("  - cannot get window text; error %lu\n", GetLastError());
    }

    info.cbSize = sizeof info;
    ret = GetWindowInfo(h, &info);
    if (ret) {
        RECT rect;

        rect = info.rcWindow;
        printf("  - window coordinates: (%ld, %ld), (%ld, %ld)\n",
               rect.top, rect.left, rect.bottom, rect.right);

        rect = info.rcClient;
        printf("  - client coordinates: (%ld, %ld), (%ld, %ld)\n",
               rect.top, rect.left, rect.bottom, rect.right);

        printf("  - window status: %d\n", info.dwWindowStatus);
    } else {
        printf("  - cannot get window info; error %lu\n", GetLastError());
    }

    printf("\n");
}

int main()
{
    HWND h;

    printf("FindWindow(\"ConsoleWindowClass\", NULL):\n");
    h = FindWindow("ConsoleWindowClass", NULL);
    printWindowDetails(h);

    printf("GetConsoleWindow():\n");
    h = GetConsoleWindow();
    printWindowDetails(h);

    printf("press ENTER to exit\n");
    getchar();

    return 0;
}

This code can be compiled with GCC (MinGW) as follows:

gcc -std=c89 -Wall -Wextra -Wpedantic foo.c -o foo

Cmder Not Running

Here is the output when this program is run by double-clicking when Cmder is not running:

FindWindow("ConsoleWindowClass", NULL):
  - window text: C:\Users\susam\Downloads\uncap\foo.exe
  - window module file name: C:\Users\susam\Downloads\uncap\foo.exe
  - window coordinates: (130, 130), (649, 1123)
  - client coordinates: (161, 138), (641, 1098)
  - window status: 1

GetConsoleWindow():
  - window text: C:\Users\susam\Downloads\uncap\foo.exe
  - window module file name: C:\Users\susam\Downloads\uncap\foo.exe
  - window coordinates: (130, 130), (649, 1123)
  - client coordinates: (161, 138), (641, 1098)
  - window status: 1

press ENTER to exit

We can see above that both FindWindow() and GetConsoleWindow() return the same window as expected.

Cmder Launching

Here is the output when Cmder is launching:

FindWindow("ConsoleWindowClass", NULL):
  - window text: cmd - "C:\Users\susam\Downloads\cmder_mini\vendor\conemu-maximus5\..\init.bat"
  - window module file name: C:\Users\susam\Downloads\uncap\foo.exe
  - window coordinates: (0, 0), (189, 393)
  - client coordinates: (31, 8), (181, 368)
  - window status: 0

GetConsoleWindow():
  - window text: C:\Users\susam\Downloads\uncap\foo.exe
  - window module file name: C:\Users\susam\Downloads\uncap\foo.exe
  - window coordinates: (130, 130), (649, 1123)
  - client coordinates: (161, 138), (641, 1098)
  - window status: 1

press ENTER to exit

We can see that FindWindow() returns a different window in which Cmder initialization script is running. This is the issue.

Cmder Launched

Here is the output when Cmder has launched:

FindWindow("ConsoleWindowClass", NULL):
  - window text: Administrator: cmd
  - window module file name: C:\Users\susam\Downloads\uncap\foo.exe
  - window coordinates: (0, 0), (189, 393)
  - client coordinates: (31, 8), (181, 368)
  - window status: 0

GetConsoleWindow():
  - window text: C:\Users\susam\Downloads\uncap\foo.exe
  - window module file name: C:\Users\susam\Downloads\uncap\foo.exe
  - window coordinates: (130, 130), (649, 1123)
  - client coordinates: (161, 138), (641, 1098)
  - window status: 1

press ENTER to exit

We can see that FindWindow() returns a different window.

Fix

The correct fix this to issue is to use GetConsoleWindow() instead of FindWindow() to get the handle to the current window. Commit 0bbf27e implements this fix. I will later release a new version of Uncap that contains this fix and then close this issue.

from uncap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.