Skip to content

Commit

Permalink
[LibExtractTask] Fix debug information section linked when `StripDebu…
Browse files Browse the repository at this point in the history
…gInfo` specified, and skip up-to-date items
  • Loading branch information
RatinCN committed Jan 12, 2024
1 parent 7f2b35c commit bcd73a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Source/3rdParty/C4Lib
25 changes: 24 additions & 1 deletion Source/Tasks/LibExtractTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,20 @@ public override Boolean Execute()
{
try
{
DateTime TempTime, LastWriteTime;

LastWriteTime = new FileInfo(Source).LastWriteTime;
TempTime = new FileInfo(BuildEngine.ProjectFileOfTaskNode).LastWriteTime;
if (LastWriteTime < TempTime)
{
LastWriteTime = TempTime;
}

XmlDocument doc = new();
doc.Load(Source);

Log.LogMessage(MessageImportance.High, "Project: " + BuildEngine.ProjectFileOfTaskNode);

if (doc.DocumentElement == null)
{
throw new InvalidDataException("Invalid XML file: " + Source);
Expand Down Expand Up @@ -74,6 +85,10 @@ public override Boolean Execute()
throw new FileNotFoundException("Multiple " + LibName + " found in specified directories");
}

if (LastWriteTime < Libs[0].LastWriteTime)
{
LastWriteTime = Libs[0].LastWriteTime;
}
Byte[] LibData = File.ReadAllBytes(Libs[0].FullName);
ArchiveFile Ar = new(LibData);
DirectoryInfo OutputLibDirectoryInfo = Directory.CreateDirectory(OutputDirectory + Path.DirectorySeparatorChar + Libs[0].Name);
Expand Down Expand Up @@ -102,8 +117,15 @@ public override Boolean Execute()
String OutputObjectFilePath = OutputLibDirectoryInfo.FullName +
Path.DirectorySeparatorChar +
Path.GetFileName(ExtractImport.Name);
Byte[] ObjectData = ExtractImport.Data;
FileInfo OutputObject = new(OutputObjectFilePath);
if (OutputObject.Exists && OutputObject.LastWriteTime > LastWriteTime)
{
ExtractedObjectFiles.Add(OutputObjectFilePath);
Log.LogMessage(MessageImportance.High, "\t-> " + OutputObjectFilePath + " is up-to-date");
continue;
}

Byte[] ObjectData = ExtractImport.Data;
if (StripDebugInfo)
{
IMAGE_FILE_HEADER FileHeader = Rtl.RawToStruct<IMAGE_FILE_HEADER>(Rtl.ArrayResize(ObjectData, Marshal.SizeOf<IMAGE_FILE_HEADER>()));
Expand All @@ -119,6 +141,7 @@ public override Boolean Execute()
if (SectionHeader.Name.SequenceEqual(".debug$T"u8.ToArray()))
{
SectionHeader.Name = [0, 0, 0, 0, 0, 0, 0, 0];
SectionHeader.Characteristics |= (UInt32)IMAGE_SCN.LNK_REMOVE;
Rtl.StructToRaw(SectionHeader).CopyTo(ObjectData, SectionHeaderIndex);
}
SectionHeaderIndex += Marshal.SizeOf<IMAGE_SECTION_HEADER>();
Expand Down

0 comments on commit bcd73a9

Please sign in to comment.