Skip to content

Instantly share code, notes, and snippets.

@hasherezade
Last active July 27, 2021 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasherezade/fc83a1b2946bb36f579b590fc09a4733 to your computer and use it in GitHub Desktop.
Save hasherezade/fc83a1b2946bb36f579b590fc09a4733 to your computer and use it in GitHub Desktop.
A simple app to decode #PurpleFoxEK stegano payloads
using System;
using System.Drawing;
using System.IO;
namespace PurpleFoxPNGDec
{
internal class Program
{
public static int getPrintableLen(byte[] array)
{
int i = 0;
for (i = 0; i < array.Length; i++)
{
byte c = array[i];
var isPrintable = (c >= 0x20 && c < 0x7f) || Char.IsWhiteSpace((char)c);
if (!isPrintable)
{
break;
}
}
return i;
}
public static byte[] decode(Bitmap bm, int maxX, int maxY)
{
byte[] outData = new byte[maxX * maxY];
for (int i = 0; i < outData.Length; i++)
{
outData[i] = 0;
}
for (int y = 0; y < maxY; y++)
{
for (int x = 0; x < maxX; x++)
{
Color pixel = bm.GetPixel(x, y);
outData[y * maxX + x] = (byte)(pixel.B * 16 | pixel.G & 0xF);
}
}
return outData;
}
private static int Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Decoder for Purple Fox stegano components");
Console.WriteLine("Arguments: <input: PNG> <ouput: decoded>");
Console.ReadKey();
return 0;
}
string inPath = Path.GetFullPath(args[0]);
string outPath = Path.GetFullPath(args[1]);
Console.WriteLine(inPath);
Bitmap bitmap = new Bitmap(inPath);
int maxX = bitmap.Width;
int maxY = bitmap.Height;
byte[] array = Program.decode(bitmap, maxX, maxY);
int len = getPrintableLen(array);
Console.WriteLine("Decoded size: " + len);
Array.Resize(ref array, len);
try {
File.WriteAllBytes(outPath, array);
} catch (Exception e)
{
Console.Write("[ERROR]" + e.Message);
return (-1);
}
Console.Write("Saved output to: " + outPath);
return 0;
}
}
}
@hasherezade
Copy link
Author

hasherezade commented Jul 27, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment