Skip to content

Commit

Permalink
Merge pull request #33 from stavroskasidis/release/1.9.0
Browse files Browse the repository at this point in the history
Release/1.9.0
  • Loading branch information
stavroskasidis authored Nov 7, 2022
2 parents 4a6acb8 + a69c846 commit 7845412
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 20 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ 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>1.8.5</summary>
<details open="open"><summary>1.9.0</summary>

>- Changed "blazor.boot.json.gz" and "blazor.boot.json.br" to be recompressed instead of deleted. (Contribution by [jsakamoto](https://github.com/jsakamoto))
</details>
<details><summary>1.8.5</summary>

>- Changed default Xor key to be smaller so that the resulting obfuscated dlls are more compression friendly.
</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.8.5-beta" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.9.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.1" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.8.5-beta" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.9.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.8" PrivateAssets="all" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.8.0" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.9.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.8.0" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.9.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.2" PrivateAssets="all" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.8.0-beta" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.9.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.2" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.8.0-beta" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="1.9.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

Expand Down
47 changes: 41 additions & 6 deletions src/BlazorWasmAntivirusProtection.Tasks/RenameDlls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class RenameDlls : Task

public string RenameDllsTo { get; set; } = "bin";
public bool DisableRenamingDlls { get; set; }
public bool BlazorEnableCompression { get; set; } = true;
public string CompressionLevel { get; set; }

public override bool Execute()
{
Expand Down Expand Up @@ -75,15 +77,15 @@ public override bool Execute()
File.WriteAllText(serviceWorkerPathAssets, serviceWorkerAssets);
}

if (File.Exists(bootJsonGzPath))
if (File.Exists(bootJsonGzPath) && BlazorEnableCompression)
{
Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Deleting \"{bootJsonGzPath}\"");
File.Delete(bootJsonGzPath);
Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Recompressing \"{bootJsonGzPath}\"");
GZipCompress(bootJsonPath, bootJsonGzPath);
}
if (File.Exists(bootJsonBrPath))
if (File.Exists(bootJsonBrPath) && BlazorEnableCompression)
{
Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Deleting \"{bootJsonBrPath}\"");
File.Delete(bootJsonBrPath);
Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Recompressing \"{bootJsonBrPath}\"");
BrotliCompress(bootJsonPath, bootJsonBrPath);
}
}

Expand All @@ -92,6 +94,39 @@ public override bool Execute()
return true;
}

private void GZipCompress(string bootJsonPath, string bootJsonGzPath)
{
try
{
File.Delete(bootJsonGzPath);
using var fileStream = File.OpenRead(bootJsonPath);
using var stream = File.Create(bootJsonGzPath);
using var destination = new GZipStream(stream, System.IO.Compression.CompressionLevel.Optimal);
fileStream.CopyTo(destination);
}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
}
}

private void BrotliCompress(string bootJsonPath, string bootJsonBrPath)
{
try
{
File.Delete(bootJsonBrPath);
var compressionLevel = Enum.TryParse<CompressionLevel>(CompressionLevel, out var level) ? level : System.IO.Compression.CompressionLevel.Optimal;
using var fileStream = File.OpenRead(bootJsonPath);
using var stream = File.Create(bootJsonBrPath);
using var destination = new BrotliStream(stream, compressionLevel);
fileStream.CopyTo(destination);
}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
}
}

string ComputeSha256Hash(string rawData)
{
using var sha256Hash = SHA256.Create();
Expand Down
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>1.8.5</Version>
<Version>1.9.0</Version>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<!-- Runs in the published project (server if hosted)-->
<Target Name="_ChangeDLLFileExtensions" AfterTargets="Publish">
<RenameDlls PublishDir="$(PublishDir)" RenameDllsTo="$(RenameDllsTo)" DisableRenamingDlls="$(DisableRenamingDlls)"></RenameDlls>
<RenameDlls PublishDir="$(PublishDir)" RenameDllsTo="$(RenameDllsTo)" DisableRenamingDlls="$(DisableRenamingDlls)" BlazorEnableCompression="$(BlazorEnableCompression)" CompressionLevel="$(_BlazorBrotliCompressionLevel)"></RenameDlls>
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function beforeStart(wasmOptions, extensions) {

}
} catch (error) {
console.log(error);
console.error(error);
}
}

Expand All @@ -63,11 +63,11 @@ async function unobfuscateResponse(response, settings, type, name) {
var data = new Uint8Array(buffer);
if (type == "assembly") {
if (settings.obfuscationMode == 1) {//Changed Headers
console.log("Restoring binary header: " + name);
console.debug("Restoring binary header: " + name);
data[0] = 77; //This restores header from BZ to MZ
}
else if (settings.obfuscationMode == 2) { //Xored dll
console.log("Restoring binary file Xor: " + name);
console.debug("Restoring binary file Xor: " + name);
var key = settings.xorKey;
for (let i = 0; i < data.length; i++)
data[i] = data[i] ^ key.charCodeAt(i % key.length); //This reverses the Xor'ing of the dll
Expand Down

0 comments on commit 7845412

Please sign in to comment.