Results 1 to 14 of 14

Thread: How do I corrupt an Excel File?

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Resolved How do I corrupt an Excel File?

    A friend needs a favor from me...
    I need to "corrupt" an excel file so it wont open
    I cant just delete the file becuase thats too obvious

    How can I make the excle file still there but wont load.
    I tried opening it in wordpad...and deleting the 1st 20 rows...
    and that sort of works but it still kind of loads.

    I know this sounds fishy...but many of you know me and you know Im doing anything funny (like creating a virus! )

    any Ideas?
    -Static
    Last edited by Static; Feb 25th, 2005 at 01:49 PM.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159

    Re: How do I corrupt an Excel File?

    Hiya,

    I suppose you could try opening the file for read/write access, read in a byte at a time, divide by two, write out, next byte, etc, etc...

    Alternatively add a script to the "Workbooks_Open" method to show a messagebox saying "This file is corrupt" and then close it. That may work?

    DJ

  3. #3

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do I corrupt an Excel File?

    Option 2 is no good...

    but the read write is a good idea...

    Ive never played with Bytes..not sure how I would do it.

    Open FileName for Binary as #1 ?
    etc...

    code sample please! Thanks!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: How do I corrupt an Excel File?

    Attached is some file load and save functions.
    Use these to get a byte array of the file...ie

    If the file was say: 1234567890
    Then the byte array will have 10 entries.
    Create a 2nd byte array of the same length, then copy

    12345 to the LAST 5 bytes, and

    67890 to the 1st

    then save the byte array to another file.

    The file should look like 6789012345

    I am sure this will bust the file

    Woka
    Attached Files Attached Files

  5. #5

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do I corrupt an Excel File?

    ok..will check it out at home tonight... (No VB here at work...just Access )
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159

    Re: How do I corrupt an Excel File?

    Hi,

    An easy easy way to break this is to take any file (a Zip for example) and copy it to the file making sure that the file extension becomes .XLS. When Excel tries to open the file it will be reading and looking for certain file structures/signatures/etc... so it will fail. A nice easy method....

    HTH,
    DJ

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: How do I corrupt an Excel File?

    Using the code I attached in my above post, you then need:
    Code:
    Dim lngIndex    As Long
    Dim bytData()   As Byte
    Dim bytNew()    As Byte
    Dim lngUBound   As Long
    Dim lngMid      As Long
        bytData = GetFile("C:\Woof.xls")
        lngUBound = UBound(bytData)
        lngMid = lngUBound / 2
        ReDim bytNew(lngUBound)
        For lngIndex = 0 To lngMid
            bytNew(lngIndex) = bytData(lngUBound - lngMid + lngIndex)
        Next lngIndex
        For lngIndex = lngMid + 1 To lngUBound
            bytNew(lngIndex - lngMid - 1) = bytData(lngIndex)
        Next lngIndex
        SaveFile "C:\new.xls", bytNew
    When I try to open the xls file it says it doesn't recognise the form.

    This seems to work, but a better way would be to take the byte array:

    1234567890
    And then split in half

    12345
    67890

    and then interweave the bytes

    6172839405

    That would bust any file

    But you cans till get the file back by doing the reverse.

    Woka

  8. #8
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: How do I corrupt an Excel File?

    A nice way would be to change the file in such a way so you reverse the change if really needed.

    You can use the NOT operator to reverse the bytes in the file, and if you reverse again, then the file will be readable again, same way you can use XOR.

    Here's what I mean:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub ReverseByteNumbers(ByVal FileName As String)
    4.     Dim K As Long, byteArr() As Byte, FL As Integer
    5.    
    6.     FL = FreeFile
    7.     Open FileName For Binary Access Read Write Lock Read Write As FL
    8.    
    9.     ReDim byteArr(LOF(FL) - 1)
    10.     Get FL, , byteArr
    11.    
    12.     For K = 0 To UBound(byteArr)
    13.         byteArr(K) = Not byteArr(K)
    14.     Next K
    15.    
    16.     Put FL, 1, byteArr
    17.    
    18.     Close FL
    19. End Sub
    20.  
    21. Private Sub XORFile(ByVal FileName As String, XORNumber As Byte)
    22.     Dim K As Long, byteArr() As Byte, FL As Integer
    23.    
    24.     FL = FreeFile
    25.     Open FileName For Binary Access Read Write Lock Read Write As FL
    26.    
    27.     ReDim byteArr(LOF(FL) - 1)
    28.     Get FL, , byteArr
    29.    
    30.     For K = 0 To UBound(byteArr)
    31.         byteArr(K) = byteArr(K) Xor XORNumber
    32.     Next K
    33.    
    34.     Put FL, 1, byteArr
    35.    
    36.     Close FL
    37. End Sub
    38.  
    39. Private Sub Form_Load()
    40.     ReverseByteNumbers "C:\TestFile.xls"
    41.     XORFile "C:\TestFile 2.xls", 200
    42. End Sub
    I did not actually try this code...

    If you run the same function on the "damaged" file, it will fix it back...

  9. #9

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do I corrupt an Excel File?

    the XOR code is perfect!

    "Can not Access 'TestFile2.xls'"

    wont even load it!

    Thanks Much!!

    EDIT - Oops.. lol..I can load it...I did 'Close FL'

    but it works...both functions scramble it
    Thanks!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  10. #10

    Re: How do I corrupt an Excel File?

    Hi,
    You can try using this manual process to recover your workbook:

    1- Click File > Open.
    2- Click the location and folder that contains the corrupted workbook.
    3- In the Open dialog box, select the corrupted workbook.
    4- Click the arrow next to the Open button, and then click Open and Repair.
    Name:  308a7773-9c32-4a26-a632-7ef5b3df2b07.png
Views: 13867
Size:  9.4 KB
    5- To recover as much of the workbook data as possible, pick Repair.

  11. #11
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: How do I corrupt an Excel File?

    Quote Originally Posted by Static View Post
    A friend needs a favor from me...
    I need to "corrupt" an excel file so it wont open
    I cant just delete the file becuase thats too obvious

    How can I make the excle file still there but wont load.
    I tried opening it in wordpad...and deleting the 1st 20 rows...
    and that sort of works but it still kind of loads.

    I know this sounds fishy...but many of you know me and you know Im doing anything funny (like creating a virus! )

    any Ideas?
    -Static
    Change an image file's extension to .xlsx. That should do it
    Please remember next time...elections matter!

  12. #12
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: How do I corrupt an Excel File?

    Quote Originally Posted by Static View Post
    A friend needs a favor from me...
    I need to "corrupt" an excel file so it wont open
    I cant just delete the file becuase thats too obvious

    How can I make the excle file still there but wont load.
    I tried opening it in wordpad...and deleting the 1st 20 rows...
    and that sort of works but it still kind of loads.

    I know this sounds fishy...but many of you know me and you know Im doing anything funny (like creating a virus! )

    any Ideas?
    -Static
    Change an image file's extension to .xlsx. That should do it
    Please remember next time...elections matter!

  13. #13
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: How do I corrupt an Excel File?

    This thread is 13 years old...

  14. #14
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine on fire (country of slaves)
    Posts
    750

    Re: How do I corrupt an Excel File?

    eric_hayes, OP 13-years ago wanted to damage file.
    However, interesting info from you.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width