crypt

package module
v0.0.0-...-02623e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2023 License: MIT Imports: 8 Imported by: 12

README

noxcrypt

Go Reference

Go library to encrypt/decrypt Nox game files.

Documentation

Overview

Package crypt implements Blowfish encryption algorithm with keys used in Nox.

Index

Constants

View Source
const (
	SoundSetBin = 5
	ThingBin    = 7
	GameDataBin = 8
	ModifierBin = 13
	MonsterBin  = 23
	MapKey      = 19
	SaveKey     = 27
)

Constants for known crypto keys.

View Source
const ZeroCRC = uint32(0xFFFFFFFF)

ZeroCRC is an initial value for UpdateCRC function.

View Source
const ZeroCRCStd = uint32(0)

ZeroCRCStd is an initial value for UpdateCRCStd function.

Variables

This section is empty.

Functions

func Decode

func Decode(p []byte, key int) error

Decode a buffer with a given key.

func DecodeWith

func DecodeWith(c *blowfish.Cipher, p []byte) error

DecodeWith decodes a buffer with a given cipher.

func Encode

func Encode(p []byte, key int) error

Encode a buffer with a given key.

func EncodeWith

func EncodeWith(c *blowfish.Cipher, p []byte) error

EncodeWith encodes a buffer with a given cipher.

func KeyForFile

func KeyForFile(path string) (int, bool)

KeyForFile return crypto key for a given file. If the file is unknown, it returns false.

func NewCipher

func NewCipher(key int) (*blowfish.Cipher, error)

NewCipher creates a new cipher using Nox key with a given index.

func UpdateCRC

func UpdateCRC(crc uint32, p []byte) uint32

UpdateCRC is a CRC update function used in Nox.

func UpdateCRCStd

func UpdateCRCStd(crc uint32, p []byte) uint32

UpdateCRCStd is a standard CRC update function.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

func NewFile

func NewFile(f io.ReadWriteSeeker, key int) (*File, error)

NewFile creates a file that support encode/decode and seek operations.

func (*File) Align

func (f *File) Align() error

Align the read or write offset to the nearest block boundary.

func (*File) Buffered

func (f *File) Buffered() int

Buffered returns a number of bytes buffered either by read or write operations.

func (*File) Close

func (f *File) Close() error

Close flushes the data. See Flush.

func (*File) Flush

func (f *File) Flush() error

Flush buffered data to the underlying writer. The data will be aligned to the block size.

func (*File) Read

func (f *File) Read(p []byte) (int, error)

Read implements io.Reader.

func (*File) ReadAligned

func (f *File) ReadAligned(p []byte) (int, error)

ReadAligned is a special case of aligned read used by the engine.

func (*File) Reset

func (f *File) Reset(d io.ReadWriteSeeker)

Reset internal state and assign a new underlying source for the file.

func (*File) Seek

func (f *File) Seek(off int64, whence int) (int64, error)

Seek implements io.Seeker.

func (*File) Write

func (f *File) Write(p []byte) (int, error)

Write implements io.Writer.

func (*File) WriteEmpty

func (f *File) WriteEmpty() (int64, error)

WriteEmpty flushes the data (if any), which aligns it to a block size, and then writes an additional empty block without encryption.

func (*File) WriteString

func (f *File) WriteString(s string) (int, error)

WriteString implements io.StringWriter.

func (*File) Written

func (f *File) Written() int64

Written returns a number of bytes written. It will differ from the actual number of written bytes unless Flush is called.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r io.Reader, key int) (*Reader, error)

NewReader creates a decoder with a given key and byte stream.

func (*Reader) Align

func (r *Reader) Align() error

func (*Reader) Buffered

func (r *Reader) Buffered() int

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

func (*Reader) ReadAligned

func (r *Reader) ReadAligned(p []byte) (int, error)

func (*Reader) ReadI16

func (r *Reader) ReadI16() (int16, error)

func (*Reader) ReadI32

func (r *Reader) ReadI32() (int32, error)

func (*Reader) ReadI64

func (r *Reader) ReadI64() (int64, error)

func (*Reader) ReadI8

func (r *Reader) ReadI8() (int8, error)

func (*Reader) ReadU16

func (r *Reader) ReadU16() (uint16, error)

func (*Reader) ReadU32

func (r *Reader) ReadU32() (uint32, error)

func (*Reader) ReadU64

func (r *Reader) ReadU64() (uint64, error)

func (*Reader) ReadU8

func (r *Reader) ReadU8() (byte, error)

func (*Reader) Reset

func (r *Reader) Reset(s io.Reader)

func (*Reader) Seek

func (r *Reader) Seek(off int64, whence int) (int64, error)

type Writer

type Writer struct {

	// NoZero is a compatibility flag that forces the writer to not cleanup internal buffer with zeros.
	// The result is that short writes followed by Flush may expose data from previous long writes.
	// It is needed to keep 1:1 output from the original game engine.
	NoZero bool
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer, key int) (*Writer, error)

NewWriter creates an encoder with a given key and a destination writer.

func (*Writer) CRC

func (w *Writer) CRC() uint32

CRC returns current CRC checksum.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes the data. See Flush.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush buffered data to the underlying writer. The data will be aligned to the block size.

func (*Writer) Reset

func (w *Writer) Reset(d io.Writer)

Reset internal state and assign a new underlying writer to it.

func (*Writer) ResetCRC

func (w *Writer) ResetCRC()

ResetCRC resets CRC internal state.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write implements io.Writer.

func (*Writer) WriteBlockAt

func (w *Writer) WriteBlockAt(buf [Block]byte, off int64) error

WriteBlockAt encrypts and writes a block at an offset, previously returned by WriteEmpty. It requires the underlying writer to implement io.WriterAt.

func (*Writer) WriteEmpty

func (w *Writer) WriteEmpty() (int64, error)

WriteEmpty flushes the data (if any), which aligns it to a block size, and then writes an additional empty block without encryption. This block can be later written with WriteBlockAt, WriteU64At, WriteU32At, etc.

func (*Writer) WriteI16

func (w *Writer) WriteI16(v int16) error

func (*Writer) WriteI32

func (w *Writer) WriteI32(v int32) error

func (*Writer) WriteI32At

func (w *Writer) WriteI32At(v int32, off int64) error

WriteI32At encrypts and writes int32 at an offset, previously returned by WriteEmpty. It requires the underlying writer to implement io.WriterAt.

func (*Writer) WriteI64

func (w *Writer) WriteI64(v int64) error

func (*Writer) WriteI64At

func (w *Writer) WriteI64At(v int64, off int64) error

WriteI64At encrypts and writes int64 at an offset, previously returned by WriteEmpty. It requires the underlying writer to implement io.WriterAt.

func (*Writer) WriteI8

func (w *Writer) WriteI8(v int8) error

func (*Writer) WriteU16

func (w *Writer) WriteU16(v uint16) error

func (*Writer) WriteU32

func (w *Writer) WriteU32(v uint32) error

func (*Writer) WriteU32At

func (w *Writer) WriteU32At(v uint32, off int64) error

WriteU32At encrypts and writes uint32 at an offset, previously returned by WriteEmpty. It requires the underlying writer to implement io.WriterAt.

func (*Writer) WriteU64

func (w *Writer) WriteU64(v uint64) error

func (*Writer) WriteU64At

func (w *Writer) WriteU64At(v uint64, off int64) error

WriteU64At encrypts and writes uint64 at an offset, previously returned by WriteEmpty. It requires the underlying writer to implement io.WriterAt.

func (*Writer) WriteU8

func (w *Writer) WriteU8(v byte) error

func (*Writer) Written

func (w *Writer) Written() int64

Written returns a number of bytes written. It will differ from the actual number of written bytes unless Flush is called.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL