Jump to content

cbox


Recommended Posts

Posted (edited)

Injecting Images in C#

 

Ok, so before using this tutorial I recommend you mess around with the language a little bit. Follow my other tutorial on how to show images then, I am sure you will be ready for this.

Note: In this tutorial I will only be showing pictures of the code, I want you to get used to typing it rather then copy and pasting.

Overview of process:

  1. Open a file.
  2. Show the image in the container header.
  3. Add an option to save the image.
  4. Add an option to inject the image.

Ok, so open C# create a new windows app and name it whatever you want. In this case I will be naming it iBotModz.

 

Be sure to do our usual steps to the form to make sure no one can resize it or maximize it. Go to tutorial 1 for that.

 

Now, add 3 buttons and name them "Open", "Extract", and "Inject". Also add a picturebox to your form. It should look like:

 

post-2-125608282016_thumb.png

 

Notice we made the picturebox's properties to "stretch" so the image will fill the full box.

 

Now, double click the "open button" so that the code will appear. Now, instead of using a textbox like last time, we will be using a string. The string will act as an 'invisible' textbox. The code for a string looks like so:

 

post-2-125608282087_thumb.png

 

Below it is the OpenFileDialog coding as well. Input that and your code should look exactly like mines.

 

Ok, now we want to add a class so that when we open a file, the image will automatically load. To input this, we add a 'void'. Enter the void like so:

 

post-2-125608282159_thumb.png

 

If you noticed I added that class to the OpenFileDialog result box. That will make this void automatically occur when a file is opened. Now we need to add some code to this void. The code we will add will display the image in the picture box. Just like my previous tutorial we will need to add the IO into the namespace. If you don't know how to do that just enter this at the top:

 

using System.IO;

 

Now in our void we will add the following code:

 

post-2-125608282243_thumb.png

 

Explanation of code:

  • FileStream fs is creating the 'browsing' of the file. It is what opens the file and makes it readable like in a hex editor.
  • BinaryReader br is what will read ASCII or hex for you.
  • The BaseStream.Position is the offset you will be on.
  • Creating the stream is what will read the image from hex and send it to memory so it can be used at a different time in the code.
  • Then we load the image from the stream to show it.

Now, debug you app and load a CON file. It should work flawlessly. Now we are ready to move on to the next part which is extracting or saving the image.

 

Go double click your "extract button" so that you can enter code for it.

 

post-2-12560828193_thumb.png

 

Explanation of code - All you are really doing here is creating a SaveFileDialog and saving the image that is in the picturebox. This code is pretty self-explanatory.

 

Now debug it, at it should now be able to save images. Now, the hard part... Injecting images.

 

Go double click on your inject button to bring up the code. Just type in this following code and read the explanation after:

 

post-1274-1237226027_thumb.png

 

Explanation of code:

  • The open file dialog is going to allow the user to select the image he/she wants.
  • The filestream imageReader is going to be used for reading the image selected.
  • The byte[] imageLength is getting the length of the image they select and declaring it as a byte[] (which is basically bytes)
  • Then the BinaryReader br is going to read the image.
  • The int data is basically getting the length of the file in a decimal or integer rather then in hex data.
  • Then we reset the postition to 0.
  • Now, we read the whole image. The whole process above gives us a 'read to end' method.
  • We then close them streams and open new ones for the container to inject.
  • We declare a BinaryWriter and set the position to the image beginning.
  • We need to create a loop (while) in order to null out the original image will null bytes. This prevent your image from being smaller and writing and then having all excess data at the end from the old image.
  • We then reset the position to the image beginning and write the image.
  • We input the showImage class to make the new image display.
  • We close our streams.

Now, that is really hard and advanced, but if you get that down, you are set to move on. That was something I just learned and it can probably be done many different ways, so if someone has another way, let me know.

Now, debug your app and bam! You can now open, extract, and inject images.

Edited by iBotPeaches
Fixed Images.
Posted
Nice tut keep it up. Also I'm more used to VB so I tried writing this in Vb and I have this one error. It says "Image.FromStream" is not a member of System.IO so I tried writing it differently and it still didn't work so I tried converting it using a Vb to C# converter and It still didn't work. I know your more into C#, but I thought I'd ask if you knew whats wrong.
Posted (edited)

Are you declaring your Stream properly?

 

Dim image As Stream = New MemoryStream(location)

pictureBox1.Image = Image.FromStream(image)

 

^ That is VB.NET, anyone following this tut don't pay attention to that reply lol.

Edited by yungbol
Posted (edited)

Ok, lol I just installed VB.NET and made it no problem. Here is the code for VB.NET:

 

Dim fs As New FileStream(TextBox1.Text, FileMode.Open)
       Dim br As New BinaryReader(fs)
       br.BaseStream.Position = &H171A
       Dim imaged As New MemoryStream(br.ReadBytes(16000))
       PictureBox1.Image = Image.FromStream(imaged)

 

vb.net gets confused here and there... another reason I use c#.

 

The reason why I changed it to imaged was because when you put image it would get confused from the one with the capital I. C# is case-sensitive, that is why it was different. You also need to declare the MemoryStream as it's own, not as a Stream.

Edited by yungbol
Posted

bw.BaseStream.Position = 0x1712;

bw.Write(imageLength);

bw.Write(imageLength);

 

If you're replacing both PNGs that fixes the lengths I believe (no files or hex editor on this computer ATM :/). Just thought I'd add that :p

Posted
Yea lol, so it makes it proper to read the image. I don't think it has any effect on the file though... I don't know but in all my image readers I am more lenient and make it read 16000 bytes rather then the int before the PNG.
  • 1 month later...
Posted

I got about this far then i started getting some errors

 

http://i211.photobucket.com/albums/bb95/element18592/Yungbolhelp.jpg

 

 

then i went a little bit further and got all this

 

 

http://i211.photobucket.com/albums/bb95/element18592/yungbolhelp2.jpg

 

 

 

 

 

Please tell me, what am i doing wrong???

  • Like 1
Posted (edited)

Your problem is letter case. Example:

 

Openfiledialog should be OpenFileDialog.

 

C# is a case sensitive language.

 

Also, I just noticed your brackets are backwards. Your code should look exactly like mines in the first post.

Edited by yungbol
Posted
Your problem is letter case. Example:

 

Openfiledialog should be OpenFileDialog.

 

C# is a case sensitive language.

 

Also, I just noticed your brackets are backwards. Your code should look exactly like mines in the first post.

 

ok thanks a lot guys

  • Like 1
Posted
Dude, you act like I don't know that, I could read the Int32 if I wanted to.. But some programs that inject (Modio) don't fix that Int32 so mines reads the max size.
Posted

ok i got everthing else to work correctly now im having trouble with the inject part...i just cant seem to get it working...can somebody please point out what i need to do?

 

 

 

http://i211.photobucket.com/albums/bb95/element18592/Inject.jpg

 

 

 

http://i211.photobucket.com/albums/bb95/element18592/ErrorList.jpg

  • Like 1
Posted

What Peaches said. In hex there are no O's, it is a 0.

 

Also, I noticed that you had a "," where it should be a "=".

 

And Peaches, everyone is always still learning.

  • 5 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...