Created
March 30, 2018 12:11
-
-
Save cugu/139d520f93d4e43720c14c52dd5991d6 to your computer and use it in GitHub Desktop.
XOR generation for kaitai in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild | |
package test_formats | |
import "github.com/kaitai-io/kaitai_struct_go_runtime/kaitai" | |
type ProcessXor4Const struct { | |
Key []byte | |
Buf []byte | |
_io *kaitai.Stream | |
_root *ProcessXor4Const | |
_parent interface{} | |
_raw_Buf []byte | |
} | |
func (this *ProcessXor4Const) Read(io *kaitai.Stream, parent interface{}, root *ProcessXor4Const) (err error) { | |
this._io = io | |
this._parent = parent | |
this._root = root | |
tmp1, err := this._io.ReadBytes(int(4)) | |
if err != nil { | |
return err | |
} | |
this.Key = tmp1 | |
tmp2, err := this._io.ReadBytesFull() | |
if err != nil { | |
return err | |
} | |
// Addition: | |
xorValue := []byte{0xec, 0xbb, 0xa3, 0x14} | |
for index, element := range tmp2 { | |
tmp2[index] = element ^ xorValue[index % len(xorValue)] | |
} | |
// -- | |
this.Buf = tmp2 | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild | |
package test_formats | |
import "github.com/kaitai-io/kaitai_struct_go_runtime/kaitai" | |
type ProcessXor4Value struct { | |
Key []byte | |
Buf []byte | |
_io *kaitai.Stream | |
_root *ProcessXor4Value | |
_parent interface{} | |
_raw_Buf []byte | |
} | |
func (this *ProcessXor4Value) Read(io *kaitai.Stream, parent interface{}, root *ProcessXor4Value) (err error) { | |
this._io = io | |
this._parent = parent | |
this._root = root | |
tmp1, err := this._io.ReadBytes(int(4)) | |
if err != nil { | |
return err | |
} | |
this.Key = tmp1 | |
tmp2, err := this._io.ReadBytesFull() | |
if err != nil { | |
return err | |
} | |
// Addition: | |
xorValue := this.Key | |
for index, element := range tmp2 { | |
tmp2[index] = element ^ xorValue[index % len(xorValue)] | |
} | |
// -- | |
this.Buf = tmp2 | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild | |
package test_formats | |
import "github.com/kaitai-io/kaitai_struct_go_runtime/kaitai" | |
type ProcessXorConst struct { | |
Key uint8 | |
Buf []byte | |
_io *kaitai.Stream | |
_root *ProcessXorConst | |
_parent interface{} | |
_raw_Buf []byte | |
} | |
func (this *ProcessXorConst) Read(io *kaitai.Stream, parent interface{}, root *ProcessXorConst) (err error) { | |
this._io = io | |
this._parent = parent | |
this._root = root | |
tmp1, err := this._io.ReadU1() | |
if err != nil { | |
return err | |
} | |
this.Key = tmp1 | |
tmp2, err := this._io.ReadBytesFull() | |
if err != nil { | |
return err | |
} | |
// Addition: | |
xorValue := []byte{0xff} | |
for index, element := range tmp2 { | |
tmp2[index] = element ^ xorValue[index % len(xorValue)] | |
} | |
// -- | |
this.Buf = tmp2 | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild | |
package test_formats | |
import "github.com/kaitai-io/kaitai_struct_go_runtime/kaitai" | |
type ProcessXorValue struct { | |
Key uint8 | |
Buf []byte | |
_io *kaitai.Stream | |
_root *ProcessXorValue | |
_parent interface{} | |
_raw_Buf []byte | |
} | |
func (this *ProcessXorValue) Read(io *kaitai.Stream, parent interface{}, root *ProcessXorValue) (err error) { | |
this._io = io | |
this._parent = parent | |
this._root = root | |
tmp1, err := this._io.ReadU1() | |
if err != nil { | |
return err | |
} | |
this.Key = tmp1 | |
tmp2, err := this._io.ReadBytesFull() | |
if err != nil { | |
return err | |
} | |
// Addition: | |
xorValue := []byte{this.Key} | |
for index, element := range tmp2 { | |
tmp2[index] = element ^ xorValue[index % len(xorValue)] | |
} | |
// -- | |
this.Buf = tmp2 | |
return err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment