-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rewriting of the __LINKEDIT section.
There was an incorrect assumption that __LINKEDIT section can only change when contents of MachLinkEditData change. However, that's not the only case when that can happen. It also changes when load commands are added or removed. Added basic test for code signing an a.out file to ensure that it does not regress.
- Loading branch information
1 parent
5278c2c
commit 27b5e9c
Showing
8 changed files
with
136 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dotnet-test-explorer.testProjectPath": "**/*Tests.@(csproj|vbproj|fsproj)" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Xunit; | ||
using System.IO; | ||
using System.Linq; | ||
using Melanzana.CodeSign.Requirements; | ||
using Melanzana.MachO; | ||
using Melanzana.Streams; | ||
|
||
namespace Melanzana.CodeSign.Tests | ||
{ | ||
public class ResignTest | ||
{ | ||
[Fact] | ||
public void Resign() | ||
{ | ||
// Read the test executable | ||
var aOutStream = typeof(ResignTest).Assembly.GetManifestResourceStream("Melanzana.CodeSign.Tests.Data.a.out")!; | ||
var objectFile = MachReader.Read(aOutStream).FirstOrDefault(); | ||
Assert.NotNull(objectFile); | ||
|
||
// Strip the signature | ||
var codeSignature = objectFile!.LoadCommands.OfType<MachCodeSignature>().FirstOrDefault(); | ||
Assert.NotNull(codeSignature); | ||
var originalSignatureSize = codeSignature!.FileSize; | ||
objectFile!.LoadCommands.Remove(codeSignature); | ||
|
||
// Write the stripped file to disk | ||
var tempFileName = Path.GetTempFileName(); | ||
using (var tempFile = new FileStream(tempFileName, FileMode.Create)) | ||
{ | ||
MachWriter.Write(tempFile, objectFile); | ||
Assert.Equal(aOutStream.Length - originalSignatureSize, tempFile.Length); | ||
} | ||
|
||
// Ad-hoc sign the file | ||
var codeSignOptions = new CodeSignOptions { }; | ||
var signer = new Signer(codeSignOptions); | ||
signer.Sign(tempFileName); | ||
|
||
// TODO: Check signature | ||
|
||
File.Delete(tempFileName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters