Jump to content
Sign in to follow this  
Ptifou78

Erase bit in file

Recommended Posts

Ptifou78

Hello everybody I would like to know how to erase *n bits into a file previously open with de the binary mod :)

I have an idea is to read all bit what i need and rewrite a new file but is very slow :/

Thanks in advance ;)

Share this post


Link to post
Share on other sites
water

If you know the position of the data in the file you can use function FileSetPos to overwrite the data. The following example writes an "x" at position 10 of a text file.

$hFile = FileOpen("C:\temp\test.txt", 1)
$iPos = FileSetPos($hFile, 10, 0)
FileWrite($hFile, "x")
FileClose($hFile)

You need to change the script to replace binary data.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

My example overwrites data but if you really need to erase (remove) the data (so the file gets shorter) then there is no other way then rewriting the file as you already do.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ptifou78

Shit and i can not do a string replace like? ^^'

Share this post


Link to post
Share on other sites
water

How big is the file you need to process?

What have you coded so far?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ptifou78

I have multiple file to process from 1/2mb to 40mb... :/

$F_output = @ScriptDir&"test_output.txt"
$F_input =  @ScriptDir&"test.txt"
FileOpen($F_output,17)
FileOpen($F_input,17)
Filewrite($F_output,'header')
FileSetPos($F_input,128,0);lenght of header
$nb_ligne = Hex_to_int32(FileRead($F_input,4))
For $i to $nb_ligne
    $1st_part = FileRead($F_input,xxx bit)
    FileSetPos($F_input,4,1);bits to skip
    $2nd_part = FileRead($F_input,xxx bit)
    FileWrite($F_output,$1st_part&$2nd_part)
Next
MsgBox(0,"","Finnish")

Share this post


Link to post
Share on other sites
water

To enhance performance you could read the file in one go using FileRead without setting the number of characters to read.

Then use StringReplace($StringContainingTheFile, $StringToReplace, "") and then write the file in one go using FileWrite.

That should enhance performance considerable.

One question. What kind of files do you want to remove binary content? Pictures ...?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ptifou78

I can't because the string is not always the same ;)

It's a rdb file for a game it contain some information about data i jjust want to extract them but for that i need to change a litlle bit his structur :)

Moreover i have a stupid question if i do that

$data_original = fileread($myfile)
Filewrite($my_outputfile,$daata_original

If the data original is a binary content i need to translate it for rewrite it or is good?

Share this post


Link to post
Share on other sites
water

Would you be so kind to tell us the name of the game?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ptifou78

Rappelz a MMoRPG ;) is not a crack i just want it for have model data to use in my art work >.<

Edited by Ptifou78

Share this post


Link to post
Share on other sites
Valik

This thread was perfectly fine right up until you mentioned that you were violating our forum rules. Thread locked. I suggest reading the rules before you post again.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×