Skip to content

Commit

Permalink
Terminal (Windows): tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Jan 19, 2024
1 parent d810245 commit 4d1f242
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/detection/terminalshell/terminalshell_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ static uint32_t getShellInfo(FFShellResult* result, uint32_t pid)
continue;
}

ffStrbufClear(&result->version);
fftsGetShellVersion(&result->exe, result->prettyName.chars, &result->version);

result->pid = pid;
result->ppid = ppid;

Expand Down Expand Up @@ -320,14 +317,11 @@ static uint32_t getTerminalInfo(FFTerminalResult* result, uint32_t pid)
// A CUI program created by Windows Explorer will spawn a conhost as its child.
// However the conhost process is just a placeholder;
// The true terminal can be Windows Terminal or others.
if (!getTerminalFromEnv(result) && !detectDefaultTerminal(result))
{
ffStrbufClear(&result->processName);
ffStrbufClear(&result->prettyName);
ffStrbufClear(&result->exe);
result->exeName = "";
return 0;
}
ffStrbufClear(&result->processName);
ffStrbufClear(&result->prettyName);
ffStrbufClear(&result->exe);
result->exeName = "";
return 0;
}
else
{
Expand Down Expand Up @@ -382,7 +376,16 @@ const FFShellResult* ffDetectShell(void)
return &result;

ppid = getShellInfo(&result, ppid);
setShellInfoDetails(&result);

if (result.processName.length > 0)
{
setShellInfoDetails(&result);
char tmp[MAX_PATH];
strcpy(tmp, result.exeName);
char* ext = strrchr(tmp, '.');
if (ext) *ext = '\0';
fftsGetShellVersion(&result.exe, tmp, &result.version);
}

return &result;
}
Expand Down Expand Up @@ -410,10 +413,14 @@ const FFTerminalResult* ffDetectTerminal(void)

if(result.processName.length == 0)
getTerminalFromEnv(&result);
if(result.processName.length == 0)
detectDefaultTerminal(&result);

setTerminalInfoDetails(&result);

fftsGetTerminalVersion(&result.processName, &result.exe, &result.version);
if(result.processName.length > 0)
{
setTerminalInfoDetails(&result);
fftsGetTerminalVersion(&result.processName, &result.exe, &result.version);
}

return &result;
}

0 comments on commit 4d1f242

Please sign in to comment.