Add files via upload

This commit is contained in:
Sora 2023-01-02 17:50:15 +08:00 committed by GitHub
parent 2befbc037b
commit 303d99ba00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 165 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D114E96D-3EF0-4F82-83E9-E604A30980A2}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ChangeTimestamp</RootNamespace>
<AssemblyName>ChangeTimestamp</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -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);
}
}
}

View File

@ -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")]