From e03e50a993581217b24d6064ece9ee4b124d752c Mon Sep 17 00:00:00 2001 From: REDxEYE Date: Thu, 10 Dec 2020 20:09:27 +0300 Subject: [PATCH] fixed mfa writting --- NetMFAPatcher/MMFParser/Data/MFA.cs | 2 +- .../MMFParser/Decompiling/MFAGenerator.cs | 4 +-- NetMFAPatcher/Utils/ByteFlag.cs | 2 +- NetMFAPatcher/Utils/ByteWriter.cs | 35 +++++++------------ NetMFAPatcher/Utils/Helper.cs | 16 +++++++-- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/NetMFAPatcher/MMFParser/Data/MFA.cs b/NetMFAPatcher/MMFParser/Data/MFA.cs index b08328a..ece1cd8 100644 --- a/NetMFAPatcher/MMFParser/Data/MFA.cs +++ b/NetMFAPatcher/MMFParser/Data/MFA.cs @@ -282,7 +282,7 @@ namespace DotNetCTFDumper.MMFParser.Data unknown_string_2 = Helper.AutoReadUnicode(Reader); CommandLine = Helper.AutoReadUnicode(Reader); Aboutbox = Helper.AutoReadUnicode(Reader); - + Reader.ReadUInt32(); var binCount = Reader.ReadInt32(); //wtf i cant put it in loop fuck shit diff --git a/NetMFAPatcher/MMFParser/Decompiling/MFAGenerator.cs b/NetMFAPatcher/MMFParser/Decompiling/MFAGenerator.cs index e46cf2f..f0d2df8 100644 --- a/NetMFAPatcher/MMFParser/Decompiling/MFAGenerator.cs +++ b/NetMFAPatcher/MMFParser/Decompiling/MFAGenerator.cs @@ -6,8 +6,8 @@ namespace DotNetCTFDumper.MMFParser.Decompiling { public static class MFAGenerator { - //public static readonly string TemplatePath = @"F:\CPP\DotNetCTFDumper\testNoFrames.mfa"; - public static readonly string TemplatePath = @"C:\Users\ivani\Desktop\CTFResearch\testNoFrames.mfa"; + public static readonly string TemplatePath = @"C:\Users\MED45\Downloads\testNoFrames.mfa"; + // public static readonly string TemplatePath = @"C:\Users\ivani\Desktop\CTFResearch\testNoFrames.mfa"; public static void BuildMFA() { diff --git a/NetMFAPatcher/Utils/ByteFlag.cs b/NetMFAPatcher/Utils/ByteFlag.cs index ce51382..183cbf8 100644 --- a/NetMFAPatcher/Utils/ByteFlag.cs +++ b/NetMFAPatcher/Utils/ByteFlag.cs @@ -6,7 +6,7 @@ namespace DotNetCTFDumper.Utils { public static bool GetFlag(UInt32 flagbyte, int pos) { - UInt32 mask = (uint) (2 << pos); + UInt32 mask = (uint) (1 << pos); UInt32 result = flagbyte & mask; return result == mask; } diff --git a/NetMFAPatcher/Utils/ByteWriter.cs b/NetMFAPatcher/Utils/ByteWriter.cs index 7472ef5..69f385c 100644 --- a/NetMFAPatcher/Utils/ByteWriter.cs +++ b/NetMFAPatcher/Utils/ByteWriter.cs @@ -36,7 +36,7 @@ namespace DotNetCTFDumper.Utils { BaseStream.Seek(count, SeekOrigin.Current); } - + public Int64 Tell() { @@ -57,19 +57,19 @@ namespace DotNetCTFDumper.Utils { return BaseStream.Position < BaseStream.Length; } + public void WriteInt8(byte value) => Write(value); - public void WriteInt16(short value)=>Write(value); + public void WriteInt16(short value) => Write(value); public void WriteInt32(int value) => Write(value); public void WriteInt64(long value) => Write(value); - + public void WriteUInt16(ushort value) => Write(value); public void WriteUInt32(UInt32 value) => Write(value); public void WriteUInt64(ulong value) => Write(value); public void WriteSingle(float value) => Write(value); - + public void WriteBytes(byte[] value) => Write(value); - public void WriteAscii(string value) { @@ -79,42 +79,31 @@ namespace DotNetCTFDumper.Utils WriteInt8(bytes[i]); } } - public void WriteUnicode(string value) + + public void WriteUnicode(string value, bool appendZero = false) { var bytes = Encoding.Unicode.GetBytes(value); for (int i = 0; i < bytes.Length; i++) { WriteInt8(bytes[i]); - } + + if (appendZero) WriteInt16(0); } + public void WriteColor(Color color) { - WriteInt8(color.R); WriteInt8(color.G); WriteInt8(color.B); WriteInt8(0); - - } + public void WriteWriter(ByteWriter toWrite) { byte[] data = ((MemoryStream) toWrite.BaseStream).GetBuffer(); - Array.Resize(ref data,(int) toWrite.Size()); + Array.Resize(ref data, (int) toWrite.Size()); this.WriteBytes(data); } - - - - - - - - - - - - } } \ No newline at end of file diff --git a/NetMFAPatcher/Utils/Helper.cs b/NetMFAPatcher/Utils/Helper.cs index f1c52d3..083f732 100644 --- a/NetMFAPatcher/Utils/Helper.cs +++ b/NetMFAPatcher/Utils/Helper.cs @@ -65,7 +65,7 @@ namespace DotNetCTFDumper.Utils writer.WriteInt16((short) value.Length); writer.Skip(1); writer.WriteInt8(0x80); - writer.WriteUnicode(value); + writer.WriteUnicode(value,false); } public static DataLoader LoadParameter(int code, ByteReader reader) @@ -289,7 +289,19 @@ namespace DotNetCTFDumper.Utils // Step 3: return the new array. return result; } - + + } + public static class StringExtensionMethods + { + public static string ReplaceFirst(this string text, string search, string replace) + { + int pos = text.IndexOf(search); + if (pos < 0) + { + return text; + } + return text.Substring(0, pos) + replace + text.Substring(pos + search.Length); + } } } \ No newline at end of file