Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Understanding image bytes/ Sending image bytes through TCP

Hey, I'm here trying to send image bytes through TCP.
But it's not working.
I even tried to copy/paste the bytes manually and didn't work, why this?
🤝
(Dec 21, 2019 11:16 AM)C++ Wrote:  Hey, I'm here trying to send image bytes through TCP.
But it's not working.
I even tried to copy/paste the bytes manually and didn't work, why this?
🤝

Can you explain "copy/paste the bytes manually"
(Dec 21, 2019 11:54 AM)NYANxCAT Wrote:  Can you explain "copy/paste the bytes manually"

Opening notepad++, copying the whole text then pasting in another .png file.
its not working like this read the image bytes by io.file.readallbytes and send it
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
(Dec 21, 2019 02:56 PM)HFDone Wrote:  its not working like this read the image bytes by io.file.readallbytes and send it

I don't want to read the bytes of the image nor save the image somewhere. It's stored in bytes and I send it through TCP.
The example I gave above was just explaining that even if I tried to change the bytes of the .png won't work.
Read this:
https://princetonuniversity.github.io/PU...otcamp.pdf

Spoiler (Click to View)
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."
(Dec 21, 2019 06:07 PM)Washi Wrote:  Read this:
https://princetonuniversity.github.io/PU...otcamp.pdf

Spoiler (Click to View)

That is exactly why I stopped replying.
Here's an example with TcpClient (which is basically the same as a regular TCP Socket)

[Image: Syr3DlV.png]
Here's what I got:

After the TCP connection is made and receiving the bytes:
asd is the string that is received by TCP.
Code
byte[] asd1 = System.Text.Encoding.ASCII.GetBytes(asd);
                               using (Image image = Image.FromStream(new MemoryStream(asd1)))
                               {
                                   image.Save(fileName);  // Or Png
                               }
Throws out this expection: "System.ArgumentException: Parameter is not valid."
why you using string you cant do it like "Opening notepad++, copying the whole text then pasting in another .png file." theres few problems with it
giga gave you example and me too if you must use string then convert the image to base64 string and back
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
Yes but since I don't save the image I can't use the method you said.
Here's how I create the bytearray:


Bitmap memoryImage;
memoryImage = new Bitmap(1000, 900);
Size s = new Size(memoryImage.Width, memoryImage.Height);

Graphics memoryGraphics = Graphics.FromImage(memoryImage);

memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);

//That's it! Save the image in the directory and this will work like charm.
string fileName = string.Format(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
@"\Screen1shot" + "_" +
DateTime.Now.ToString("(dd_MMMM_hh_mm_ss_tt)") + ".png");

// save it
//memoryImage.Save(fileName);

byte[] byteArray = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
memoryImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Close();

byteArray = stream.ToArray();
}
Console.WriteLine(System.Text.Encoding.ASCII.GetString(byteArray));
return byteArray;
not going to bother to read the garbage you just posted, but you can just get the byte array of image, convert that to base64 string, then send that
(Dec 23, 2019 07:30 AM)C++ Wrote:  Here's what I got:

After the TCP connection is made and receiving the bytes:
asd is the string that is received by TCP.
Code
byte[] asd1 = System.Text.Encoding.ASCII.GetBytes(asd);
                              using (Image image = Image.FromStream(new MemoryStream(asd1)))
                              {
                                  image.Save(fileName);  // Or Png
                              }
Throws out this expection: "System.ArgumentException: Parameter is not valid."

As stated before in my previous reply, you really gotta be more specific if you want to get meaningful answers. There is a lot of things unclear in your posts.

What line or function call is it occurring? Why are you using strings to store the image data? What is meant by copied manually? An image is binary data, not textual data. This could very well be the core of your issues, though the only thing we can do is guess, as we cannot see the full picture or inside your head...

(Dec 25, 2019 01:45 PM)kelsin123j Wrote:  not going to bother to read the garbage you just posted, but you can just get the byte array of image, convert that to base64 string, then send that

Why would you transform the binary data to a base64 string if the socket network stream accepts binary data as input just fine?  ❓
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."
(Dec 25, 2019 05:40 PM)Washi Wrote:  As stated before in my previous reply, you really gotta be more specific if you want to get meaningful answers. There is a lot of things unclear in your posts.

What line or function call is it occurring? Why are you using strings to store the image data? What is meant by copied manually? An image is binary data, not textual data. This could very well be the core of your issues, though the only thing we can do is guess, as we cannot see the full picture or inside your head...


Why would you transform the binary data to a base64 string if the socket network stream accepts binary data as input just fine?  ❓

I solved it, but thanks for your help.
Lmfao jesus christ this thread was a train wreck.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by thejhexclamationFeb 16, 2020 06:14 PM 3 198 Feb 16, 2020 06:14 PM
Last Post: b3twiise
[Python] by Vishnu™May 6, 2018 02:15 AM 4 205 May 6, 2018 02:15 AM
Last Post: Blackshield_real
[C#] by trueJan 26, 2017 10:06 PM 6 335 Jan 26, 2017 10:06 PM
Last Post: Ninja