[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Retrieved GIF image from SNMP Device and its not valid, why? (Fix my GIF please!)

I am retrieving the contents of the display panel of a printer in the form of a GIF image.
(More information here http://www.mibdepot.com/cgi-bin/getmib3.cgi?i=1&n=LJ4200-MIB&r=hp&f=lj4200.mib&v=v1&t=sca&o=control-panel-display-graphical-contents )

I am able to retrieve the OID and using GetNext, obtain the remaining chunks of the image in this tree.  I used StreamWriter to directly write the values to a file (each SNMP octet stream is directly written to the filestream)  The first 480 bytes came in the first GET and then an additional 5 bytes in the second GET

But for some reason the image isn't valid.  I looked at the output in a hex editor and there are 4 bytes _before_ the "GIF89a" header.  I tried removing the first 4 bytes of the file but no luck.
The invalid GIF can be found here: http://www.ls1powered.net/test1.gif << Try saving it locally and looking at it in a hex editor.  

  Does anyone know what's wrong with this GIF?
If you figure out what's wrong with the file, I need to know what portion of the file was changed to make it valid.
0
masoncooper
Asked:
masoncooper
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
How did you write the file?  Did you wait for both parts before you wrote the file to disk?

Bob
0
 
masoncooperAuthor Commented:
Here is the code I used to retrieve the values:

Dim selector As String = "1.3.6.1.4.1.11.2.3.9.4.2.1.1.2.65"

            Dim response As SnmpResponse = snmp.GetNext(selector, 3)

         
            Dim sw As StreamWriter

            sw = New StreamWriter("C:\test.gif")

            While response.ErrorStatus = 0
                Dim oid As String = response.VariableBindings(0).OID.ToString

                If selector.Length > oid.Length Or selector <> oid.Substring(0, selector.Length) Then
                    Exit While
                End If


                response.VariableBindings(0).Value.Write(sw.BaseStream)

                Console.WriteLine("Bytes Written: " & response.VariableBindings(0).Value.Size)
                response = snmp.GetNext(response.VariableBindings(0).OID.ToString(), 3)

            End While
            sw.Flush()
            sw.Close()
            Console.WriteLine("Done")
0
 
masoncooperAuthor Commented:
Ok, I've made some progress here, contrary to what I said earlier, If I delete the leading 4 bytes from the file, it displays in Internet Explorer, minus a tiny sliver (see http://www.ls1powered.net/test2.gif )

But the file still isn't valid.  If I try and do an Image.FromFile in VB.Net, it throws an exception "Out of Memory", my guess is that it still isn't a properly formed GIF
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Bob LearnedCommented:
Is it my imagination, or does that function return an octet string?  I would try using a BinaryWriter, instead of StreamWriter, and write the bytes to the file.

Bob
0
 
masoncooperAuthor Commented:
TheLearnedOne, Thanks for the tip, I forgot about that, but yes, the file is still writing the same even after using the binarywriter (my guess is that its because the SNMP object is using the .baseStream object to write the data)

In the meantime, I _did_ come up with a perfectly valid GIF.
If you look at the image test2.gif (mentioned in the comments), and remove the leading 4 bytes, then remove 2 bytes that are 5 bytes from the end, they should be 0x04 0x05 and then the file is valid!  What strikes my attention is that the chunks were 480 bytes and 5 bytes, leading me to believe that the first two bytes of the second chunk were garbage.  As far as I can tell, its not so, because applying that theory to other images obtained from this process do not yield the same result.

Here is another image, this one also came in two chunks but I had it write the streams out as two separate chunks IN ADDITION to the original portion that writes it all as one:
First Chunk: http://www.ls1powered.net/bTestFirst.gif
Second Chunk: http://www.ls1powered.net/bTestLast.gif
Product of both chunks: http://www.ls1powered.net/bTestAll.gif
I wanted to be certian that the streams were being written properly and that no additional data was being appended.
0
 
LunchyCommented:
Closed, 500 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now