What's new

Trouble with binary reader

  • Thread starter DaftHacker
  • Start date
  • Views 370
Status
Not open for further replies.
DaftHacker

DaftHacker

Jet fuel can't melt steel beams
Programmer Forum Addict Fabled Veteran
Messages
2,606
Reaction score
917
Points
440
Sin$
7
Ok so what im trying to do is read an images length and then from the image length read the image and i have to use an int which is shorter than the byte or whatever length im suppose to read.

For example here is my code
Code:
                //IMAGE SIZE
                br.BaseStream.Position = 0x1712;
                int FirstImageSize = Convert.ToInt32(BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                //WHAT I READ LOOKS LIKE: 00 00 21 37 or 00 00 0C 0F

                //PICTURE
                br.BaseStream.Position = 0x171A;
                BitmapImage FirstBitmapImage = new BitmapImage();
                FirstBitmapImage.BeginInit();
                FirstBitmapImage.StreamSource = new MemoryStream(br.ReadBytes(FirstImageSize));
                FirstBitmapImage.EndInit();
                picture.Source = FirstBitmapImage;


So what i need is FirstBitmapImage.StreamSource = new MemoryStream(br.ReadBytes(0x2137));
but br.ReadBytes() will only allow either an int or 0x2137 in plain.
When i try to read the file using the int length the picture will only load a little.

Here is a picture of the file in hxd:
acdbf7042ab9c85c374b3a2252e56516.png
 
Im4eversmart

Im4eversmart

The hacks are real
Glitcher Modder Programmer
Messages
2,156
Reaction score
1,903
Points
455
Sin$
7
What is the value of FirstImageSize? Also, what do you mean when you say, "will only allow either an int or 0x2137 in plain."?
 
DaftHacker

DaftHacker

Jet fuel can't melt steel beams
Programmer Forum Addict Fabled Veteran
Messages
2,606
Reaction score
917
Points
440
Sin$
7
What is the value of FirstImageSize? Also, what do you mean when you say, "will only allow either an int or 0x2137 in plain."?
The value is whatever i read from the file, the image could be any size so first i read the image size and then from the image size i will read the image data, for example the image size could be: 2137
So i need to read 2137 bytes by putting it as an int in br.ReadBytes() but it didnt fully read the image so i put as 0x2137 in there plainly (image size not calculated) and it fully load the image but 0x2137 is too big for a single byte value and im not even sure if thats bigger then what im suppose to read. So my first problem is figuring out why br.ReadBytes() wont read the correct amount of bytes using (int)2137 and why it does fully read the image with 0x2137. My second problem is finding out if 0x2137 is bigger than (int)2137 and my third problem is figuring out what 0x2137 would even be that br.ReadBytes() will accept. Would that be a uint value or what ? Its too long for a byte value.
 
Im4eversmart

Im4eversmart

The hacks are real
Glitcher Modder Programmer
Messages
2,156
Reaction score
1,903
Points
455
Sin$
7
In this context, int is 32 bit, so it has 4 bytes of data. 0x2137 would be presentable as a signed or unsigned int. As far as converting 0x2137 to an int, which would change its representation to decimal, the decimal value of it is smaller than the hex's face value.

As for your code, you convert it to a string before converting it to an int32. A string 0x2137 is different from a byte array of 0x2137, which are both different from an int value of 2137.
 
Status
Not open for further replies.
Top Bottom
Login
Register