public void Dispose() { PostingLists?.Dispose(); Dictionary?.Dispose(); Fields?.Dispose(); HeaderReader?.Dispose(); }
private void Button_Click(object sender, RoutedEventArgs e) { //Test code, please ignore OpenFileDialog fileDialog = new OpenFileDialog(); if (fileDialog.ShowDialog() == true) { //open file dialog to open the map Stream str = File.Open(fileDialog.FileName, FileMode.Open); //Get the header MapHeader mh = HeaderReader.ReadHeader(str); ///Break out the sections of the file in order to avoid seeks and shit /// //First get the debug section. What the f**k is this for anyways? int debug_offset = (int)mh.section_offsets[0] + (int)mh.section_bounds[0].offset; int debug_size = (int)mh.section_bounds[0].size; byte[] debug_section = new byte[debug_size]; if (str.Position != debug_offset) { str.Seek(debug_offset, SeekOrigin.Begin); } str.Read(debug_section, 0, debug_size); //Then get the resources section. Images and models maybe? and strings probably! int resource_offset = (int)mh.section_offsets[1] + (int)mh.section_bounds[1].offset; int resource_size = (int)mh.section_bounds[1].size; byte[] resource_section = new byte[resource_size]; if (str.Position != resource_offset) { str.Seek(resource_offset, SeekOrigin.Begin); } str.Read(resource_section, 0, resource_size); //Get the actual tags int tag_offset = (int)mh.section_offsets[2] + (int)mh.section_bounds[2].offset; int tag_size = (int)mh.section_bounds[2].size; byte[] tag_section = new byte[tag_size]; long pos = str.Position; if (str.Position != tag_offset) { str.Seek(tag_offset, SeekOrigin.Begin); } str.Read(tag_section, 0, tag_size); //Lastly get the localization data //But I dont need it now so f**k it ConsoleOutput.AppendText("Read in the map file!\n"); } }
public void HeaderReadOneElementInMapStandar_Tests() { HeaderReader headerReader = new HeaderReader(); byte[] map = new Byte[] { 65, 3, 0 }; headerReader.Read(map, true, HuffmanCoder.Logic.Entities.HuffmanEncodeModel.Standard); Assert.AreEqual((uint)3, headerReader.symbolCounts["A"]); }
public void HeaderReadOnelementInMapMarkov() { HeaderReader headerReader = new HeaderReader(); byte[] map = new Byte[] { 65, 66, 3, 0 }; headerReader.Read(map, false, HuffmanCoder.Logic.Entities.HuffmanEncodeModel.Markov); Assert.AreEqual((uint)3, headerReader.symbolCounts["AB"]); }
/// <summary> /// Parses the header of the current packet and assigns the read values to the proper variables. /// </summary> /// <param name="packetBuffer">The packet buffer the way it was received.</param> private void ParseHeader(byte[] packetBuffer) { HeaderReader reader = new HeaderReader(packetBuffer); Size = reader.ReadInt16(); Prefix = reader.ReadInt16(); Count = reader.ReadInt32(); }
public void HeaderReadTwoElementsInMapMarkovWithSpecialSymbol() { HeaderReader headerReader = new HeaderReader(); byte[] map = new Byte[] { 65, 66, 3, 0, 66, 4, 0 }; headerReader.Read(map, true, HuffmanCoder.Logic.Entities.HuffmanEncodeModel.Markov); Assert.AreEqual((uint)3, headerReader.symbolCounts["AB"]); Assert.AreEqual((uint)4, headerReader.symbolCounts["B"]); }
public void HeaderReadTwoElementsInMapBlock() { HeaderReader headerReader = new HeaderReader(); byte[] map = new Byte[] { 65, 66, 3, 0, 66, 67, 4, 0 }; headerReader.Read(map, true, HuffmanCoder.Logic.Entities.HuffmanEncodeModel.Block); Assert.AreEqual((uint)3, headerReader.symbolCounts["AB"]); Assert.AreEqual((uint)4, headerReader.symbolCounts["BC"]); }
public MainWindow() { InitializeComponent(); ErrorMsg.Content = ""; RomTypes.ItemsSource = HeaderReader.GetRomTypes(); RomTypes.DisplayMemberPath = "Value"; RomTypes.SelectedValuePath = "Key"; }
public int Recieve(int _timeout = 5000) { if (State != RunnerSocketState.Connected) { return(0); } Sender.ReceiveTimeout = _timeout; try { int dataRec = Sender.Receive(HeaderData, 0, 8, SocketFlags.None); HeaderReader.BaseStream.Seek(0, SeekOrigin.Begin); uint dataHeader = HeaderReader.ReadUInt32(); int dataSize = HeaderReader.ReadInt32() - 8; if (dataRec != 8) { Console.WriteLine("Failed to read packet header!"); } else { int num = 0; if (dataHeader == RunnerNetworkPacket.PK_HEADER) { if (dataSize > HeaderData.Length) { HeaderStream.SetLength(dataSize); } while (num < dataSize) { dataRec = Sender.Receive(HeaderData, num, dataSize - num, SocketFlags.None); num += dataRec; if (dataRec > 0) { continue; } break; } if (num > 0) { return(num); } State = RunnerSocketState.Error; return(0); } else { Console.WriteLine("Wrong packet header!"); } } } catch { return(0); } return(0); }
private static ISampleProvider CreateSampleProvider(BinaryReader binaryReader) { var reader = new StreamSequentialReader(binaryReader); var header = HeaderReader.Read(reader); var commands = CommandsReader.Read(header, reader); var values = Renderer.Render(commands); var provider = new EnumerableSampleProvider(values); return(provider); }
private bool TryReadHeader(string data, out Header header) { var headerReader = new HeaderReader(); var sequence = new ReadOnlySequence <byte>(CreateByteArray(data)); var reader = new SequenceReader <byte>(sequence); var result = headerReader.TryReadHeader(ref reader, out var readHeader); header = readHeader; return(result); }
public void Start() { Action Stop = delegate { this.Stop = null; }; foreach (var Port in Ports) { var t = Port.ToThreadedTcpListener( s => { var hr = new HeaderReader(); var hr_Method_path = ""; hr.Method += (method, path) => { hr_Method_path = path; }; hr.Header += (key, value) => { //Console.WriteLine(key + ": " + value); }; hr.Read(s); if (!string.IsNullOrEmpty(hr_Method_path)) { Console.WriteLine(">> " + hr_Method_path); this.CommandRequest(s, hr_Method_path); } s.Close(); } ); Stop += delegate { t.IsDisposed = true; t.Listener.Server.Close(); t.Thread.Join(); }; } this.Stop = Stop; }
private void changeDropdownFromTextbox() { int result; bool idk = int.TryParse(RomType.Text, System.Globalization.NumberStyles.HexNumber, null, out result); if (idk && RomType.Text.Length == 2 && (HeaderReader.GetRomTypes().ContainsKey(result))) { RomTypes.SelectedValue = result; } else { RomTypes.SelectedValue = -1; } }
public string[] GetExportedFunctions(HeaderReader header) { try { List <string> result = new List <string>(header.exports.Count); foreach (export function in header.exports.Values) { result.Add(function.Name); } return(result.ToArray()); } catch { return(new string[0]); } }
public static async Task <PassthroughMessage> Extract(HttpRequest request, CancellationToken cancellation) { var incomingHeaders = HeaderReader.GetIncomingHeaders(request.Headers); var form = await request.ReadFormAsync(cancellation); return(new( destination : incomingHeaders.Destination, id : incomingHeaders.MessageId, correlationId : incomingHeaders.MessageId, type : incomingHeaders.MessageType, @namespace : incomingHeaders.MessageNamespace, clientUrl : incomingHeaders.Referrer, body : GetMessageBody(form), attachments : GetAttachments(form).ToList() )); }
public List <UInt64> MemoryFindAll(string library, List pattern) { // Find the module List <MemoryFunctions.PROCESS_MODULE> modules = MemoryFunctions.EnumurateProcessModules(ProcessDotNet, !IsWin64); foreach (MemoryFunctions.PROCESS_MODULE module in modules) { if (module.Name.ToLower() == library.ToLower()) { HeaderReader header = new HeaderReader(ProcessDotNet, (UInt64)module.BaseAddress); return(MemoryFunctions.MemoryFindAll(ProcessDotNet, (IntPtr)module.BaseAddress, header.optHeader.SizeOfImage, pattern.ToArray <object>())); } } return(null); // No results }
public HeaderReader GetModuleHeader(string library) { // Find the module List <MemoryFunctions.PROCESS_MODULE> modules = MemoryFunctions.EnumurateProcessModules(ProcessDotNet, !IsWin64); foreach (MemoryFunctions.PROCESS_MODULE module in modules) { if (module.Name.ToLower() == library.ToLower()) { // Found the module, parse it's pe header in-memory HeaderReader header = new HeaderReader(ProcessDotNet, (ulong)module.BaseAddress); return(header); } } return(null); // No results }
public UInt64 GetProcedureAddress(HeaderReader header, string procedure) { // Found the module, parse it's pe header in-memory try { if (header.exports.Contains(procedure.ToLower())) { return(((export)header.exports[procedure.ToLower()]).Address); } } catch { throw new Exception("Unknown failure in Engine.GetProcedureAddress()."); } Console.WriteLine(string.Format("ERROR: Failed to call 'Engine.GetProcedureAddress()'. Was unable to resolve export {0}.", procedure)); return(0); }
private void InitHeader() { bool specialSymbol = true; uint headerSize = binaryReader.ReadUInt32(); this.huffmanEncodeModel = binaryReader.ReadByte(); this.specialSymbolByte = binaryReader.ReadByte(); if (specialSymbolByte == 0) { specialSymbol = false; } byte[] map = binaryReader.ReadBytes((int)headerSize - 6); HeaderReader headerReader = new HeaderReader(); headerReader.Read(map, specialSymbol, (HuffmanEncodeModel)huffmanEncodeModel); this.symbolCounts = headerReader.symbolCounts; }
private static void ProcessVgm(string fileName, VgmFileProcessor processor) { var fileInfo = new FileInfo(fileName); using (var stream = new GZipStream(fileInfo.OpenRead(), CompressionMode.Decompress)) { using (var binaryReader = new BinaryReader(stream)) { var reader = new StreamSequentialReader(binaryReader); var header = HeaderReader.Read(reader); var commands = CommandsReader.Read(header, reader); processor(fileName, header, commands); } } }
private void doLoad() { ErrorMsg.Content = ""; try { headerReader = new HeaderReader(InputFilename.Text); RomType.Text = headerReader.GetCurrentRomType().ToString("X").PadLeft(2, '0'); RamSize.Text = headerReader.GetCurrentRamSize().ToString("X").PadLeft(2, '0'); changeDropdownFromTextbox(); RomType.Text = headerReader.GetCurrentRomType().ToString("X").PadLeft(2, '0'); RamSize.Text = headerReader.GetCurrentRamSize().ToString("X").PadLeft(2, '0'); } catch (Exception hmm) { ErrorMsg.Content = "★ " + hmm.Message; } }
public string[] GetExportedFunctions(UInt64 libraryBase) { try { HeaderReader header = new HeaderReader(ProcessDotNet, libraryBase); List <string> result = new List <string>(header.exports.Count); foreach (export function in header.exports.Values) { result.Add(function.Name); } return(result.ToArray()); } catch { return(new string[0]); } }
public UInt64[] GetProcedureAddresses(string library, object procedures) { // Find the module List <MemoryFunctions.PROCESS_MODULE> modules = MemoryFunctions.EnumurateProcessModules(ProcessDotNet, !IsWin64); foreach (MemoryFunctions.PROCESS_MODULE module in modules) { if (module.Name.ToLower() == library.ToLower()) { // Found the module, parse it's pe header in-memory HeaderReader header = new HeaderReader(ProcessDotNet, (ulong)module.BaseAddress); Hashtable namesToAddresses = new Hashtable(header.exports.Count); foreach (export function in header.exports.Values) { if (!namesToAddresses.Contains(function.Name.ToLower())) { namesToAddresses.Add(function.Name.ToLower(), function.Address); } } // Resolve the provided imports List <UInt64> result; result = new List <UInt64>(10); foreach (string procedure in (IEnumerable)procedures) { if (namesToAddresses.Contains(procedure.ToLower())) { result.Add((UInt64)namesToAddresses[procedure.ToLower()]); } else { result.Add(0); } } return(result.ToArray()); } } return(new UInt64[0]); }
public UInt64 GetProcedureAddress(string library, string procedure) { // Find the module foreach (System.Diagnostics.ProcessModule module in ProcessDotNet.Modules) { if (module.ModuleName.ToLower() == library.ToLower()) { // Found the module, parse it's pe header in-memory HeaderReader header = new HeaderReader(ProcessDotNet, (ulong)module.BaseAddress); List <string> result = new List <string>(header.exports.Count); foreach (export function in header.exports.Values) { if (function.Name.ToLower() == procedure.ToLower()) { return(function.Address); } } } } return(0); }
public UInt64 GetProcedureAddress(IntPtr libraryBase, string procedure) { // Found the module, parse it's pe header in-memory try { HeaderReader header = new HeaderReader(ProcessDotNet, (ulong)libraryBase); foreach (export function in header.exports.Values) { if (function.Name.ToLower() == procedure.ToLower()) { return(function.Address); } } } catch { throw new Exception("Unknown failure in Engine.GetProcedureAddress()."); } Console.WriteLine(string.Format("ERROR: Failed to call 'Engine.GetProcedureAddress()'. Was unable to resolve export {0}.", procedure)); return(0); }
public string[] GetExportedFunctions(string library) { // Find the module List <MemoryFunctions.PROCESS_MODULE> modules = MemoryFunctions.EnumurateProcessModules(ProcessDotNet, !IsWin64); foreach (MemoryFunctions.PROCESS_MODULE module in modules) { if (module.Name.ToLower() == library.ToLower()) { // Found the module, parse it's pe header in-memory HeaderReader header = new HeaderReader(ProcessDotNet, (UInt64)module.BaseAddress); List <string> result = new List <string>(header.exports.Count); foreach (export function in header.exports.Values) { result.Add(function.Name); } return(result.ToArray()); } } return(new string[0]); // No results }
public UInt64[] GetProcedureAddresses(UInt64 libraryBase, object procedures) { // Found the module, parse it's pe header in-memory try { HeaderReader header = new HeaderReader(ProcessDotNet, libraryBase); Hashtable namesToAddresses = new Hashtable(header.exports.Count); foreach (export function in header.exports.Values) { if (!namesToAddresses.Contains(function.Name.ToLower())) { namesToAddresses.Add(function.Name.ToLower(), function.Address); } } // Resolve the provided imports List <UInt64> result; result = new List <UInt64>(10); foreach (string procedure in (IEnumerable)procedures) { if (namesToAddresses.Contains(procedure.ToLower())) { result.Add((UInt64)namesToAddresses[procedure.ToLower()]); } else { result.Add(0); } } return(result.ToArray()); } catch { return(new UInt64[0]); } }
//public static bool TryGetReader(MyZipArchive archive, out Reader reader) //{ //} public static Writer GetWriter(MyZipArchive archive, bool overwrite, string encryptionKey = "") { int basicType; using (var reader = new HeaderReader(archive)) { basicType = reader.GetArchiveType().BasicType; } switch (basicType) { case 0: return(new Writer(archive, overwrite)); case 1: return(new CompressionWriter(archive, overwrite)); case 2: return(new EncryptionWriter(archive, overwrite, encryptionKey)); default: return(null); } }
public string[] GetExportedFunctions(HeaderReader header) { try { List<string> result = new List<string>(header.exports.Count); foreach (export function in header.exports.Values) { result.Add(function.Name); } return result.ToArray(); } catch { return new string[0]; } }
public UInt64[] GetProcedureAddresses(string library, object procedures) { // Find the module List<MemoryFunctions.PROCESS_MODULE> modules = MemoryFunctions.EnumurateProcessModules(ProcessDotNet, !IsWin64); foreach (MemoryFunctions.PROCESS_MODULE module in modules) { if (module.Name.ToLower() == library.ToLower()) { // Found the module, parse it's pe header in-memory HeaderReader header = new HeaderReader(ProcessDotNet, (ulong)module.BaseAddress); Hashtable namesToAddresses = new Hashtable(header.exports.Count); foreach (export function in header.exports.Values) { if (!namesToAddresses.Contains(function.Name.ToLower())) namesToAddresses.Add(function.Name.ToLower(), function.Address); } // Resolve the provided imports List<UInt64> result; result = new List<UInt64>(10); foreach (string procedure in (IEnumerable)procedures) { if (namesToAddresses.Contains(procedure.ToLower())) result.Add((UInt64)namesToAddresses[procedure.ToLower()]); else result.Add(0); } return result.ToArray(); } } return new UInt64[0]; }
public UInt64[] GetProcedureAddresses(UInt64 libraryBase, object procedures) { // Found the module, parse it's pe header in-memory try { HeaderReader header = new HeaderReader(ProcessDotNet, libraryBase); Hashtable namesToAddresses = new Hashtable(header.exports.Count); foreach (export function in header.exports.Values) { if (!namesToAddresses.Contains(function.Name.ToLower())) namesToAddresses.Add(function.Name.ToLower(), function.Address); } // Resolve the provided imports List<UInt64> result; result = new List<UInt64>(10); foreach (string procedure in (IEnumerable)procedures) { if (namesToAddresses.Contains(procedure.ToLower())) result.Add((UInt64)namesToAddresses[procedure.ToLower()]); else result.Add(0); } return result.ToArray(); } catch { return new UInt64[0]; } }
private void button1_Click(object sender, EventArgs e) { int p = 1; int f5; int SizeX = 32; int SizeY = 32; UInt32 DataOffset = 0; List <int> imageOffsets = new List <int>(); List <string> imageNames = new List <string>(); OpenFileDialog open = new OpenFileDialog(); open.Filter = "bin file|*.bin"; DialogResult res = open.ShowDialog(); CommonOpenFileDialog FolSelect = new CommonOpenFileDialog(); FolSelect.IsFolderPicker = true; if (res == DialogResult.OK && FolSelect.ShowDialog() == CommonFileDialogResult.Ok) { try { //OpenFileDialog open = new OpenFileDialog(); //open.Filter = "BIN file|*.bin"; //DialogResult res = open.ShowDialog(); //if (res == DialogResult.OK) { foreach (PictureBox b in LoadedImgs) { b.Dispose(); } foreach (Label l in Labels) { l.Dispose(); } //vScrollBar1.Maximum = 0; //LoadedImgs.Clear(); byte[] Data = File.ReadAllBytes(open.FileName); //detect if header contains offsets or DL's contain offsets /*List<string> HeaderData = new List<string>(); * HeaderData.AddRange(new HeaderReader().ReadHeader(Data).Split('\n')); * HeaderData.RemoveAll(x => !x.Contains("Offset:")); */ int[] Offsets = new HeaderReader().ReadOffsets(Data); bool HeaderIsDL = true; for (int i = 0; i < Offsets.Length / 2; i++) { if (Data[Offsets[i]] != 4) { HeaderIsDL = false; } } if (HeaderIsDL) { f5 = 0; int CurOffset = Offsets[0]; while (CurOffset < Data.Length) { if (Data[CurOffset] == 0x04 || Data[CurOffset] == 0xB8) { f5 = 0; } //count f5 third instance = pallette if (Data[CurOffset] == 0xF5) { f5++; int OffsetPrevFD = CurOffset; while (Data[OffsetPrevFD] != 0xFD) { OffsetPrevFD -= 1; } if (OffsetPrevFD >= CurOffset - 15) { //texture command //get sizes switch (Data[CurOffset + 6]) { case (0x40): { SizeY = 32; break; } case (0x80): { SizeY = 64; break; } } switch (Data[CurOffset + 7]) { case (0x50): { SizeX = 32; break; } case (0x60): { SizeX = 64; break; } } byte[] FixedData = new byte[4]; Array.Copy(Data, OffsetPrevFD + 4, FixedData, 0, 4); FixedData[0] = 0; DataOffset = ByteTools.Read4Bytes(FixedData, 0); //UInt32 //store offset at this point imageOffsets.Add((int)DataOffset); } } if (f5 == 3) { Bitmap b = new Bitmap(SizeX, SizeY, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(b); byte[] Palette; int colval; //string ColourType = Convert.ToString(Data[CurOffset + 1], 2); //ColourType += Convert.ToString(Data[CurOffset + 2], 2); //ColourType = ColourType.Substring(4, 2); colval = (Data[CurOffset + 1]); colval = (colval & 24); colval = colval >> 3; //Convert.ToInt32(ColourType, 2); switch (colval) { //ci4 case (0): { Palette = new byte[32]; int PalOff = (int)DataOffset + 0x200; Array.Copy(Data, PalOff, Palette, 0, 32); N64GraphicsCoding.RenderTexture(g, Data, Palette, (int)DataOffset, SizeX, SizeY, 1, N64Codec.CI4, N64IMode.AlphaBinary); break; } //rgb16 case (1): { Palette = new byte[512]; int arrayoffset = (int)DataOffset + 0x400; Array.Copy(Data, arrayoffset, Palette, 0, 512); N64GraphicsCoding.RenderTexture(g, Data, Palette, (int)DataOffset, SizeX, SizeY, 1, N64Codec.CI8, N64IMode.AlphaCopyIntensity); break; } //rgb16 case (2): { Palette = new byte[32]; int PalOff = (int)DataOffset + 0x200; Array.Copy(Data, PalOff, Palette, 0, 32); N64GraphicsCoding.RenderTexture(g, Data, Palette, (int)DataOffset, SizeX, SizeY, 1, N64Codec.RGBA16, N64IMode.AlphaBinary); break; } } PictureBox box = new PictureBox(); box.Image = b; box.Width = SizeX; box.Height = SizeY; LoadedImgs.Add(box); Label l = new Label(); l.Text = DataOffset.ToString("X"); Labels.Add(l); b.RotateFlip(RotateFlipType.RotateNoneFlipY); string filepath = @"\textures\" + Path.GetFileName(open.FileName.Substring(0, open.FileName.Length - 4) + "-" + p + ".bmp"); b.Save(FolSelect.FileName + filepath); imageNames.Add(FolSelect.FileName + filepath); p++; f5 = 0; } CurOffset += 8; } } else { /* * foreach(int off in Offsets) * { * byte[] pal = new byte[32]; * * Array.Copy(Data, off, pal, 0, 32); * Bitmap b = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb); * Graphics g = Graphics.FromImage(b); * N64GraphicsCoding.RenderTexture(g, Data, pal, off, 32,32,1,N64Codec.CI4, N64IMode.AlphaBinary); * * PictureBox box = new PictureBox(); * box.Image = b; * box.Width = 32; * box.Height = 32; * LoadedImgs.Add(box); * * pal = new byte[256]; * * Array.Copy(Data, off, pal, 0, 256); * b = new Bitmap(256, 256, System.Drawing.Imaging.PixelFormat.Format32bppArgb); * g = Graphics.FromImage(b); * N64GraphicsCoding.RenderTexture(g, Data, pal, off, 64, 64, 1, N64Codec.CI8, N64IMode.AlphaBinary); * * box = new PictureBox(); * box.Image = b; * box.Width = 32; * box.Height = 32; * LoadedImgs.Add(box); * } * byte[] Pal = new byte[32]; * */ } int CurPosY = BaseBox.Location.Y; int CurPosX = BaseBox.Location.X; /*foreach (PictureBox b in LoadedImgs) * { * b.Location = new System.Drawing.Point(CurPosX, CurPosY); * CurPosY += b.Image.Height + 10; * vScrollBar1.Maximum += b.Image.Height + 10; * this.Controls.Add(b); * OrigY.Add(CurPosY); * }*/ for (int i = 0; i < LoadedImgs.Count; i++) { LoadedImgs[i].Location = new System.Drawing.Point(CurPosX, CurPosY); CurPosY += LoadedImgs[i].Image.Height + 10; //vScrollBar1.Maximum += LoadedImgs[i].Image.Height + 10; this.Controls.Add(LoadedImgs[i]); OrigY.Add(CurPosY); Labels[i].Location = new System.Drawing.Point(CurPosX + LoadedImgs[i].Width + 32, CurPosY); this.Controls.Add(Labels[i]); } BaseBox.Visible = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } try { SaveFileDialog mtl = new SaveFileDialog(); mtl.Filter = "material file|*.mtl"; res = mtl.ShowDialog(); if (res == DialogResult.OK) { //string[] OutObj = generateMtl(mtl.FileName, imageNames, RList); //File.WriteAllLines(mtl.FileName, OutObj); } SaveFileDialog obj = new SaveFileDialog(); obj.Filter = "object file|*.obj"; res = obj.ShowDialog(); if (res == DialogResult.OK) { string[] OutObj = new DLParser().GetParsedObject2(File.ReadAllBytes(open.FileName), imageOffsets, imageNames, mtl.FileName.Substring(0, mtl.FileName.Length - 4)); File.WriteAllLines(obj.FileName, OutObj); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void button2_Click(object sender, EventArgs e) { List <string> V = new List <string>(); List <string> VT = new List <string>(); List <string> F = new List <string>(); List <int> imgOffList = new List <int>(); List <int> palOffList = new List <int>(); List <string> RList = new List <string>(); List <string> GList = new List <string>(); List <string> BList = new List <string>(); List <int> fMat = new List <int>(); int palOffset = 0; int imgOffset = 0; int imgFormat = 0; //int cCount; int AdditionalOffset; int[] mtlCol = new int[3]; float R = 0; float G = 0; float B = 0; int p = 0; int lastImg = 0; int FD; int FD4B = 0; int SizeX = 32; int SizeY = 32; UInt32 DataOffset = 0; List <int> imageOffsets = new List <int>(); List <string> imageNames = new List <string>(); List <DLObject> Temp = new List <DLObject>(); //open bin OpenFileDialog open = new OpenFileDialog(); open.Filter = "bin file|*.bin"; DialogResult res = open.ShowDialog(); CommonOpenFileDialog FolSelect = new CommonOpenFileDialog(); FolSelect.IsFolderPicker = true; if (res == DialogResult.OK && FolSelect.ShowDialog() == CommonFileDialogResult.Ok) { Directory.CreateDirectory(FolSelect.FileName + @"\textures\"); try { //clear images foreach (PictureBox b in LoadedImgs) { b.Dispose(); } foreach (Label l in Labels) { l.Dispose(); } //get file offsets byte[] Data = File.ReadAllBytes(open.FileName); int[] Offsets = new HeaderReader().ReadOffsets(Data); //bool HeaderIsDL = true; //for (int i = 0; i < Offsets.Length / 2; i++) //{ foreach (int Offset in Offsets) { //try each offset try { DLObject Buf = new DLObject(); int CurOffset = Offset; //if (Data[Offsets[i]] != 4) //{ // HeaderIsDL = false; //} //process offset //if (HeaderIsDL) //{ FD = 0; //int CurOffset = Offsets[0]; while (Data[CurOffset] != 0xB8)//Data.Length { if (Data[CurOffset] == 0x04) { FD = 0; Buf = new DLObject(); byte[] Pos = new byte[4]; Array.Copy(Data, CurOffset + 4, Pos, 0, 4); Pos[0] = 0; if (BitConverter.IsLittleEndian) { Array.Reverse(Pos); } Buf.DataOffset = BitConverter.ToInt32(Pos, 0); string Length = Convert.ToString(Data[CurOffset + 2], 2).PadLeft(8, '0'); Length = Length.Substring(0, 6); Buf.Length = Convert.ToInt32(Length, 2); //gets last paint value for block of coordinates. Needs work mtlCol = getvtPaint(Data, Buf.DataOffset, Buf.Length); R = mtlCol[0] / (float)255; G = mtlCol[1] / (float)255; B = mtlCol[2] / (float)255; Temp.Add(Buf); } else if (Data[CurOffset] == 0xFD) { FD++; //check whether pallette, image or image format byte[] Pos = new byte[2]; Array.Copy(Data, CurOffset + 6, Pos, 0, 2); if (Data[CurOffset + 0x10] == 0xF5) { palOffset = Pos[0] * 256 + Pos[1]; } else if (Data[CurOffset + 0x08] == 0xF5) { imgOffset = Pos[0] * 256 + Pos[1]; } imgFormat = (Data[CurOffset + 1] & 24) >> 3; } else if (Data[CurOffset] == 0xF5) { imgFormat = (Data[CurOffset + 1] & 24) >> 3; //byte[] Pos = new byte[2]; //switch (f5) //{ // case 0: // Array.Copy(Data, CurOffset - 10, Pos, 0, 2); // //if (BitConverter.IsLittleEndian) // //{ // // Array.Reverse(Pos); // //} // palOffset = Pos[0] * 256 + Pos[1]; //BitConverter.ToInt32(Pos, 0); // imgOffset = Pos[0] * 256 + Pos[1]; // imgFormat = (Data[CurOffset + 1] & 24) >> 3; // f5++; // break; // case 1: // Array.Copy(Data, CurOffset - 2, Pos, 0, 2); // //if (BitConverter.IsLittleEndian) // //{ // // Array.Reverse(Pos); // //} // FD4B = Data[CurOffset - 5]; // imgOffset = Pos[0] * 256 + Pos[1]; // BitConverter.ToInt32(Pos, 0); // imgFormat = (Data[CurOffset + 1] & 24) >> 3; // f5++; // break; // case 2: // //p++; // imgFormat = (Data[CurOffset + 1] & 24) >> 3; // //int[] sizes = getImgSize(imgFormat, imgOffset, palOffset, FD4B); // //SizeX = sizes[0]; // //SizeY = sizes[1]; // //Bitmap b = new Bitmap(SizeX, SizeY, System.Drawing.Imaging.PixelFormat.Format32bppArgb); // //Graphics g = Graphics.FromImage(b); // //createImg(g, Data, imgFormat, imgOffset, palOffset, SizeX, SizeY); // //PictureBox box = new PictureBox(); // //box.Image = b; // //box.Width = SizeX; // //box.Height = SizeY; // //LoadedImgs.Add(box); // //Label l = new Label(); // //l.Text = DataOffset.ToString("X"); // //Labels.Add(l); // //b.RotateFlip(RotateFlipType.RotateNoneFlipY); // //string filepath = open.FileName.Substring(0, open.FileName.Length - 4) + "-" + p; // //b.Save(filepath + ".bmp"); // //if (SizeX == 1 && SizeY == 1) imageNames.Add(" "); // //else imageNames.Add(filepath + ".bmp"); // //RList.Add(R.ToString()); // //GList.Add(G.ToString()); // //BList.Add(B.ToString()); // //f5 = 0; // break; //} } //f2 states texture size according to documentation else if (Data[CurOffset] == 0xF2) { // incorrect for some textures int uppNib; int lowNib; byte[] Pos = new byte[3]; Array.Copy(Data, CurOffset + 5, Pos, 0, 3); uppNib = Pos[1] >> 4; lowNib = Pos[1] & 15; SizeX = ((((((Pos[0] << 4) + uppNib) >> 2) + 1) >> 1) << 1); SizeY = (((((Pos[2]) >> 2) + 1) >> 1) << 1); } else if (Data[CurOffset] == 0xB1) { //checks if using last image, new image or vtx paint if (FD != 0) { int listImg = -1; //checks existing images to assign faces with existing created image for (int i = 0; i < imgOffList.Count; i++) { if (imgOffset == imgOffList[i]) { listImg = i + 1; } } if (listImg == -1) { p++; //original sizing function to get size of image from colformat and length not consistent //int[] sizes = getImgSize(imgFormat, imgOffset, palOffset, FD4B); //SizeX = sizes[0]; //SizeY = sizes[1]; Bitmap b = new Bitmap(SizeX, SizeY, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(b); createImg(g, Data, imgFormat, imgOffset, palOffset, SizeX, SizeY); PictureBox box = new PictureBox(); box.Image = b; box.Width = SizeX; box.Height = SizeY; LoadedImgs.Add(box); Label l = new Label(); l.Text = DataOffset.ToString("X"); Labels.Add(l); b.RotateFlip(RotateFlipType.RotateNoneFlipY); string filepath = open.FileName.Substring(0, open.FileName.Length - 4) + "-" + p; b.Save(filepath + ".bmp"); if (imgOffset == 0 && palOffset == 0) { imageNames.Add(" "); } else { imageNames.Add(filepath + ".bmp"); } RList.Add(R.ToString()); GList.Add(G.ToString()); BList.Add(B.ToString()); imgOffList.Add(imgOffset); palOffList.Add(palOffset); FD = 0; lastImg = p; } else { lastImg = listImg; } } Connection c = new Connection(); c.Connection1 = Data[CurOffset + 1] / 2; c.Connection2 = Data[CurOffset + 2] / 2; c.Connection3 = Data[CurOffset + 3] / 2; //if (SizeX == 1 && SizeY == 1) c.mtlId = 0; //else c.mtlId = lastImg; Buf.connections.Add(c); //fMat.Add(p); c = new Connection(); c.Connection1 = Data[CurOffset + 5] / 2; c.Connection2 = Data[CurOffset + 6] / 2; c.Connection3 = Data[CurOffset + 7] / 2; //if (SizeX == 1 && SizeY == 1) c.mtlId = 0; //else //storing mtl id c.mtlId = lastImg; Buf.connections.Add(c); //fMat.Add(p); } else if (Data[CurOffset] == 0xBF) { if (FD != 0) { int listImg = -1; for (int i = 0; i < imgOffList.Count; i++) { if (imgOffset == imgOffList[i]) { listImg = i + 1; } } if (listImg == -1) { p++; //int[] sizes = getImgSize(imgFormat, imgOffset, palOffset, FD4B); //SizeX = sizes[0]; //SizeY = sizes[1]; Bitmap b = new Bitmap(SizeX, SizeY, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(b); createImg(g, Data, imgFormat, imgOffset, palOffset, SizeX, SizeY); PictureBox box = new PictureBox(); box.Image = b; box.Width = SizeX; box.Height = SizeY; LoadedImgs.Add(box); Label l = new Label(); l.Text = DataOffset.ToString("X"); Labels.Add(l); b.RotateFlip(RotateFlipType.RotateNoneFlipY); string filepath = @"\textures\" + Path.GetFileName(open.FileName.Substring(0, open.FileName.Length - 4) + "-" + p + ".bmp"); b.Save(FolSelect.FileName + filepath); if (imgOffset == 0 && palOffset == 0) { imageNames.Add(" "); } else { imageNames.Add(FolSelect.FileName + filepath); } RList.Add(R.ToString()); GList.Add(G.ToString()); BList.Add(B.ToString()); imgOffList.Add(imgOffset); palOffList.Add(palOffset); FD = 0; lastImg = p; } else { lastImg = listImg; } } Connection c = new Connection(); c.Connection1 = Data[CurOffset + 5] / 2; c.Connection2 = Data[CurOffset + 6] / 2; c.Connection3 = Data[CurOffset + 7] / 2; //if (SizeX == 1 && SizeY == 1) c.mtlId = 0; //else c.mtlId = lastImg; Buf.connections.Add(c); //fMat.Add(p); } CurOffset += 0x08; } Temp.Add(Buf); //} } catch (Exception ex) { //MessageBox.Show(ex.Message); } } //get vertices & uvs AdditionalOffset = 1; foreach (DLObject obj in Temp) { try { int CurOffset = obj.DataOffset; for (int i = 0; i < obj.Length; i++) { Vector3 buf = new Vector3(); byte[] temp = new byte[2]; Array.Copy(Data, CurOffset, temp, 0, 2); if (BitConverter.IsLittleEndian) { Array.Reverse(temp); } buf.X = (float)BitConverter.ToInt16(temp, 0); temp = new byte[2]; Array.Copy(Data, CurOffset + 2, temp, 0, 2); if (BitConverter.IsLittleEndian) { Array.Reverse(temp); } buf.Y = (float)BitConverter.ToInt16(temp, 0); temp = new byte[2]; Array.Copy(Data, CurOffset + 4, temp, 0, 2); if (BitConverter.IsLittleEndian) { Array.Reverse(temp); } buf.Z = (float)BitConverter.ToInt16(temp, 0); string Builder = "v "; Builder += buf.ToString(); V.Add(Builder); //new Vector3 VertexTexture = new Vector3(); temp = new byte[2]; Array.Copy(Data, CurOffset + 8, temp, 0, 2); if (BitConverter.IsLittleEndian) { Array.Reverse(temp); } VertexTexture.X = (float)BitConverter.ToInt16(temp, 0) / 1024; temp = new byte[2]; Array.Copy(Data, CurOffset + 10, temp, 0, 2); if (BitConverter.IsLittleEndian) { Array.Reverse(temp); } VertexTexture.Y = (float)BitConverter.ToInt16(temp, 0) / 1024; VT.Add("vt " + VertexTexture.X.ToString() + " " + VertexTexture.Y.ToString()); AdditionalOffset++; CurOffset += 0x10; } } catch (Exception ex) { //MessageBox.Show(ex.Message); } } try { //get all faces AdditionalOffset = 1; foreach (DLObject obj in Temp) { foreach (Connection connection in obj.connections) { if (connection.Connection1 + AdditionalOffset <= V.Count && connection.Connection2 + AdditionalOffset <= V.Count && connection.Connection3 + AdditionalOffset <= V.Count) { string builder = "f "; builder += $"{connection.Connection1 + AdditionalOffset}{"/"}{connection.Connection1 + AdditionalOffset} {connection.Connection2 + AdditionalOffset}{"/"}{connection.Connection2 + AdditionalOffset} {connection.Connection3 + AdditionalOffset}{"/"}{connection.Connection3 + AdditionalOffset}"; F.Add(builder); fMat.Add(connection.mtlId); } } AdditionalOffset += obj.Length; } } catch (Exception ex) { //MessageBox.Show(ex.Message); } } catch (Exception ex) { //MessageBox.Show(ex.Message); } try { //SaveFileDialog mtl = new SaveFileDialog(); //mtl.Filter = "material file|*.mtl"; //res = mtl.ShowDialog(); //if (res == DialogResult.OK) //{ // string[] OutObj = generateMtl(mtl.FileName, imageNames,RList,GList,BList); // File.WriteAllLines(mtl.FileName, OutObj); //} //SaveFileDialog obj = new SaveFileDialog(); //obj.Filter = "object file|*.obj"; //res = obj.ShowDialog(); //if (res == DialogResult.OK) //{ // string[] OutObj = GenerateObj("name", mtl.FileName, V, VT, F,fMat); //new DLParser().GetParsedObject2(File.ReadAllBytes(open.FileName), imageOffsets, imageNames, mtl.FileName.Substring(0, mtl.FileName.Length - 4)); // File.WriteAllLines(obj.FileName, OutObj); //} string[] OutObj = generateMtl(FolSelect.FileName + @"\exported.mtl", imageNames, RList, GList, BList); File.WriteAllLines(FolSelect.FileName + @"\exported.mtl", OutObj); OutObj = new DLParser().GetParsedObject2(File.ReadAllBytes(open.FileName), imageOffsets, imageNames, (FolSelect.FileName + @"exported.mtl").Substring(0, (FolSelect.FileName + @"exported.mtl").Length - 4)); File.WriteAllLines(FolSelect.FileName + @"\exported.obj", OutObj); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public string[] GetExportedFunctions(UInt64 libraryBase) { try { HeaderReader header = new HeaderReader(ProcessDotNet, libraryBase); List<string> result = new List<string>(header.exports.Count); foreach (export function in header.exports.Values) { result.Add(function.Name); } return result.ToArray(); } catch { return new string[0]; } }
public List<UInt64> MemoryFindAll(string library, List pattern) { // Find the module List<MemoryFunctions.PROCESS_MODULE> modules = MemoryFunctions.EnumurateProcessModules(ProcessDotNet, !IsWin64); foreach (MemoryFunctions.PROCESS_MODULE module in modules) { if (module.Name.ToLower() == library.ToLower()) { HeaderReader header = new HeaderReader(ProcessDotNet, (UInt64) module.BaseAddress); return MemoryFunctions.MemoryFindAll(ProcessDotNet, (IntPtr) module.BaseAddress, header.optHeader.SizeOfImage, pattern.ToArray<object>()); } } return null; // No results }
public UInt64 GetProcedureAddress(IntPtr libraryBase, string procedure) { // Found the module, parse it's pe header in-memory try { HeaderReader header = new HeaderReader(ProcessDotNet, (ulong)libraryBase); foreach (export function in header.exports.Values) { if (function.Name.ToLower() == procedure.ToLower()) return function.Address; } } catch { throw new Exception("Unknown failure in Engine.GetProcedureAddress()."); } Console.WriteLine(string.Format("ERROR: Failed to call 'Engine.GetProcedureAddress()'. Was unable to resolve export {0}.", procedure)); return 0; }
public string[] GetExportedFunctions(string library) { // Find the module List<MemoryFunctions.PROCESS_MODULE> modules = MemoryFunctions.EnumurateProcessModules(ProcessDotNet, !IsWin64); foreach (MemoryFunctions.PROCESS_MODULE module in modules) { if (module.Name.ToLower() == library.ToLower()) { // Found the module, parse it's pe header in-memory HeaderReader header = new HeaderReader(ProcessDotNet, (UInt64) module.BaseAddress); List<string> result = new List<string>(header.exports.Count); foreach (export function in header.exports.Values) { result.Add(function.Name); } return result.ToArray(); } } return new string[0]; // No results }
public HeaderReader GetModuleHeader(string library) { // Find the module List<MemoryFunctions.PROCESS_MODULE> modules = MemoryFunctions.EnumurateProcessModules(ProcessDotNet, !IsWin64); foreach (MemoryFunctions.PROCESS_MODULE module in modules) { if (module.Name.ToLower() == library.ToLower()) { // Found the module, parse it's pe header in-memory HeaderReader header = new HeaderReader(ProcessDotNet, (ulong)module.BaseAddress); return header; } } return null; // No results }
public UInt64 GetProcedureAddress(string library, string procedure) { // Find the module foreach (System.Diagnostics.ProcessModule module in ProcessDotNet.Modules) { if (module.ModuleName.ToLower() == library.ToLower()) { // Found the module, parse it's pe header in-memory HeaderReader header = new HeaderReader(ProcessDotNet, (ulong)module.BaseAddress); List<string> result = new List<string>(header.exports.Count); foreach (export function in header.exports.Values) { if (function.Name.ToLower() == procedure.ToLower()) { return function.Address; } } } } return 0; }
public UInt64 GetProcedureAddress(HeaderReader header, string procedure) { // Found the module, parse it's pe header in-memory try { if( header.exports.Contains(procedure.ToLower()) ) { return ((export) header.exports[procedure.ToLower()]).Address; } } catch { throw new Exception("Unknown failure in Engine.GetProcedureAddress()."); } Console.WriteLine(string.Format("ERROR: Failed to call 'Engine.GetProcedureAddress()'. Was unable to resolve export {0}.", procedure)); return 0; }