PDA

View Full Version : direct file modification



unreg
01-29-2003, 12:32 PM
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?

Hammer
01-29-2003, 03:23 PM
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 (http://www.rt.com/man/fopen.3.html) 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.

Unreg
01-29-2003, 05:46 PM
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.

Carlos
02-03-2003, 09:32 AM
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!