mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add deheader to git
This code is based on the deheader experimental code in the web version. It is very rough but it works for now.
This commit is contained in:
@@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.23107.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DATabase", "DATabase\DATabase.csproj", "{3B615702-1866-4D7B-8AF1-7B43FD0CC1D0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Deheader", "Deheader\Deheader.csproj", "{66339C8A-F331-467C-B311-08A8F7284671}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{3B615702-1866-4D7B-8AF1-7B43FD0CC1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3B615702-1866-4D7B-8AF1-7B43FD0CC1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3B615702-1866-4D7B-8AF1-7B43FD0CC1D0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{66339C8A-F331-467C-B311-08A8F7284671}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{66339C8A-F331-467C-B311-08A8F7284671}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{66339C8A-F331-467C-B311-08A8F7284671}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{66339C8A-F331-467C-B311-08A8F7284671}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
6
Deheader/App.config
Normal file
6
Deheader/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
60
Deheader/Deheader.csproj
Normal file
60
Deheader/Deheader.csproj
Normal file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{66339C8A-F331-467C-B311-08A8F7284671}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Deheader</RootNamespace>
|
||||
<AssemblyName>Deheader</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</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.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
113
Deheader/Program.cs
Normal file
113
Deheader/Program.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Deheader
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static string help = @"Deheader.exe type filename|dirname
|
||||
|
||||
Type can be one of the following:
|
||||
a7800, fds, lynx, nes, snes";
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Type mapped to header size (in decimal bytes)
|
||||
Dictionary<string, int> types = new Dictionary<string, int>();
|
||||
types.Add("a7800", 128);
|
||||
types.Add("fds", 16);
|
||||
types.Add("lynx", 64);
|
||||
types.Add("nes", 16);
|
||||
types.Add("snes", 512);
|
||||
|
||||
if (args.Length != 2 || !types.ContainsKey(args[0]))
|
||||
{
|
||||
Console.WriteLine(help);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get type of file and the filename (or foldername) itself
|
||||
string type = args[0];
|
||||
string file = args[1];
|
||||
int hs = types[type];
|
||||
|
||||
// If it's a single file, just check it
|
||||
if (File.Exists(file))
|
||||
{
|
||||
DetectRemoveHeader(type, file, hs);
|
||||
}
|
||||
// If it's a directory, recursively check all
|
||||
else if (Directory.Exists(file))
|
||||
{
|
||||
foreach (string sub in Directory.GetFiles(file))
|
||||
{
|
||||
if (sub != ".." && sub != ".")
|
||||
{
|
||||
DetectRemoveHeader(type, sub, hs);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Else, show that help text
|
||||
else
|
||||
{
|
||||
Console.WriteLine(help);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DetectRemoveHeader(string type, string file, int hs)
|
||||
{
|
||||
// Open the file in read mode
|
||||
BinaryReader br = new BinaryReader(File.OpenRead(file));
|
||||
|
||||
// Extract the header from the file
|
||||
byte[] hbin = br.ReadBytes(hs);
|
||||
string header = BitConverter.ToString(hbin).Replace("-", string.Empty);
|
||||
|
||||
Console.WriteLine("Possible header: " + header);
|
||||
|
||||
// Deal with each possible type
|
||||
bool hasHeader = false;
|
||||
switch (type)
|
||||
{
|
||||
case "a7800":
|
||||
bool a7800a = Regex.IsMatch(header, "^.415441524937383030");
|
||||
bool a7800b = Regex.IsMatch(header, "^.{64}41435455414C20434152542044415441205354415254532048455245");
|
||||
hasHeader = a7800a || a7800b;
|
||||
break;
|
||||
case "fds":
|
||||
hasHeader = Regex.IsMatch(header, "^4644531A0[1-4]0000000000000000000000");
|
||||
break;
|
||||
case "lynx":
|
||||
bool lynxa = Regex.IsMatch(header, "^4C594E58");
|
||||
bool lynxb = Regex.IsMatch(header, "^425339");
|
||||
hasHeader = lynxa || lynxb;
|
||||
break;
|
||||
case "nes":
|
||||
hasHeader = Regex.IsMatch(header, "^4E45531A");
|
||||
break;
|
||||
case "snes":
|
||||
bool fig = Regex.IsMatch(header, "^.{16}0000000000000000");
|
||||
bool smc = Regex.IsMatch(header, "^.{16}AABB040000000000");
|
||||
bool ufo = Regex.IsMatch(header, "^.{16}535550455255464F");
|
||||
hasHeader = fig || smc || ufo;
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine("File has header: " + hasHeader);
|
||||
|
||||
if (hasHeader)
|
||||
{
|
||||
Console.WriteLine("Creating unheadered file: " + file + ".new");
|
||||
BinaryWriter bw = new BinaryWriter(File.OpenWrite(file + ".new"));
|
||||
FileInfo fi = new FileInfo(file);
|
||||
bw.Write(br.ReadBytes((int)fi.Length - hs));
|
||||
bw.Close();
|
||||
Console.WriteLine("Unheadered file created!");
|
||||
}
|
||||
|
||||
br.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Deheader/Properties/AssemblyInfo.cs
Normal file
36
Deheader/Properties/AssemblyInfo.cs
Normal 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("Deheader")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Deheader")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[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("66339c8a-f331-467c-b311-08a8f7284671")]
|
||||
|
||||
// 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")]
|
||||
Reference in New Issue
Block a user