예제 #1
0
void CFGCheckSummer::processCFG(WorkSpace *ws, CFG *cfg) {
	checksum::Fletcher sum;
	for(CFG::BBIterator bb(cfg); bb; bb++)
		if(!bb->isEnd()) {
			char buf[bb->size()];
			ws->process()->get(bb->address(), buf, bb->size());
			sum.put(buf, bb->size());
		}
	CHECKSUM(cfg) = sum.sum();
	if(logFor(LOG_PROC))
		log << "\t\tchecksum = " << (void *)(unsigned long)CHECKSUM(cfg) << io::endl;
}
예제 #2
0
파일: socktest.c 프로젝트: basecq/q2dos
int fix_tcp_packet (in_Header *ip, tcp_Header *tcp, int ack_len, int data_len)
{
  static DWORD seq_num = 12345678;  /* starting sequence */
  tcp_PseudoHeader ph;
  WORD src_port;

  tcp->checksum = 0;
  src_port      = tcp->srcPort;
  tcp->srcPort  = tcp->dstPort;
  tcp->dstPort  = src_port;
  tcp->acknum   = intel (intel(tcp->seqnum) + ack_len);
  tcp->seqnum   = intel (seq_num);
  tcp->offset   = sizeof(*tcp) / 4;    /* in dwords */
  seq_num      += data_len;

  ph.src        = ip->source;
  ph.dst        = ip->destination;
  ph.mbz        = 0;
  ph.protocol   = TCP_PROTO;
  ph.length     = intel16 (sizeof(*tcp) + data_len);
  ph.checksum   = CHECKSUM (tcp, sizeof(*tcp) + data_len);

  ip->length    = intel16 (data_len + sizeof(*tcp) + sizeof(*ip));
  ip->checksum  = 0;
  ip->checksum  = ~CHECKSUM (ip, sizeof(*ip));
  tcp->checksum = ~CHECKSUM (&ph, sizeof(ph));
  return (sizeof(*ip) + sizeof(*tcp) + data_len);
}
예제 #3
0
void LegoIr::send()
{
    uint8_t i, j;
    uint16_t message = _nib1 << 12 | _nib2 << 8 | _nib3 << 4 | CHECKSUM();
    for(i = 0; i < 6; i++)
    {
        pause(i);
        start_stop_bit();
        for(j = 0; j < 16; j++) {
            send_bit();
            delayMicroseconds((0x8000 & (message << j)) != 0 ? HIGH_PAUSE : LOW_PAUSE);
        }
        start_stop_bit();
    }
}
예제 #4
0
static int icmp_loopback (ICMP_PKT *icmp, unsigned icmp_len)
{
  if (icmp_len >= sizeof(icmp->echo)    &&
      CHECKSUM(icmp,icmp_len) == 0xFFFF &&
      icmp->echo.type == ICMP_ECHO)
  {
    static WORD echo_seq_num = 0;

    icmp->echo.type     = ICMP_ECHOREPLY;
    icmp->echo.sequence = echo_seq_num++;
    icmp->echo.checksum = 0;
    icmp->echo.checksum = ~CHECKSUM (icmp, icmp_len);
    STAT (icmpstats.icps_reflect++);
    STAT (icmpstats.icps_outhist[ICMP_ECHOREPLY]++);
    return (icmp_len);
  }
  /** \todo fall-through to another ICMP loopback handler */

  return (0);
}
예제 #5
0
#include <malloc.h>
#include <mri.h>
#include <stdio.h>
#include <stdint.h>

extern "C" uint32_t  __end__;
extern "C" uint32_t  __malloc_free_list;
extern "C" uint32_t  _sbrk(int size);

#define get_temp_command_checksum CHECKSUM("temp")
#define get_pos_command_checksum  CHECKSUM("pos")

// command lookup table
SimpleShell::ptentry_t SimpleShell::commands_table[] = {
    {CHECKSUM("ls"),       &SimpleShell::ls_command},
    {CHECKSUM("cd"),       &SimpleShell::cd_command},
    {CHECKSUM("pwd"),      &SimpleShell::pwd_command},
    {CHECKSUM("cat"),      &SimpleShell::cat_command},
    {CHECKSUM("rm"),       &SimpleShell::rm_command},
    {CHECKSUM("reset"),    &SimpleShell::reset_command},
    {CHECKSUM("dfu"),      &SimpleShell::dfu_command},
    {CHECKSUM("break"),    &SimpleShell::break_command},
    {CHECKSUM("help"),     &SimpleShell::help_command},
    {CHECKSUM("version"),  &SimpleShell::version_command},
    {CHECKSUM("mem"),      &SimpleShell::mem_command},
    {CHECKSUM("get"),      &SimpleShell::get_command},
    {CHECKSUM("set_temp"), &SimpleShell::set_temp_command},
    {CHECKSUM("test"),     &SimpleShell::test_command},

    // unknown command
예제 #6
0
/***
	Verifica se a copia pode executar normalmente.
	Parametros:
		nenhum
	Retorno:
		PE_INSTALA - Copia nao personalizada
		PE_DATA - Copia Out of date (estouro de data)
		PE_OK - Pode executar numa boa.
***/
int
CheckForRun()
{
	int	iIsTimeBomb = FALSE;
	int	check = 0;
	int	chk_check;
	char	data[MAXDATA+1];
	char	szBufAux[MAXDATA+1];
	struct tm	*dma;
	struct tm	data_aux;
	time_t		t1;
	time_t		t2;
	int		num_dias;
	long		tloc;

	if( !iIsDecrypt ){
		check = Decriptografa( DATAINST(str_pers), CHECKSUM( str_pers ) );
		iIsDecrypt = TRUE;
		chk_check = ((CHECKSUM( str_pers )[0]&0xFF)<<8) | (CHECKSUM( str_pers )[1] & 0xFF);
		chk_check &= 0xFFFF;
		if( check != chk_check ) {
			return( PE_INSTALA );
		}
	}
	if( PERS( str_pers ) != PE_PERS ){
		return( PE_INSTALA ); // Copia nao personalizada
	}

	// Calcula os deslocamentos para DATA, NUMTTY, SERIE, ETC.
	if( CalculaDeslocamentos( SERIE( str_pers ) ) != PE_OK ){
		return( PE_INSTALA ); // algum pau no numero de serie
	}

	/* Verificando Time Bomb */
	if( DATA( str_pers )[0] == '0' ){
		iIsTimeBomb = TRUE;
	}

	if( iIsTimeBomb ){	/* Tem time bomb */
		t1 = time( &t1 ); /* Dia de hoje em segundos */
		memset( &data_aux, 0, sizeof(data_aux) );
		// Pego o dia da instalacao do produto e somo o numero de dias
		// do time bomb. Tudo em segundos.
		data_aux.tm_year = (1000*(DATAINST(str_pers)[0]-'0')) +
				   (100*(DATAINST(str_pers)[1]-'0')) +
				   (10*(DATAINST(str_pers)[2]-'0')) +
				   DATAINST(str_pers)[3] - '0' - 1900;
		data_aux.tm_mon = (10* (DATAINST(str_pers)[4]-'0') ) + DATAINST(str_pers)[5] - '0' - 1 ;
		data_aux.tm_mday = (10* (DATAINST(str_pers)[6]-'0') ) + DATAINST(str_pers)[7] - '0';
		t2 = mktime( &data_aux );	/* Dia da instalacao do produto */
		if( t1 < t2 ) {
			/* O sacana mudou a data voltou a data para tras
			 * para rodar o aplicativo.
			 * Pau nele.
			 */
			return( PE_DATA );
		}
		/* o dia de instalacao nao guarda horas/minutos e portanto
		 * eh como se tivessemos instalado a meia noite do dia.
		 * por isso, dah um dia de graca. Pegamos agora o
		 * numero de dias do time bomb.
		 */
		istrncpychar( data, DATA(str_pers), MAXDATA, '.' );
		t2 += ( atol(data) + 1 ) * 3600 * 24;
		num_dias = CmpDatas( t2, t1 );
		if( num_dias < 0 ) {
			return( PE_DATA );
		}
		return( PE_OK );
	}
	if( isdigit( DATA(str_pers)[0] ) && DATA(str_pers)[0]>'0' ){
		/* Eh uma copia demo com data absoluta. VAMOS VERIFICAR!!! */
		time( &tloc );
		dma = localtime( &tloc );
		sprintf( szBufAux, "%04.2d%02.2d",
			dma->tm_year + 1900,
			dma->tm_mon + 1
		);
		// MAXDATA deve ser 6 ; yyyymm. Assim mesmo nos protegemos procurando o '.'
		istrncpychar( data, DATA(str_pers), MAXDATA, '.' );
		if( strncmp( szBufAux, data, MAXDATA ) > 0 ) {
			return( PE_DATA );
		}
		return( PE_OK );
	}
	// Qualquer outra coisa no campo data indica uma copia
	// Full (nao demo). Logo, retornamos PE_OK para a galera.
	return( PE_OK );
}
예제 #7
0
/***
	Personaliza um arquivo dado.
	Parametros:
		FileName: Nome do arquivo a personalizar
		Name: Nome do usuario
		Company: Nome da compania
		Serial: Serial Number
		ActKey: Chave de ativacao
	Inportante:
		· O número serial deve estar na forma 11.222222.3333.444444
		  com pontos separando os campos. Ele deve sempre ter o
		  strlen() <= 32.
		. O campo 1 eh de tamanho fixo. Os demais sao de tamanho variavel
		  ate o limite maximo de 32 caracteres.
		· 11 = tipo da cópia
		· 222222 = Data. Se começar com número > 0 é data absoluta.
		  Se começar (ATENCAO) com 0 é time bomb e se começar com letra
		  indica cópia não demo.
		· 3333 = Número de terminais
		· 444444 = Um número serial
	Retorna:
		PE_DATA: Chave com data absoluta ja expirou
		PE_TYPE: Tipo nao bate
		PE_ACTKEY: Chave de ativacao nao bate
		PE_SERIAL: Numero de serie com formacao ou tamanho errado
		PE_PARAM: Parametros invalidos
		PE_TIMEBOMB: Tentando personalizar copia time-bomb de novo. Deve Re-instalar
		PE_LOCALIZA: Nao achou marca no arquivo
		PE_POSERROR: Falhou no seek
		PE_WRITEERROR: Falhou ao tentar escrever no arquivo
		PE_OK: Ok
***/
int
Personalize( char *szFileName, char *szName, char *szCompany, char*szSerial, char *szActKey )
{
	char	data_hoje[MAXDATAINST+1];
	time_t	time_aux;
	FILE	*fp;
	int	check = 0;
	char	data[MAXDATA+1];
	char	szBufAux[MAXDATA+1];
	struct tm	*dma;
	long		tloc;
	


	if( szFileName == NULL || szName == NULL || szCompany == NULL || szSerial == NULL || szActKey == NULL ){
		return( PE_PARAM );
	}
	if( strlen( szSerial ) > MAXSIZESERIAL ){
		return( PE_SERIAL );
	}
	if( !ValidKey( szSerial, szActKey ) ){
		return( PE_ACTKEY );
	}
	// Calculo os deslocamentos variaveis em relacao ao serial passado
	if( CalculaDeslocamentos( szSerial ) != PE_OK ){
		return( PE_SERIAL );
	}

	// Verifico se eh uma data absoluta e se ja expirou.
	if( isdigit( szSerial[DESLOCDATA] ) && szSerial[DESLOCDATA]>'0' ){
		/* Eh uma copia demo com data absoluta. VAMOS VERIFICAR!!! */
		time( &tloc );
		dma = localtime( &tloc );
		sprintf( szBufAux, "%04.2d%02.2d",
			dma->tm_year + 1900,
			dma->tm_mon + 1
		);
		// MAXDATA deve ser 6 ; yyyymm. Assim mesmo nos protegemos procurando o '.'
		istrncpychar( data, szSerial+DESLOCDATA, MAXDATA, '.' );
		if( strncmp( szBufAux, data, MAXDATA ) > 0 ) {
			return( PE_DATA );
		}
	}

	/* procura a estrutura str_pers
	 */
	if( (fp = localiza( szFileName, str_pers )) == NULL ) {
		return( PE_LOCALIZA );
	}

	// Verifico TIPO da copia antes de decriptografar pois esta em
	// area nao criptografada.
	if( strncmp( TIPO( str_pers ), szSerial+DESLOCTIPO, MAXTIPO ) != 0 ){
		return( PE_TYPE );
	}

	if( PERS( str_pers ) == PE_PERS ) {
		/* Jah passou o "person" por aqui antes.
		 * decriptografo a estrutura, para nao perder as
		 * demais informacoes nela contidas: data_instalacao, num_serie, etc.
		 */
		Decriptografa( DATAINST(str_pers), CHECKSUM( str_pers ) );
		iIsDecrypt = TRUE;
	}
	
	if( szSerial[DESLOCDATA] == '0' ){
		// Eh um numero de serie time-bomb
		if( PERS( str_pers ) == PE_PERS ){
			/* Tentando fazer person de time bomb sobre uma copia
			 * previamente personalizada. Nao deixo!!!! Que o filho
			 * da mae re-instale o produto.
			 */
			fclose( fp );
			return( PE_TIMEBOMB );
		}
	}


	// Posiciono no inicio da marca para gravar estrutura de
	// personalizacao
	if( fseek( fp, lPosicao, 0 ) == -1 ) {
		fclose( fp );
		return( PE_POSERROR );
	}

	// Monto a estrutura de personalizacao
	time_aux = time( &time_aux );
	strftime( data_hoje, sizeof( data_hoje ), "%Y%m%d", localtime( &time_aux ) );
	istrncpy( DATAINST( str_pers ), data_hoje, MAXDATAINST );
	istrncpy( NOME( str_pers ), szName, MAXNOME );
	istrncpy( NAMECOMPANY( str_pers ), szCompany, MAXCOMPANY );
	istrncpy( SERIE( str_pers ), szSerial, MAXSIZESERIAL );

	// O tipo da copia ja vem pre-gravado e nao preciso colocar.

	/* indica que o produto estah personalizado */
	PERS( str_pers ) = PE_PERS;

	check = Criptografa( DATAINST( str_pers ), CHECKSUM( str_pers ) );
	CHECKSUM( str_pers )[ 0 ] = ( check & 0xFF00 ) >> 8;
	CHECKSUM( str_pers )[ 1 ] = ( check & 0x00FF );

	if( fwrite( (char *) str_pers, sizeof str_pers, 1, fp ) != 1 ) {
		fclose( fp );
		return( PE_WRITEERROR );
	}
	fclose( fp );
	return( PE_OK );
}
예제 #8
0
파일: shell.cpp 프로젝트: 0x23/Smoothieware
        free(buf);
        */
}

/*---------------------------------------------------------------------------*/

static void unknown(char *str, Shell *sh)
{
    // its some other command, so queue it for mainloop to find
    if (strlen(str) > 0) {
        CommandQueue::getInstance()->add(str, sh->getStream());
    }
}
/*---------------------------------------------------------------------------*/
static struct ptentry parsetab[] = {
    {CHECKSUM("netstat"), connections},
    {CHECKSUM("exit"), quit},
    {CHECKSUM("quit"), quit},
    {CHECKSUM("test"), test},
    {CHECKSUM("?"), help},

    /* Default action */
    {0, unknown}
};
/*---------------------------------------------------------------------------*/
// this callback gets the results of a command, line by line
// NULL means command completed
// static
int Shell::command_result(const char *str, void *p)
{
    // FIXME problem when shell is deleted and this gets called from slow command
예제 #9
0
파일: pcicmp.c 프로젝트: basecq/q2dos
/**
 * Handler for incoming ICMP packets.
 */
void icmp_handler (const in_Header *ip, BOOL broadcast)
{
  union ICMP_PKT  *icmp;
  const in_Header *orig_ip;
  int              type, code;
  unsigned         len;
  DWORD            delta_time;
  BOOL             for_me, i_orig;  /* is it for me, did I originate it */
  const char      *msg;

  DEBUG_RX (NULL, ip);

  if (block_icmp)   /* application is handling ICMP; not needed */
     return;

  len    = in_GetHdrLen (ip);
  icmp   = (union ICMP_PKT*) ((BYTE*)ip + len);
  len    = intel16 (ip->length) - len;
  for_me = _ip4_is_multihome_addr (intel(ip->destination));

  if (!for_me || broadcast)  /* drop broadcast pings.. */
     return;

  if (len < sizeof(icmp->info))
  {
    STAT (icmpstats.icps_tooshort++);
    return;
  }

  if (CHECKSUM(icmp,len) != 0xFFFF)
  {
    STAT (icmpstats.icps_checksum++);
    icmp_print (1, _LANG("bad checksum"), ip->source);
    return;
  }

  type    = icmp->unused.type;
  code    = icmp->unused.code;
  orig_ip = &icmp->ip.ip;
  i_orig  = _ip4_is_local_addr (intel(orig_ip->source));

  if (type == ICMP_MASKREPLY)
  {
    if (!_do_mask_req)
       return;
    i_orig = TRUE;
  }

  /* !! this needs work
   */
  if (!i_orig &&
      (type != ICMP_ECHOREPLY && type != ICMP_ECHO &&
       type != ICMP_IREQREPLY && type != ICMP_TSTAMP))
  {
    icmp_bogus (ip, type, NULL);
    return;
  }

  switch (type)
  {
    case ICMP_ECHOREPLY:  /* check if we were waiting for it */
         delta_time = set_timeout(0) - icmp->echo.identifier;
         add_ping (intel(ip->source), delta_time, icmp->echo.index);
         return;

    case ICMP_UNREACH:
         if (code < DIM(icmp_unreach_str))
         {
           UINT len_needed = 8 + in_GetHdrLen (orig_ip);
           WORD next_mtu   = 0;

           msg = _LANG (icmp_unreach_str[code]);
           icmp_print (1, msg, ip->source);

           if (orig_ip->proto == TCP_PROTO ||
               orig_ip->proto == UDP_PROTO)
              len_needed += 4;  /* Need the src/dest port numbers */

           if (len >= len_needed)
           {
             if (code == ICMP_UNREACH_NEEDFRAG)
                next_mtu = intel16 (icmp->needfrag.next_mtu);

#if !defined(USE_UDP_ONLY)
             if (orig_ip->proto == TCP_PROTO)
                _tcp_cancel (orig_ip, ICMP_UNREACH, code, msg, &next_mtu);
             else
#endif
             if (orig_ip->proto == UDP_PROTO)
                _udp_cancel (orig_ip, ICMP_UNREACH, code, msg, &next_mtu);

             /** \todo Handle cancelling raw sockets */
#if defined(USE_BSD_API) && 0  
             else
              _raw_cancel (orig_ip, ICMP_UNREACH, code, msg);
#endif
           }
           else
             STAT (icmpstats.icps_tooshort++);
         }
         else
           STAT (icmpstats.icps_badcode++);
         return;

    case ICMP_SOURCEQUENCH:
#if !defined(USE_UDP_ONLY)
         if (orig_ip->proto == TCP_PROTO)
         {
           msg = _LANG (icmp_type_str[type]);
           icmp_print (1, msg, ip->source);
           _tcp_cancel (orig_ip, ICMP_SOURCEQUENCH, code, msg, NULL);
         }
#endif
         return;

    case ICMP_REDIRECT:
         if (code < DIM(icmp_redirect_str))
              icmp_redirect (icmp, ip, orig_ip, code);
         else STAT (icmpstats.icps_badcode++);
         return;

    case ICMP_ECHO:
         icmp_print (2, _LANG("PING requested of us"), ip->source);
         icmp_echo_reply (ip, icmp, len);
         return;

    case ICMP_TIMXCEED:
         if (code >= DIM(icmp_exceed_str))
         {
           STAT (icmpstats.icps_badcode++);
           return;
         }
         if (code == 0)  /* "TTL exceeded in transit" */
            switch (orig_ip->proto)
            {
#if !defined(USE_UDP_ONLY)
              case TCP_PROTO:
                   msg = _LANG (icmp_exceed_str[0]);
                   icmp_print (1, msg, ip->source);
                   _tcp_cancel (orig_ip, ICMP_TIMXCEED, code, msg, NULL);
                   break;
#endif
              case UDP_PROTO:
                   msg = _LANG (icmp_exceed_str[0]);
                   icmp_print (1, msg, ip->source);
                   _udp_cancel (orig_ip, ICMP_TIMXCEED, code, msg, NULL);
                   break;
            }
         return;

    case ICMP_PARAMPROB:
         msg = _LANG (icmp_type_str[ICMP_PARAMPROB]);
         switch (orig_ip->proto)
         {
#if !defined(USE_UDP_ONLY)
           case TCP_PROTO:
                icmp_print (0, msg, ip->source);
                _tcp_cancel (orig_ip, ICMP_PARAMPROB, code, msg, NULL);
                break;
#endif
           case UDP_PROTO:
                icmp_print (0, msg, ip->source);
                _udp_cancel (orig_ip, ICMP_PARAMPROB, code, msg, NULL);
                break;
         }
         return;

    case ICMP_ROUTERADVERT:  /* todo !! */
         msg = _LANG (icmp_type_str[ICMP_ROUTERADVERT]);
         icmp_print (1, msg, ip->source);
         return;

    case ICMP_ROUTERSOLICIT: /* todo !! */
         msg = _LANG (icmp_type_str[ICMP_ROUTERSOLICIT]);
         icmp_print (1, msg, ip->source);
         return;

    case ICMP_TSTAMP:
         msg = _LANG (icmp_type_str[ICMP_TSTAMP]);
         icmp_print (1, msg, ip->source);
         /**< \todo send reply? */
         return;

    case ICMP_TSTAMPREPLY:
         msg = _LANG (icmp_type_str[ICMP_TSTAMPREPLY]);
         icmp_print (1, msg, ip->source);
         /**< \todo should store */
         return;

    case ICMP_IREQ:
         msg = _LANG (icmp_type_str[ICMP_IREQ]);
         icmp_print (1, msg, ip->source);
         /**< \todo send reply */
         return;

    case ICMP_IREQREPLY:
         msg = _LANG (icmp_type_str[ICMP_IREQREPLY]);
         icmp_print (1, msg, ip->source);
         /**< \todo send reply upwards */
         return;

    case ICMP_MASKREQ:
         /* might be sent by us, never answer */
         break;

    case ICMP_MASKREPLY:
         msg = _LANG (icmp_type_str[ICMP_MASKREPLY]);
         icmp_print (0, msg, ip->source);
         if ((icmp->mask.identifier == addr_mask_id)    &&
             (icmp->mask.sequence   == addr_mask_seq-1) &&
             sin_mask != intel(icmp->mask.mask))
            outsnl ("Conflicting net-mask from \"ICMP Addr Mask Reply\"\7");
         addr_mask_id = 0;
         return;
  }
}