Skip to content

Commit

Permalink
Merge pull request #50 from stavroskasidis/release/2.4.5
Browse files Browse the repository at this point in the history
Release/2.4.5
  • Loading branch information
stavroskasidis authored Feb 7, 2023
2 parents 3ffdadc + 0d1c6d0 commit eb5af43
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ You can see its [virustotal.com](https://www.virustotal.com/) scan result [here]
This work was inspired by the post in https://github.com/dotnet/aspnetcore/issues/31048#issuecomment-915152791 by github user [tedd](https://github.com/tedd)

## Release Notes
<details open="open"><summary>2.4.5</summary>

>- Fixes [#48](https://github.com/stavroskasidis/BlazorWasmAntivirusProtection/issues/48) (Contribution by [sykesbPragmatics](https://github.com/sykesbPragmatics))
</details>

<details open="open"><summary>2.4.0</summary>
<details><summary>2.4.0</summary>

>- Fix for gzip satellite assemblies being compressed from original verion instead of obfuscated one.
>- Changed target back to .net 6.0.
Expand Down
41 changes: 33 additions & 8 deletions src/BlazorWasmAntivirusProtection.Tasks/ObfuscateDlls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace BlazorWasmAntivirusProtection.Tasks
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading;

public class ObfuscateDlls : Task
{
Expand All @@ -28,11 +29,11 @@ public class ObfuscateDlls : Task

public override bool Execute()
{
//#if DEBUG
// System.Diagnostics.Debugger.Launch();
//#endif
//#if DEBUG
// System.Diagnostics.Debugger.Launch();
//#endif
if (PublishBlazorBootStaticWebAsset.Length == 0) return true;
if(!Enum.TryParse<ObfuscationMode>(ObfuscationMode, out var obfuscationMode))
if (!Enum.TryParse<ObfuscationMode>(ObfuscationMode, out var obfuscationMode))
{
return false;
}
Expand All @@ -55,7 +56,7 @@ public override bool Execute()
Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Changing .dll headers from MZ to BZ finished");

}
else if(obfuscationMode == Tasks.ObfuscationMode.Xor)
else if (obfuscationMode == Tasks.ObfuscationMode.Xor)
{
var key = Encoding.ASCII.GetBytes(XorKey);
Log.LogMessage(MessageImportance.High, "BlazorWasmAntivirusProtection: Xor'ing .dlls");
Expand All @@ -74,7 +75,7 @@ public override bool Execute()
{
obfuscationMode = obfuscationMode,
xorKey = XorKey,
cacheBootResourcesObfuscated = OriginalBlazorCacheBootResources
cacheBootResourcesObfuscated = OriginalBlazorCacheBootResources
});
File.WriteAllText(SettingsPath, settings);

Expand All @@ -96,13 +97,37 @@ void ChangeDllHeaderToBz(string fn)
bw.Write(bz);
}

void XorDllWithKey(string fn,byte[] key)
void XorDllWithKey(string fn, byte[] key)
{
var data = File.ReadAllBytes(fn);
for (int i = 0; i < data.Length; i++)
data[i] = (byte)(data[i] ^ key[i % key.Length]);

File.WriteAllBytes(fn, data);
//Ensure file is not locked
//Some VM based systems are having issues replacing the file
int attempts = 0;
bool complete = false;
do
{
try
{
attempts++;
File.WriteAllBytes(fn, data);
complete = true;
}
catch (Exception)
{
if (attempts > 11)
{
//Tried 10 times, abort
throw;
}
//Sleep for .5 second, hopefully lock will clear
Log.LogMessage(MessageImportance.High, "BlazorWasmAntivirusProtection: File locked, will re-attempt");
Thread.Sleep(500);
}
}
while (!complete);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageProjectUrl>https://github.com/stavroskasidis/BlazorWasmAntivirusProtection</PackageProjectUrl>
<Description>This package attempts to guard against false positives from antiviruses that flag Blazor Wasm as malware</Description>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version>2.4.0</Version>
<Version>2.4.5</Version>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
</PropertyGroup>

Expand Down

0 comments on commit eb5af43

Please sign in to comment.