Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Modify Jpeg via BinaryWriter renders "useless" output

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard Coltrane - 17 Feb 2008 21:21 GMT
Hello,

If i take a jpeg and pipe it from a binary reader to a binary writer,
everything is fine and I can still use it.
If i take that same jpeg and piping code and simply add a byte encoded
string to the front of the file then I can no longer open it in an image
editor. This i would expect.

However if i open that image in notebook and remove the string I entered,
then i still cant open the file in an image editor, does anyone know why
this is?? Once ive removed the 4 character string with notepad the files are
"seemingly" exactly the same?? They have precisely the same file size (down
to the byte) and the bytes within the file are also exactly the same??

Whats different?

Thanks
Jon Skeet [C# MVP] - 17 Feb 2008 21:40 GMT
> If i take a jpeg and pipe it from a binary reader to a binary writer,
> everything is fine and I can still use it.
[quoted text clipped - 9 lines]
>
> Whats different?

That's almost certainly due to using notepad rather than anything the
.NET code is doing. When anything tries to interpret arbitrary binary
data as text it's very easy to lose information.

Take the .NET code out of the equation by doing the same steps manually
with your text editor and you're likely to see the exact same
behaviour. If you don't, we'd need to see the actual code involved.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Richard Coltrane - 18 Feb 2008 21:41 GMT
Hi there,

You're right.

But if i do a byte by byte comaprision the files (the original vrs the
modified after i use notepad to take out the test string and then save the
file) they are still the same?
So if i was removing or altering something other than the 4 byte test string
surely the file contents would be different.

Is this something to do with the os file system itself?? Other than
partition types etc, I didn't realise the file system actually "defined" the
file. I thought the whole idea of the file was that it encapsulated its own
meaning??

Thanks

>> If i take a jpeg and pipe it from a binary reader to a binary writer,
>> everything is fine and I can still use it.
[quoted text clipped - 19 lines]
> with your text editor and you're likely to see the exact same
> behaviour. If you don't, we'd need to see the actual code involved.
Jon Skeet [C# MVP] - 18 Feb 2008 22:13 GMT
> You're right.
>
> But if i do a byte by byte comaprision the files (the original vrs the
> modified after i use notepad to take out the test string and then save the
> file) they are still the same?

How are you doing the comparison?

> So if i was removing or altering something other than the 4 byte test string
> surely the file contents would be different.

Yes, and I suspect you'll find they *are* different.

> Is this something to do with the os file system itself?? Other than
> partition types etc, I didn't realise the file system actually "defined" the
> file. I thought the whole idea of the file was that it encapsulated its own
> meaning??

No, I suspect it's more likely to be to do with opening the file in
Notepad, and the way you're comparing the two files.

If you've got two files with the same contents and file A opens up fine
as a JPEG, then I would expect file B to open fine likewise.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Richard Coltrane - 19 Feb 2008 21:34 GMT
Hi there,

Im using a couple of binary reader to loop through each byte in each file in
sequential order and doing a compare on each byte.... although i suspect a
simple hash would work just as well.

Reversing the process as per Hans suggestion gives me back a useable Jpeg
which in turn supports your idea that its notepad... which makes sense....
but i cant find the "difference" between the two files.

Thanks

>> You're right.
>>
[quoted text clipped - 23 lines]
> If you've got two files with the same contents and file A opens up fine
> as a JPEG, then I would expect file B to open fine likewise.
Jon Skeet [C# MVP] - 19 Feb 2008 22:43 GMT
> Im using a couple of binary reader to loop through each byte in each file in
> sequential order and doing a compare on each byte.... although i suspect a
[quoted text clipped - 3 lines]
> which in turn supports your idea that its notepad... which makes sense....
> but i cant find the "difference" between the two files.

That suggests that your comparison code is broken. Could you post it?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Lasse Vågsæther Karlsen - 20 Feb 2008 07:36 GMT
> Hi there,
>
[quoted text clipped - 7 lines]
>
> Thanks

<snip replies from Jon>

Try using the command line file comparison tool built into Windows:

fc /B a.jpg b.jpg

The /B is just to make sure you're using a binary comparison, since I do
not know the heuristics involved in determining if the files are text.

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

Peter Bromberg [C# MVP] - 17 Feb 2008 22:52 GMT
If your goal is to embed messages into images, you want to look into
steganography. Corinna Johns has a series of articles on codeproject.com on
the subject.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: htp://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net

> Hello,
>
[quoted text clipped - 13 lines]
>
> Thanks
Richard Coltrane - 18 Feb 2008 21:43 GMT
Hi Peter,

no it wasn't but thanks for the response, ive always wonderd what that was
called. Spies and school kids use that stuff right?

> If your goal is to embed messages into images, you want to look into
> steganography. Corinna Johns has a series of articles on codeproject.com
[quoted text clipped - 24 lines]
>>
>> Thanks
Hans Kesting - 18 Feb 2008 10:56 GMT
Richard Coltrane formulated on zondag :
> Hello,
>
[quoted text clipped - 13 lines]
>
> Thanks

Try using your own process in reverse: use a .Net program to strip
those first bytes and leave the rest of the data intact.
I suspect that that *will* work (see the other replies)

Hans Kesting

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.