More tweaks after pen-testing.

This commit is contained in:
CloneTrooper1019 2020-08-20 02:03:05 -05:00
parent f4899b4ce6
commit 2ff5d82218
7 changed files with 31 additions and 21 deletions

View File

@ -6,6 +6,7 @@ using System.Text;
using RobloxFiles.Enums;
using RobloxFiles.DataTypes;
using System.Diagnostics;
namespace RobloxFiles.BinaryFormat.Chunks
{
@ -571,7 +572,6 @@ namespace RobloxFiles.BinaryFormat.Chunks
else if (prop.Type != Type)
throw new Exception($"Property {Name} is not using the correct type in {instance.GetFullName()}!");
prop.CurrentWriter = writer;
props.Add(prop);
}
@ -628,7 +628,12 @@ namespace RobloxFiles.BinaryFormat.Chunks
writer.WriteFloats(floats);
break;
case PropertyType.Double:
props.ForEach(prop => prop.WriteValue<double>());
props.ForEach(prop =>
{
double value = prop.CastValue<double>();
writer.Write(BinaryRobloxFileWriter.GetBytes(value));
});
break;
case PropertyType.UDim:
var UDim_Scales = new List<float>();
@ -689,7 +694,12 @@ namespace RobloxFiles.BinaryFormat.Chunks
break;
case PropertyType.Faces:
case PropertyType.Axes:
props.ForEach(prop => prop.WriteValue<byte>());
props.ForEach(prop =>
{
byte value = prop.CastValue<byte>();
writer.Write(value);
});
break;
case PropertyType.BrickColor:
var BrickColorIds = new List<int>();
@ -1003,6 +1013,13 @@ namespace RobloxFiles.BinaryFormat.Chunks
props.ForEach(prop =>
{
var shared = prop.CastValue<SharedString>();
if (shared == null)
{
byte[] empty = Array.Empty<byte>();
shared = SharedString.FromBuffer(empty);
}
string key = shared.Key;
if (!sstr.Lookup.ContainsKey(key))

View File

@ -1,6 +1,7 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections.Concurrent;
using Konscious.Security.Cryptography;
namespace RobloxFiles.DataTypes
@ -15,7 +16,7 @@ namespace RobloxFiles.DataTypes
public class SharedString
{
private static Dictionary<string, byte[]> Lookup = new Dictionary<string, byte[]>();
private static ConcurrentDictionary<string, byte[]> Lookup = new ConcurrentDictionary<string, byte[]>();
public string Key { get; internal set; }
public string ComputedKey { get; internal set; }
@ -29,12 +30,15 @@ namespace RobloxFiles.DataTypes
internal static void Register(string key, byte[] buffer)
{
Lookup.Add(key, buffer);
if (Lookup.ContainsKey(key))
return;
Lookup.TryAdd(key, buffer);
}
private SharedString(byte[] buffer)
{
using (HMACBlake2B blake2B = new HMACBlake2B(16 * 8))
using (var blake2B = new HMACBlake2B(16 * 8))
{
byte[] hash = blake2B.ComputeHash(buffer);
ComputedKey = Convert.ToBase64String(hash);

View File

@ -2252,7 +2252,7 @@ namespace RobloxFiles
public ModelLevelOfDetail LevelOfDetail = ModelLevelOfDetail.Automatic;
public CFrame ModelInPrimary = new CFrame();
public CFrame ModelMeshCFrame = new CFrame();
public byte[] ModelMeshData = Array.Empty<byte>();
public SharedString ModelMeshData;
public Vector3 ModelMeshSize = new Vector3();
public BasePart PrimaryPart;
}

View File

@ -42,6 +42,7 @@ namespace RobloxFiles
}
}
string lead = Encoding.UTF8.GetString(buffer, 0, 100);
throw new Exception("Unrecognized header!");
}

View File

@ -48,6 +48,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>1</WarningLevel>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup>
<StartupObject />

Binary file not shown.

View File

@ -56,10 +56,8 @@ namespace RobloxFiles
public byte[] RawBuffer { get; internal set; }
internal object RawValue;
internal BinaryRobloxFileWriter CurrentWriter;
internal static BindingFlags BindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase;
internal static MemberTypes FieldOrProperty = MemberTypes.Field | MemberTypes.Property;
// !! FIXME: Map typeof(ProtectedString) to PropertyType.ProtectedString when binary files are allowed to read it.
public static readonly IReadOnlyDictionary<Type, PropertyType> Types = new Dictionary<Type, PropertyType>()
@ -329,16 +327,5 @@ namespace RobloxFiles
return (T)result;
}
internal void WriteValue<T>() where T : struct
{
if (CurrentWriter == null)
throw new Exception("Property.CurrentWriter must be set to use WriteValue<T>");
T value = CastValue<T>();
byte[] bytes = BinaryRobloxFileWriter.GetBytes(value);
CurrentWriter.Write(bytes);
}
}
}