Better logging

master
1987kostya 4 years ago
parent 4b9b4fa6a4
commit 5d920b2506

@ -3,6 +3,7 @@ using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using DotNetCTFDumper.Utils;
namespace DotNetCTFDumper.GUI
{
@ -21,8 +22,9 @@ namespace DotNetCTFDumper.GUI
if (filename == null) filename = "UnknownFile";
textBox1.Text +=
$" {(filename)} : {sf.GetMethod()}: Line {sf.GetFileLineNumber()}\r\n\r\n";
}
Logger.Log("ERROR: ",false,ConsoleColor.White,false);
Logger.Log(textBox1.Text,false,ConsoleColor.White,false);
//Console.ReadKey();
}

@ -32,25 +32,21 @@ namespace DotNetCTFDumper.GUI
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainConsole));
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.AllowDrop = true;
this.textBox1.BackColor = System.Drawing.Color.Black;
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox1.ForeColor = System.Drawing.Color.Lime;
this.textBox1.Location = new System.Drawing.Point(0, 0);
this.textBox1.Margin = new System.Windows.Forms.Padding(4, 15, 4, 3);
this.textBox1.MaxLength = 32767000;
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox1.Size = new System.Drawing.Size(496, 592);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.WordWrap = false;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// MainConsole
//
@ -65,10 +61,9 @@ namespace DotNetCTFDumper.GUI
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Console";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.RichTextBox textBox1;
#endregion
}

@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DotNetCTFDumper.GUI
@ -25,5 +26,64 @@ namespace DotNetCTFDumper.GUI
? $"[{date.Hour,2}:{date.Minute,2}:{date.Second,2}:{date.Millisecond,3}] {msg}\r\n"
: "\r\n");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
setLineFormat(1,1);
textBox1.SelectionStart = textBox1.Text.Length;
// scroll it automatically
textBox1.ScrollToCaret();
}
[DllImport("user32", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref PARAFORMAT lParam);
const int PFM_SPACEBEFORE = 0x00000040;
const int PFM_SPACEAFTER = 0x00000080;
const int PFM_LINESPACING = 0x00000100;
const int SCF_SELECTION = 1;
const int EM_SETPARAFORMAT = 1095;
private void setLineFormat(byte rule, int space)
{
PARAFORMAT fmt = new PARAFORMAT();
fmt.cbSize = Marshal.SizeOf(fmt);
fmt.dwMask = PFM_LINESPACING;
fmt.dyLineSpacing = space;
fmt.bLineSpacingRule = rule;
textBox1.SelectAll();
SendMessage( new HandleRef( textBox1, textBox1.Handle ),
EM_SETPARAFORMAT,
SCF_SELECTION,
ref fmt
);
}
public struct PARAFORMAT
{
public int cbSize;
public uint dwMask;
public short wNumbering;
public short wReserved;
public int dxStartIndent;
public int dxRightIndent;
public int dxOffset;
public short wAlignment;
public short cTabCount;
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 32 )]
public int[] rgxTabs;
// PARAFORMAT2 from here onwards
public int dySpaceBefore;
public int dySpaceAfter;
public int dyLineSpacing;
public short sStyle;
public byte bLineSpacingRule;
public byte bOutlineLevel;
public short wShadingWeight;
public short wShadingStyle;
public short wNumberingStart;
public short wNumberingStyle;
public short wNumberingTab;
public short wBorderSpace;
public short wBorderWidth;
public short wBorders;
}
}
}

@ -547,7 +547,7 @@ namespace DotNetCTFDumper.GUI
try
{
var previewKey = Decryption.MakeKeyFromBytes(rawData, (byte) int.Parse((charBox.Text)));
var previewKey = Decryption.MakeKeyFromComb(rawData, (byte) int.Parse((charBox.Text)));
hexBox1.ByteProvider = new DynamicByteProvider(previewKey);
}
@ -769,7 +769,9 @@ namespace DotNetCTFDumper.GUI
Thread.Sleep((int) (delay*1500));
}
_isAnimRunning = false;
Thread.CurrentThread.Abort();
try {Thread.CurrentThread.Abort();}
catch {}
}
else
{
@ -785,7 +787,7 @@ namespace DotNetCTFDumper.GUI
{
_isAnimRunning = false;
_breakAnim = false;
Thread.CurrentThread.Abort();
if(Thread.CurrentThread.IsAlive) Thread.CurrentThread.Abort();
break;
}
@ -828,10 +830,7 @@ namespace DotNetCTFDumper.GUI
PluginAPI.PluginAPI.ActivatePlugin(PluginAPI.PluginAPI.Plugins[pluginsList.SelectedIndex]);
}
public void SoundTest()
{
}
public void InitSounds()
{

@ -14,18 +14,18 @@ namespace DotNetCTFDumper.MMFParser.EXE
public bool Verbose = false;
public List<Frame> Frames = new List<Frame>();
public void Read(ByteReader exeReader)
public void Read(ByteReader reader)
{
Chunks.Clear();
while (true)
{
Chunk chunk = new Chunk(Chunks.Count, this);
chunk.Verbose = Verbose;
chunk.Read(exeReader);
chunk.Read(reader);
chunk.Loader = LoadChunk(chunk);
Chunks.Add(chunk);
if (chunk.Id == 8750) chunk.BuildKey();
if (exeReader.Tell() >= exeReader.Size()) break;
if (reader.Tell() >= reader.Size()) break;
if (chunk.Id == 32639) break; //LAST chunkID
}
}
@ -41,7 +41,7 @@ namespace DotNetCTFDumper.MMFParser.EXE
public byte[] ChunkData;
public byte[] RawData;
public ChunkFlags Flag;
public int Size = 0;
public int Size;
public int DecompressedSize = -1;
public bool Verbose = false;
@ -51,7 +51,7 @@ namespace DotNetCTFDumper.MMFParser.EXE
_chunkList = actualChunkList;
}
public ByteReader get_reader()
public ByteReader GetReader()
{
return new ByteReader(ChunkData);
}
@ -99,7 +99,7 @@ namespace DotNetCTFDumper.MMFParser.EXE
}
}
public void Print(bool extented)
{
if(extented)

@ -16,7 +16,7 @@ namespace DotNetCTFDumper.MMFParser.EXE
protected DataLoader(Chunk chunk)
{
this._chunk = chunk;
this.Reader = chunk.get_reader();
this.Reader = chunk.GetReader();
}
public abstract void Read();

@ -20,7 +20,7 @@ namespace DotNetCTFDumper.MMFParser.EXE.Loaders
protected ChunkLoader(Chunk chunk)
{
this.Chunk = chunk;
this.Reader = chunk.get_reader();
this.Reader = chunk.GetReader();
}

@ -92,8 +92,7 @@ namespace DotNetCTFDumper.MMFParser.EXE.Loaders
var frameReader = new ByteReader(Chunk.ChunkData);
Chunks = new ChunkList();
Chunks.Verbose = false;
Chunks.Read(frameReader);
var name = Chunks.GetChunk<FrameName>();
if (name != null) //Just to be sure

@ -4,7 +4,7 @@ using static DotNetCTFDumper.MMFParser.EXE.ChunkList;
namespace DotNetCTFDumper.MMFParser.EXE.Loaders
{
class ObjectNames : ChunkLoader//Fucking trash
class ObjectNames : ChunkLoader//2.5+ trash
{
public override void Print(bool ext)
{

@ -46,7 +46,7 @@ namespace DotNetCTFDumper.Utils
public static string ToDebugString<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
{
return string.Join(";", dictionary.Select(kv => kv.Key + "=" + kv.Value).ToArray());
return string.Join(";", dictionary.Select(kv => kv.Key + "=" + kv.Value).ToArray());
}
public override string ToString()

@ -18,10 +18,8 @@ namespace DotNetCTFDumper.Utils
public static ByteReader DecompressAsReader(ByteReader exeReader, out int decompressed)
{
Int32 decompSize = exeReader.ReadInt32();
Int32 compSize = exeReader.ReadInt32();
decompressed = decompSize;
return new ByteReader(decompress_block(exeReader, compSize, decompSize));
return new ByteReader(Decompress(exeReader, out decompressed));
}
public static byte[] decompress_block(ByteReader reader, int size, int decompSize)

@ -6,7 +6,7 @@ namespace DotNetCTFDumper.Utils
{
static class Decryption
{
private static byte[] DecryptionKey;
private static byte[] _decryptionKey;
public static byte MagicChar = 54;
public static void MakeKey(string data1, string data2, string data3)
@ -25,17 +25,14 @@ namespace DotNetCTFDumper.Utils
Marshal.FreeHGlobal(rawKeyPtr);
DecryptionKey = key;
Logger.Log($"First 16-Bytes of key: {DecryptionKey.GetHex(16)}", true, ConsoleColor.Yellow);
File.WriteAllBytes($"{Settings.DumpPath}\\key.bin", DecryptionKey);
_decryptionKey = key;
Logger.Log($"First 16-Bytes of key: {_decryptionKey.GetHex(16)}", true, ConsoleColor.Yellow);
File.WriteAllBytes($"{Settings.DumpPath}\\key.bin", _decryptionKey);
}
public static byte[] MakeKeyFromBytes(string data, byte magicChar = 54)
public static byte[] MakeKeyFromComb(string data, byte magicChar = 54)
{
var rawKeyPtr = Marshal.StringToHGlobalAnsi(data);
//var bytes = Encoding.UTF8.GetBytes(data);
//var rawKeyPtr = Marshal.AllocHGlobal(bytes.Length);
//Marshal.Copy(bytes,0,rawKeyPtr,bytes.Length);
var ptr = Decryption.make_key_combined(rawKeyPtr, magicChar);
byte[] key = new byte[256];
@ -73,8 +70,8 @@ namespace DotNetCTFDumper.Utils
IntPtr inputChunkPtr = Marshal.AllocHGlobal(chunkData.Length);
Marshal.Copy(chunkData, 0, inputChunkPtr, chunkData.Length);
IntPtr keyPtr = Marshal.AllocHGlobal(DecryptionKey.Length);
Marshal.Copy(DecryptionKey, 0, keyPtr, DecryptionKey.Length);
IntPtr keyPtr = Marshal.AllocHGlobal(_decryptionKey.Length);
Marshal.Copy(_decryptionKey, 0, keyPtr, _decryptionKey.Length);
var outputChunkPtr = decode_chunk(inputChunkPtr, chunkSize, MagicChar, keyPtr);

Loading…
Cancel
Save