Skip to content

Commit

Permalink
Merge pull request #91 from JustArion/master
Browse files Browse the repository at this point in the history
Invert Console Logic in the ChromeDllInjector to be more user friendly
  • Loading branch information
Ceiridge authored Dec 31, 2022
2 parents da061fd + 03b37a7 commit 4dcfe7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ChromeDllInjector/ChromeDllInjector.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>6.0.0.0</Version>
Expand Down
15 changes: 11 additions & 4 deletions ChromeDllInjector/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Program {
static void Main(string[] _) {
try {
#if !DEBUG
RedirectConsole();
RedirectOutput();
#else
AttachConsole();
#endif
CreateInjector();
LoadChromeExePaths();
Expand Down Expand Up @@ -61,10 +63,15 @@ private static void OnProcessStart(int processId) {
}
}

// Init functions to make the code cleaner
private static void RedirectConsole() {
Kernel32.FreeConsole(); // Hide the console window
private static void AttachConsole()
{
if (!Kernel32.AttachConsole(Kernel32.ATTACH_PARENT_PROCESS)) { // If we can't attach to the parent console, create a new one
Kernel32.AllocConsole();
}
}

// Init functions to make the code cleaner
private static void RedirectOutput() {
StreamWriter writer;
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
writer.AutoFlush = true;
Expand Down

0 comments on commit 4dcfe7f

Please sign in to comment.