diff --git a/Agent.Installer.Win/Models/EmbeddedServerData.cs b/Agent.Installer.Win/Models/EmbeddedServerData.cs index dd096e6d3..e1eaaff46 100644 --- a/Agent.Installer.Win/Models/EmbeddedServerData.cs +++ b/Agent.Installer.Win/Models/EmbeddedServerData.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using System.Runtime.Serialization; namespace Remotely.Agent.Installer.Models; @@ -23,5 +24,5 @@ public EmbeddedServerData(Uri serverUrl, string organizationId) public string OrganizationId { get; set; } = string.Empty; [DataMember] - public Uri ServerUrl { get; set; } + public Uri? ServerUrl { get; set; } } diff --git a/Agent.Installer.Win/Services/EmbeddedServerDataReader.cs b/Agent.Installer.Win/Services/EmbeddedServerDataReader.cs index fd2825aa3..42f55db71 100644 --- a/Agent.Installer.Win/Services/EmbeddedServerDataReader.cs +++ b/Agent.Installer.Win/Services/EmbeddedServerDataReader.cs @@ -1,14 +1,10 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.Serialization.Json; using System.Text; using System.Threading.Tasks; using System.Web.Script.Serialization; using Remotely.Agent.Installer.Models; using Remotely.Agent.Installer.Win.Utilities; -using Remotely.Shared; namespace Remotely.Agent.Installer.Win.Services; @@ -16,7 +12,7 @@ internal class EmbeddedServerDataReader { private readonly JavaScriptSerializer _serializer = new JavaScriptSerializer(); - public Task TryGetEmbeddedData(string filePath) + public async Task TryGetEmbeddedData(string filePath) { try { @@ -25,60 +21,35 @@ public Task TryGetEmbeddedData(string filePath) throw new Exception($"File path does not exist: {filePath}"); } - using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - var result = SearchBuffer(fs, AppConstants.EmbeddedImmySignature); - if (result == -1) - { - throw new Exception("Signature not found in file buffer."); - } + using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); + using var br = new BinaryReader(fs); + using var sr = new StreamReader(fs); - Logger.Write($"Found data signature at index {result}."); + fs.Seek(-4, SeekOrigin.End); + var dataSize = br.ReadInt32(); + fs.Seek(-dataSize - 4, SeekOrigin.End); - fs.Seek(result + AppConstants.EmbeddedImmySignature.Length, SeekOrigin.Begin); - using (var reader = new BinaryReader(fs, Encoding.UTF8)) - { - var serializedData = reader.ReadString(); + if (dataSize == 0) + { + return EmbeddedServerData.Empty; + } - Logger.Write($"Extracted embedded data from EXE: {serializedData}"); + var buffer = new byte[dataSize]; + await fs.ReadAsync(buffer, 0, dataSize); + var json = Encoding.UTF8.GetString(buffer); - var embeddedData = _serializer.Deserialize(serializedData); - if (embeddedData != null) - { - return Task.FromResult(embeddedData); - } - } + Logger.Write($"Extracted embedded data from EXE: {json}"); + + var embeddedData = _serializer.Deserialize(json); + if (embeddedData is not null) + { + return embeddedData; } } catch (Exception ex) { Logger.Write(ex); } - return Task.FromResult(EmbeddedServerData.Empty); - } - - private long SearchBuffer(FileStream fileStream, byte[] matchPattern) - { - var matchSize = matchPattern.Length; - var limit = fileStream.Length - matchSize; - - for (var i = 0; i <= limit; i++) - { - var k = 0; - - for (; k < matchSize; k++) - { - if (matchPattern[k] != fileStream.ReadByte()) - { - break; - } - } - - if (k == matchSize) - { - return fileStream.Position - matchSize; - } - } - return -1; + return EmbeddedServerData.Empty; } } diff --git a/Remotely.sln b/Remotely.sln index 1f64a816f..1c6bb4216 100644 --- a/Remotely.sln +++ b/Remotely.sln @@ -55,14 +55,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Submodules", "Submodules", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Desktop.Shared", "Desktop.Shared\Desktop.Shared.csproj", "{38099844-F6B6-4975-BEC5-D58A547145F0}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docker", "Docker", "{963B5555-30AE-428E-9686-59C4B6FEC052}" - ProjectSection(SolutionItems) = preProject - .docker\Dockerfile = .docker\Dockerfile - .docker\Dockerfile.old = .docker\Dockerfile.old - .docker\Dockerfile.rootless = .docker\Dockerfile.rootless - .docker\DockerMain.sh = .docker\DockerMain.sh - EndProjectSection -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immense.RemoteControl.Desktop.Shared", "submodules\Immense.RemoteControl\Immense.RemoteControl.Desktop.Shared\Immense.RemoteControl.Desktop.Shared.csproj", "{3EB48B01-A672-4658-868B-8CA21FF73929}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immense.RemoteControl.Desktop.Windows", "submodules\Immense.RemoteControl\Immense.RemoteControl.Desktop.Windows\Immense.RemoteControl.Desktop.Windows.csproj", "{7FA4456D-8695-4990-B20A-B897CF9DF0EF}" @@ -79,6 +71,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immense.RemoteControl.Deskt EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose\docker-compose.dcproj", "{90EC49B2-B56A-4ECD-8F63-2162DD140F7C}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pipelines", "pipelines", "{9484AB47-2F99-43DE-9F5D-5B8679B01B3B}" + ProjectSection(SolutionItems) = preProject + .azure-pipelines\Release Build.yml = .azure-pipelines\Release Build.yml + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -301,7 +298,6 @@ Global {48D9D0E6-5781-44A9-84C0-56F56C2A1193} = {0754E195-7080-4AAC-B5A3-A9923B1283CE} {6C25240C-613D-4A86-A04E-784BA6726094} = {0754E195-7080-4AAC-B5A3-A9923B1283CE} {B6C1030D-1F74-4143-BB70-FC79C0274653} = {0754E195-7080-4AAC-B5A3-A9923B1283CE} - {963B5555-30AE-428E-9686-59C4B6FEC052} = {2176596E-12DA-4766-96E1-4D23EA7DBEC8} {3EB48B01-A672-4658-868B-8CA21FF73929} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8} {7FA4456D-8695-4990-B20A-B897CF9DF0EF} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8} {8CBED18D-64A8-44C0-8433-EE14E93B472A} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8} @@ -309,6 +305,7 @@ Global {E4D83C37-8B98-44FB-898B-9AA1BB223C66} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8} {2FF27827-1F43-474E-A0E3-DA76BC598BCC} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8} {3095BA44-D5E0-42B4-9161-7F7AB8E68A10} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8} + {9484AB47-2F99-43DE-9F5D-5B8679B01B3B} = {2176596E-12DA-4766-96E1-4D23EA7DBEC8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {EAE10B28-119B-437C-9E68-06F0EE3F968A} diff --git a/Server/API/ClientDownloadsController.cs b/Server/API/ClientDownloadsController.cs index 6d1dddc9e..1967a4854 100644 --- a/Server/API/ClientDownloadsController.cs +++ b/Server/API/ClientDownloadsController.cs @@ -1,18 +1,12 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Mvc; using Remotely.Server.Auth; using Remotely.Server.Extensions; using Remotely.Server.Services; +using Remotely.Shared.Extensions; using Remotely.Shared.Models; using Remotely.Shared.Services; -using System; -using System.Collections.Generic; -using System.IO; using System.Text; -using System.Threading; -using System.Threading.Tasks; +using FileIO = System.IO.File; namespace Remotely.Server.API; @@ -25,6 +19,7 @@ public class ClientDownloadsController : ControllerBase private readonly SemaphoreSlim _fileLock = new(1, 1); private readonly IWebHostEnvironment _hostEnv; private readonly ILogger _logger; + public ClientDownloadsController( IWebHostEnvironment hostEnv, IEmbeddedServerDataSearcher embeddedDataSearcher, @@ -128,7 +123,7 @@ public async Task GetInstaller(string organizationID, string plat private async Task GetBashInstaller(string fileName, string organizationId) { var fileContents = new List(); - fileContents.AddRange(await System.IO.File.ReadAllLinesAsync(Path.Combine(_hostEnv.WebRootPath, "Content", fileName))); + fileContents.AddRange(await FileIO.ReadAllLinesAsync(Path.Combine(_hostEnv.WebRootPath, "Content", fileName))); var hostIndex = fileContents.IndexOf("HostName="); var orgIndex = fileContents.IndexOf("Organization="); @@ -150,7 +145,7 @@ private async Task GetDesktopFile(string filePath, string? organi var effectiveScheme = settings.ForceClientHttps ? "https" : Request.Scheme; var serverUrl = $"{effectiveScheme}://{Request.Host}"; var embeddedData = new EmbeddedServerData(new Uri(serverUrl), organizationId); - var result = await _embeddedDataSearcher.GetRewrittenStream(filePath, embeddedData); + var result = await _embeddedDataSearcher.GetAppendedStream(filePath, embeddedData); if (!result.IsSuccess) { @@ -177,17 +172,39 @@ private async Task GetInstallFile(string organizationId, string p case "WindowsInstaller": { var effectiveScheme = settings.ForceClientHttps ? "https" : Request.Scheme; - var serverUrl = $"{effectiveScheme}://{Request.Host}"; - var filePath = Path.Combine(_hostEnv.WebRootPath, "Content", "Remotely_Installer.exe"); - var embeddedData = new EmbeddedServerData(new Uri(serverUrl), organizationId); - var result = await _embeddedDataSearcher.GetRewrittenStream(filePath, embeddedData); + //var serverUrl = $"{effectiveScheme}://{Request.Host}"; + //var filePath = Path.Combine(_hostEnv.WebRootPath, "Content", "Remotely_Installer.exe"); + //var embeddedData = new EmbeddedServerData(new Uri(serverUrl), organizationId); + //var result = await _embeddedDataSearcher.GetAppendedStream(filePath, embeddedData); + + //if (!result.IsSuccess) + //{ + // throw result.Exception ?? new Exception(result.Reason); + //} - if (!result.IsSuccess) + + var filePath = Path.Combine(_hostEnv.WebRootPath, "Content", "Install-Remotely.ps1"); + if (!FileIO.Exists(filePath)) { - throw result.Exception ?? new Exception(result.Reason); + return NotFound(); } + + var fileContents = await FileIO.ReadAllLinesAsync(filePath); + var hostIndex = fileContents.IndexWhere(x => + x.Contains("[string]$HostName = $null", StringComparison.OrdinalIgnoreCase)); + var orgIndex = fileContents.IndexWhere(x => + x.Contains("[string]$Organization = $null", StringComparison.OrdinalIgnoreCase)); + + if (hostIndex < 0 || orgIndex < 0) + { + return NotFound(); + } + + fileContents[hostIndex] = $"$HostName = \"{effectiveScheme}://{Request.Host}\""; + fileContents[orgIndex] = $"$Organization = \"{organizationId}\""; + var fileBytes = Encoding.UTF8.GetBytes(string.Join("\n", fileContents)); - return File(result.Value, "application/octet-stream", "Remotely_Installer.exe"); + return File(fileBytes, "application/octet-stream", "Install-Remotely.ps1"); } case "ManjaroInstaller-x64": { diff --git a/Server/wwwroot/Content/Install-Win.ps1 b/Server/wwwroot/Content/Install-Remotely.ps1 similarity index 87% rename from Server/wwwroot/Content/Install-Win.ps1 rename to Server/wwwroot/Content/Install-Remotely.ps1 index 1011e0558..078ea2641 100644 --- a/Server/wwwroot/Content/Install-Win.ps1 +++ b/Server/wwwroot/Content/Install-Remotely.ps1 @@ -4,8 +4,8 @@ .DESCRIPTION Do not modify this script. It was generated specifically for your account. .EXAMPLE - powershell.exe -f Install-Win.ps1 - powershell.exe -f Install-Win.ps1 -DeviceAlias "My Super Computer" -DeviceGroup "My Stuff" + powershell.exe -f Install-Remotely.ps1 + powershell.exe -f Install-Remotely.ps1 -DeviceAlias "My Super Computer" -DeviceGroup "My Stuff" #> param ( @@ -71,7 +71,7 @@ function Stop-Remotely { function Uninstall-Remotely { Stop-Remotely Remove-Item -Path $InstallPath -Force -Recurse -ErrorAction SilentlyContinue - Remove-NetFirewallRule -Name "Remotely ScreenCast" -ErrorAction SilentlyContinue + Remove-NetFirewallRule -Name "Remotely Desktop Unattended" -ErrorAction SilentlyContinue } function Install-Remotely { @@ -118,7 +118,7 @@ function Install-Remotely { } Stop-Remotely - Get-ChildItem -Path "C:\Program Files\Remotely" | Where-Object {$_.Name -notlike "ConnectionInfo.json"} | Remove-Item -Recurse -Force + Get-ChildItem -Path $InstallPath | Where-Object {$_.Name -notlike "ConnectionInfo.json"} | Remove-Item -Recurse -Force Expand-Archive -Path "$env:TEMP\Remotely-Win-$Platform.zip" -DestinationPath "$InstallPath" -Force @@ -127,7 +127,7 @@ function Install-Remotely { if ($DeviceAlias -or $DeviceGroup) { $DeviceSetupOptions = @{ DeviceAlias = $DeviceAlias; - DeviceGroup = $DeviceGroup; + DeviceGroupName = $DeviceGroup; OrganizationID = $Organization; DeviceID = $ConnectionInfo.DeviceID; } @@ -138,8 +138,6 @@ function Install-Remotely { New-Service -Name "Remotely_Service" -BinaryPathName "$InstallPath\Remotely_Agent.exe" -DisplayName "Remotely Service" -StartupType Automatic -Description "Background service that maintains a connection to the Remotely server. The service is used for remote support and maintenance by this computer's administrators." Start-Process -FilePath "cmd.exe" -ArgumentList "/c sc.exe failure `"Remotely_Service`" reset=5 actions=restart/5000" -Wait -WindowStyle Hidden Start-Service -Name Remotely_Service - - New-NetFirewallRule -Name "Remotely Desktop Unattended" -DisplayName "Remotely Desktop Unattended" -Description "The agent that allows screen sharing and remote control for Remotely." -Direction Inbound -Enabled True -Action Allow -Program "C:\Program Files\Remotely\Desktop\Remotely_Desktop.exe" -ErrorAction SilentlyContinue } try { diff --git a/Shared/AppConstants.cs b/Shared/AppConstants.cs index 98a263205..c87f9b9f6 100644 --- a/Shared/AppConstants.cs +++ b/Shared/AppConstants.cs @@ -16,8 +16,4 @@ public class AppConstants public const double ScriptRunExpirationMinutes = 30; public const string ApiKeyHeaderName = "X-Api-Key"; public const string ExpiringTokenHeaderName = "X-Expiring-Token"; - -#pragma warning disable IDE0230 // Use UTF-8 string literal - public static byte[] EmbeddedImmySignature { get; } = new byte[] { 73, 109, 109, 121, 66, 111, 116, 32, 114, 111, 99, 107, 115, 32, 116, 104, 101, 32, 115, 111, 99, 107, 115, 32, 117, 110, 116, 105, 108, 32, 116, 104, 101, 32, 101, 113, 117, 105, 110, 111, 120, 33 }; -#pragma warning restore IDE0230 // Use UTF-8 string literal } diff --git a/Shared/Services/EmbeddedServerDataSearcher.cs b/Shared/Services/EmbeddedServerDataSearcher.cs index db5fb013b..72b948b7b 100644 --- a/Shared/Services/EmbeddedServerDataSearcher.cs +++ b/Shared/Services/EmbeddedServerDataSearcher.cs @@ -1,7 +1,9 @@ #nullable enable using Immense.RemoteControl.Shared; +using MessagePack; using Microsoft.Extensions.Logging; +using Remotely.Shared.Entities; using Remotely.Shared.Models; using Remotely.Shared.Utilities; using System; @@ -17,115 +19,64 @@ namespace Remotely.Shared.Services; public interface IEmbeddedServerDataSearcher { - Task> GetRewrittenStream(string filePath, EmbeddedServerData serverData); + Task> GetAppendedStream(string filePath, EmbeddedServerData serverData); Task> TryGetEmbeddedData(string filePath); } -public class EmbeddedServerDataSearcher : IEmbeddedServerDataSearcher +public class EmbeddedServerDataSearcher() : IEmbeddedServerDataSearcher { public static EmbeddedServerDataSearcher Instance { get; } = new(); - public Task> TryGetEmbeddedData(string filePath) + public async Task> TryGetEmbeddedData(string filePath) { try { if (!File.Exists(filePath)) { - return Task.FromResult(Result.Fail($"File path does not exist: {filePath}")); + return Result.Fail($"File path does not exist: {filePath}"); } using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); - var result = SearchBuffer(fs, AppConstants.EmbeddedImmySignature); - if (result == -1) - { - return Task.FromResult(Result.Fail("Signature not found in file buffer.")); - } + using var br = new BinaryReader(fs); + using var sr = new StreamReader(fs); - fs.Seek(result + AppConstants.EmbeddedImmySignature.Length, SeekOrigin.Begin); + fs.Seek(-4, SeekOrigin.End); + var dataSize = br.ReadInt32(); + fs.Seek(-dataSize - 4, SeekOrigin.End); - using var reader = new BinaryReader(fs, Encoding.UTF8, true); - var serializedData = reader.ReadString(); + var buffer = new byte[dataSize]; + await fs.ReadExactlyAsync(buffer); + var json = Encoding.UTF8.GetString(buffer); - var embeddedData = JsonSerializer.Deserialize(serializedData); + var embeddedData = JsonSerializer.Deserialize(json); if (embeddedData is null) { - return Task.FromResult(Result.Fail("Embedded data is empty.")); + return Result.Fail("Embedded data is empty."); } - return Task.FromResult(Result.Ok(embeddedData)); + return Result.Ok(embeddedData); } catch (Exception ex) { - return Task.FromResult(Result.Fail(ex)); + return Result.Fail(ex); } } - public async Task> GetRewrittenStream(string filePath, EmbeddedServerData serverData) + public Task> GetAppendedStream(string filePath, EmbeddedServerData serverData) { try { - using var dataStream = new MemoryStream(); - using var writer = new BinaryWriter(dataStream, Encoding.UTF8, true); - var serializedData = JsonSerializer.Serialize(serverData); - writer.Write(serializedData); - var dataBytes = dataStream.ToArray(); - - if (dataBytes.Length > AppConstants.EmbeddedDataBlockLength) - { - throw new Exception($"Embedded data size exceeds the maximum of {AppConstants.EmbeddedDataBlockLength}"); - } - + var json = JsonSerializer.Serialize(serverData); + var jsonBytes = Encoding.UTF8.GetBytes(json); + byte[] appendPayload = [.. jsonBytes, .. BitConverter.GetBytes(jsonBytes.Length)]; var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); - - var result = SearchBuffer(fs, AppConstants.EmbeddedImmySignature); - if (result == -1) - { - await fs.DisposeAsync(); - return Result.Fail("Signature not found in file buffer."); - } - - var rewriteMap = new Dictionary(); - var rewriteIndex = result + AppConstants.EmbeddedImmySignature.Length; - - for (var i = 0; i < dataBytes.Length; i++) - { - rewriteMap.TryAdd(rewriteIndex++, dataBytes[i]); - } - - fs.Seek(0, SeekOrigin.Begin); - var rewriteStream = new RewritableStream(fs, rewriteMap); - return Result.Ok(rewriteStream); - + var appendableStream = new AppendableStream(fs, appendPayload); + return Task.FromResult(Result.Ok(appendableStream)); } catch (Exception ex) { - return Result.Fail(ex); - } - } - - private long SearchBuffer(FileStream fileStream, byte[] matchPattern) - { - var matchSize = matchPattern.Length; - var limit = fileStream.Length - matchSize; - - for (var i = 0; i <= limit; i++) - { - var k = 0; - - for (; k < matchSize; k++) - { - if (matchPattern[k] != fileStream.ReadByte()) - { - break; - } - } - - if (k == matchSize) - { - return fileStream.Position - matchSize; - } + return Task.FromResult(Result.Fail(ex)); } - return -1; } } diff --git a/Shared/Utilities/RewritableStream.cs b/Shared/Utilities/RewritableStream.cs deleted file mode 100644 index 9434142f2..000000000 --- a/Shared/Utilities/RewritableStream.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.Buffers; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Remotely.Shared.Utilities; - -public class RewritableStream : Stream -{ - private readonly Stream _underlyingStream; - private readonly Dictionary _rewriteMap; - - public RewritableStream(Stream underlyingStream, Dictionary rewriteMap) - { - _underlyingStream = underlyingStream; - _rewriteMap = rewriteMap; - } - - public override bool CanRead => _underlyingStream.CanRead; - - public override bool CanSeek => _underlyingStream.CanSeek; - - public override bool CanTimeout => _underlyingStream.CanTimeout; - - public override bool CanWrite => _underlyingStream.CanWrite; - - public override long Length => _underlyingStream.Length; - - public override long Position - { - get => _underlyingStream.Position; - set => _underlyingStream.Position = value; - } - - public override int ReadTimeout - { - get => _underlyingStream.ReadTimeout; - set => _underlyingStream.ReadTimeout = value; - } - - public override int WriteTimeout - { - get => _underlyingStream.WriteTimeout; - set => _underlyingStream.WriteTimeout = value; - } - - public override void Close() - { - _underlyingStream.Close(); - base.Close(); - } - - - public override ValueTask DisposeAsync() - { - GC.SuppressFinalize(this); - return _underlyingStream.DisposeAsync(); - } - - public override void Flush() - { - _underlyingStream.Flush(); - } - - - public override int Read(byte[] buffer, int offset, int count) - { - var i = 0; - for (; i < count; i++) - { - if (_rewriteMap.TryGetValue(Position, out var newValue)) - { - buffer[offset + i] = newValue; - Seek(1, SeekOrigin.Current); - } - else - { - var current = _underlyingStream.ReadByte(); - if (current == -1) - { - break; - } - buffer[offset + i] = current == -1 ? (byte)0 : (byte)current; - } - } - return i; - } - - public override long Seek(long offset, SeekOrigin origin) - { - return _underlyingStream.Seek(offset, origin); - } - - public override void SetLength(long value) - { - _underlyingStream.SetLength(value); - } - - public override void Write(byte[] buffer, int offset, int count) - { - _underlyingStream.Write(buffer, offset, count); - } - - protected override void Dispose(bool disposing) - { - _underlyingStream.Dispose(); - base.Dispose(disposing); - } -} diff --git a/Utilities/Publish.ps1 b/Utilities/Publish.ps1 index 480344ddc..3cdc3bb19 100644 --- a/Utilities/Publish.ps1 +++ b/Utilities/Publish.ps1 @@ -69,18 +69,6 @@ function Replace-LineInFile($FilePath, $MatchPattern, $ReplaceLineWith, $MaxCoun ($Content | Out-String).Trim() | Out-File -FilePath $FilePath -Force -Encoding utf8 } -function Add-DataBlock($FilePath) { - [System.Byte[]]$ImmySignature = @(73, 109, 109, 121, 66, 111, 116, 32, 114, 111, 99, 107, 115, 32, 116, 104, 101, 32, 115, 111, 99, 107, 115, 32, 117, 110, 116, 105, 108, 32, 116, 104, 101, 32, 101, 113, 117, 105, 110, 111, 120, 33) - $DataBlock = New-Object System.Byte[] 256 - - $FS = [System.IO.File]::OpenWrite($FilePath) - $FS.Seek(0, [System.IO.SeekOrigin]::End) - - $FS.Write($ImmySignature, 0, $ImmySignature.Length) - $FS.Write($DataBlock, 0, $DataBlock.Length) - $FS.Close() -} - function Wait-ForExists($FilePath) { while ((Test-Path -Path $FilePath) -eq $false){ Write-Host "Waiting for file: $FilePath" @@ -127,7 +115,6 @@ dotnet publish /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion -p:Publ # Publish Linux GUI App dotnet publish /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion -p:PublishProfile=desktop-linux-x64 --configuration Release "$Root\Desktop.Linux\" -Add-DataBlock -FilePath "$Root\Server\wwwroot\Content\Linux-x64\Remotely_Desktop" # Publish Windows ScreenCaster (32-bit) dotnet publish /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion -p:PublishProfile=packaged-win-x86 --configuration Release "$Root\Desktop.Win" @@ -138,7 +125,6 @@ dotnet publish /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion -p:Publ # Publish Windows GUI App (64-bit) dotnet publish /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion -p:PublishProfile=desktop-win-x64 --configuration Release "$Root\Desktop.Win" -Add-DataBlock -FilePath "$Root\Server\wwwroot\Content\Win-x64\Remotely_Desktop.exe" if ($SignAssemblies) { &"$Root\Utilities\signtool.exe" sign /fd SHA256 /f "$CertificatePath" /p $CertificatePassword /t http://timestamp.digicert.com "$Root\Server\wwwroot\Content\Win-x64\Remotely_Desktop.exe" @@ -147,7 +133,6 @@ if ($SignAssemblies) { # Publish Windows GUI App (32-bit) dotnet publish /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion -p:PublishProfile=desktop-win-x86 --configuration Release "$Root\Desktop.Win" -Add-DataBlock -FilePath "$Root\Server\wwwroot\Content\Win-x86\Remotely_Desktop.exe" if ($SignAssemblies) { &"$Root\Utilities\signtool.exe" sign /fd SHA256 /f "$CertificatePath" /p $CertificatePassword /t http://timestamp.digicert.com "$Root\Server\wwwroot\Content\Win-x86\Remotely_Desktop.exe" @@ -157,7 +142,6 @@ if ($SignAssemblies) { &"$MSBuildPath" "$Root\Agent.Installer.Win" /t:Restore &"$MSBuildPath" "$Root\Agent.Installer.Win" /t:Build /p:Configuration=Release /p:Platform=AnyCPU /p:Version=$CurrentVersion /p:FileVersion=$CurrentVersion Copy-Item -Path "$Root\Agent.Installer.Win\bin\Release\Remotely_Installer.exe" -Destination "$Root\Server\wwwroot\Content\Remotely_Installer.exe" -Force -Add-DataBlock -FilePath "$Root\Server\wwwroot\Content\Remotely_Installer.exe" if ($SignAssemblies) { &"$Root\Utilities\signtool.exe" sign /fd SHA256 /f "$CertificatePath" /p $CertificatePassword /t http://timestamp.digicert.com "$Root\Server\wwwroot\Content\Remotely_Installer.exe"