private void btnInjectImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title = "Opem an image to be injected";
                ofd.Filter = "JPEG Image (*.jpg)|*.jpg|JPEG Image (*.jpeg)|*.jpeg";

                if ((bool)ofd.ShowDialog())
                {
                    byte[] newImage = File.ReadAllBytes(ofd.FileName);
                    EndianStream stream = new EndianStream(new MemoryStream(newImage), Endian.BigEndian);

                    // Check if it's a JIFI
                    stream.SeekTo(0x02);
                    string imageMagic = stream.ReadAscii();
                    if (imageMagic != "JFIF")
                        throw new Exception("Invalid image type, it has to be a JPEG (JFIF in the header).");

                    // Check if it's the right size
                    BitmapImage image = new BitmapImage();
                    image.BeginInit();
                    image.StreamSource = new MemoryStream(newImage);
                    image.EndInit();

                    if (image.PixelWidth != ((BitmapImage)imgBLF.Source).PixelWidth || image.PixelHeight != ((BitmapImage)imgBLF.Source).PixelHeight)
                        throw new Exception(string.Format("Image isn't the right size. It must be {0}x{1}", ((BitmapImage)imgBLF.Source).PixelWidth, ((BitmapImage)imgBLF.Source).PixelHeight));

                    // It's the right everything! Let's inject

                    List<byte> newImageChunkData = new List<byte>();
                    newImageChunkData.AddRange(new byte[] { 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 });
                    byte[] imageLength = BitConverter.GetBytes(newImage.Length);
                    Array.Reverse(imageLength);
                    newImageChunkData.AddRange(imageLength);
                    newImageChunkData.AddRange(newImage);

                    // Write data to chunk file
                    _blf.BLFChunks[1].ChunkData = newImageChunkData.ToArray<byte>();

                    _blf.RefreshRelativeChunkData();
                    _blf.UpdateChunkTable();

                    imgBLF.Source = image;

                    MetroMessageBox.Show("Injected!", "The BLF Image has been injected.");
                }
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show("Inject Failed!", "The BLF Image failed to be injected: \n " + ex.Message);
            }
        }
Beispiel #2
0
        private void StartupDetermineType(string path)
        {
            try
            {
                if (File.Exists(path))
                {
                    // Magic Check
                    var stream = new EndianStream(new FileStream(path, FileMode.Open), Endian.BigEndian);
                    stream.SeekTo(0);

                    switch (stream.ReadAscii(0x04))
                    {
                        case "head":
                            // Map File
                            stream.Close();
                            AddCacheTabModule(path);
                            return;

                        case "_blf":
                            // BLF Container, needs more checking
                            stream.Close();
                            var blf = new PureBLF(path);
                            blf.Close();
                            if (blf.BLFChunks.Count > 2)
                            {
                                switch (blf.BLFChunks[1].ChunkMagic)
                                {
                                    case "levl":
                                        AddInfooTabModule(path);
                                        return;
                                    case "mapi":
                                        AddImageTabModule(path);
                                        return;
                                }
                            }
                            MetroMessageBox.Show("Unsupported BLF Type", "The selected BLF file is not supported in assembly.");
                            return;

                        default:
                            MetroMessageBox.Show("Unsupported file type", "The selected file is not supported in assembly.");
                            return;
                    }
                }

                MetroMessageBox.Show("Unable to find file", "The selected file could no longer be found");
            }
            catch (Exception ex) { MetroException.Show(ex); }
        }