Skip to content

Commit

Permalink
clean up a couple of old cmf handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ZingBallyhoo committed Oct 26, 2023
1 parent a3700ac commit 52a68a2
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_36859.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public byte[] IV(CMFHeader header, byte[] digest, int length) {
0x20, 0x6C, 0xA4, 0xF0, 0xDE, 0xC4, 0x8C, 0x1F, 0xD2, 0xBA, 0x63, 0x77, 0xDD, 0x2C, 0xE2, 0xBD,
0xC9, 0x19, 0x9F, 0x00, 0x41, 0xC5, 0xCF, 0x39, 0x93, 0x13, 0x74, 0x93, 0xE4, 0xAA, 0xEF, 0xC2,
0xDE, 0x74, 0xE3, 0xA5, 0x5E, 0xAB, 0x44, 0x73, 0x9B, 0x46, 0xD5, 0x49, 0xE6, 0xBD, 0xB4, 0x95,
0xF9, 0xF3, 0x64, 0x75, 0x81, 0x0F, 0x22, 0xC5, 0x8A, 0x86, 0xFE, 0xC3, 0x78, 0x4B, 0x74, 0x4B
0xF9, 0xF3, 0x64, 0x75, 0x81, 0x0F, 0x22, 0xC5, 0x8A, 0x86, 0xFE, 0xC3, 0x78, 0x4B, 0x74, 0x4B
};
}
}
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_37275.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public byte[] IV(CMFHeader header, byte[] digest, int length) {
for (int i = 0; i != length; ++i) {
buffer[i] = Keytable[kidx % 512];
kidx += increment;
buffer[i] ^= digest[(kidx + 0x14666D63) % SHA1_DIGESTSIZE];
buffer[i] ^= digest[(kidx + header.GetNonEncryptedMagic()) % SHA1_DIGESTSIZE];
}

return buffer;
Expand Down
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_37734.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using static TACTLib.Core.Product.Tank.ContentManifestFile;

namespace TACTLib.Core.Product.Tank.CMF {
[ManifestCrypto(AutoDetectVersion = true, BuildVersions = new uint[] {37679}, Product = TACTProduct.Overwatch)]
[ManifestCrypto(AutoDetectVersion = true, Product = TACTProduct.Overwatch)]
public class ProCMF_37734 : ICMFEncryptionProc {
public byte[] Key(CMFHeader header, int length) {
byte[] buffer = new byte[length];
Expand Down
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_38044.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using static TACTLib.Core.Product.Tank.ContentManifestFile;

namespace TACTLib.Core.Product.Tank.CMF {
[ManifestCrypto(AutoDetectVersion = true, BuildVersions = new uint[] {38024}, Product = TACTProduct.Overwatch)]
[ManifestCrypto(AutoDetectVersion = true, Product = TACTProduct.Overwatch)]
public class ProCMF_38044 : ICMFEncryptionProc {
public byte[] Key(CMFHeader header, int length) {
byte[] buffer = new byte[length];
Expand Down
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_42665.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public byte[] IV(CMFHeader header, byte[] digest, int length) {
for (int i = 0; i != length; ++i) {
buffer[i] = Keytable[SignedMod(kidx, 512)];
kidx += increment;
buffer[i] ^= digest[SignedMod(kidx + 0x15666D63, SHA1_DIGESTSIZE)];
buffer[i] ^= digest[SignedMod(kidx + header.GetNonEncryptedMagic(), SHA1_DIGESTSIZE)];
}

return buffer;
Expand Down
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_43435.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public byte[] IV(CMFHeader header, byte[] digest, int length) {
for (int i = 0; i != length; ++i) {
buffer[i] = Keytable[SignedMod(kidx, 512)];
kidx += increment;
buffer[i] ^= digest[SignedMod(kidx + 0x15666D63, SHA1_DIGESTSIZE)];
buffer[i] ^= digest[SignedMod(kidx + header.GetNonEncryptedMagic(), SHA1_DIGESTSIZE)];
}

return buffer;
Expand Down
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_46510.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using static TACTLib.Core.Product.Tank.ContentManifestFile;

namespace TACTLib.Core.Product.Tank.CMF {
[ManifestCrypto(AutoDetectVersion = true, BuildVersions = new uint[] { 46457 }, Product = TACTProduct.Overwatch)]
[ManifestCrypto(AutoDetectVersion = true, Product = TACTProduct.Overwatch)]
public class ProCMF_46510 : ICMFEncryptionProc {
public byte[] Key(CMFHeader header, int length) {
byte[] buffer = new byte[length];
Expand Down
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_46823.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public byte[] IV(CMFHeader header, byte[] digest, int length) {
{
buffer[i] = Keytable[SignedMod(kidx, 512)];
kidx += increment;
buffer[i] ^= digest[SignedMod(kidx + 0x16666D63 , SHA1_DIGESTSIZE)];
buffer[i] ^= digest[SignedMod(kidx + header.GetNonEncryptedMagic() , SHA1_DIGESTSIZE)];
}

return buffer;
Expand Down
2 changes: 1 addition & 1 deletion TACTLib/Core/Product/Tank/CMF/ProCMF_51575.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public byte[] IV(CMFHeader header, byte[] digest, int length)
{
buffer[i] = Keytable[SignedMod(kidx, 512)];
kidx += increment;
buffer[i] ^= digest[SignedMod(kidx + 0x16666D63, SHA1_DIGESTSIZE)];
buffer[i] ^= digest[SignedMod(kidx + header.GetNonEncryptedMagic(), SHA1_DIGESTSIZE)];
}

return buffer;
Expand Down
9 changes: 1 addition & 8 deletions TACTLib/Core/Product/Tank/ManifestCryptoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void GenerateKeyIV<T>(string name, string manifestType, T header,

Logger.Warn("Manifest", $"No {manifestType} procedure for build {buildVersion}, trying closest version");
try {
var pair = providerVersions.Where(it => it.Key < buildVersion).OrderByDescending(it => it.Key).First();
var pair = providerVersions.Where(it => it.Key < buildVersion).MaxBy(it => it.Key);
Logger.Info("Manifest", $"Using {manifestType} procedure {pair.Key}");
providerRaw = pair.Value;
} catch {
Expand Down Expand Up @@ -146,12 +146,6 @@ public static void AddProvidersFromAssembly<T>(Assembly asm) {
if (metadata.AutoDetectVersion) {
AddProvider(metadata.Product, typeof(T), provider, uint.Parse(tt.Name.Split('_')[1]));
}

if (metadata.BuildVersions != null) {
foreach (var buildVersion in metadata.BuildVersions) {
AddProvider(metadata.Product, typeof(T), provider, buildVersion);
}
}
}
}

Expand All @@ -166,7 +160,6 @@ private static void FindProviders() {
public class ManifestCryptoAttribute : Attribute {
public bool AutoDetectVersion = true;
public TACTProduct Product = TACTProduct.Overwatch;
public uint[]? BuildVersions = Array.Empty<uint>();
}
}
}
14 changes: 14 additions & 0 deletions TACTLib/Helpers/SpanHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@ public static Span<byte> Advance(ref Span<byte> input, int numBytes)

return result;
}

public static ReadOnlySpan<byte> Advance(ref ReadOnlySpan<byte> input, int numBytes)
{
var result = input.Slice(0, numBytes);
input = input.Slice(numBytes);

return result;
}

public static unsafe ref T ReadStruct<T>(ref Span<byte> input) where T : unmanaged
{
ref var result = ref MemoryMarshal.AsRef<T>(input);
input = input.Slice(sizeof(T));
return ref result;
}

public static unsafe ReadOnlySpan<T> ReadArray<T>(ref ReadOnlySpan<byte> input, int count) where T : unmanaged
{
var resultBytes = Advance(ref input, sizeof(T) * count);
return MemoryMarshal.Cast<byte, T>(resultBytes);
}

public static byte ReadByte(ref Span<byte> input)
{
Expand Down

0 comments on commit 52a68a2

Please sign in to comment.