Rizin
unix-like reverse engineering framework and cli tools
puff.h File Reference

Go to the source code of this file.

Macros

#define NIL   ((unsigned char *)0) /* for no output option */
 

Functions

int puff (unsigned char *dest, unsigned long *destlen, const unsigned char *source, unsigned long *sourcelen)
 

Macro Definition Documentation

◆ NIL

#define NIL   ((unsigned char *)0) /* for no output option */

Definition at line 29 of file puff.h.

Function Documentation

◆ puff()

int puff ( unsigned char *  dest,
unsigned long destlen,
const unsigned char *  source,
unsigned long sourcelen 
)

Definition at line 793 of file puff.c.

797 {
798  struct state s; /* input/output state */
799  int last, type; /* block information */
800  int err; /* return value */
801 
802  /* initialize output state */
803  s.out = dest;
804  s.outlen = *destlen; /* ignored if dest is NIL */
805  s.outcnt = 0;
806 
807  /* initialize input state */
808  s.in = source;
809  s.inlen = *sourcelen;
810  s.incnt = 0;
811  s.bitbuf = 0;
812  s.bitcnt = 0;
813 
814  /* return if bits() or decode() tries to read past available input */
815  if (setjmp(s.env) != 0) /* if came back here via longjmp() */
816  err = 2; /* then skip do-loop, return error */
817  else {
818  /* process blocks until last block or error */
819  do {
820  last = bits(&s, 1); /* one if last block */
821  type = bits(&s, 2); /* block type 0..3 */
822  err = type == 0 ?
823  stored(&s) :
824  (type == 1 ?
825  fixed(&s) :
826  (type == 2 ?
827  dynamic(&s) :
828  -1)); /* type == 3, invalid */
829  if (err != 0)
830  break; /* return with error */
831  } while (!last);
832  }
833 
834  /* update the lengths and return */
835  if (err <= 0) {
836  *destlen = s.outcnt;
837  *sourcelen = s.incnt;
838  }
839  return err;
840 }
static bool err
Definition: armass.c:435
const char * source
Definition: lz4.h:699
char * dest
Definition: lz4.h:697
int type
Definition: mipsasm.c:17
int stored(struct state *s)
Definition: puff.c:164
int dynamic(struct state *s)
Definition: puff.c:665
int fixed(struct state *s)
Definition: puff.c:536
int bits(struct state *s, int need)
Definition: puff.c:126
static RzSocket * s
Definition: rtr.c:28
Definition: dis.h:43

References bits(), dest, dynamic(), err, fixed(), s, source, stored(), and type.

Referenced by main().