Exemple #1
0
bool WPUtils::fromHex(const QString in, QByteArray & toReturn) {
	QString temp(in);
	temp.replace(" ","");
	temp.replace(":","");
	temp.replace(".","");
	QByteArray content(temp.toLocal8Bit());

	const char * c(content.constData());

	if (content.length() == 0 || ((content.length() % 2) != 0)) {
		return false;
	}

	for (int i = 0; i < content.length(); i += 2) {
		char a = c[i];
		char b = c[i + 1];
		a = nibble(a);
		b = nibble(b);
		if (a < 0 || b < 0) {
			toReturn.clear();
			return false;
		}
		toReturn.append((a << 4) | b);
	}
	return true;
}
static char *formatDosToAmiga_ShouldCapStrikeOutsAndMoveExcessFromActionToSimulated_GivenAPlayersFile()
{
     fileplayer_s *players_file = buildFilePlayers();
     int           player_idx   = 0;

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               int2byte( players_file[i].acc_stats.action.batting.acc_so,    229 );
               int2byte( players_file[i].acc_stats.simulated.batting.acc_so,   0 );

               player_idx = i;

               break;
          }
     }

     formatDosToAmiga( players_file );

     assertEquals( 225, byte2int( players_file[player_idx].acc_stats.simulated.batting.acc_so ) );
     assertEquals(   4, byte2int( players_file[player_idx].acc_stats.action.batting.acc_so    ) );

     return NULL;
}
static char *formatDosToAmiga_ShouldMovePitcherActionGamesToSimulatedStarts_GivenAPlayersFile()
{
     fileplayer_s *players_file    = buildFilePlayers();
     int           expected_starts = 0;
     int           player_idx      = 0;

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos == fpos_Pitcher )
          {
               acc_pch_stats_s *sim = &(players_file[i].acc_stats.simulated.pitching);
               acc_bat_stats_s *act = &(players_file[i].acc_stats.action.batting);

               expected_starts = byte2int( sim->acc_starts );
               player_idx      = i;

               int2byte( sim->acc_starts, byte2int( act->acc_games ) );
               int2byte( act->acc_games,  expected_starts            );

               break;
          }
     }

     assertEquals( bl_True, formatDosToAmiga( players_file ) );

     acc_pch_stats_s *sim = &(players_file[player_idx].acc_stats.simulated.pitching);

     assertEquals( expected_starts, byte2int( sim->acc_starts ) );

     return NULL;
}
Exemple #4
0
boolean_e copyLongevity( fileplayer_s *players_file1, fileplayer_s *players_file2 )
{
     fileplayer_s *matchingPlayer;

     clearErrorMessage();

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          if ( EMPTY( players_file1[i].last_name ) ) continue;

          if ( (matchingPlayer = findMatchingPlayer( &players_file1[i], players_file2 )) == NULL )
          {
               sprintf( error_message, "Player <%.*s, %.*s> not found!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          int pos = nibble( players_file1[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               players_file1[i].filestats.filebatting.ratings[2] = matchingPlayer->filestats.filebatting.ratings[2];
          }
     }

     return bl_True;
}
static char *formatDosToAmiga_ShouldSwapBatterSimulatedWithAction_GivenAPlayersFile()
{
     fileplayer_s    *players_file = buildFilePlayers();
     acc_bat_stats_s  expected_sim = { 0 };
     acc_bat_stats_s  expected_act = { 0 };
     int              player_idx   =   0;

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               if ( byte2int( players_file[i].acc_stats.action.batting.acc_rbi ) < STAT_CAP_AMOUNT &&
                    byte2int( players_file[i].acc_stats.action.batting.acc_so  ) < STAT_CAP_AMOUNT    )
               {
                    expected_act = players_file[i].acc_stats.simulated.batting;
                    expected_sim = players_file[i].acc_stats.action.batting;
                    player_idx   = i;

                    break;
               }
          }
     }

     assertEquals( bl_True, formatDosToAmiga( players_file ) );

     compareBattingStats( &expected_act, &(players_file[player_idx].acc_stats.action.batting)    );
     compareBattingStats( &expected_sim, &(players_file[player_idx].acc_stats.simulated.batting) );

     return NULL;
}
static char *formatDosToAmiga_ShouldReturnFalseIfBatterNeedingOverflowHasPitchingStats_GivenAPlayersFile()
{
     fileplayer_s *players_file = buildFilePlayers();

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               acc_bat_stats_s *batting = &(players_file[i].acc_stats.action.batting);

               int2byte( batting->acc_rbi, STAT_CAP_AMOUNT + 1 );
               int2byte( batting->acc_so,  STAT_CAP_AMOUNT + 1 );

               acc_pch_stats_s *pitching = &(players_file[i].acc_stats.simulated.pitching);

               int2word( pitching->acc_innings, 1 );
               int2word( pitching->acc_hits,    1 );

               break;
          }
     }

     assertEquals( bl_False, formatDosToAmiga( players_file ) );

     return NULL;
}
int usbnet_get_ethernet_addr(struct usbnet *dev, int iMACAddress)
{
	int 		tmp, i;
	unsigned char	buf [13];

	tmp = usb_string(dev->udev, iMACAddress, buf, sizeof buf);
	if (tmp != 12) {
		dev_dbg(&dev->udev->dev,
			"bad MAC string %d fetch, %d\n", iMACAddress, tmp);
		if (tmp >= 0)
			tmp = -EINVAL;
		return tmp;
	}
	for (i = tmp = 0; i < 6; i++, tmp += 2)
		dev->net->dev_addr [i] =
			(nibble(buf [tmp]) << 4) + nibble(buf [tmp + 1]);
	return 0;
}
Exemple #8
0
int main(int argc, char * argv []) {
  unsigned int length = 0;
  unsigned int i = 0;
  unsigned char * input;
  unsigned char * output;
  unsigned char * key;

  if ((argc != 2) || (strlen(argv[1]) != 40)) {
    puts("Usage : ./bruteforce <hash> (ex: 2c3422d33fb9dd9cde87657408e48f4e635713cb)");
    return EXIT_FAILURE;
  }

  input   = malloc(20);
  output  = malloc(20);
  key     = malloc(9);

  /* fill input with argv[1] */
  printf("Buffer: ");
  for (i=0;i<40;i++) {
    if (i%2) {
      input [i/2] <<= 4;
      input [i/2] += nibble(argv[1][i]);
      printf("%02x",input[i/2]);
    } else {
      input [i/2] =  nibble(argv[1][i]);
    }
  }
  putchar('\n');

  /* launch recursions */
  for ( length = 4; length < 10; length++) {
    printf("Length: %d\n",length);
    memset(key,0,length);
    recursion(length,length,0,output,input,key);
  }

  free(key);
  free(input);
  free(output);

  return EXIT_SUCCESS;
}
Exemple #9
0
SECStatus
SECU_SECItemHexStringToBinary(SECItem* srcdest)
{
    int i;

    if (!srcdest) {
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
        return SECFailure;
    }
    if (srcdest->len < 4 || (srcdest->len % 2) ) {
        /* too short to convert, or even number of characters */
        PORT_SetError(SEC_ERROR_BAD_DATA);
        return SECFailure;
    }
    if (PORT_Strncasecmp((const char*)srcdest->data, "0x", 2)) {
        /* wrong prefix */
        PORT_SetError(SEC_ERROR_BAD_DATA);
        return SECFailure;
    }

    /* 1st pass to check for hex characters */
    for (i=2; i<srcdest->len; i++) {
        char c = PORT_Tolower(srcdest->data[i]);
        if (! ( ( c >= '0' && c <= '9') ||
                ( c >= 'a' && c <= 'f')
              ) ) {
            PORT_SetError(SEC_ERROR_BAD_DATA);
            return SECFailure;
        }
    }

    /* 2nd pass to convert */
    for (i=2; i<srcdest->len; i+=2) {
        srcdest->data[(i-2)/2] = (nibble(srcdest->data[i]) << 4) +
                                 nibble(srcdest->data[i+1]);
    }

    /* adjust length */
    srcdest->len -= 2;
    srcdest->len /= 2;
    return SECSuccess;
}
Exemple #10
0
/* convert the string version of a joystick guid to the struct */
SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
{
    SDL_JoystickGUID guid;
    int maxoutputbytes= sizeof(guid);
    size_t len = SDL_strlen(pchGUID);
    Uint8 *p;
    size_t i;

    /* Make sure it's even */
    len = (len) & ~0x1;

    SDL_memset(&guid, 0x00, sizeof(guid));

    p = (Uint8 *)&guid;
    for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i+=2, p++) {
        *p = (nibble(pchGUID[i]) << 4) | nibble(pchGUID[i+1]);
    }

    return guid;
}
Exemple #11
0
static int get_ether_addr(const char *str, u8 *dev_addr)
{
	if (str) {
		unsigned	i;

		for (i = 0; i < 6; i++) {
			unsigned char num;

			if ((*str == '.') || (*str == ':'))
				str++;
			num = nibble(*str++) << 4;
			num |= (nibble(*str++));
			dev_addr [i] = num;
		}
		if (is_valid_ether_addr(dev_addr))
			return 0;
	}
	random_ether_addr(dev_addr);
	return 1;
}
Exemple #12
0
void init_lcd() {
    TRISBbits.RB7 = 0;
    TRISBbits.RB6 = 0;
    TRISBbits.RB5 = 0;

    TRISAbits.RA0 = 0;
    TRISAbits.RA1 = 0;
    TRISAbits.RA2 = 0;
    TRISAbits.RA3 = 0;

    RS = 0;
    RW = 0;
    E = 0;

    delay_s(1);

    nibble(0x03);
    __delay_ms(5);
    nibble(0x03);
    __delay_ms(5);
    nibble(0x03);
    delay_10us(15);
    nibble(0x02);

    send_command(LCD_FUNCTIONSET | LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS);
    send_command(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF);

    TRISCbits.RC0 = 0;
    backlight_on();

    clear();
    home();

    splash(SPLASH_MSG);

    clear();
    home();

    backlight_off();
}
Exemple #13
0
static uint8_t* uint32_to_string(uint32_t x)
{
  static uint8_t buf[8];

  buf[7] = hex(nibble(x, 0));
  buf[6] = hex(nibble(x, 1));
  buf[5] = hex(nibble(x, 2));
  buf[4] = hex(nibble(x, 3));
  buf[3] = hex(nibble(x, 4));
  buf[2] = hex(nibble(x, 5));
  buf[1] = hex(nibble(x, 6));
  buf[0] = hex(nibble(x, 7));

  return buf;
}
Exemple #14
0
void
vsprintf(char *str, char *fmt, va_list ap)
{
	u8 buf[14], i;
	u32 n;

	do {
		while (*fmt != '%') {
			if (*fmt == 0x5c) /* '\' escape character */
				fmt++;
			if (!(*str++ = *fmt++)) /* actual text copy */
				return;
		}

		switch (*++fmt) {
		case 'c' :
			buf[0] = va_arg(ap, int);
			*str++ = buf[0];
			break;
		case 's' :
			for (char *c = va_arg(ap, char *); *c; *str++ = *c++);
			break;
		case 'd' :
			n = va_arg(ap, u32);
			if (!n) {
				*str++ = '0';
				break;
			}

			memset(buf, 0, sizeof(buf));
			for (i = 13; (buf[i] = n % 10) || (n > 9); n /= 10)
				buf[i--] += '0'; 
			while (*str++ = buf[++i], i < 13);
			break;
		case 'x' :
			n = va_arg(ap, u32);
			if (!n) {
				*str++ = '0';
				break;
			}
#define nibble(i, n) (n >> ((7 - i) * 4)) & 0xf
			for (i = 8; i--; buf[i] = xdigs[nibble(i, n)]);
			while (buf[++i] == '0');
			for (buf[8] = 0; i != 8; *str++ = buf[i++]);
			break;
		}
	} while (*fmt++);
}
Exemple #15
0
static int deflate( z_stream *z, int mode )
{
#if TRACE_SUBSTRINGS
/***  instrumentation purposes -- write out the stream contents
 ***  and all up-to-SUBSTR_LEN-byte substrings
 ***/
  size_t i, j, k;
  int only_of_len = 0; /* 0=>all */

  if (getenv( "TRACE_SUBSTR_LEN" ))
    only_of_len = atoi( getenv( "TRACE_SUBSTR_LEN" ) );

  fprintf( substring_trace_file, ";; ZIP %u\n", (unsigned)z->avail_in );

  for (i=0; i<z->avail_in; i++)
    {
      /* for each input character, print out its substrings */
      fprintf( substring_trace_file, ";; [%u] %#02x\n", 
	       (unsigned)i, z->next_in[i] );

      for (j=0; j<SUBSTR_LEN-1; j++)
	z->past[j] = z->past[j+1];

      z->past[SUBSTR_LEN-1] = z->next_in[i];
      z->n_past++;
      if (z->n_past > SUBSTR_LEN)
	z->n_past = SUBSTR_LEN;
      for (j=1; j<=z->n_past; j++)
	{
	  if (!only_of_len || (j == only_of_len))
	    {
	      /* the substring of length `j' */
	      char *p, temp[200];
	      p = temp;
	      for (k=SUBSTR_LEN-j; k<SUBSTR_LEN; k++)
		{
		  *p++ = nibble( z->past[k] >> 4 );
		  *p++ = nibble( z->past[k] & 0xF );
		  *p++ = ' ';
		}
	      *--p = 0;
	      fprintf( substring_trace_file, "%s\n", temp );
	    }
	}
    }
static void swapBatterStats( fileplayer_s *players_file )
{
     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               acc_stats_u *sim = &(players_file[i].acc_stats.simulated);
               acc_stats_u *act = &(players_file[i].acc_stats.action);

               acc_stats_u temp = *sim;

               *sim = *act;
               *act = temp;
          }
     }
}
std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, int _endNibble, unsigned _offset)
{
	unsigned begin = _beginNibble + _offset;
	unsigned end = (_endNibble < 0 ? ((int)(_data.size() * 2 - _offset) + 1) + _endNibble : _endNibble) + _offset;
	bool odd = (end - begin) & 1;

	std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16);
	ret.reserve((end - begin) / 2 + 1);

	unsigned d = odd ? 1 : 2;
	for (auto i = begin; i < end; ++i, ++d)
	{
		byte n = nibble(_data, i);
		if (d & 1)	// odd
			ret.back() |= n;		// or the nibble onto the back
		else
			ret.push_back(n << 4);	// push the nibble on to the back << 4
	}
	return ret;
}
Exemple #18
0
bool UUID::tryParse(const std::string& uuid)
{
    if (uuid.size() < 32)
        return false;

    bool haveHyphens = false;
    if (uuid[8] == '-' && uuid[13] == '-' && uuid[18] == '-' && uuid[23] == '-')
    {
        if (uuid.size() >= 36)
            haveHyphens = true;
        else
            return false;
    }

    std::string::const_iterator it = uuid.begin();
    _timeLow = 0;
    for (int i = 0; i < 8; ++i)
    {
        _timeLow = (_timeLow << 4) | nibble(*it++);
    }
    if (haveHyphens) ++it;
    _timeMid = 0;
    for (int i = 0; i < 4; ++i)
    {
        _timeMid = (_timeMid << 4) | nibble(*it++);
    }
    if (haveHyphens) ++it;
    _timeHiAndVersion = 0;
    for (int i = 0; i < 4; ++i)
    {
        _timeHiAndVersion = (_timeHiAndVersion << 4) | nibble(*it++);
    }
    if (haveHyphens) ++it;
    _clockSeq = 0;
    for (int i = 0; i < 4; ++i)
    {
        _clockSeq = (_clockSeq << 4) | nibble(*it++);
    }
    if (haveHyphens) ++it;
    for (int i = 0; i < 6; ++i)
    {
        _node[i] = (nibble(*it++) << 4) | nibble(*it++) ;
    }

    return true;
}
Exemple #19
0
void UUID::parse(const std::string& uuid)
{
	if(uuid.size() < 36)
	{
		throw SyntaxException(uuid);
	}
	if(uuid[8] != '-' || uuid[13] != '-' || uuid[18] != '-' || uuid[23] != '-')
	{
		throw SyntaxException(uuid);
	}
	std::string::const_iterator it  = uuid.begin();
	for (int i = 0; i < 8; ++i)
	{
		_timeLow = (_timeLow << 4) | nibble(*it++);
	}
	++it;
	for (int i = 0; i < 4; ++i)
	{
		_timeMid = (_timeMid << 4) | nibble(*it++);
	}
	++it;
	for (int i = 0; i < 4; ++i)
	{
		_timeHiAndVersion = (_timeHiAndVersion << 4) | nibble(*it++);
	}
	++it;
	for (int i = 0; i < 4; ++i)
	{
		_clockSeq = (_clockSeq << 4) | nibble(*it++);
	}
	++it;
	for (int i = 0; i < 6; ++i)
	{
		_node[i] = (nibble(*it++) << 4) | nibble(*it++) ;			
	}
}
Exemple #20
0
rpmRC rpmnsProbeSignature(void * _ts, const char * fn, const char * sigfn,
		const char * pubfn, const char * pubid,
		/*@unused@*/ int flags)
{
    rpmts ts = (rpmts) _ts;
    pgpDig dig = rpmtsDig(ts);
    pgpDigParams sigp = pgpGetSignature(dig);
    pgpDigParams pubp = pgpGetPubkey(dig);
    rpmuint8_t * sigpkt = NULL;
    size_t sigpktlen = 0;
    DIGEST_CTX ctx = NULL;
    rpmRC rc = RPMRC_FAIL;	/* assume failure */
    int xx;
rpmhkp hkp = NULL;
pgpPkt pp = (pgpPkt) alloca(sizeof(*pp));
size_t pleft;
int validate = 1;

SPEW((stderr, "==> check(%s, %s, %s, %s)\n", fn,
	(sigfn ? sigfn : "(null)"),
	(pubfn ? pubfn : "(null)"),
	(pubid ? pubid : "(null)")));

    /* Choose signature location: clearsign from fn if sigfn is NULL */
assert(fn && *fn);
    if (!(sigfn && *sigfn))
	sigfn = fn;

    /* Load the signature from the file. */
    {	const char * _sigfn = rpmExpand(sigfn, NULL);
	xx = pgpReadPkts(_sigfn, &sigpkt, &sigpktlen);
	if (xx != PGPARMOR_SIGNATURE) {
SPEW((stderr, "==> pgpReadPkts(%s) SIG %p[%u] ret %d\n", _sigfn, sigpkt, (unsigned)sigpktlen, xx));
	    _sigfn = _free(_sigfn);
	    goto exit;
	}
	_sigfn = _free(_sigfn);
    }

    pleft = sigpktlen;
    xx = pgpPktLen(sigpkt, pleft, pp);
    xx = rpmhkpLoadSignature(NULL, dig, pp);
    if (xx) goto exit;

    if (sigp->version != (rpmuint8_t)3 && sigp->version != (rpmuint8_t)4) {
SPEW((stderr, "==> unverifiable V%u\n", (unsigned)sigp->version));
	goto exit;
    }

    if (ts->hkp == NULL)
	ts->hkp = rpmhkpNew(NULL, 0);
    hkp = rpmhkpLink(ts->hkp);

    /* Load the pubkey. Use pubfn if specified, otherwise rpmdb keyring. */
    if (pubfn && *pubfn) {
	const char * _pubfn = rpmExpand(pubfn, NULL);
/*@-type@*/
hkp->pkt = _free(hkp->pkt);	/* XXX memleaks */
hkp->pktlen = 0;
	xx = pgpReadPkts(_pubfn, &hkp->pkt, &hkp->pktlen);
/*@=type@*/

	if (xx != PGPARMOR_PUBKEY) {
SPEW((stderr, "==> pgpReadPkts(%s) PUB %p[%u] rc %d\n", _pubfn, hkp->pkt, (unsigned)hkp->pktlen, xx));
	    _pubfn = _free(_pubfn);
	    goto exit;
	}
	_pubfn = _free(_pubfn);

	/* Split the result into packet array. */
hkp->pkts = _free(hkp->pkts);	/* XXX memleaks */
hkp->npkts = 0;
	xx = pgpGrabPkts(hkp->pkt, hkp->pktlen, &hkp->pkts, &hkp->npkts);

#ifdef	DYING
_rpmhkpDumpDig(__FUNCTION__, dig, NULL);
#endif

	if (!xx)
	    (void) pgpPubkeyFingerprint(hkp->pkt, hkp->pktlen, hkp->keyid);
	memcpy(pubp->signid, hkp->keyid, sizeof(pubp->signid));/* XXX useless */

	/* Validate pubkey self-signatures (if any). */
	/* XXX TODO: only validate once, then cache using rpmku */
	/* XXX need at least 3 packets to validate a pubkey */
	if (validate && hkp->npkts >= 3) {
#ifdef	DYING
pgpPrtPkts(hkp->pkt, hkp->pktlen, NULL, 1);
#endif
	    xx = rpmhkpValidate(hkp, NULL);
	    switch (xx) {
	    case RPMRC_OK:
		break;
	    case RPMRC_NOTFOUND:
	    case RPMRC_FAIL:	/* XXX remap to NOTFOUND? */
	    case RPMRC_NOTTRUSTED:
	    case RPMRC_NOKEY:
	    default:
SPEW((stderr, "\t<-- rpmhkpValidate() rc %d\n", xx));
		rc = (rpmRC)xx;
		goto exit;
	    }
	}

	/* Retrieve parameters from pubkey/subkey packet(s). */
	xx = rpmhkpFindKey(hkp, dig, sigp->signid, sigp->pubkey_algo);
	if (xx) {
SPEW((stderr, "\t<-- rpmhkpFindKey() rc %d\n", xx));
	    goto exit;
	}

    } else {
	rc = (rpmRC)pgpFindPubkey(dig);
	if (rc != RPMRC_OK) {
SPEW((stderr, "\t<-- pgpFindPubkey() rc %d\n", rc));
	    goto exit;
	}
    }

    /* Is this the requested pubkey? */
    if (pubid && *pubid) {
	size_t ns = strlen(pubid);
	const char * s;
	char * t;
	size_t i;

	/* At least 8 hex digits please. */
	for (i = 0, s = pubid; *s && isxdigit(*s); s++, i++)
	    {};
	if (!(*s == '\0' && i > 8 && (i%2) == 0)) {
SPEW((stderr, "==> invalid pubid:  %s\n", pubid));
	    goto exit;
	}

	/* Truncate to key id size. */
	s = pubid;
	if (ns > 16) {
	    s += (ns - 16);
	    ns = 16;
	}
	ns >>= 1;
	t = (char *) memset(alloca(ns), 0, ns);
	for (i = 0; i < ns; i++)
	    t[i] = (char)((nibble(s[2*i]) << 4) | nibble(s[2*i+1]));

	/* Compare the pubkey id. */
	s = (const char *)pubp->signid;
	xx = memcmp(t, s + (8 - ns), ns);

#ifdef	DYING
	/* XXX HACK: V4 RSA key id's are wonky atm. */
	if (pubp->pubkey_algo == (rpmuint8_t)PGPPUBKEYALGO_RSA)
	    xx = 0;
#endif

	if (xx) {
SPEW((stderr, "==> mismatched: pubkey id (%08x %08x) != %s\n",
pgpGrab(pubp->signid, 4), pgpGrab(pubp->signid+4, 4), pubid));
	    goto exit;
	}
    }
char* TX23UWindSensor::getSentence(char sentence[], size_t maxSize) {
  if (!requestData) { // request data
    if (millis() - start < 4000)
      return NULL;

    pinMode(TxD, OUTPUT);
    digitalWrite(TxD, HIGH);

    delay(1);

    digitalWrite(TxD, LOW); // pull reset signal start

    requestData = true;
    start = millis();

    return NULL;
  } else {
    if (millis() - start < 500)
      return NULL;

    requestData = false;
    start = millis();

    pinMode(TxD, OUTPUT);
    digitalWrite(TxD, HIGH);

    delay(16); // wait 1-2ms high, + half of the low period, approx 9ms = 11ms

    pinMode(TxD, INPUT);
    int pulse = pulseIn(TxD, HIGH, 10000) / 2;

    delayMicroseconds(pulse * 3 + pulse / 2);

    bool data[20];
    for (byte pointer = 0; pointer < 36; pointer++) {
      bool b = digitalRead(TxD) ? 1 : 0;

      if (pointer < 20)
        data[pointer] = b;
      else if (data[pointer - 20] == b)
        return NULL;

      delayMicroseconds(pulse - 5);
    }

    // validate data
    byte checksum = 0;
    for (byte i = 0; i < 4; i++)
      checksum += nibble(data, i << 2);

    if (nibble(data, 16) != (checksum & 0x0F))
      return NULL;

    //process data
    unsigned int speed = 0;
    for (byte pointer = 15; pointer >= 4; pointer--)
      speed |= data[pointer] << (pointer - 4);

    MWVSentence mwv;
    mwv.windAngle = fmod(nibble(data, 0) * 22.5 + 281.25, 360.0);
    mwv.windSpeed = speed * 0.194384; //knots

    return mwv.get(sentence, maxSize);
  }
}
Exemple #22
0
int main(int argc, char * argv[]) {
  struct bbox b;
  unsigned int h1;
  unsigned int h2;
  unsigned int h3;

  struct bbox results[10];
  unsigned int result_index = 0;

  unsigned char serial_number [13];

  unsigned char sha1_output_buffer[20];
  SHA1Context ctx;

  unsigned int i = 0;

  /* récupération du ssid depuis argv */
  if (argc != 2 || strlen(argv[1]) < 6) {
    puts("usage : ./pwn ssid[-6]");
    return 0;
  }

  b.ssid1 = (nibble(argv[1][0]) << 4) + nibble(argv[1][1]);
  b.ssid2 = (nibble(argv[1][2]) << 4) + nibble(argv[1][3]);
  b.ssid3 = (nibble(argv[1][4]) << 4) + nibble(argv[1][5]);

  serial_number[0] = 'C';
  serial_number[1] = 'P';
  serial_number[12] = 0x00;

  for (b.year = 2006; b.year < 2012; b.year++) {
    printf("Year %d\n",b.year);
    /* write year */
    serial_number[2] = 0x30 + (b.year % 100) / 10;
    serial_number[3] = 0x30 + (b.year % 10);

    for (b.week = 1; b.week < 52; b.week++) {
      /* write week */
      serial_number[4] = 0x30 + (b.week / 10);
      serial_number[5] = 0x30 + (b.week % 10);

      for (h1 = 0; h1 < 72; h1 += 2) {
        /* write hexvalue 1 */
        serial_number[6] = hexvalues[h1];
        serial_number[7] = hexvalues[h1 + 1];
        for (h2 = 0; h2 < 72; h2 += 2) {
          /* write hexvalue 2 */
          serial_number[8] = hexvalues[h2];
          serial_number[9] = hexvalues[h2+1];
          for (h3 = 0; h3 < 72; h3 += 2) {
            /* write hexvalue 3 */
            serial_number[10] = hexvalues[h3];
            serial_number[11] = hexvalues[h3+1];
            /* évaluation du sha1 */
            SHA1Reset(&ctx);
            SHA1Input(&ctx,serial_number,12);
            SHA1Result(&ctx,sha1_output_buffer);

            /* validation du ssid */
            if (sha1_output_buffer[17] == b.ssid1) {
              if (sha1_output_buffer[18] == b.ssid2) {
                if (sha1_output_buffer[19] == b.ssid3) {
                  results[result_index].year = b.year;
                  results[result_index].week = b.week;
                  results[result_index].h1 = h1;
                  results[result_index].h2 = h2;
                  results[result_index].h3 = h3;
                  memcpy(&results[result_index].pass,&sha1_output_buffer,5);   
                  result_index++;
                }
              }
            }
          }
        }
      }
    }
  }

  /* bruteforce done : */
  printf("Got %d possibilities\n",result_index);
  printf("pass        serial\n");
  for (i=0;i<result_index;i++) {
    printf("%02X%02X%02X%02X%02X  CP%02d%02d%c%c%c%c%c%c\n",
      results[i].pass[0],
      results[i].pass[1],
      results[i].pass[2],
      results[i].pass[3],
      results[i].pass[4],
      results[i].year % 100,
      results[i].week,
      hexvalues[results[i].h1],
      hexvalues[results[i].h1+1],
      hexvalues[results[i].h2],
      hexvalues[results[i].h2+1],
      hexvalues[results[i].h3],
      hexvalues[results[i].h3+1]
      );
  }
}
Exemple #23
0
/* Retrieves the arbitrary buffer of bytes from the server that was stored
	for a user with master_gamesave() (see above).  The user is the one
	with username 'user', and password 'pass'.  The data bytes are
	stored into 'buf'.  The number of bytes retrieved is stored in
	'len' (note 'len' is a pointer).
	Returns 0 on success, 1 on failure.
	A 'len' of 0 is returned if no gamedata has been saved for the user. */
int master_gameload(const char *user, const char *pass, unsigned char *buf, unsigned long *len)
{
	if(strlen(user) >= 25)
		return 1;
	if(strlen(pass) >= 25)
		return 1;

	strcpy(path, master_path);
	strcat(path, "?action=gameload&");
	if(URLEncode::addParam(path, sizeof(path), user, "username") == false)
		return 1;
	if(URLEncode::addParam(path, sizeof(path), pass, "password") == false)
		return 1;

	/* XXX If the windows HTTPGetRequest() thing can be made to work with
	long, 4K char paths (which it's supposed to, but for some reason
	refused to work for me) then the following, commented out code can
	be used instead of the httpGet() call below it (which requires you to
	roll your own Socket() class. */
#if 0
	HTTPGetRequest *hgr = new HTTPGetRequest(master_host, 80, path, false, true, false);
	if(!hgr)
		return 1;
	int r = 0;
	char *b = master_http_buf;
	int bs = sizeof(master_http_buf);
	while(true)
	{
		int n = hgr->read(b, bs);
		if(n == 0)
			break;		// normal EOF
		if(hgr->failed)
			break;
		bs -= n;
		b += n;
		r += n;
	}
	bool f = hgr->failed;
	delete hgr;
	if(f)
		return 1;	// error
#else
	char *b = master_http_buf;
	int bs = sizeof(master_http_buf);
	if(httpGet(master_host, 80, path, b, bs) == -1)
		return 1;
#endif


	int r = bustup_response();


	// unhexify
	const char *gamedata = master_retval("gamedata");
	*len = strlen(gamedata) / 2;
	for(unsigned long i = 0; i < *len; i++)
	{
		unsigned char hn = nibble(gamedata[(i * 2) + 0]);
		unsigned char ln = nibble(gamedata[(i * 2) + 1]);
		buf[i] = (hn << 4) + ln;
	}


	return r;
}
Exemple #24
0
int identify_ins(uint16_t opcode) {

        switch (opcode & 0xF000) {
        case 0x0000: 
                if (opcode == 0x00E0) { /* CLS */
                        return CLS;
                } else if (opcode == 0x00EE) { /* RET */
                        return RET;
                } else { /* SYS */
                        return SYS_addr;
                }
        case 0x1000: /* JP addr */
                return JP_addr;
        case 0x2000: /* CALL addr */
                return CALL_addr;
        case 0x3000: /* SE Vx, byte */
                return SE_Vx_byte;
        case 0x4000: /* SNE Vx, byte */
                return SNE_Vx_byte;
        case 0x5000: /* SE Vx, Vy */
                return SE_Vx_Vy;
        case 0x6000: /* LD Vx, byte */
                return LD_Vx_byte; 
        case 0x7000: /* ADD Vx, byte */
                return ADD_Vx_byte;
        case 0x8000: { /* Group of INSTRUCTIONS */
                uint8_t ins = nibble(opcode, 0);
                switch (ins) {
                case 0x0: /* LD Vx, Vy */
                        return LD_Vx_Vy;
                case 0x1: /* OR Vx, Vy */
                        return OR_Vx_Vy;
                case 0x2: /* AND Vx, Vy */
                        return AND_Vx_Vy;
                case 0x3: /* XOR Vx, Vy */
                        return XOR_Vx_Vy;
                case 0x4: /* ADD Vx, Vy */
                        return ADD_Vx_Vy;
                case 0x5: /* SUB Vx, Vy */
                        return SUB_Vx_Vy;
                case 0x6: /* SHR Vx {, Vy} */
                        return SHR_Vx;
                case 0x7: /* SUBN Vx, Vy */
                        return SUBN_Vx_Vy;
                case 0xE: /* SHL Vx {, Vy} */
                        return SHL_Vx;
                }
        }
        case 0x9000: /* SNE Vx, Vy */
                return SNE_Vx_Vy;
        case 0xA000: /* LD I, addr */
                return LD_I_addr;
        case 0xB000: /* JP V0, addr */
                return JP_V0_addr;
        case 0xC000: /* RND Vx, byte */
                return RND_Vx_byte;
        case 0xD000: { /* DRW Vx, Vy, nibble */
                return DRW_Vx_Vy_nibble;
        }
        case 0xE000: { /* Group of instructions */
                uint8_t lb = low_byte(opcode);
                switch (lb) {
                case 0x9E: /* SKP Vx */
                        return SKP_Vx;
                case 0xA1: /* SKNP Vx */
                        return SKNP_Vx;
                }
        }
        case 0xF000: { /* Group of instructions */
                uint8_t lb = low_byte(opcode);
                switch (lb) {
                case 0x07: /* LD Vx, DT */
                        return LD_Vx_DT;
                case 0x0A: /* LD Vx, K */
                        return LD_Vx_K;
                case 0x15: /* LD DT, Vx */
                        return LD_DT_Vx;
                case 0x18: /* LD ST, Vx */
                        return LD_ST_Vx;
                case 0x1E: /* ADD I, Vx */
                        return ADD_I_Vx;
                case 0x29: /* LD F, Vx */
                        return LD_F_Vx;
                case 0x33: /* LD B, Vx */
                        return LD_B_Vx;
                case 0x55: /* LD [I], Vx */
                        return LD_memI_Vx;
                case 0x65: /* LD Vx, [I] */
                        return LD_Vx_memI;
                }
        }
        default:
                return -1;
        }
}
Exemple #25
0
void chip8disasm(const char* rom_file, const char* output) {
        uint8_t rom_data[4096];
        int rom_size = read_rom(rom_file, &(rom_data[0]), 4096);

        if (rom_size != -1) {
                printf("%d bytes read.\n", rom_size);

                FILE *output_file = fopen(output, "w");
                if (output_file == NULL) {
                        printf("Could not open output file %s.\n", output);
                        return;
                }

                size_t i;
                for (i = 0; i < rom_size; i += 2) {
                        fprintf(output_file, "%x: ", i);

                        uint16_t opcode = rom_data[i];
                        opcode <<= 8;
                        opcode |= rom_data[i + 1];

                        /*  
                         * Pieces of interest.  The vast majority of the 
                         *  instructions will use one of these.  
                        
                         *  x and y represent one of the 16 registers.
                         *  n is a nibble representing a constant.
                         *  kk is a byte constant.
                         *  addr is a 12-bit address vaue.
                         */
                        uint8_t x = nibble(opcode, 2);
                        uint8_t y = nibble(opcode, 1);
                        uint8_t n = nibble(opcode, 0);
                        uint8_t kk = low_byte(opcode);
                        uint16_t addr = get_addr(opcode);

                        switch (identify_ins(opcode)) {
                        case SYS_addr:
                                fprintf(output_file, "SYS %x", 
                                                        get_addr(opcode));
                                break;
                        case CLS:
                                fprintf(output_file, "CLS");
                                break;
                        case RET:
                                fprintf(output_file, "RET");
                                break;
                        case JP_addr:
                                fprintf(output_file, "JP %x", 
                                                        get_addr(opcode));
                                break;
                        case CALL_addr:
                                fprintf(output_file, "CALL %x", 
                                                        get_addr(opcode));
                                break;
                        case SE_Vx_byte:
                                fprintf(output_file, "SE V%x, %x", x, kk);
                                break;
                        case SNE_Vx_byte:
                                fprintf(output_file, "SNE, V%x, %x", x, kk);
                                break;
                        case SE_Vx_Vy:
                                fprintf(output_file, "SE V%x, V%x", x, y);
                                break;
                        case LD_Vx_byte:
                                fprintf(output_file, "LD V%x, %x", x, kk);
                                break;
                        case ADD_Vx_byte:
                                fprintf(output_file, "ADD V%x, %x", x, kk);
                                break;
                        case LD_Vx_Vy:
                                fprintf(output_file, "LD V%x, V%x", x, y);
                                break;
                        case OR_Vx_Vy:
                                fprintf(output_file, "OR V%x, V%x", x, y);
                                break;
                        case AND_Vx_Vy:
                                fprintf(output_file, "AND V%x, V%x", x, y);
                                break;
                        case XOR_Vx_Vy:
                                fprintf(output_file, "XOR V%x, V%x", x, y);
                                break;
                        case ADD_Vx_Vy:
                                fprintf(output_file, "ADD V%x, V%x", x, y);
                                break;
                        case SUB_Vx_Vy:
                                fprintf(output_file, "SUB V%x, V%x", x, y);
                                break;
                        case SHR_Vx:
                                fprintf(output_file, "SHR V%x", x);
                                break;
                        case SUBN_Vx_Vy:
                                fprintf(output_file, "SUBN V%x, V%x", x, y);
                                break;
                        case SHL_Vx:
                                fprintf(output_file, "SHL V%x", x);
                                break;
                        case SNE_Vx_Vy:
                                fprintf(output_file, "SNE V%x, V%x", x, y);
                                break;
                        case LD_I_addr:
                                fprintf(output_file, "LD I, %x", addr);
                                break;
                        case JP_V0_addr:
                                fprintf(output_file, "JP V0, %x", addr);
                                break;
                        case RND_Vx_byte:
                                fprintf(output_file, "RND V%x, %x", x, kk);
                                break;
                        case DRW_Vx_Vy_nibble:
                                fprintf(output_file, "DRW V%x, V%x, %x", x, y,
                                                                        n);
                                break;
                        case SKP_Vx:
                                fprintf(output_file, "SKP V%x", x);
                                break;
                        case SKNP_Vx:
                                fprintf(output_file, "SKNP V%x", x);
                                break;
                        case LD_Vx_DT:
                                fprintf(output_file, "LD V%x, DT", x);
                                break;
                        case LD_Vx_K:
                                fprintf(output_file, "LD V%x, K", x);
                                break;
                        case LD_DT_Vx:
                                fprintf(output_file, "LD DT, V%x", x);
                                break;
                        case LD_ST_Vx:
                                fprintf(output_file, "LD ST, V%x", x);
                                break;
                        case ADD_I_Vx:
                                fprintf(output_file, "ADD I, V%x", x);
                                break;
                        case LD_F_Vx:
                                fprintf(output_file, "LD F, V%x", x);
                                break;
                        case LD_B_Vx:
                                fprintf(output_file, "LD B, V%x", x);
                                break;
                        case LD_memI_Vx:
                                fprintf(output_file, "LD [I], V%x", x);
                                break;
                        case LD_Vx_memI:
                                fprintf(output_file, "LD V%x, [I]", x);
                                break;
                        default:
                                fprintf(output_file, "UNKNOWN");
                        }
                        fprintf(output_file, "\n");
                }
                fclose(output_file);
        } else {
                printf("Could not read rom file.\n");
        }
}
boolean_e formatDosToAmiga( fileplayer_s *players_file )
{
     clearErrorMessage();

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
	  if ( EMPTY( players_file[i].last_name ) ) continue;

          unsigned int pos = nibble( players_file[i].position[0], n_High );

          if   ( pos != fpos_Pitcher )
          {
               acc_bat_stats_s *action = &(players_file[i].acc_stats.action.batting);

               if ( byte2int( action->acc_rbi ) >= STAT_CAP_AMOUNT ||
                    byte2int( action->acc_so  ) >= STAT_CAP_AMOUNT    )
               {
                    acc_pch_stats_s *pch = &(players_file[i].acc_stats.simulated.pitching);

                    unsigned int act_inn  = word2int( pch->acc_innings );
                    unsigned int act_hits = word2int( pch->acc_hits    );

                    if ( act_inn > 0  ||  act_hits > 0 )
                    {
                         sprintf( error_message, "ERROR: Player %.*s, %.*s requires overflow and has pitching stats.",
                                  sizeof(players_file[i].last_name),  players_file[i].last_name,
                                  sizeof(players_file[i].first_name), players_file[i].first_name );

                         return bl_False;
                    }
               }

               acc_stats_s *acc_stats = &(players_file[i].acc_stats);

               acc_stats_u sim = acc_stats->simulated;

               acc_stats->simulated = acc_stats->action;
               acc_stats->action    = sim;

               capStat( acc_stats->simulated.batting.acc_rbi, acc_stats->action.batting.acc_rbi );
               capStat( acc_stats->simulated.batting.acc_so,  acc_stats->action.batting.acc_so  );
          }
          else
          {
               acc_bat_stats_s *act = &(players_file[i].acc_stats.action.batting);
               acc_pch_stats_s *sim = &(players_file[i].acc_stats.simulated.pitching);

               unsigned char games = act->acc_games[0];

               act->acc_games[0] = 0;

               sim->acc_starts[0] = games;
          }

          acc_player_id_s *id_info = &(players_file[i].acc_stats.action.id_info);

          int player_id = word2int( id_info->player_id );

          if ( player_id == 0  ||  calcChecksum( player_id ) != byte2int( id_info->checksum ) )
          {
               sprintf( error_message, "ERROR: Player %.*s, %.*s has a player id checksum mismatch.",
                        sizeof(players_file[i].last_name),  players_file[i].last_name,
                        sizeof(players_file[i].first_name), players_file[i].first_name );

               return bl_False;
          }
     }

     return bl_True;
}
Exemple #27
0
bool UUID::tryParse(const std::string& uuid)
{
	if (uuid.size() < 32)
		return false;

	bool haveHyphens = false;
	if (uuid[8] == '-' && uuid[13] == '-' && uuid[18] == '-' && uuid[23] == '-')
	{
		if (uuid.size() >= 36) 
			haveHyphens = true;
		else
			return false;
	}
	
	UUID newUUID;
	std::string::const_iterator it = uuid.begin();
	newUUID._timeLow = 0;
	for (int i = 0; i < 8; ++i)
	{
		Int16 n = nibble(*it++);
		if (n < 0) return false;
		newUUID._timeLow = (newUUID._timeLow << 4) | n;
	}
	if (haveHyphens) ++it;
	newUUID._timeMid = 0;
	for (int i = 0; i < 4; ++i)
	{
		Int16 n = nibble(*it++);
		if (n < 0) return false;
		newUUID._timeMid = (newUUID._timeMid << 4) | n;
	}
	if (haveHyphens) ++it;
	newUUID._timeHiAndVersion = 0;
	for (int i = 0; i < 4; ++i)
	{
		Int16 n = nibble(*it++);
		if (n < 0) return false;
		newUUID._timeHiAndVersion = (newUUID._timeHiAndVersion << 4) | n;
	}
	if (haveHyphens) ++it;
	newUUID._clockSeq = 0;
	for (int i = 0; i < 4; ++i)
	{
		Int16 n = nibble(*it++);
		if (n < 0) return false;
		newUUID._clockSeq = (newUUID._clockSeq << 4) | n;
	}
	if (haveHyphens) ++it;
	for (int i = 0; i < 6; ++i)
	{
		Int16 n1 = nibble(*it++);
		if (n1 < 0) return false;
		Int16 n2 = nibble(*it++);
		if (n2 < 0) return false;

		newUUID._node[i] = (n1 << 4) | n2;			
	}
	swap(newUUID);

	return true;
}
Exemple #28
0
/*===========================================================================
METHOD:
   QCUSBNetProbe (Public Method)

DESCRIPTION:
   Run usbnet_probe
   Setup QMI device

PARAMETERS
   pIntf        [ I ] - Pointer to interface
   pVIDPIDs     [ I ] - Pointer to VID/PID table

RETURN VALUE:
   int - 0 for success
         Negative errno for error
===========================================================================*/
int QCUSBNetProbe( 
   struct usb_interface *        pIntf, 
   const struct usb_device_id *  pVIDPIDs )
{
   int status;
   struct usbnet * pDev;
   sQCUSBNet * pQCDev;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION( 2,6,29 ))
   struct net_device_ops * pNetDevOps;
#endif
   int i;
   u8 *addr;

   status = usbnet_probe( pIntf, pVIDPIDs );
   if(status < 0 )
   {
      DBG( "usbnet_probe failed %d\n", status );
      return status;
   }

#if (LINUX_VERSION_CODE > KERNEL_VERSION( 2,6,23 ))
   pDev = usb_get_intfdata( pIntf );
#else
   pDev = (struct usbnet *)pIntf->dev.platform_data;
#endif

   if (pDev == NULL || pDev->net == NULL)
   {
      DBG( "failed to get netdevice\n" );
      usbnet_disconnect( pIntf );
      return -ENXIO;
   }

   pQCDev = kmalloc( sizeof( sQCUSBNet ), GFP_KERNEL );
   if (pQCDev == NULL)
   {
      DBG( "falied to allocate device buffers" );
      usbnet_disconnect( pIntf );
      return -ENOMEM;
   }
   
   pDev->data[0] = (unsigned long)pQCDev;
   
   pQCDev->mpNetDev = pDev;

   // Overload PM related network functions
#if (LINUX_VERSION_CODE < KERNEL_VERSION( 2,6,29 ))
   pQCDev->mpUSBNetOpen = pDev->net->open;
   pDev->net->open = QCUSBNetOpen;
   pQCDev->mpUSBNetStop = pDev->net->stop;
   pDev->net->stop = QCUSBNetStop;
   pDev->net->hard_start_xmit = QCUSBNetStartXmit;
   pDev->net->tx_timeout = QCUSBNetTXTimeout;
#else
   pNetDevOps = kmalloc( sizeof( struct net_device_ops ), GFP_KERNEL );
   if (pNetDevOps == NULL)
   {
      DBG( "falied to allocate net device ops" );
      usbnet_disconnect( pIntf );
      return -ENOMEM;
   }
   memcpy( pNetDevOps, pDev->net->netdev_ops, sizeof( struct net_device_ops ) );
   
   pQCDev->mpUSBNetOpen = pNetDevOps->ndo_open;
   pNetDevOps->ndo_open = QCUSBNetOpen;
   pQCDev->mpUSBNetStop = pNetDevOps->ndo_stop;
   pNetDevOps->ndo_stop = QCUSBNetStop;
   pNetDevOps->ndo_start_xmit = QCUSBNetStartXmit;
   pNetDevOps->ndo_tx_timeout = QCUSBNetTXTimeout;

   pDev->net->netdev_ops = pNetDevOps;
#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION( 2,6,31 ))
   memset( &(pQCDev->mpNetDev->stats), 0, sizeof( struct net_device_stats ) );
#else
   memset( &(pQCDev->mpNetDev->net->stats), 0, sizeof( struct net_device_stats ) );
#endif

   pQCDev->mpIntf = pIntf;
   memset( &(pQCDev->mMEID), '0', 14 );

   pQCDev->mbQMIValid = false;
   memset( &pQCDev->mQMIDev, 0, sizeof( sQMIDev ) );
   pQCDev->mQMIDev.mbCdevIsInitialized = false;

   pQCDev->mQMIDev.mpDevClass = gpClass;
   
   init_completion( &pQCDev->mAutoPM.mThreadDoWork );
   spin_lock_init( &pQCDev->mQMIDev.mClientMemLock );

   // Default to device down
   pQCDev->mDownReason = 0;
   QSetDownReason( pQCDev, NO_NDIS_CONNECTION );
   QSetDownReason( pQCDev, NET_IFACE_STOPPED );

   // Register QMI
   status = RegisterQMIDevice( pQCDev );
   if (status != 0)
   {
      // usbnet_disconnect() will call QCUSBNetUnbind() which will call
      // DeregisterQMIDevice() to clean up any partially created QMI device
      usbnet_disconnect( pIntf );
      return status;
   }

   // After calling RegisterQMIDevice mMEID is valid.  Although most
   // drivers set the MAC address in bind(), we need to wait until the
   // MEID is available.
   addr = &pDev->net->dev_addr[0];
   for (i = 0; i < 6; i++)
     addr[i] = (nibble(pQCDev->mMEID[i*2+2]) << 4) +
         nibble(pQCDev->mMEID[i*2+3]);
   addr [0] &= 0xfe;       /* clear multicast bit */
   addr [0] |= 0x02;       /* set local assignment bit (IEEE802) */

   DBG( "Mac Address:\n" );
   PrintHex( &pQCDev->mpNetDev->net->dev_addr[0], 6 );

   // Success
   return 0;
}
Exemple #29
0
/*
 * Function: PreprocUrlDecode(Packet *)
 *
 * Purpose: Inspects the packet's payload for "Escaped" characters and 
 *          converts them back to their ASCII values.  This function
 *          is based on the NCSA code and was contributed by Michael Henry!
 *
 * Arguments: p => pointer to the current packet data struct 
 *
 * Returns: void function
 *
 */
void PreprocUrlDecode(Packet *p)
{
    char *url;       /* this is where the converted data will be written */
    char *index;     /* this is the index pointer to walk thru the data */
    char *end;       /* points to the end of the payload, for loop control */
    u_int16_t psize; /* payload size */
    int i;           /* loop counter */
    char logMessage[180];
    int temp;

#ifdef DEBUG
    printf("http decoder init on %d bytes\n", p->dsize);
#endif

    /* check to make sure we're talking TCP and that the TWH has already
       completed before processing anything */
    if(!PacketIsTCP(p))
    {
#ifdef DEBUG
        printf("It isn't TCP session traffic\n");
#endif
        return;
    }

    if(!IsTcpSessionTraffic(p))
    {
#ifdef DEBUG
        printf("It isn't TCP session traffic\n");
#endif
        return;
    }

    /* check the port against the decode port list */
    for(i = 0; i < HttpDecodePorts.num_entries; i++)
    {
        if(HttpDecodePorts.ports[i] == p->dp)
        {
            /* on match, normalize the data */
#ifdef DEBUG
            printf("Got HTTP traffic (%d bytes)!\n", p->dsize);
            printf("%s\n", p->data);
#endif
            /* setup the pointers */
            url =   (char *) p->data;
            index = (char *) p->data;
            end =   (char *) p->data + p->dsize;
            psize = (u_int16_t) (p->dsize);

            /* walk thru each char in the payload */
            while(index < end)
            {
                /* if it's potentially "escaped" and not too close to the end of 
                   the payload */
                if((*index == '%') && (index < end - 2))
                {
                    /* and if the following two chars are hex digits */
                    if(isxdigit((int)*(index+1)) && isxdigit((int)*(index+2)))
                    {
                        /*convert it and stuff it */
                        temp = (nibble(*(index+1)) << 4) | nibble(*(index+2));
                        if(((temp == 192) || /* c0 */
                            (temp == 193) || /* c1 */
                            (temp == 224) || /* e0 */
                            (temp == 240) || /* f0 */
                            (temp == 248) || /* f8 */
                            (temp == 252)) &&/* fc */
                           check_iis_unicode)
                        {
                            snprintf(logMessage, sizeof(logMessage), 
                                     MODNAME ": IIS Unicode attack detected");

                            /*(*AlertFunc)(p, logMessage);*/
                            CallAlertFuncs(p, logMessage, NULL);
                            CallLogFuncs(p, logMessage, NULL);
                        }

                        if(temp == 0 && check_cgi_null)
                        {
                            snprintf(logMessage, sizeof(logMessage), 
                                     MODNAME ": CGI Null Byte attack detected");

                            /*(*AlertFunc)(p, logMessage);*/
                            CallAlertFuncs(p, logMessage, NULL);
                            CallLogFuncs(p, logMessage, NULL);
                        }

                        *url = temp;

                        index += 3; 
                        url++;
                        psize -= 2;
                    }
                    else
                    {
                        *url = *index;
                        url++;
                        index++;
                    }        
                }
                else
                {
                    *url = *index;
                    url++;
                    index++;
                }
            }

            /* set the payload size to reflect the new size */ 
            p->dsize = psize;

#ifdef DEBUG
            printf("New size: %d\n", p->dsize);
            printf("converted data:\n");
            PrintNetData(stdout, p->data, psize);
#endif

            return;
        }
    }
}