Skip to content

Commit 03b37a7

Browse files
committed
RemoveConsole at Startup to AllocConsole if Debug build
1 parent da061fd commit 03b37a7

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ChromeDllInjector/ChromeDllInjector.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
4+
<OutputType>WinExe</OutputType>
55
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<Version>6.0.0.0</Version>

ChromeDllInjector/Program.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class Program {
1717
static void Main(string[] _) {
1818
try {
1919
#if !DEBUG
20-
RedirectConsole();
20+
RedirectOutput();
21+
#else
22+
AttachConsole();
2123
#endif
2224
CreateInjector();
2325
LoadChromeExePaths();
@@ -61,10 +63,15 @@ private static void OnProcessStart(int processId) {
6163
}
6264
}
6365

64-
// Init functions to make the code cleaner
65-
private static void RedirectConsole() {
66-
Kernel32.FreeConsole(); // Hide the console window
66+
private static void AttachConsole()
67+
{
68+
if (!Kernel32.AttachConsole(Kernel32.ATTACH_PARENT_PROCESS)) { // If we can't attach to the parent console, create a new one
69+
Kernel32.AllocConsole();
70+
}
71+
}
6772

73+
// Init functions to make the code cleaner
74+
private static void RedirectOutput() {
6875
StreamWriter writer;
6976
Console.SetOut(writer = new StreamWriter(new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\Temp\ChromePatcherInjector.log", FileMode.Append, FileAccess.Write, FileShare.Read))); // Redirect to C:\Windows\Temp\ChromePatcherInjector.log
7077
writer.AutoFlush = true;

0 commit comments

Comments
 (0)