Skip to content
Permalink
Browse files

FirmwareImage.ps1: explicitly close output files ...

or they will get flushed and closed only during garbage collection and
this is much too late, if they have to be reused within the same PS
session.

The changes avoid the needs of an additional 'exit' command as mentioned
here:

https://www.ip-forum.eu/howto-fritz-box-firmware-images-auch-unsignierte-ueber-den-bootloader-installieren-577?view-post=3859#p3859
  • Loading branch information...
PeterPawn committed Dec 1, 2018
1 parent e539f67 commit 0601e619311d8bb2cca6e4cd0812e4f019769166
Showing with 21 additions and 7 deletions.
  1. +21 −7 signimage/FirmwareImage.ps1
@@ -1284,7 +1284,9 @@ Class TarFile
# write the data stream of the specified member to $outputName
[void] extractMember([TarMember] $member, [string] $outputName)
{
$member.data.WriteTo([System.IO.File]::Create($outputName));
[System.IO.FileStream] $file = [System.IO.File]::Create($outputName);
$member.data.WriteTo($file);
$file.Close();
}

# search the members collection for an entry with name exactly $memberName (no wildcards)
@@ -2070,7 +2072,9 @@ Class SigningKey
# save the stream from 'toDERStream' to file $outputFileName
[void] toDERFile([bool] $withPrivateData, [string] $outputFileName)
{
$this.toDERStream($withPrivateData).WriteTo([System.IO.File]::Create($outputFileName));
[System.IO.FileStream] $file = [System.IO.File]::Create($outputFileName);
$this.toDERStream($withPrivateData).WriteTo($file);
$file.Close();
}

# get an array containing the public key parts in PEM format
@@ -2102,7 +2106,9 @@ Class SigningKey
# save stream from 'toRSAPublicKeyStream' to file $outputFileName
[void] toRSAPublicKeyFile([string] $outputFileName)
{
$this.toRSAPublicKeyStream().WriteTo([System.IO.File]::Create($outputFileName));
[System.IO.FileStream] $file = [System.IO.File]::Create($outputFileName);
$this.toRSAPublicKeyStream().WriteTo($file);
$file.Close();
}

# get an array containing the private key in PEM format, optionally encrypted and with
@@ -2163,7 +2169,9 @@ Class SigningKey
# save the outcome of 'toRSAPrivateKeyStream' to file $outputFileName
[void] toRSAPrivateKeyFile([string] $outputFileName, [string] $keyPassword)
{
$this.toRSAPrivateKeyStream($keyPassword).WriteTo([System.IO.File]::Create($outputFileName));
[System.IO.FileStream] $file = [System.IO.File]::Create($outputFileName);
$this.toRSAPrivateKeyStream($keyPassword).WriteTo($file);
$file.Close();
}

# read a text file containing modulus and exponent as hexadecimal string (AVM's public key file format)
@@ -2569,7 +2577,9 @@ Class FirmwareImage : TarFile
# get the specified member data after removing the TI checksum, if any - save data to $outputName
[void] extractMemberAndRemoveChecksum([TarMember] $member, [string] $outputName)
{
$this.extractMemberAndRemoveChecksum($member).WriteTo([System.IO.File]::Create($outputName));
[System.IO.FileStream] $file = [System.IO.File]::Create($outputName);
$this.extractMemberAndRemoveChecksum($member).WriteTo($file);
$file.Close();
}

# get the image to start from RAM of a FRITZ!Box device
@@ -2593,7 +2603,9 @@ Class FirmwareImage : TarFile
# store the bootable image to a file
[void] getBootableImage([string] $outputName)
{
$this.getBootableImage().WriteTo([System.IO.File]::Create($outputName));
[System.IO.FileStream] $file = [System.IO.File]::Create($outputName);
$this.getBootableImage().WriteTo($file);
$file.Close();
}

# verify the current signature with the specified public key, which was loaded from somewhere else
@@ -2699,7 +2711,9 @@ Class FirmwareImage : TarFile
[void] addSignature([SigningKey] $key, [string] $outputFileName)
{
$this.addSignature($key);
$this.contentStream().WriteTo([System.IO.File]::Create($outputFileName));
[System.IO.FileStream] $file = [System.IO.File]::Create($outputFileName);
$this.contentStream().WriteTo($file);
$file.Close();
}

# add a new signature to the whole image data, replaces any existing signature or creates a new one

0 comments on commit 0601e61

Please sign in to comment.
You can’t perform that action at this time.