direct file modification

This is a discussion on direct file modification within the A Brief History of Cprogramming.com forums, part of the Community Boards category; is it possible to modify files directly without creating a copy of the file ("token files"). if it is, what ...

  1. #1
    unreg
    Guest

    direct file modification

    is it possible to modify files directly without creating a copy of the file ("token files").
    if it is, what functions are required to perform this task?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Yes, and the usual bunch of standard IO functions would do, depending on how you want to modify it.

    Make sure you open the file in the correct mode, check this page for a list of fopen() modes. I expect you'll be wanting a binary based mode.

    However, it is not possible to do things like insert a new line of text etc, as that involves shifting the data. You can only ovewrite what is already there.

    If this doesn't help enough, provide a clearer example of what you're trying to do.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Unreg
    Guest
    um, let's say i want to modify the 100th byte of a file to "A" (65 in char).

    so what i usually do is make a copy of the file in memory (part or full) and modify that in memory. afterwards, i write from memory to file. from my previous post, i just wanted to know if there was a function that can just write to the file directly instead of what i mentioned.

  4. #4
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    um, let's say i want to modify the 100th byte of a file to "A" (65 in char).
    Well, you can directly write to the disk (at least under DOS).
    Given the information in the FAT, you have to seek the file, position to it's 100th byte, and write there what you want to.

    Easy said, but not so easy to perform . You have to know exactly what you're doing, as directly accessing a disk is really dangerous.

    Usually device drivers, boot loaders and viruses are using this technique.

    Which one are you working on? ;)

    In real mode, BIOS's Int13h is responsible to do that:
    function 02h will read sectors, 03h will write sectors.
    If you're a real hacker, do not even rely on BIOS - program directly disk's HW ports (see Ralph Brown's Hardware list for details).

    Have fun!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. file processing updating record error
    By uuser in forum C Programming
    Replies: 2
    Last Post: 04-27-2003, 01:13 AM
  3. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21