Documentation ¶
Index ¶
- Constants
- Variables
- func BorlandRand(seed uint32) (newSeed uint32, output uint16)
- func BorlandRandNextSeed(seed uint32) uint32
- func BorlandRandOutput(seed uint32) uint16
- func BorlandRandPreviousSeed(seed uint32) uint32
- func BorlandRandXORBytes(src, dst []byte, seed uint32) (newSeed uint32)
- func BorlandRandXORInPlace(data []byte, seed uint32) (newSeed uint32)
- func BorlandRandXORUint32(value, seed uint32) (newValue, newSeed uint32)
- func BruteforceBorlandSeed(b EncryptedBlock, material KeyMaterial) ([]uint32, error)
- func BruteforceBorlandSeedBytes(b EncryptedBlock, material KeyMaterial) ([]uint32, error)
- func DecryptDeviceCode(deviceId DeviceId, code []byte) []byte
- func EncryptDeviceCode(deviceId DeviceId, code []byte) []byte
- func IsKeyBorlandSeedLikely(b EncryptedBlock, material KeyMaterial) bool
- func JavaRand(seed uint64) (newSeed uint64, output uint16)
- func JavaRandNextSeed(seed uint64) uint64
- func JavaRandOutput(seed uint64) uint16
- func JavaRandOutputBits(seed uint64, bits int) uint64
- func JavaRandPreviousSeed(seed uint64) uint64
- type BorlandRandByteKeyGenerator
- type BorlandRandKeyGenerator
- type DeviceId
- type EncryptedBlock
- func (b EncryptedBlock) CRC() (crc1, crc2 uint32)
- func (b EncryptedBlock) DataBlock() []byte
- func (b EncryptedBlock) Decrypt(material KeyMaterial, verifyCrc bool) (err error)
- func (b EncryptedBlock) Encrypt(material KeyMaterial) error
- func (b EncryptedBlock) KeyBlock() []byte
- func (b EncryptedBlock) MangleIndex() uint32
- func (b EncryptedBlock) MangleKey() MangleKeyData
- func (b EncryptedBlock) MangleKeyBlock() []byte
- func (b EncryptedBlock) Reset()
- type KeyGenerator
- type KeyMaterial
- type MangleKeyData
- type MangleKeyTable
- type OuterMangleKeyOffset
- type SecureRandomKeyGenerator
- type ZeroKeyGenerator
Constants ¶
const ( MangleIndexNormalKey0 = iota MangleIndexNormalKey1 MangleIndexNormalKey2 MangleIndexNormalKey3 MangleIndexNormalKey4 MangleIndexNormalKey5 MangleIndexNormalKey6 MangleIndexNormalKey7 MangleIndexAlternateKey0 MangleIndexAlternateKey1 MangleIndexAlternateKey2 MangleIndexAlternateKey3 MangleIndexAlternateKey4 MangleIndexAlternateKey5 MangleIndexAlternateKey6 MangleIndexAlternateKey7 MangleIndexDeviceKey = 0xffff )
const ( OuterMangleKeyOffsetDefault = 0 OuterMangleKeyOffsetFlash = OuterMangleKeyOffsetDefault OuterMangleKeyOffsetDeviceId = 1 OuterMangleKeyOffsetMemory = 6 )
const BorlandRandAddend uint32 = 1
const BorlandRandModulus = 0xFFFFFFFF
const BorlandRandMultiplier uint32 = 0x015A4E35
BorlandRandMultiplier 22695477
const BorlandRandMultiplierInverse uint32 = 0x2925141D
BorlandRandMultiplierInverse Calculated using math.ModularMultiplicativeInverseFixed(uint32(BorlandRandMultiplier))
const BorlandRandOutputMask uint32 = 0x7FFF
const BorlandRandOutputShift = 16
const EncryptedBlockCRC1Offset = EncryptedBlockMangleKeyOffset + MangleKeyDataSize
const EncryptedBlockCRC2Offset = EncryptedBlockCRC1Offset + 4
const EncryptedBlockKeySize = 512
const EncryptedBlockMangleIndexOffset = 0
const EncryptedBlockMangleKeyOffset = EncryptedBlockMangleIndexOffset + 2
const EncryptedBlockPaddingKeyOffset = EncryptedBlockCRC2Offset + 4
const JavaRandAddend uint64 = 11
const JavaRandModulus = (1 << 48) - 1
const JavaRandMultiplier uint64 = 0x5DEECE66D
JavaRandMultiplier 25214903917
const JavaRandMultiplierInverse uint64 = 0xdfe05bcb1365
JavaRandMultiplierInverse Calculated using math.ModularMultiplicativeInverseBits(uint64(JavaRandMultiplier), 48)
const JavaRandOutputMask uint64 = 0xFFFF
const JavaRandOutputShift = 48 - 16
const MangleKeyBlockSize = 8
const MangleKeyDataSize = 4 * 4
const MangleKeyRounds = 48
Variables ¶
var AlternateMangleTable = MangleKeyTable{
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
}
var HardcodedMangleTable = MangleKeyTable{
{0x6f, 0xc0, 0x39, 0x05, 0x01, 0x58, 0x23, 0x3a, 0x80, 0xda, 0xb4, 0x1b, 0x65, 0x6a, 0x91, 0x44},
{0x35, 0xcb, 0x01, 0x5b, 0xfb, 0xa4, 0x98, 0xb4, 0x82, 0x6d, 0x48, 0xe9, 0x10, 0x50, 0x94, 0xf4},
{0xec, 0xbc, 0xba, 0xe8, 0xf8, 0x3d, 0xa7, 0x2a, 0x9c, 0xf7, 0xf9, 0x4c, 0xe7, 0x73, 0x6d, 0x88},
{0x03, 0x35, 0x48, 0x25, 0xaf, 0xa8, 0xa0, 0xb1, 0xb2, 0x45, 0xa7, 0x24, 0x39, 0x13, 0xe2, 0xf5},
{0x88, 0x90, 0xd8, 0x42, 0xaf, 0x79, 0xa3, 0x37, 0xe0, 0x89, 0x26, 0x42, 0xe9, 0x39, 0x62, 0x63},
{0xf0, 0x61, 0xd0, 0xab, 0x79, 0x05, 0x71, 0x7f, 0x51, 0x6b, 0x62, 0xbd, 0x15, 0x2c, 0xf2, 0x2a},
{0x06, 0xbc, 0x41, 0xb3, 0x74, 0x46, 0x6e, 0x6e, 0x01, 0x7b, 0xeb, 0xb3, 0x32, 0x5b, 0x96, 0xf1},
{0x6f, 0x3e, 0xf3, 0x52, 0xf9, 0xa2, 0x69, 0x4d, 0xc4, 0x77, 0xab, 0x77, 0x08, 0x45, 0x8f, 0x46},
}
Functions ¶
func BorlandRand ¶
BorlandRand Borland C++ rand()
func BorlandRandNextSeed ¶
func BorlandRandOutput ¶
func BorlandRandPreviousSeed ¶
func BorlandRandXORBytes ¶
func BorlandRandXORInPlace ¶
func BorlandRandXORUint32 ¶
func BruteforceBorlandSeed ¶
func BruteforceBorlandSeed(b EncryptedBlock, material KeyMaterial) ([]uint32, error)
func BruteforceBorlandSeedBytes ¶
func BruteforceBorlandSeedBytes(b EncryptedBlock, material KeyMaterial) ([]uint32, error)
func DecryptDeviceCode ¶
DecryptDeviceCode Decrypts code specifically encrypted to only work on a specific device id
func EncryptDeviceCode ¶
EncryptDeviceCode Encrypt code specifically encrypted to only work on a specific device id
func IsKeyBorlandSeedLikely ¶
func IsKeyBorlandSeedLikely(b EncryptedBlock, material KeyMaterial) bool
IsKeyBorlandSeedLikely The generator used on BorlandRand does not set the highest bit, as such it can be detected
func JavaRandNextSeed ¶
func JavaRandOutput ¶
func JavaRandOutputBits ¶
func JavaRandPreviousSeed ¶
Types ¶
type BorlandRandByteKeyGenerator ¶
type BorlandRandByteKeyGenerator uint32
BorlandRandByteKeyGenerator Generates random numbers with its value as current seed
func (*BorlandRandByteKeyGenerator) FillKeyBlock ¶
func (g *BorlandRandByteKeyGenerator) FillKeyBlock(data []byte)
func (*BorlandRandByteKeyGenerator) MangleIndex ¶
func (g *BorlandRandByteKeyGenerator) MangleIndex() uint32
type BorlandRandKeyGenerator ¶
type BorlandRandKeyGenerator uint32
BorlandRandKeyGenerator Generates random numbers with its value as current seed
func (*BorlandRandKeyGenerator) FillKeyBlock ¶
func (g *BorlandRandKeyGenerator) FillKeyBlock(data []byte)
func (*BorlandRandKeyGenerator) MangleIndex ¶
func (g *BorlandRandKeyGenerator) MangleIndex() uint32
type EncryptedBlock ¶
type EncryptedBlock []byte
func NewEncryptedBlock ¶
func NewEncryptedBlock(size int) EncryptedBlock
func (EncryptedBlock) CRC ¶
func (b EncryptedBlock) CRC() (crc1, crc2 uint32)
func (EncryptedBlock) DataBlock ¶
func (b EncryptedBlock) DataBlock() []byte
func (EncryptedBlock) Decrypt ¶
func (b EncryptedBlock) Decrypt(material KeyMaterial, verifyCrc bool) (err error)
func (EncryptedBlock) Encrypt ¶
func (b EncryptedBlock) Encrypt(material KeyMaterial) error
func (EncryptedBlock) KeyBlock ¶
func (b EncryptedBlock) KeyBlock() []byte
func (EncryptedBlock) MangleIndex ¶
func (b EncryptedBlock) MangleIndex() uint32
func (EncryptedBlock) MangleKey ¶
func (b EncryptedBlock) MangleKey() MangleKeyData
func (EncryptedBlock) MangleKeyBlock ¶
func (b EncryptedBlock) MangleKeyBlock() []byte
MangleKeyBlock Includes inner MangleKeyData and CRC1, CRC2
func (EncryptedBlock) Reset ¶
func (b EncryptedBlock) Reset()
type KeyGenerator ¶
func NewMangleIndexGeneratorWrapper ¶
func NewMangleIndexGeneratorWrapper(generator KeyGenerator, mangleIndex uint32) KeyGenerator
func NewMangleIndexOffsetGeneratorWrapper ¶
func NewMangleIndexOffsetGeneratorWrapper(generator KeyGenerator, offset uint32) KeyGenerator
type KeyMaterial ¶
type KeyMaterial struct { // Generator Random source to generate the inline material Generator KeyGenerator OuterKeyOffset OuterMangleKeyOffset DeviceKey *MangleKeyData AlternateKeyTable *MangleKeyTable // CRC method to calculate CRC. If none is set, default is used. CRC func(data []byte) uint32 }
func NewFlashKeyMaterial ¶
func NewFlashKeyMaterial(generator KeyGenerator) KeyMaterial
func NewMemoryKeyMaterial ¶
func NewMemoryKeyMaterial(generator KeyGenerator) KeyMaterial
type MangleKeyData ¶
type MangleKeyData [MangleKeyDataSize]byte
MangleKeyData Key entries of 128-bit length
func DeviceMangleKeyOffset0 ¶
func DeviceMangleKeyOffset0(deviceId DeviceId) *MangleKeyData
func DeviceMangleKeyOffset6 ¶
func DeviceMangleKeyOffset6(deviceId DeviceId) *MangleKeyData
func (MangleKeyData) Decrypt ¶
func (d MangleKeyData) Decrypt(data []byte)
func (MangleKeyData) DecryptBlock ¶
func (d MangleKeyData) DecryptBlock(block uint64) uint64
func (MangleKeyData) Encrypt ¶
func (d MangleKeyData) Encrypt(data []byte)
func (MangleKeyData) EncryptBlock ¶
func (d MangleKeyData) EncryptBlock(block uint64) uint64
func (MangleKeyData) RoundKey ¶
func (d MangleKeyData) RoundKey(round int) uint32
type MangleKeyTable ¶
type MangleKeyTable [8]MangleKeyData
type OuterMangleKeyOffset ¶
type OuterMangleKeyOffset int
type SecureRandomKeyGenerator ¶
type SecureRandomKeyGenerator struct{}
SecureRandomKeyGenerator Generates random numbers using the system secure random number generator
func (*SecureRandomKeyGenerator) FillKeyBlock ¶
func (g *SecureRandomKeyGenerator) FillKeyBlock(data []byte)
func (*SecureRandomKeyGenerator) MangleIndex ¶
func (g *SecureRandomKeyGenerator) MangleIndex() uint32
type ZeroKeyGenerator ¶
type ZeroKeyGenerator struct{}
ZeroKeyGenerator Always outputs zero
func (*ZeroKeyGenerator) FillKeyBlock ¶
func (g *ZeroKeyGenerator) FillKeyBlock(data []byte)
func (*ZeroKeyGenerator) MangleIndex ¶
func (g *ZeroKeyGenerator) MangleIndex() uint32