Fix TXE decoding with bad image sizes

This commit is contained in:
KillzXGaming 2019-08-08 17:12:11 -04:00
parent 79d78f64ad
commit 855037d21c
8 changed files with 50 additions and 14 deletions

View file

@ -77,7 +77,7 @@ namespace FirstPlugin
//Lets set our method of decoding
PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
int imageDataSize = reader.ReadInt32();
int imageDataSize = (int)reader.BaseStream.Length - 32;
reader.SeekBegin(32);

View file

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
using System.Reflection;
namespace Toolbox.Library
{
public class StaticDynamic : DynamicObject
{
private Type _type;
public StaticDynamic(Type type) { _type = type; }
// Handle static properties
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
PropertyInfo prop = _type.GetProperty(binder.Name, BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public);
if (prop == null)
{
result = null;
return false;
}
result = prop.GetValue(null, null);
return true;
}
// Handle static methods
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
MethodInfo method = _type.GetMethod(binder.Name, BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public);
if (method == null)
{
result = null;
return false;
}
result = method.Invoke(null, args);
return true;
}
}
}

View file

@ -744,7 +744,7 @@ namespace Toolbox.Library
private static byte[] DecodeRgb5A3(FileReader stream, uint width, uint height)
{
uint numBlocksW = width / 4; //4 byte block width
uint numBlocksW = width / 4; //4 byte block width
uint numBlocksH = height / 4; //4 byte block height
byte[] decodedData = new byte[width * height * 4];

View file

@ -295,6 +295,7 @@
<Compile Include="Rendering\GenericModelRenderer\GenericRenderedObject.cs" />
<Compile Include="Security\Cryptography\crc32.cs" />
<Compile Include="DrawableContainer.cs" />
<Compile Include="StaticDynamic.cs" />
<Compile Include="Texture Decoding\3DS\ETC1.cs" />
<Compile Include="FileFormats\Animation\SMD.cs" />
<Compile Include="FileFormats\APNG\APNG.cs" />

View file

@ -29,8 +29,9 @@ namespace Toolbox
{
listViewCustom1.Items.Clear();
foreach (var item in FileManager.GetFileFormats())
foreach (Type t in FileManager.GetFileFormats())
{
dynamic item = new StaticDynamic(t);
for (int i = 0; i < item.Extension.Length; i++)
{
string Extension;

View file

@ -25,8 +25,8 @@ namespace Toolbox
private static MainForm _instance;
public static MainForm Instance { get { return _instance == null ? _instance = new MainForm() : _instance; } }
IFileFormat[] SupportedFormats;
IFileMenuExtension[] FileMenuExtensions;
IFileFormat[] SupportedFormats { get { return FileManager.GetFileFormats(); } }
IFileMenuExtension[] FileMenuExtensions { get { return FileManager.GetMenuExtensions(); } }
public void AddChildContainer(Form form)
{
@ -64,12 +64,6 @@ namespace Toolbox
}
}
public void Reload()
{
SupportedFormats = FileManager.GetFileFormats();
FileMenuExtensions = FileManager.GetMenuExtensions();
}
//Use for files opened with program
public List<string> openedFiles = new List<string>();
@ -122,7 +116,6 @@ namespace Toolbox
LoadPLugins();
UpdateToolbar(HasVersionFile);
Reload();
LoadConfig();
LoadMDITheme();
LoadRecentList();
@ -247,8 +240,6 @@ namespace Toolbox
public void OpenFile(string FileName, bool InActiveEditor = false)
{
Reload();
if (File.Exists(FileName))
SaveRecentFile(FileName);