Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. VC++ -> Want to modify a binary file that contain "ab 0e" to "0xab 0x0e".

VC++ -> Want to modify a binary file that contain "ab 0e" to "0xab 0x0e".

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++com
4 Posts 4 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pankaj Bhalla
    wrote on last edited by
    #1

    Hi All. I need help related to files. I have a binary file...let say abc.bin. If i open this file with notepad, the content is something like as follows... 5b 7a 82 43 2c 03 b0 12 02 a6 0c 93 03 24 b0 12 24 a0 02 3c b0 12 0e a1 92 43 2c 03 e2 93 17 12 And so on... Now, I want to convert that file to a file that have contents as 0x5b 0x7a 0x82 0x43 0x2c 0x03 0xb0 0x12 0x02 0xa6 0x0c 0x93 0x03 0x24 0xb0 0x12 0x24 0xa0 0x02 0x3c 0xb0 0x12 0x0e 0xa1 0x92 0x43 0x2c 0x03 0xe2 0x93 0x17 0x12 And so on... I am trying to use CFile to open and then modifying it, but not able to do. If anyone can suggest anything that can resolve my issue, it will be really great for me. Thanks and Regards, Pankaj Bhalla pankajbhalla@mantraonline.com

    S 1 Reply Last reply
    0
    • P Pankaj Bhalla

      Hi All. I need help related to files. I have a binary file...let say abc.bin. If i open this file with notepad, the content is something like as follows... 5b 7a 82 43 2c 03 b0 12 02 a6 0c 93 03 24 b0 12 24 a0 02 3c b0 12 0e a1 92 43 2c 03 e2 93 17 12 And so on... Now, I want to convert that file to a file that have contents as 0x5b 0x7a 0x82 0x43 0x2c 0x03 0xb0 0x12 0x02 0xa6 0x0c 0x93 0x03 0x24 0xb0 0x12 0x24 0xa0 0x02 0x3c 0xb0 0x12 0x0e 0xa1 0x92 0x43 0x2c 0x03 0xe2 0x93 0x17 0x12 And so on... I am trying to use CFile to open and then modifying it, but not able to do. If anyone can suggest anything that can resolve my issue, it will be really great for me. Thanks and Regards, Pankaj Bhalla pankajbhalla@mantraonline.com

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      You mean you want to read in each line, and for each hex value, prefix it with '0x'. You'll need to read from one file, write to another, and then delete the original, and rename your output file. Doing this in place is awkward because you are changing the size of the file. Hope that helps a bit. Steve S

      T 1 Reply Last reply
      0
      • S Steve S

        You mean you want to read in each line, and for each hex value, prefix it with '0x'. You'll need to read from one file, write to another, and then delete the original, and rename your output file. Doing this in place is awkward because you are changing the size of the file. Hope that helps a bit. Steve S

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        why using 2 different files ? we can add bytes into a file without overwrite it. an we can move into the file stream...


        TOXCCT >>> GEII power

        T 1 Reply Last reply
        0
        • T toxcct

          why using 2 different files ? we can add bytes into a file without overwrite it. an we can move into the file stream...


          TOXCCT >>> GEII power

          T Offline
          T Offline
          Tim Smith
          wrote on last edited by
          #4

          Using what functions? Anyway, even if those functions existed, the excessive IO to support such a function would vastly dwarf the extra code to create a new file and rename it. Also, there are other issues involved. What if the program failed halfway through. Now you have a partially converted file which is totally worthless. This is a major concern for real life applications. Either the operation completes successfully or it fails without damaging the original. BTW, we are converting 1 binary bytes to 10 ASCII bytes. We are doing a lot more than just inserting two characters. Tim Smith I'm going to patent thought. I have yet to see any prior art.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups