locked
Replacing JPG File inside a File RRS feed

  • Question

  • hi I am new in here and New in vb.net, I have question that very difficult for me, I have one File that contains 2 Image File in footer of File, The Image File is Jpg and Bmp File, in Offset 200 of File contain Jpg File and in end of Size Jpg File, there are BMP File.

    For Example The Size of Jpg File is 250 bytes then that mean Bmp File Start in Offset 451, in end of Bmp File is end of File...

    I think if you replacing Jpg with size more than 250 bytes the BMP will changed...

    Now how to replace jpg File without changing / damaging the Bmp File?

    Sorry if my english is bad, thanks!


    • Edited by ChronoCross Thursday, September 29, 2011 2:22 PM
    Thursday, September 29, 2011 2:16 PM

Answers

  • Manipulating file content can corrupt the file if it doesn't match the file format anymore. That's why I asked about the file format.

    If you want to insert something into a file, you can either manipulate the file itself, or, the way that I prefer, create a new file. Afterwards, you can delete the original file and rename the new one. To do this, first copy part 1 of the original file to the new file, then write the part to be inserted, then copy part 2 of the original file. You know the System.IO namespace already to do this?

    Be aware that this also changes the creation date of the file even though it's considered as a modification, which should alter the LastWriteTime only.


    Armin
    • Edited by Armin Zingler Thursday, September 29, 2011 2:52 PM
    • Proposed as answer by Mike Feng Monday, October 3, 2011 7:56 AM
    • Marked as answer by Mike Feng Tuesday, October 11, 2011 2:56 AM
    Thursday, September 29, 2011 2:52 PM

All replies

  • Without a documentation of the file format, I wouldn't change the file at all. What file type is it?
    Armin
    Thursday, September 29, 2011 2:22 PM
  • Without a documentation of the file format, I wouldn't change the file at all. What file type is it?
    Armin

    hmm its lot of the file using this method, but the offset is different, usually the starting offset of jpg is stored in other offset and its fixed data and the bmp is right after jpg data, for example of type is .bms

    btw why you need type of file? I just need to write jpg in a file without damaging / changing existing bmp data after the data of jpg... oh yea, I am not using it for bms file, I just want to make own file that store jpg and bmp and can be replaced anytime with my program... and please don't ask me to select other method...

    btw thanks for reply and sorry if my english so bad


    • Edited by ChronoCross Thursday, September 29, 2011 2:40 PM
    Thursday, September 29, 2011 2:34 PM
  • Manipulating file content can corrupt the file if it doesn't match the file format anymore. That's why I asked about the file format.

    If you want to insert something into a file, you can either manipulate the file itself, or, the way that I prefer, create a new file. Afterwards, you can delete the original file and rename the new one. To do this, first copy part 1 of the original file to the new file, then write the part to be inserted, then copy part 2 of the original file. You know the System.IO namespace already to do this?

    Be aware that this also changes the creation date of the file even though it's considered as a modification, which should alter the LastWriteTime only.


    Armin
    • Edited by Armin Zingler Thursday, September 29, 2011 2:52 PM
    • Proposed as answer by Mike Feng Monday, October 3, 2011 7:56 AM
    • Marked as answer by Mike Feng Tuesday, October 11, 2011 2:56 AM
    Thursday, September 29, 2011 2:52 PM
  • What program generates the .bms files?

    Often a file with multiple parts will have data in it like

    <file format identifier><length of following part><part 1><length of following part><part 2>...<length of following part><part n>

    In which case you would need to extract all the parts, change the one you want, and re-create the file with the correct <length of following part> values.

    --
    Andrew

    Thursday, September 29, 2011 6:27 PM
  • ultimately you need two peices of info to make this work: the offset of the old jpg, and either the old jpeg length, or the offset of the first byte of the bmp.  with out both of those, you cannot safely replace the jpg.
    Thursday, September 29, 2011 7:01 PM
  • What program generates the .bms files?

    Often a file with multiple parts will have data in it like

    <file format identifier><length of following part><part 1><length of following part><part 2>...<length of following part><part n>

    In which case you would need to extract all the parts, change the one you want, and re-create the file with the correct <length of following part> values.

    --
    Andrew

    Like I said before I don't use it for .bms file, but I maybe you right, rebuild is good way, but can you give me the code that can rebuild my example in first post?

    sorry if my english so bad, thanks for reply

    Friday, September 30, 2011 6:32 AM
  • Like you can see on this page is BMS a rather free format (has not one format), so you have first to investigate what is the correct description of your file format and than how images are added.

    After that it is probably quite simple to get the images and sound from that.

    http://en.wikipedia.org/wiki/Be-Music_Script

     

    Be aware that if you had written instead of 

    Replacing a JPG file inside a file, 

    Replacing a JPG file inside a BMS file.

    Than some including me had maybe taken the challenge to do it for you, because of the way you inform us, you are not inviting to do that, so at least I give you only this information.

     

     


    Success
    Cor
    Friday, September 30, 2011 6:41 AM
  • Like I said before I don't use it for .bms file, but I maybe you right, rebuild is good way, but can you give me the code that can rebuild my example in first post?

    I gave you an explanation of how to write the new file. I also gave the hint about the System.IO namespace. With which part of implementing a solution I can help you with? The documentation has chapters about file I/O but if you don't look at it, I only have to repeat it here.

    Armin
    Friday, September 30, 2011 11:05 AM