mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
Some fixes
This commit is contained in:
parent
7de923f90c
commit
5062d774b7
|
@ -15,16 +15,16 @@ namespace WelsonJS.Service
|
||||||
private Rules rules;
|
private Rules rules;
|
||||||
private EventLogWatcher eventLogWatcher;
|
private EventLogWatcher eventLogWatcher;
|
||||||
private ServiceMain parent;
|
private ServiceMain parent;
|
||||||
private string ruleFolderPath;
|
private string ruleDirectoryPath;
|
||||||
|
|
||||||
public FileEventMonitor(ServiceBase parent, string workingDirectory)
|
public FileEventMonitor(ServiceBase parent, string workingDirectory)
|
||||||
{
|
{
|
||||||
this.parent = (ServiceMain)parent;
|
this.parent = (ServiceMain)parent;
|
||||||
ruleFolderPath = Path.Combine(workingDirectory, "app/assets/yar");
|
ruleDirectoryPath = Path.Combine(workingDirectory, "app/assets/yar");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AddYaraRules(new List<string>(Directory.GetFiles(ruleFolderPath, "*.yar")));
|
AddYaraRules(new List<string>(Directory.GetFiles(ruleDirectoryPath, "*.yar")));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,14 +53,15 @@ public class ScreenMatching
|
||||||
|
|
||||||
private ServiceMain parent;
|
private ServiceMain parent;
|
||||||
private List<Bitmap> templateImages;
|
private List<Bitmap> templateImages;
|
||||||
private string templateFolderPath;
|
private string templateDirectoryPath;
|
||||||
private int currentTemplateIndex = 0;
|
private int templateCurrentIndex = 0;
|
||||||
|
private double threshold = 0.97;
|
||||||
private string captureMode;
|
private string captureMode;
|
||||||
|
|
||||||
public ScreenMatching(ServiceBase parent, string workingDirectory)
|
public ScreenMatching(ServiceBase parent, string workingDirectory)
|
||||||
{
|
{
|
||||||
this.parent = (ServiceMain)parent;
|
this.parent = (ServiceMain)parent;
|
||||||
templateFolderPath = Path.Combine(workingDirectory, "app/assets/img/_templates");
|
templateDirectoryPath = Path.Combine(workingDirectory, "app/assets/img/_templates");
|
||||||
templateImages = new List<Bitmap>();
|
templateImages = new List<Bitmap>();
|
||||||
|
|
||||||
SetCaptureMode("screen");
|
SetCaptureMode("screen");
|
||||||
|
@ -78,7 +79,7 @@ public class ScreenMatching
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
files = Directory.GetFiles(templateFolderPath, "*.png");
|
files = Directory.GetFiles(templateDirectoryPath, "*.png");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -119,7 +120,7 @@ public class ScreenMatching
|
||||||
Screen screen = Screen.AllScreens[i];
|
Screen screen = Screen.AllScreens[i];
|
||||||
Bitmap mainImage = CaptureScreen(screen);
|
Bitmap mainImage = CaptureScreen(screen);
|
||||||
|
|
||||||
Bitmap image = templateImages[currentTemplateIndex];
|
Bitmap image = templateImages[templateCurrentIndex];
|
||||||
parent.Log($"Trying match the template {image.Tag as string} on the screen {i}...");
|
parent.Log($"Trying match the template {image.Tag as string} on the screen {i}...");
|
||||||
|
|
||||||
Point matchLocation = FindTemplate(mainImage, (Bitmap)image.Clone(), out double maxCorrelation);
|
Point matchLocation = FindTemplate(mainImage, (Bitmap)image.Clone(), out double maxCorrelation);
|
||||||
|
@ -132,7 +133,7 @@ public class ScreenMatching
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTemplateIndex = ++currentTemplateIndex % templateImages.Count;
|
templateCurrentIndex = ++templateCurrentIndex % templateImages.Count;
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -166,7 +167,7 @@ public class ScreenMatching
|
||||||
Bitmap windowImage = CaptureWindow(hWnd);
|
Bitmap windowImage = CaptureWindow(hWnd);
|
||||||
if (windowImage != null)
|
if (windowImage != null)
|
||||||
{
|
{
|
||||||
Bitmap image = templateImages[currentTemplateIndex];
|
Bitmap image = templateImages[templateCurrentIndex];
|
||||||
Point matchLocation = FindTemplate(windowImage, image, out double maxCorrelation);
|
Point matchLocation = FindTemplate(windowImage, image, out double maxCorrelation);
|
||||||
string templateFileName = image.Tag as string;
|
string templateFileName = image.Tag as string;
|
||||||
|
|
||||||
|
@ -186,7 +187,7 @@ public class ScreenMatching
|
||||||
return true;
|
return true;
|
||||||
}, IntPtr.Zero);
|
}, IntPtr.Zero);
|
||||||
|
|
||||||
currentTemplateIndex = ++currentTemplateIndex % templateImages.Count;
|
templateCurrentIndex = ++templateCurrentIndex % templateImages.Count;
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -234,7 +235,7 @@ public class ScreenMatching
|
||||||
{
|
{
|
||||||
for (int y = 0; y <= mainHeight - templateHeight; y++)
|
for (int y = 0; y <= mainHeight - templateHeight; y++)
|
||||||
{
|
{
|
||||||
if (IsTemplateMatch(mainImage, templateImage, x, y, 0.8)) // matched 80% or above
|
if (IsTemplateMatch(mainImage, templateImage, x, y, threshold))
|
||||||
{
|
{
|
||||||
bestMatch = new Point(x, y);
|
bestMatch = new Point(x, y);
|
||||||
maxCorrelation = 1;
|
maxCorrelation = 1;
|
||||||
|
@ -246,7 +247,7 @@ public class ScreenMatching
|
||||||
return bestMatch;
|
return bestMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsTemplateMatch(Bitmap mainImage, Bitmap templateImage, int offsetX, int offsetY, double threshold = 1.0)
|
private bool IsTemplateMatch(Bitmap mainImage, Bitmap templateImage, int offsetX, int offsetY, double threshold)
|
||||||
{
|
{
|
||||||
int templateWidth = templateImage.Width;
|
int templateWidth = templateImage.Width;
|
||||||
int templateHeight = templateImage.Height;
|
int templateHeight = templateImage.Height;
|
||||||
|
|
|
@ -82,13 +82,46 @@
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="RestSharp, Version=111.4.1.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\RestSharp.111.4.1\lib\net48\RestSharp.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Configuration.Install" />
|
<Reference Include="System.Configuration.Install" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Management" />
|
<Reference Include="System.Management" />
|
||||||
|
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Numerics" />
|
||||||
|
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.ServiceProcess" />
|
<Reference Include="System.ServiceProcess" />
|
||||||
|
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Text.Json.8.0.4\lib\net462\System.Text.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Web" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
|
</configuration>
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net48" />
|
||||||
<package id="Microsoft.O365.Security.Native.libyara.NET" version="4.5.1" targetFramework="net48" />
|
<package id="Microsoft.O365.Security.Native.libyara.NET" version="4.5.1" targetFramework="net48" />
|
||||||
|
<package id="RestSharp" version="111.4.1" targetFramework="net48" />
|
||||||
|
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
|
||||||
|
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
|
||||||
|
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
|
||||||
|
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Text.Encodings.Web" version="8.0.0" targetFramework="net48" />
|
||||||
|
<package id="System.Text.Json" version="8.0.4" targetFramework="net48" />
|
||||||
|
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
|
||||||
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in New Issue
Block a user