Android Question Improve speed in replacing a certain byte with a different byte in a binary file

aironium

Member
Context is I am modifying some hex in a zip for a particular case for my experiment. I have posted the same case before (and I'd rather be more specific, I suppose), and after some attempts, I have the following snippet:
Snippet:
Dim dat() As Byte = File.ReadBytes(baseDir, specimen & ".zip")
            
            Log("byte size is: " & dat.Length)
            ProgressDialogShow("Phase 2: PROTECC Process")
            For i = 0 To dat.Length -1
                If dat(i) = 64 Then '@
                    dat(i) = 47 '/
                    Log("Case " & i & "- byte swapped")
                End If
            Next

            ProgressDialogHide

            File.WriteBytes(baseDir, specimen & ".zip", dat)

I am trying to speed up the process of replacing any existence of "@" with slashes, but with their designated binary code. The snippet above somehow swapped more "matches" than anticipated.

(Why am I doing this in the first place? secret)
 
Last edited:

drgottjr

Expert
Licensed User
Longtime User
64 only means "@" in the context of a string
of characters. wanting to exchange a byte's
value from "@" to "/" only makes sense in the
context of a string of text. a .zip archive's directory
entries can be read as text, and you can get away
with changing any "@'s" you find there to "/'s", but
changing values in the archive's headers and
compressed data, would corrupt the file. a byte
with a value of 64 means one thing in one context
and another thing in another. if you're looking to
speed up the corruption process, you can probably
pick a single random byte near the start of the file
and change its value. that should be enough to
do it. no need to change all matching bytes.
 
Upvote 0

aironium

Member
Welp, after reading some technical information about .zip headers, i am barking at the wrong tree.

The point of the zip manipulation is to intentionally alter some bytes in the header and central directory. (Not corrupting the .zip to make it fubar).

That is all for now.
 
Upvote 0
Top