This C # program can hide the text file in the bitmap, or can be exported

xiaoxiao2021-03-06  106

// How to use: // bmpsafe.exe / file2BMP (Input File] // bmpsafe.exe / bmp2file (data bmp) [Output File] Using System; use system.io; using System.drawing;

Public Class Bitmap24writer {Protected Bitmap Bmp; Protected Int Curx, Cury, Irgb; Protected Uint BitsLesleft, BitStotal; Protected Byte R, G, B;

public Bitmap24Writer (Bitmap bmp) {if (bmp.PixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb!) throw new ArgumentException (); // assign vars curX = curY = iRGB = 0; this.bmp = bmp; bitsLeft = BitStotal = (uint) bmp.height * (uint) bmp.width * 3;}

Public uint getunusedbit () {return bitsLesLes

Public uint getmaxbitostoragecount () {return bitstotal;}

Public Bitmap getBitmap () {Return BMP;}

Public Bool WritebyTe (BYTE BY) {IF (BitsLesleft <8) Return False;

Uint bits2do = 8;

For (; curX = bmp.height) CURY = 0;

For (; CURY

Color color color (curX, cury); r = col.r; g = col.g; b = col.b;

For (;;) {byte curbit = (byt) (by & 1);

Switch (IRGB) {Case 0: R = (Byte) (R & 0xfe); R | = Curbit; Break;

Case 1: g = (Byte) (g & 0xfe); g | = Curbit; Break;

Case 2: B = (BYTE) (B & 0xfe); B | = Curbit; Break;} --BITS2DO; --BITSLEFT; BY >> = 1; Bmp.Setpixel (Curx, Cury, Color.Fromargb (R, g, b)); if (IRGB == 2) {IRGB = 0; Break;} IRGB ; if (bits2do == 0) Return true;}}} Return True;}}}}}}}}}}}}}}}}} Return True;}} public class bitmap24reader {Protected Bitmap bmp; protected Int Curx, Cury, Irgb; Protected uint BitsLesleft, BitStotal

public Bitmap24Reader (Bitmap bmp) {if (bmp.PixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb!) throw new ArgumentException (); curX = curY = iRGB = 0; this.bmp = bmp; bitsLeft = bitsTotal = (uint ) bmp.height * (uint) bmp.width * 3;}

Public uint getunusedbit () {return bitsLesLes

Public uint getmaxbitostoragecount () {return bitstotal;}

Public Bitmap getBitmap () {Return BMP;}

Public Bool ReadByte (Out byte by) {by = 0;

IF (BitsLesleft <8) Return False;

Byte bit = 0; uint bits2do = 8; for (; curX = bmp.height) Cury = 0;

For (; CURY

Color col = bmp.getpixel (curx, cury); for (;;) {switch (IRGB) {cas 0: bit = (byte) (col.r & 1);

Case 1: Bit = (Byte) (Col.g & 1); Break;

Case 2: Bit = (Byte) (Col.b & 1); Break;} --bits2do; --bitsLeft; BY | = (BITE) (BitS2Do! = 0) BY >> = 1; if (IRGB == 2) {IRGB = 0; Break;} IRGB ; if (bits2do == 0) Return true;}}} Return true;}} public class bitmapworks}} public class bitmapworks {public static bool data2bmp (Filestream DataStream, FileStream Bmpstream, String Outfname, Out String Error) {Error = "";

Bitmap bmp; try {bmp = new Bitmap (bmpStream);} catch {error = "Are you sure the specified bitmap is a valid bitmap?"; Return false;}! If (bmp.PixelFormat = System.Drawing.Imaging.PixelFormat .Format24bpprgb) {Error = "please drop" "} false;}

Error = "-> Bitmap info: height =" bmp.height "width =" bmp.width "... / n";

IF (DataStream.Length == 0) {Error = "INPUT DATA HAS A Not Supported Size Of 0!"; Return False;} uint maxBytestorage = ((uint) bmp.height * (uint) bmp.width * 3) / 8; Error = "-> Up to" (MaxBytestorage-4) "Bytes Could Be Stored in this Bitmap ... / n"; if (MaxBytestorage

Bitmap24writer bmpwriter = new bitmap24writer (bmp); uint dataize = (uint) DataStream.Length; try {for (uint u = 0; u <4; u ) {bmpWriter.writebyte (Byte) DataSize; DataSize >> = 8 } For (uint u = 0; u

Try {if (file.exists (outfname)) file.delete (outfname); bmpwriter.getbitmap (). save (outfname);} catch {error = "COULDN'T Save Output to" Outfname "!"; Return False;}

Error = "-> Output Saved TO:" Outfname "... / N";

Return True;}

Public Static Bool B Mp2Data (FileStream Bmpstream, String Outfname, Out String Error) {Error = "

Bitmap bmp; try {bmp = new bitmap (bmpstream);} catch {error = "Are you sute the specified bitmap is a valid bitmap?"; Return False;}

Bitmap24reader bmpreader; try {bmpreader = new bitmap24reader (bmp);} catch (argumentexception) {error = "this isn't a 24bit bitmap!"; Return false;}

FileStream outStream; try {outStream = File.Create (outFName);} catch {error = "Could not create output file:" "!" OutFName ; return false;} uint dataSize = 0; byte outByte; try {for (uint u = 0; u <4; u ) {if (! bmpreader.readByte (out outbete)) throw new exception (); dataize | = (uint) (Outbyte << 8 * 3); if (u! = 3) DATASIZE >> = 8;} error = "-> Size of hidden data:" DataSize "bytes ... / n"; for (uint u = 0; u

Return True;}

}

Class bmpsafe {public static string cmdline = "Command line: / n" "BMPSAFE.EXE / FILE2BMP (INPUT BMP) [OUTPUT FILE] / N" "bmpsafe.exe / bmp2file (Data BMP) [OUTPUT FILE] "

Private static string serviceOne = "/ file2bmp"; private static string service; "/ bmp2file";

[Stathread] static void main (string [] args) {console.writeline ("bmpsafe - hide files in 24bit bitmaps / n" a little steganografie usteation / n " " by yoda / n " " ---- -------------------------------------------------- ----------------------- / n ");

String infile = "", INBMP, OUTFILE; BOOL BFILE2BMP; IF (Args.Length <2) {Console.Writeline ("! Invalid Number of Arguments: ("); console.writeline (cmdline); return; // err } IF (string.Compare (args [0], serviceOne, true) == 0) bfile2bmp = true; else if (string.compare (args [0], serviceetwo, true) == 0) bfile2bmp = false; else { Console.writeline ("!! first parameters must be each either /" / file2bmp / ​​"ory); return;} inBMP = args [1]; if (bfile2bmp) {ix (args.length < 3) {Console.Writeline ("!); Console.writeline (cmdline); return;} infile = args [2]; if (args.length> 3) Outfile = args [3] Else outfile = "secret.bmp";} else {if (args.length> 2) Outfile = args [2]; else outfile = "secret.bin";} console.writeline ("-> processing input ... "); Try {string err; bool ret;

IF (bFile2BMP) Ret = BitmapWorks.data2bmp (file.openread (Infile), File.Openread (Inbmp), Outfile, Out Err); Else Ret = BitmapWorks.Bmp2Data (Inbmp), Outfile, Out Err); IF (!! err); return;} else console.write (err); filenotfoundexception {console.writeline ("!! at Least One File Could Not Be found :( "); Return;} catCh {console.writeline (" !! an exception}; Return;

Console.writeline ("-> Job Done ...");

Return;}}

转载请注明原文地址:https://www.9cbs.com/read-104626.html

New Post(0)