c# - How can I convert a binary file to another binary representation, like an image -
I want to take a binary file (exe, msi, dll, whatever) and actually look at "binary" Enabled code or whatever base I like (hexadecimal whatever) is the easiest way to output one code to a textile, so I can check it.
What is the best and easiest way to do this? Actually I want to convert binary code into a picture for one of my projects.
Similarly, if I can take some binary code, then it will be nice and then convert it to a binary file.
What are your methods to do this, I have listed C, C ++ and C # because they are the fastest programming languages and I thought it might take some time. I think I am more interested in the answer in C, but I am looking for some arguments behind this.
Here's a way to pack byte in images ... The funny part is that if you If you record the length of the original file and use a lossless image format, you can safely remove the binary data later.
has been packaged as ARG ...
var exefile = Directory.GetFiles (" . "," * .exe "). first (); Var fi = new file info (xfile); Var dimension = (int) Math.Sqrt ((fi.Length + 1d) / 4); (Keep the length of the first pixel of the file // using the file bitmap = new bitmap (dimension, dimension + 2)). Bitmap.setpixel (0, 0, color. Formarb.bb (int));) Var buffer = new byte [fi. Long + 4 - fi. Length% 4]; Array.Copy (File. Redlabettes (Eximble), Buffer, Final Lange); Int x = 1, y = 0; (Var offset = 0; offset & lt; buffer length; offset + = 4) {var colorValue = BitConverter.ToInt32 (buffer, offset); Bitmap.setPixel (x, y, color.fromArgb (colorValue)); X ++; If (x> = dimension) {x = 0; Y ++; }} Bitmap.Save (Path.ChangeExtension (exefile, ".png"), ImageFormat.Png); }
Packed as Black End; White binary ...
var width = (int) Math.Sqrt (fi.Length * 8); Width = width + 8 - (width% 8); Var length = (int) (fi length * 8 / width); Function & lt; Byte, Int, Color & gt; Getcolor = (B, M) => (B & M) == M? Colour. Black: Color. White; (Var bitmap = using new bitmap (width, length + 1)) {var buffer = file. Reducers (exefile); Int x = 0, y = 0; Fresh (var @by fur buffer) {bitmap.setPixel (x + 0, y, getcolor (bybyte, 0x80)); Bitmap.setpixel (x + 1, y, getcolor (bybyte, 0x40)); Bitmap.setpixel (x + 2, y, getcolor (bybyte, 0x20)); Bitmap.setPixel (x + 3, y, getcolor (bybyte, 0x10)); Bitmap.setPixel (x + 4, y, getcolor (bybyte, 0x8)); Bitmap.setPixel (x + 5, y, getcolor (bybyte, 0x4)); Bitmap. SetPixel (x + 6, y, getcolor (bybyte, 0x2)); Bitmap.setPixel (x + 7, y, getcolor (@byte, 0x1)); X + = 8; If (x> = width) {x = 0; Y ++; }} Bitmap.Save (Change Path Extension (exefile, ".tif"), ImageFormat.Tiff); }
... and yes, it looks like noise
Comments
Post a Comment