Пример #1
0
/*   void RegisterSession(struct S_Encapsulation_Data *pa_S_ReceiveData)
 *   Check supported protocol, generate session handle, send replay back to originator.
 *      pa_nSockfd       socket this request is associated to. Needed for double register check
 *      pa_S_ReceiveData pointer to received data with request/response.
 */
void
handleReceivedRegisterSessionCmd(int pa_nSockfd,
    struct S_Encapsulation_Data * pa_stReceiveData)
{
  int i;
  int nSessionIndex = 0;
  EIP_UINT8 *pacBuf;
  EIP_UINT16 nProtocolVersion = ltohs(
      &pa_stReceiveData->m_acCurrentCommBufferPos);
  EIP_UINT16 nOptionFlag = ltohs(&pa_stReceiveData->m_acCurrentCommBufferPos);

  /* check if requested protocol version is supported and the register session option flag is zero*/
  if ((0 < nProtocolVersion) && (nProtocolVersion <= SUPPORTED_PROTOCOL_VERSION)
      && (0 == nOptionFlag))
    { /*Option field should be zero*/
      /* check if the socket has already a session open */
      for (i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i)
        {
          if (anRegisteredSessions[i] == pa_nSockfd)
            {
              /* the socket has already registered a session this is not allowed*/
              pa_stReceiveData->nSession_handle = i + 1; /*return the already assigned session back, the cip spec is not clear about this needs to be tested*/
              pa_stReceiveData->nStatus =
                  OPENER_ENCAP_STATUS_UNSUPPORTED_PROTOCOL;
              nSessionIndex = INVALID_SESSION;
              pacBuf =
                  &pa_stReceiveData->m_acCommBufferStart[ENCAPSULATION_HEADER_SESSION_HANDLE_POS];
              htoll(pa_stReceiveData->nSession_handle, &pacBuf); /*encapsulate_data will not update the session handle so we have to do it here by hand*/
              break;
            }
        }

      if (INVALID_SESSION != nSessionIndex)
        {
          nSessionIndex = getFreeSessionIndex();
          if (INVALID_SESSION == nSessionIndex) /* no more sessions available */
            {
              pa_stReceiveData->nStatus = OPENER_ENCAP_STATUS_INSUFFICIENT_MEM;
            }
          else
            { /* successful session registered */
              anRegisteredSessions[nSessionIndex] = pa_nSockfd; /* store associated socket */
              pa_stReceiveData->nSession_handle = nSessionIndex + 1;
              pa_stReceiveData->nStatus = OPENER_ENCAP_STATUS_SUCCESS;
              pacBuf =
                  &pa_stReceiveData->m_acCommBufferStart[ENCAPSULATION_HEADER_SESSION_HANDLE_POS];
              htoll(pa_stReceiveData->nSession_handle, &pacBuf); /*encapsulate_data will not update the session handle so we have to do it here by hand*/
            }
        }
    }
  else
    { /* protocol not supported */
      pa_stReceiveData->nStatus = OPENER_ENCAP_STATUS_UNSUPPORTED_PROTOCOL;
    }

  pa_stReceiveData->nData_length = 4;
}
Пример #2
0
/**
 * test 'buf' for the contents of a binary Gnutella header
 * via hueristics based on the header fields
 */
static int test_bin_huer(const char *buf, size_t len, const parse_status *st)
{
  const gnut_hdr *h = (gnut_hdr *)buf;
  return len >= sizeof *h
      && guid_is_modern(h->guid)
      && msgtype_is_known(h->type)
      && ttl_hops_makes_sense(h->ttl, h->hops)
      && payload_len_conforms(ltohs(h->payload_len))
      && ltohs(h->payload_len) <= type_minbytes(h->type);
}
Пример #3
0
static size_t parse_resp(const dcerpc_hdr *h, void *buf, size_t len)
{
    dcerpc_resp *r = buf;
    if (len < sizeof *r)
        return 0;
    /* adjust endianness */
    r->fraglen    = ltohs(r->fraglen);
    r->authlen    = ltohs(r->authlen);
    r->callid     = ltohl(r->callid);
    r->alloc_hint = ltohl(r->alloc_hint);
    r->contextid  = ltohl(r->contextid);
    r->opnum      = ltohl(r->opnum);
    return len;
}
Пример #4
0
void
determineDelayTime(EIP_BYTE *pa_acBufferStart,
    struct SDelayedEncapsulationMessage *pa_pstDelayedMessageBuffer)
{
  EIP_UINT16 unMaxDelayTime;

  pa_acBufferStart += 12; /* start of the sender context */
  unMaxDelayTime = ltohs(&pa_acBufferStart);
  if (0 == unMaxDelayTime)
    {
      unMaxDelayTime = 2000;
    }
  else if (500 > unMaxDelayTime)
    {
      unMaxDelayTime = 500;
    }

  /* Limits mayDelayTime to 2000 milliseconds */
  if (unMaxDelayTime > 2000)
  {
     unMaxDelayTime = 2000;
  }

  pa_pstDelayedMessageBuffer->m_unTimeOut = (unMaxDelayTime * rand()) / RAND_MAX
      + 1;
}
Пример #5
0
 */EIP_INT16
createEncapsulationStructure(EIP_UINT8 * pa_buf, /* receive buffer*/
int pa_length, /* size of stuff in  buffer (might be more than one message)*/
struct S_Encapsulation_Data * pa_stData) /* the struct to be created*/

{
  pa_stData->m_acCommBufferStart = pa_buf;
  pa_stData->nCommand_code = ltohs(&pa_buf);
  pa_stData->nData_length = ltohs(&pa_buf);
  pa_stData->nSession_handle = ltohl(&pa_buf);
  pa_stData->nStatus = ltohl(&pa_buf);
  /*memcpy(pa_stData->anSender_context, pa_buf, SENDER_CONTEXT_SIZE);*/
  pa_buf += SENDER_CONTEXT_SIZE;
  pa_stData->nOptions = ltohl(&pa_buf);
  pa_stData->m_acCurrentCommBufferPos = pa_buf;
  return (pa_length - ENCAPSULATION_HEADER_LENGTH - pa_stData->nData_length);
}
Пример #6
0
/*
 * Walk partition tables and invoke a callback for each.
 */
static void
walk_partitions(int fd, int startsec, uint_t secsz,
    int (*f)(void *, int, uint_t, uint_t), void *arg)
{
	uint32_t buf[1024/4];
	int bufsize = 1024;
	struct mboot *mboot = (struct mboot *)&buf[0];
	struct ipart ipart[FD_NUMPART];
	uint_t sec = startsec;
	uint_t lastsec = sec + 1;
	uint_t relsect;
	int ext = 0;
	int systid;
	boolean_t valid;
	int i;

	while (sec != lastsec) {
		if (pread(fd, buf, bufsize, (off_t)sec * secsz) != bufsize) {
			break;
		}
		lastsec = sec;
		if (ltohs(mboot->signature) != MBB_MAGIC) {
			break;
		}
		bcopy(mboot->parts, ipart, FD_NUMPART * sizeof (struct ipart));

		for (i = 0; i < FD_NUMPART; i++) {
			systid = ipart[i].systid;
			relsect = sec + ltohi(ipart[i].relsect);
			if (systid == 0) {
				continue;
			}
			valid = B_TRUE;
			if (is_dos_extended(systid) && (sec == lastsec)) {
				sec = startsec + ltohi(ipart[i].relsect);
				if (ext++ == 0) {
					relsect = startsec = sec;
				} else {
					valid = B_FALSE;
				}
			}
			if (valid && f(arg, ipart[i].systid, relsect,
			    ltohi(ipart[i].numsect)) == WALK_TERMINATE) {
				return;
			}
		}
	}
}
Пример #7
0
/*   INT8 SendRRData(struct S_Encapsulation_Data *pa_stReceiveData)
 *   Call UCMM or Message Router if UCMM not implemented.
 *      pa_stReceiveData pointer to structure with data and header information.
 *  return status 	0 .. success.
 * 					-1 .. error
 */
EIP_STATUS
handleReceivedSendRRDataCmd(struct S_Encapsulation_Data * pa_stReceiveData)
{
  EIP_INT16 nSendSize;
  EIP_STATUS eRetVal = EIP_OK_SEND;

  if (pa_stReceiveData->nData_length >= 6)
    {
      /* Commandspecific data UDINT .. Interface Handle, UINT .. Timeout, CPF packets */
      /* don't use the data yet */
      ltohl(&pa_stReceiveData->m_acCurrentCommBufferPos); /* skip over null interface handle*/
      ltohs(&pa_stReceiveData->m_acCurrentCommBufferPos); /* skip over unused timeout value*/
      pa_stReceiveData->nData_length -= 6; /* the rest is in CPF format*/

      if (EIP_ERROR != checkRegisteredSessions(pa_stReceiveData)) /* see if the EIP session is registered*/
        {
          nSendSize =
              notifyCPF(pa_stReceiveData,
                  &pa_stReceiveData->m_acCommBufferStart[ENCAPSULATION_HEADER_LENGTH]);

          if (nSendSize >= 0)
            { /* need to send reply */
              pa_stReceiveData->nData_length = nSendSize;
            }
          else
            {
              eRetVal = EIP_ERROR;
            }
        }
      else
        { /* received a package with non registered session handle */
          pa_stReceiveData->nData_length = 0;
          pa_stReceiveData->nStatus = OPENER_ENCAP_STATUS_INVALID_SESSION_HANDLE;
        }
    }
  return eRetVal;
}
Пример #8
0
int			readWavData(FILE* file, char *data,
				int numSamples, int width)
{
  // read data
  int temp = fread(data, 1, width * numSamples, file);
  if (temp != width * numSamples) {
    fprintf(stderr, "Failed to read sound data\n");
    return -1;
  }

  // byte swap
  if (width == 2) {
    int16_t* sample = (int16_t*)data;
    for (int i = 0; i < numSamples; ++i)
      ltohs(sample + i);
  }
  else if (width == 4) {
    int32_t* sample = (int32_t*)data;
    for (int i = 0; i < numSamples; ++i)
      ltohl(sample + i);
  }

  return 0;
}
static int check_header(FILE *f)
{
	int type, size, formtype;
	int fmt, hsize, fact;
	short format, chans;
	int freq;
	int data;
	if (fread(&type, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (type)\n");
		return -1;
	}
	if (fread(&size, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (size)\n");
		return -1;
	}
	size = ltohl(size);
	if (fread(&formtype, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (formtype)\n");
		return -1;
	}
	if (memcmp(&type, "RIFF", 4)) {
		ast_log(LOG_WARNING, "Does not begin with RIFF\n");
		return -1;
	}
	if (memcmp(&formtype, "WAVE", 4)) {
		ast_log(LOG_WARNING, "Does not contain WAVE\n");
		return -1;
	}
	if (fread(&fmt, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (fmt)\n");
		return -1;
	}
	if (memcmp(&fmt, "fmt ", 4)) {
		ast_log(LOG_WARNING, "Does not say fmt\n");
		return -1;
	}
	if (fread(&hsize, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (formtype)\n");
		return -1;
	}
	if (ltohl(hsize) != 20) {
		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
		return -1;
	}
	if (fread(&format, 1, 2, f) != 2) {
		ast_log(LOG_WARNING, "Read failed (format)\n");
		return -1;
	}
	if (ltohs(format) != 49) {
		ast_log(LOG_WARNING, "Not a GSM file %d\n", ltohs(format));
		return -1;
	}
	if (fread(&chans, 1, 2, f) != 2) {
		ast_log(LOG_WARNING, "Read failed (format)\n");
		return -1;
	}
	if (ltohs(chans) != 1) {
		ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
		return -1;
	}
	if (fread(&freq, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (freq)\n");
		return -1;
	}
	if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
		ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
		return -1;
	}
	/* Ignore the byte frequency */
	if (fread(&freq, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (X_1)\n");
		return -1;
	}
	/* Ignore the two weird fields */
	if (fread(&freq, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (X_2/X_3)\n");
		return -1;
	}
	/* Ignore the byte frequency */
	if (fread(&freq, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (Y_1)\n");
		return -1;
	}
	/* Check for the word fact */
	if (fread(&fact, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (fact)\n");
		return -1;
	}
	if (memcmp(&fact, "fact", 4)) {
		ast_log(LOG_WARNING, "Does not say fact\n");
		return -1;
	}
	/* Ignore the "fact value" */
	if (fread(&fact, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (fact header)\n");
		return -1;
	}
	if (fread(&fact, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (fact value)\n");
		return -1;
	}
	/* Check for the word data */
	if (fread(&data, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (data)\n");
		return -1;
	}
	if (memcmp(&data, "data", 4)) {
		ast_log(LOG_WARNING, "Does not say data\n");
		return -1;
	}
	/* Ignore the data length */
	if (fread(&data, 1, 4, f) != 4) {
		ast_log(LOG_WARNING, "Read failed (data)\n");
		return -1;
	}
	return 0;
}
Пример #10
0
int dvslib_readbmpfile(char * filename, sv_storageinfo * pstorage, char * buffer, int buffersize, int * pxsize, int * pysize)
{
  bmppreheader  preheader;
  bmpheader     header;
  FILE *        fp;
  uint32        clut[256];
  uint8 * p;
  int x,y,i;
  size_t tmp;
  
  fp = fopen(filename, "r");
  if(fp == NULL) {
    printf("dvslib_readbmpfile: Could not open file '%s'\n", filename);
    return SV_ERROR_FILEOPEN;
  }
  
  tmp = fread(&preheader.magic, 1, sizeof(preheader) - 2, fp); 
  if(tmp != sizeof(bmppreheader)-2) {
    fclose(fp);
    return SV_ERROR_FILEREAD;
  }
  preheader.magic      = ltohs(&preheader.magic);
  preheader.bfsize     = ltohl(&preheader.bfsize);
  preheader.reserved1  = ltohs(&preheader.reserved1);
  preheader.reserved2  = ltohs(&preheader.reserved2);
  preheader.bfoffset   = ltohl(&preheader.bfoffset);

 
  tmp = fread(&header, 1, sizeof(bmpheader), fp); 
  if(tmp != sizeof(bmpheader)) {
    fclose(fp);
    return SV_ERROR_FILEREAD;
  }

  header.size          = ltohl (&header.size);
  if(header.size >= 40) {
    header.width         = ltohl(&header.width);
    header.height        = ltohl(&header.height);
    header.planes        = ltohs(&header.planes);  
    header.bitcount      = ltohs(&header.bitcount);
    header.compression   = ltohl(&header.compression);
    header.imagesize     = ltohl(&header.imagesize);
    header.xpelspermeter = ltohl(&header.xpelspermeter);
    header.ypelspermeter = ltohl(&header.ypelspermeter);
    header.clrused       = ltohl(&header.clrused);
    header.clrimportant  = ltohl(&header.clrimportant);
  } else if(header.size == 12) {
    bmpheaderold * h     = (bmpheaderold *) &header;
    header.bitcount      = ltohs(&h->bitcount);
    header.planes        = ltohs(&h->planes);  
    header.height        = ltohs(&h->height);
    header.width         = ltohs(&h->width);
    header.compression   = BI_RGB;
    header.imagesize     = header.width * header.bitcount * header.planes * header.height / 8;
    header.xpelspermeter = 0;
    header.ypelspermeter = 0;
    header.clrused       = 0;
    header.clrimportant  = 0;    
  } else {
    fclose(fp);
    return SV_ERROR_FILESEEK;
  }

#ifdef DEBUG_BMP
  printf("BMP header\n");
  printf("size:             %d\n", header.size);
  printf("height:           %d\n", header.height);
  printf("width:            %d\n", header.width);
  printf("planes:           %d\n", header.planes);
  printf("bitcount:         %d\n", header.bitcount);
  printf("compression:      %d\n", header.compression);
  printf("imagesize:        %d\n", header.imagesize);
  printf("xpels:            %d\n", header.xpelspermeter);
  printf("ypels:            %d\n", header.ypelspermeter);
  printf("clrused:          %d\n", header.clrused);
  printf("clrimportant:     %d\n", header.clrimportant);
#endif

  if(header.compression != BI_RGB) {
    return SV_ERROR_FILEFORMAT; 
  }

  if(!((header.bitcount == 24) ||
       (header.bitcount == 8)  ||
       (header.bitcount == 4)  ||
       (header.bitcount == 1))) {
    return SV_ERROR_FILEFORMAT; 
  }
   
  if(pxsize) {
    *pxsize = (header.width + 1) & ~1;
  }
  if(pysize) {
    *pysize = header.height;
  }

  if(!buffer) {
    fclose(fp);
    return SV_OK;
  }
    
  if(header.bitcount <= 8) {
    //int clut_start;
    size_t clut_size;

    if(header.clrused == 0) {
      header.clrused = 1 << header.bitcount;
    }

    //clut_start = sizeof(bmppreheader) - 2 + header.size;
    clut_size  = header.clrused * sizeof(uint32);
    
    tmp = fread(&clut, 1, clut_size, fp); 
    if(tmp != clut_size) {
      fclose(fp);
      return SV_ERROR_FILEREAD;
    } 

    if(header.size == 12) {
      uint8 * ptmp = (uint8 *) &clut[0];
      int  from = (int)clut_size * 3 / 4 - 3 ;
      int  to   = (int)clut_size - 4;
      for(; (to >= 0); from-=3, to-=4) {
        ptmp[to + 3] = 0;
        ptmp[to + 2] = ptmp[from + 2];
        ptmp[to + 1] = ptmp[from + 1];
        ptmp[to    ] = ptmp[from    ];
      }
    } 
  }

  for(y = 0; y < pstorage->storageysize; y++) {
    int r1,g1,b1,r2,g2,b2;
    uint32 temp, bit;
    p = (uint8*)&buffer[pstorage->fieldoffset[0] + (pstorage->storageysize - y - 1) * pstorage->lineoffset[0]];
    for(temp = bit = x = 0; x < pstorage->storagexsize; x+=2) {
      if(x < (int)header.width) {
        if(header.bitcount != 24) {
          switch(header.bitcount) {
          case 1:
            if(bit == 0) {
              temp = fgetc(fp) & 0xff;
            }
            b1 = clut[temp&(1<<bit)?1:0];
            g1 = clut[temp&(1<<bit)?1:0]>>8;
            r1 = clut[temp&(1<<bit)?1:0]>>16;
            bit++;
            b2 = clut[temp&(1<<bit)?1:0];
            g2 = clut[temp&(1<<bit)?1:0]>>8;
            r2 = clut[temp&(1<<bit)?1:0]>>16;
            bit++;
            if(bit >= 8) {
              bit = 0;
            }
            break;
          case 4:
            temp = fgetc(fp) & 0xff;
            b1 = clut[temp>>4];
            g1 = clut[temp>>4]>>8;
            r1 = clut[temp>>4]>>16;
            b2 = clut[temp&15];
            g2 = clut[temp&15]>>8;
            r2 = clut[temp&15]>>16;
	    break;
          default:
            temp = fgetc(fp) & 0xff;
            b1 = clut[temp];
            g1 = clut[temp]>>8;
            r1 = clut[temp]>>16;
            temp = fgetc(fp) & 0xff;
            b2 = clut[temp];
            g2 = clut[temp]>>8;
            r2 = clut[temp]>>16;
          }
        } else {
          b1 = fgetc(fp); g1 = fgetc(fp); r1 = fgetc(fp);
          if(x + 1 < (int)header.width) {
            b2 = fgetc(fp); g2 = fgetc(fp); r2 = fgetc(fp);
          } else {
            b2 = 0; g2 = 0; r2 = 0;
          }
        }
      } else {
        b1 = 0; g1 = 0; r1 = 0;
        b2 = 0; g2 = 0; r2 = 0;
      }

      switch(pstorage->colormode) {
      case SV_COLORMODE_MONO:
        *p++ = 0x10 + ( 67 * r1      + 131 * g1      +  25 * b1) / 256;
        *p++ = 0x10 + ( 67 * r2      + 131 * g2      + 112 * b2) / 256;
        break;
      case SV_COLORMODE_CHROMA:
        *p++ = 0x80 + (112 * (r1+r2) -  93 * (g1+g2) -  18 * (b1+b2)) / 512;
        *p++ = 0x80 + (-38 * (r1+r2) -  73 * (g1+g2) + 131 * (b1+b2)) / 512;
        break;
      case SV_COLORMODE_YUV422:
        /*
        // lum =>  16 + 224 * (0.299 * R + 0.587 * G + 0.114 * B);
	// rmy => 128 + 224 * (0.500 * R - 0.419 * G - 0.081 * B);
	// bmy => 128 + 224 * (-.169 * R - 0.331 * G + 0.500 * B);
        */
        *p++ = 0x80 + (112 * (r1+r2) -  93 * (g1+g2) -  18 * (b1+b2)) / 512;
        *p++ = 0x10 + ( 67 * r1      + 131 * g1      +  25 * b1) / 256;
        *p++ = 0x80 + (-38 * (r1+r2) -  73 * (g1+g2) + 131 * (b1+b2)) / 512;
        *p++ = 0x10 + ( 67 * r2      + 131 * g2      + 112 * b2) / 256;
        break;
      case SV_COLORMODE_YUV2QT:
        *p++ = 0x10 + ( 67 * r1      + 131 * g1      +  25 * b1) / 256;
        *p++ =        (112 * (r1+r2) -  93 * (g1+g2) -  18 * (b1+b2)) / 512;
        *p++ = 0x10 + ( 67 * r2      + 131 * g2      + 112 * b2) / 256;
        *p++ =        (-38 * (r1+r2) -  73 * (g1+g2) + 131 * (b1+b2)) / 512;
       break;
      case SV_COLORMODE_YUV422A:
        *p++ = 0x80 + (112 * (r1+r2) -  93 * (g1+g2) -  18 * (b1+b2)) / 512;
        *p++ = 0x10 + ( 67 * r1      + 131 * g1      +  25 * b1) / 256;
        *p++ = (r1 + g1 + b1) / 3;
        *p++ = 0x80 + (-38 * (r1+r2) -  73 * (g1+g2) + 131 * (b1+b2)) / 512;
        *p++ = 0x10 + ( 67 * r2      + 131 * g2      + 112 * b2) / 256;
        *p++ = (r2 + g2 + b2) / 3;
        break;
      case SV_COLORMODE_RGB_BGR:
        *p++ = b1;
        *p++ = g1;
        *p++ = r1;
        *p++ = b2;
        *p++ = g2;
        *p++ = r2;
        break;
      case SV_COLORMODE_ABGR:
      case SV_COLORMODE_ARGB:
        *p++ = (r1 + g1 + b1) / 3;
        *p++ = r1;
        *p++ = g1;
        *p++ = b1;
        *p++ = (r2 + g2 + b2) / 3;
        *p++ = r2;
        *p++ = g2;
        *p++ = b2;
        break;
      case SV_COLORMODE_BGRA:
        *p++ = b1;
        *p++ = g1;
        *p++ = r1;
        *p++ = (r1 + g1 + b1) / 3;
        *p++ = b2;
        *p++ = g2;
        *p++ = r2;
        *p++ = (r2 + g2 + b2) / 3;
        break;
      case SV_COLORMODE_RGB_RGB:
        *p++ = r1;
        *p++ = g1;
        *p++ = b1;
        *p++ = r2;
        *p++ = g2;
        *p++ = b2;
        break;
      case SV_COLORMODE_RGBA:
        *p++ = r1;
        *p++ = g1;
        *p++ = b1;
        *p++ = (r1 + g1 + b1) / 3;
        *p++ = r2;
        *p++ = g2;
        *p++ = b2;
        *p++ = (r2 + g2 + b2) / 3;
        break;
      case SV_COLORMODE_YUV444:
        *p++ = 0x80;
        *p++ = (r1 + g1 + b1) / 3;
        *p++ = 0x80;
        *p++ = 0x80;
        *p++ = (r2 + g2 + b2) / 3; 
        *p++ = 0x80;
        break;
      case SV_COLORMODE_YUV444A:
        *p++ = 0x80;
        *p++ = (r1 + g1 + b1) / 3;
        *p++ = 0x80;
        *p++ = (r1 + g1 + b1) / 3;
        *p++ = 0x80;
        *p++ = (r2 + g2 + b2) / 3; 
        *p++ = 0x80;
        *p++ = (r2 + g2 + b2) / 3;
        break;
      default:
        return SV_ERROR_PROGRAM;
      }
    }
Пример #11
0
/**
 * SMB header has been parsed, parse rest of msg
 * @return number of bytes consumed
 */
static size_t do_parse(char *buf, size_t len, const smb_hdr *h)
{
  size_t bytes = 0;
  printf("do_parse len=%u buf=", (unsigned)len);
  dump_chars(buf, len, stdout);
  fputc('\n', stdout);
  switch ((enum SMB_Cmd)h->cmd) {
  case SMB_Cmd_TransReq:
  { /* TODO: break out into own function */
    size_t namelen;
    smb_trans_req *r = (smb_trans_req *)buf;
    if (sizeof *r > len)
      return 0;
    /* convert endianness */
    r->totalparam       = ltohs(r->totalparam);
    r->totaldata        = ltohs(r->totaldata);
    r->maxparam         = ltohs(r->maxparam);
    r->maxdata          = ltohs(r->maxdata);
    r->param            = ltohs(r->param);
    r->paramoffset      = ltohs(r->paramoffset);
    r->data             = ltohs(r->data);
    r->dataoffset       = ltohs(r->dataoffset);
    r->mailslot.opcode  = ltohs(r->mailslot.opcode);
    r->mailslot.priority= ltohs(r->mailslot.priority);
    r->mailslot.class_  = ltohs(r->mailslot.class_);
    r->mailslot.bytes   = ltohs(r->mailslot.bytes);
    /* calculate length of name */
    namelen = memcspn((char *)r->name, len - sizeof *r - 1, "\x00", 1);
    bytes = namelen + sizeof *r; /* includes trailing \0 */
  }
    break;
  default:
    break;
  }
  return bytes;
}
Пример #12
0
/*
 *  XXX - right now we aren't attempting to fix anything that looks bad,
 *	instead we just give up.
 */
void
readBPB(int fd)
{
	boot_sector_t ubpb;

	/*
	 *  The BPB is the first sector of the file system
	 */
	if (lseek64(fd, PartitionOffset, SEEK_SET) < 0) {
		mountSanityCheckFails();
		perror(gettext("Cannot seek to start of disk partition"));
		(void) close(fd);
		exit(7);
	}
	if (Verbose)
		(void) fprintf(stderr,
		    gettext("Reading BIOS parameter block\n"));
	if (read(fd, ubpb.buf, BPSEC) < BPSEC) {
		mountSanityCheckFails();
		perror(gettext("Read BIOS parameter block"));
		(void) close(fd);
		exit(2);
	}

	if (ltohs(ubpb.mb.signature) != BOOTSECSIG) {
		mountSanityCheckFails();
		(void) fprintf(stderr,
		    gettext("Bad signature on BPB. Giving up.\n"));
		exit(2);
	}

#ifdef _BIG_ENDIAN
	swap_pack_grabbpb(&TheBIOSParameterBlock, &(ubpb.bs));
#else
	(void) memcpy(&(TheBIOSParameterBlock.bpb), &(ubpb.bs.bs_front.bs_bpb),
	    sizeof (TheBIOSParameterBlock.bpb));
	(void) memcpy(&(TheBIOSParameterBlock.ebpb), &(ubpb.bs.bs_ebpb),
	    sizeof (TheBIOSParameterBlock.ebpb));
#endif
	/*
	 * In general, we would expect the bytes per sector to
	 * equal 256 (BPSEC).  I personally have yet to see a file
	 * system where this isn't true but apparently some weird media
	 * have different sector sizes.  So we'll accept a couple of
	 * other small multiples of 256 as valid sizes.
	 */
	if (TheBIOSParameterBlock.bpb.bytes_per_sector != BPSEC &&
	    TheBIOSParameterBlock.bpb.bytes_per_sector != 2 * BPSEC &&
	    TheBIOSParameterBlock.bpb.bytes_per_sector != 4 * BPSEC) {
		mountSanityCheckFails();
		(void) fprintf(stderr,
		    gettext("Bogus bytes per sector value.  Giving up.\n"));
		exit(2);
	}
	if (!(ISP2(TheBIOSParameterBlock.bpb.sectors_per_cluster) &&
	    IN_RANGE(TheBIOSParameterBlock.bpb.sectors_per_cluster,
	    1, 128))) {
		mountSanityCheckFails();
		(void) fprintf(stderr,
		    gettext("Bogus sectors per cluster value.  Giving up.\n"));
		(void) close(fd);
		exit(6);
	}
	if (TheBIOSParameterBlock.bpb.sectors_per_fat == 0) {
#ifdef _BIG_ENDIAN
		swap_pack_grab32bpb(&TheBIOSParameterBlock, &(ubpb.bs));
#else
		(void) memcpy(&(TheBIOSParameterBlock.bpb32),
		    &(ubpb.bs32.bs_bpb32),
		    sizeof (TheBIOSParameterBlock.bpb32));
#endif
		IsFAT32 = 1;
	}
	if (!IsFAT32) {
		if ((TheBIOSParameterBlock.bpb.num_root_entries == 0) ||
		    ((TheBIOSParameterBlock.bpb.num_root_entries *
		    sizeof (struct pcdir)) %
		    TheBIOSParameterBlock.bpb.bytes_per_sector) != 0) {
			mountSanityCheckFails();
			(void) fprintf(stderr,
			    gettext("Bogus number of root entries.  "
			    "Giving up.\n"));
			exit(2);
		}
	} else {
		if (TheBIOSParameterBlock.bpb.num_root_entries != 0) {
			mountSanityCheckFails();
			(void) fprintf(stderr,
			    gettext("Bogus number of root entries.  "
			    "Giving up.\n"));
			exit(2);
		}
	}
	/*
	 * In general, we would expect the number of FATs field to
	 * equal 2.  Our mkfs and Windows have this as a default
	 * value.  I suppose someone could override the default,
	 * though, so we'll sort of arbitrarily accept any number
	 * between 1 and 4 inclusive as reasonable values.
	 *
	 * XXX: Warn, but continue, if value is suspicious? (>2?)
	 */
	if (TheBIOSParameterBlock.bpb.num_fats > 4 ||
	    TheBIOSParameterBlock.bpb.num_fats < 1) {
		mountSanityCheckFails();
		(void) fprintf(stderr,
		    gettext("Bogus number of FATs.  Giving up.\n"));
		exit(2);
	}
	computeFileAreaSize();
}