From 303d99ba00d158da9bb37398365fb053c82f7e97 Mon Sep 17 00:00:00 2001 From: Sora <45709238+sorabug@users.noreply.github.com> Date: Mon, 2 Jan 2023 17:50:15 +0800 Subject: [PATCH] Add files via upload --- ChangeTimestamp/ChangeTimestamp.sln | 25 +++++++++ .../ChangeTimestamp/ChangeTimestamp.csproj | 49 +++++++++++++++++ ChangeTimestamp/ChangeTimestamp/Program.cs | 55 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 ChangeTimestamp/ChangeTimestamp.sln create mode 100644 ChangeTimestamp/ChangeTimestamp/ChangeTimestamp.csproj create mode 100644 ChangeTimestamp/ChangeTimestamp/Program.cs create mode 100644 ChangeTimestamp/ChangeTimestamp/Properties/AssemblyInfo.cs diff --git a/ChangeTimestamp/ChangeTimestamp.sln b/ChangeTimestamp/ChangeTimestamp.sln new file mode 100644 index 0000000..674c0b8 --- /dev/null +++ b/ChangeTimestamp/ChangeTimestamp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33027.164 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChangeTimestamp", "ChangeTimestamp\ChangeTimestamp.csproj", "{D114E96D-3EF0-4F82-83E9-E604A30980A2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D114E96D-3EF0-4F82-83E9-E604A30980A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D114E96D-3EF0-4F82-83E9-E604A30980A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D114E96D-3EF0-4F82-83E9-E604A30980A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D114E96D-3EF0-4F82-83E9-E604A30980A2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F69342B7-C2CD-48B2-840A-4151A5F34B94} + EndGlobalSection +EndGlobal diff --git a/ChangeTimestamp/ChangeTimestamp/ChangeTimestamp.csproj b/ChangeTimestamp/ChangeTimestamp/ChangeTimestamp.csproj new file mode 100644 index 0000000..7d55363 --- /dev/null +++ b/ChangeTimestamp/ChangeTimestamp/ChangeTimestamp.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + {D114E96D-3EF0-4F82-83E9-E604A30980A2} + Exe + ChangeTimestamp + ChangeTimestamp + v4.0 + 512 + true + + + AnyCPU + false + none + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + Auto + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ChangeTimestamp/ChangeTimestamp/Program.cs b/ChangeTimestamp/ChangeTimestamp/Program.cs new file mode 100644 index 0000000..fb9649f --- /dev/null +++ b/ChangeTimestamp/ChangeTimestamp/Program.cs @@ -0,0 +1,55 @@ +using System; +using System.IO; + +namespace ChangeTimestamp +{ + class Program + { + static void Main(string[] args) + { + if (args.Length < 2) + { + Console.WriteLine("Usage: ChangeTimestamp filepath timestamp"); + return; + } + + string filePath = args[0]; + DateTime timestamp = DateTime.Parse(args[1] + " " + args[2]); + + byte[] fileData; + using (FileStream stream = File.OpenRead(filePath)) + { + fileData = new byte[stream.Length]; + stream.Read(fileData, 0, fileData.Length); + } + + int peHeaderOffset = BitConverter.ToInt32(fileData, 0x3C); + int timestampOffset = peHeaderOffset + 8; + int timestampValue = (int)(timestamp.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalSeconds; + byte[] timestampBytes = BitConverter.GetBytes(timestampValue); + + fileData[timestampOffset + 0] = timestampBytes[0]; + fileData[timestampOffset + 1] = timestampBytes[1]; + fileData[timestampOffset + 2] = timestampBytes[2]; + fileData[timestampOffset + 3] = timestampBytes[3]; + + using (FileStream stream = File.OpenWrite(filePath)) + { + stream.Write(fileData, 0, fileData.Length); + } + File.SetCreationTime(filePath, timestamp); + File.SetLastWriteTime(filePath, timestamp); + File.SetLastAccessTime(filePath, timestamp); + + DateTime creationTime = File.GetCreationTime(filePath); + DateTime lastWriteTime = File.GetLastWriteTime(filePath); + DateTime lastAccessTime = File.GetLastAccessTime(filePath); + + Console.WriteLine("Change file timestamp successfully."); + Console.WriteLine("Compilation time: " + timestamp); + Console.WriteLine("Creation time: " + creationTime); + Console.WriteLine("Last write time: " + lastWriteTime); + Console.WriteLine("Last access time: " + lastAccessTime); + } + } +} \ No newline at end of file diff --git a/ChangeTimestamp/ChangeTimestamp/Properties/AssemblyInfo.cs b/ChangeTimestamp/ChangeTimestamp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0ceabe6 --- /dev/null +++ b/ChangeTimestamp/ChangeTimestamp/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ChangeTimestamp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ChangeTimestamp")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d114e96d-3ef0-4f82-83e9-e604a30980a2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]