?
Solved

How to manually modify a size of a file ?

Posted on 2003-11-27
28
Medium Priority
?
312 Views
Last Modified: 2010-04-14
Hi,

First of all,sorry if I make mistakes but I am not english :)
I have found  a floppy disk with a file of 750Mo.
It sounds like the cd-protection.

I am verry curious and I would like to know how is it possible.
I think it s an hexa value to modify in the structure of a little file but how can we do ?

Thanks for your responses.

0
Comment
Question by:bigstyle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 5
  • +1
28 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9830743
Hi bigstyle,

you cannot modify the file size except by actually increasing it ... The file size is stored in system variables (or calculated from them depending on fs and implementation )

Cheers!
Sunny:o)
0
 
LVL 32

Expert Comment

by:jhance
ID: 9830931
The file's size is stored in the DIRECTORY of the storage device.  Windows 2000 does not go out and calculate the size of every file on the media when you list the directory.  It merely uses the size stored in the directory.

A corrupted (or intentionally modified) directory could display an invalid file size.  This is commonly done by software protection schemes for games and the like.  By misrepresnting the size of files on a CD, copying is made more difficult since CD copying programs can be fooled.

You could certainly do (or correct) this yourself but the details depend on the FILE SYSTEM used on your media.  If indeed this is a floppy, the filesystem is likely FAT.  The details of the FAT file system and its directory structure are well documented.

http://www.pcguide.com/ref/hdd/file/fat.htm
0
 

Author Comment

by:bigstyle
ID: 9832200
Thanks you both for your answers.

I would like to try to increase the file Sunny;

Jhance,I visited your website but I didnt have seen something interesting.

I remember a method that was to modify the header of an image file (iso file ?) but I dont remember how,and moreover I would like to know how it is possible for every kind of files.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 9837064
>The file's size is stored in the DIRECTORY of the storage device.  Windows 2000 does not go out and calculate the size of
>every file on the media when you list the directory.  It merely uses the size stored in the directory.
jhance, if you meant total disk space occupied by the directory, then I am inclined to disbelieve this ... if you meant individual file, I agree.

bigstyle
you can increase file size by appending any data to it ... just that you will end up trashing the file but file size will increase.

While it is possible to modify the values of filesize stored on a floppy, it should not be so trivial for files on your hard disk (if it is, virii and worms would have a ball) ....
0
 
LVL 32

Expert Comment

by:jhance
ID: 9837080
sunny...,

No you can modify the apparent size of any file on the disk by messing with the directory information in the filesystem's directory.

As I already said, this is commonly done as an [easily circumvented] copy protection scheme for CDs.  It was also done in the past with floppies.

Doing this on a hard drive, however, is NOT recommended as you risk trashing the entire filesystem.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9837083
>on the disk
floppy disk easy ... but with hard disk I am not so sure ... I know it is possible on linux by overwriting inodes and other data structures (as a super user) but windows ... ????
0
 
LVL 32

Expert Comment

by:jhance
ID: 9837150
Same technique, just different details due to different filesystem.  But all of these work in generally the same way.
0
 

Author Comment

by:bigstyle
ID: 9837285
But nobody said how it is concretely possible to modify the size of a file in a floppy :/

jhance it seems you know how to do in every situation,could you please be more precise ?

Thanks
0
 
LVL 32

Expert Comment

by:jhance
ID: 9837312
1) You valued this question at 100 pts.  That means, in effect, "I need only a pointer in the right direction and can take it from there..."
2) I posted you a URL to a full description of the FAT16 filesystem format that is used on floppies under Windows 2000.  The information is right there even though you claim otherwise.
3) If you need more assistance or a complete solution, please value this question appropriately.
0
 

Author Comment

by:bigstyle
ID: 9837362
lol jhance,
i didnt know that the rules were so weerd there.

Here is 200 points more,that s enough for having more knowledge ? :)
0
 

Author Comment

by:bigstyle
ID: 9837433
450 points sorry for the bad manipulation
0
 
LVL 32

Accepted Solution

by:
jhance earned 1800 total points
ID: 9837818
bigstyle,

Here is a quick-and-dirty example.  It takes a standard 1.4M/FAT floppy, reads the directory, DOUBLES the size of the first file in the directory, and writes the directory back to the disk.  Note that the file itself is not changed but that if you run CHKDISK or SCANDSK on this floppy, there will be an error since the file does not actually take that much room.  You can use this technique to set the file to any amount you choose.

Enjoy but please be careful.  Using this on a hard drive could be disastrous!!!


#include "stdafx.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
      HANDLE hFloppy = CreateFile(
                  "\\\\.\\A:",                              // Open the A: drive for PHYSICAL ACCESS
                  GENERIC_READ | GENERIC_WRITE,      // Want R/W Access
                  FILE_SHARE_READ | FILE_SHARE_WRITE,
                  NULL,
                  OPEN_EXISTING,
                  0,
                  NULL
            );

      if(hFloppy == INVALID_HANDLE_VALUE){
            cout << "Error opening FLOPPY drive. Error is: " << GetLastError() << endl;
            return -1;
      }
      else{
            cout << "Floppy device opened ok." << endl;
      }

      DWORD dwRead = 0;
      DWORD dwWrite = 0;
      UCHAR *pBuffer;
      pBuffer = new UCHAR[1024 * 16];

      if(ReadFile(hFloppy, (LPVOID)pBuffer, 1024 * 16, &dwRead, NULL)){
            cout << "Read OK..." << endl;

            // Make a pointer to the SIZE of the first file on the floppy
            DWORD *pSize = (DWORD *)((DWORD)pBuffer + 0x0000261c);
            DWORD dwSize = *pSize;
            dwSize = dwSize * 2;
            *pSize = dwSize;

            // Write the modified data back to disk
            SetFilePointer(hFloppy, 0, 0, FILE_BEGIN);

            if(WriteFile(hFloppy, (LPVOID)pBuffer, 1024 * 16, &dwWrite, NULL)){
                  cout << "Write OK..." << endl;
                  FlushFileBuffers(hFloppy);
            }
            else{
                  cout << "Write failed: " << GetLastError() << endl;
            }
      }
      else{
            cout << "Read Failed: " << GetLastError() << endl;
      }

      delete [] pBuffer;

      CloseHandle(hFloppy);

      return 0;
}
0
 
LVL 32

Expert Comment

by:jhance
ID: 9843093
Any further questions?  Comments?
0
 
LVL 32

Expert Comment

by:jhance
ID: 9871507
Hello???
0
 
LVL 4

Expert Comment

by:bigstyler
ID: 11192982
Weel I have tried this code but it doesnt work so the question is still opened.
Sorry
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11194295
I second the recommendation
jhance had pinged the asker twice
0
 
LVL 4

Expert Comment

by:bigstyler
ID: 11195279
ok give him the points if you want, even if for me the answer is uncomplete.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11195413
bigstyle == bigstyler

Holding multiple accounts is voilation of membership agreement
http://www.experts-exchange.com/memberAgreement.jsp
0
 
LVL 4

Expert Comment

by:bigstyler
ID: 11195471
Erf sorry I have an account for my job and one for my personal use :/
0
 
LVL 4

Expert Comment

by:bigstyler
ID: 11196104
Ok you can delete bigstyle account ...
0
 
LVL 4

Expert Comment

by:bigstyler
ID: 11196193
doesnt matter.

I have more points in bigstyle account but I have lost my password and the "Forgot Password" method doesn't work.
Give him the points if you want.
0
 
LVL 4

Expert Comment

by:bigstyler
ID: 11196277
Thank you for the points report
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question