Documentation ¶
Overview ¶
Package crc32 is an implementation of an algorithm to modify a file so that its CRC-32 checksum matches a given value. This requires four sacrificial bytes in the file that will be modified to generate the desired value.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ForceCRC32 ¶
func ForceCRC32(rws io.ReadWriteSeeker, offset int64, desiredCRC uint32) error
ForceCRC32 takes an io.ReadWriteSeeker and updates the four bytes starting at offset such that the IEEE CRC-32 value of the whole stream matches desiredCRC. If the CRC-32 value already matches, no changes are made.
Example ¶
package main import ( "encoding/hex" "fmt" "io" "os" "github.com/bodgit/crc32" ) func main() { f, err := os.CreateTemp("", "") if err != nil { panic(err) } defer func() { if err := f.Close(); err != nil { panic(err) } if err := os.RemoveAll(f.Name()); err != nil { panic(err) } }() b := []byte("This is a test 0000") if _, err := f.Write(b); err != nil { panic(err) } if err := crc32.ForceCRC32(f, int64(len(b)-4), 0xdeadbeef); err != nil { panic(err) } if _, err := f.Seek(0, io.SeekStart); err != nil { panic(err) } if _, err := io.ReadFull(f, b); err != nil { panic(err) } fmt.Print(hex.Dump(b)) }
Output: 00000000 54 68 69 73 20 69 73 20 61 20 74 65 73 74 20 99 |This is a test .| 00000010 3c 5f 27 |<_'|
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.