Skip to content

Commit

Permalink
Merge pull request GhostPack#182 from GhostPack/fix_encoding
Browse files Browse the repository at this point in the history
Check for console before setting encoding
  • Loading branch information
0xe7 authored Feb 1, 2024
2 parents b303d1c + 129c49d commit 04f81a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Rubeus/Domain/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void ShowLogo()
Console.WriteLine(" | __ /| | | | _ \\| ___ | | | |/___)");
Console.WriteLine(" | | \\ \\| |_| | |_) ) ____| |_| |___ |");
Console.WriteLine(" |_| |_|____/|____/|_____)____/(___/\r\n");
Console.WriteLine(" v2.3.1 \r\n");
Console.WriteLine(" v2.3.2 \r\n");
}

public static void ShowUsage()
Expand Down
9 changes: 7 additions & 2 deletions Rubeus/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private static void MainExecute(string commandName, Dictionary<string,string> pa

try
{
// print unicode char properly
Console.OutputEncoding = Encoding.UTF8;
// print unicode char properly if there's a console
if(IsConsolePresent()) Console.OutputEncoding = Encoding.UTF8;

var commandFound = new CommandCollection().ExecuteCommand(commandName, parsedArgs);

Expand Down Expand Up @@ -99,6 +99,11 @@ public static string MainString(string command)
return output;
}

private static bool IsConsolePresent()
{
return Interop.GetConsoleWindow() != IntPtr.Zero;
}

public static void Main(string[] args)
{
// try to parse the command line arguments, show usage on failure and then bail
Expand Down
4 changes: 4 additions & 0 deletions Rubeus/lib/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,10 @@ public static extern int DsGetDcName(
[DllImport("kernel32.dll")]
public extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();


// LSA functions

[DllImport("secur32.dll", SetLastError = false)]
Expand Down

0 comments on commit 04f81a4

Please sign in to comment.