Esempio n. 1
0
 private void ExportSnippet(TextWriter writer, Stream stream, int offset, int size)
 {
     using (PartialStream snippetStream = new PartialStream(stream, offset, size))
     {
         int decodedSize = SmolvDecoder.GetDecodedBufferSize(snippetStream);
         if (decodedSize == 0)
         {
             throw new Exception("Invalid SMOL-V shader header");
         }
         using (MemoryStream decodedStream = new MemoryStream(new byte[decodedSize]))
         {
             if (SmolvDecoder.Decode(stream, size, decodedStream))
             {
                 decodedStream.Position = 0;
                 Module module  = Module.ReadFrom(decodedStream);
                 string listing = m_disassembler.Disassemble(module, DisassemblyOptions.Default);
                 ExportListing(writer, listing);
             }
             else
             {
                 throw new Exception("Unable to decode SMOL-V shader");
             }
         }
     }
 }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("No argument. Provide a path to smolv shader");
            }
            else if (!File.Exists(args[0]))
            {
                Console.WriteLine($"File {args[0]} doesn't exists");
            }
            else
            {
                byte[] data     = null;
                string filePath = args[0];
                using (FileStream fs = File.OpenRead(filePath))
                {
                    data = new byte[fs.Length];
                    fs.Read(data, 0, data.Length);
                }

                byte[] decoded = SmolvDecoder.Decode(data);
                if (decoded == null)
                {
                    Console.WriteLine("Unable to decode smolv shader");
                }
                else
                {
                    string dirPath       = Path.GetDirectoryName(filePath);
                    string fileName      = Path.GetFileNameWithoutExtension(filePath);
                    string fileExtension = Path.GetExtension(filePath);
                    string newFilePath   = Path.Combine(dirPath, fileName + "_unpacked" + fileExtension);
                    using (FileStream fs = File.Create(newFilePath))
                    {
                        fs.Write(decoded, 0, decoded.Length);
                    }
                    Console.WriteLine("Finished");
                }
            }

            Console.ReadKey();
        }
Esempio n. 3
0
        private static string ExportSnippet(Stream stream, int offset, int size)
        {
            stream.Position = offset;
            var decodedSize = SmolvDecoder.GetDecodedBufferSize(stream);

            if (decodedSize == 0)
            {
                throw new Exception("Invalid SMOL-V shader header");
            }
            using (var decodedStream = new MemoryStream(new byte[decodedSize]))
            {
                if (SmolvDecoder.Decode(stream, size, decodedStream))
                {
                    decodedStream.Position = 0;
                    var module       = Module.ReadFrom(decodedStream);
                    var disassembler = new Disassembler();
                    return(disassembler.Disassemble(module, DisassemblyOptions.Default).Replace("\r\n", "\n"));
                }
                else
                {
                    throw new Exception("Unable to decode SMOL-V shader");
                }
            }
        }