Exemplo n.º 1
0
void CPU::PrintMemory()
{
	std::ofstream file;
	file.open("memory.txt");

	for (int i = 0; i < 0x10000; i++)
	{
		file << int_to_hex(i) << "\t" << int_to_hex(ReadByte(i)) << std::endl;
	}

	file.close();
}
Exemplo n.º 2
0
void CPU::PrintRegisters()
{
	std::ofstream file;
	file.open("registers.txt", std::ios::app | std::ios::out);

	file << "---PC:\t" << int_to_hex(PC) << std::endl;
	file << "A:\t" << int_to_hex(A) << std::endl;
	file << "B:\t" << int_to_hex(B) << std::endl;
	file << "C:\t" << int_to_hex(C) << std::endl;
	file << "D:\t" << int_to_hex(D) << std::endl;
	file << "E:\t" << int_to_hex(E) << std::endl;
	file << "F:\t" << int_to_hex(F) << std::endl;
	file << "H:\t" << int_to_hex(H) << std::endl;
	file << "L:\t" << int_to_hex(L) << std::endl;
	file << "SP:\t" << int_to_hex(SP) << std::endl << std::endl << std::endl;

	file.close();
}
Exemplo n.º 3
0
static void hex_encode(char *hexval, const unsigned char *hashval)
{
  int i;

  for (i = 0; i < APR_MD5_DIGESTSIZE; i++)
    {
      hexval[2 * i] = int_to_hex((hashval[i] >> 4) & 0xf);
      hexval[2 * i + 1] = int_to_hex(hashval[i] & 0xf);
    }
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::UpdateDataOfBootloaderConfigureArea(BOOL direction)
{
    if (direction)
    {
        UpdateData(TRUE); // Update UI to CString m_bcaBinaries

        int length = m_bcaBinaries.GetLength();
        LPWSTR buffer = m_bcaBinaries.GetBuffer();

        char tempHigh, tempLow;
        int posBin = 0, posChar = 0;
        while ((posBin < 64) && (posChar < length))
        {
            // Only convert legal characters.
            if (isxdigit(buffer[posChar * 2]) && isxdigit(buffer[posChar * 2 + 1]))
            {
                tempHigh = buffer[posChar * 2] & 0xFF;    // change TCHAR to char, abandon the high bits.
                tempLow = buffer[posChar * 2 + 1] & 0xFF; // change TCHAR to char, abandon the high bits.
                m_bcaData[posBin] = ((hex_to_int(tempHigh) & 0xFF) << 4) | (hex_to_int(tempLow) & 0xFF);
                posBin++;
                posChar++;
            }
            else
            {
                // Skip the illegal character pairs.
                posChar++;
            }
        }
        m_bcaBinaries.ReleaseBuffer();
    }
    else
    {
        LPTSTR buffer = m_bcaBinaries.GetBuffer(128 + 2 * 4 + 1); // 128 for 128 BCA characters
                                                                  // 2 * 4 for enter characters("\r\n") each line
                                                                  // 1 byte more for for terminator("\0")
        int posBin = 0, posChar = 0;
        for (; posBin < 64; posChar++, posBin++)
        {
            // 32 characters each line.
            if ((!(posBin % 0x10)) && (posBin != 0))
            {
                // Add "\r\n" at the end of each line
                buffer[posChar * 2] = '\r';
                buffer[posChar * 2 + 1] = '\n';
                posChar++;
            }
            buffer[posChar * 2] = int_to_hex(m_bcaData[posBin] >> 4);
            buffer[posChar * 2 + 1] = int_to_hex(m_bcaData[posBin]);
        }
        buffer[posChar * 2] = '\0';
        m_bcaBinaries.ReleaseBuffer();

        UpdateData(FALSE); // Update CString m_bcaBinaries to UI
    }
}
Exemplo n.º 5
0
//@strcat:test_int_to_hex3 => [int_to_hex ne retourne pas "0" quand number=0]
void test_int_to_hex3(void)
{
	unsigned int i = 0;
	char* hex = malloc(sizeof(char));
	if (hex == NULL) {
        CU_FAIL("Erreur lors l'allocation de la mémoire pendant le test test_int_to_hex3.");
        return;
  }
	int_to_hex(i,hex);
	CU_ASSERT_STRING_EQUAL(hex,"0");
	free(hex);
}
Exemplo n.º 6
0
/*
 * 0x00876543
 */
void
uart_print_hex(unsigned int data)
{
	char num[9];
	int i;

	int_to_hex(data, num);

	uart_putc('0');
	uart_putc('x');
	for (i = 0; num[i] != '\0'; ++i)
		uart_putc(num[i]);
}
Exemplo n.º 7
0
//@strcat:test_int_to_hex2 => [int_to_hex doit retourner la meme adresse que celle donnee a l'argument dest]
void test_int_to_hex2(void)
{
	unsigned int i = 10601284;
	char* hex1 = malloc(sizeof(char)*6);
	if (hex1 == NULL) {
        CU_FAIL("Erreur lors l'allocation de la mémoire pendant le test test_int_to_hex2.");
        return;
    }
	char* hex2 = NULL;
	hex2 = int_to_hex(i,hex1);
	CU_ASSERT_PTR_EQUAL(hex1,hex2);
	free(hex1);
}
Exemplo n.º 8
0
/**
 * Convert a string if ASCII characters HASHVAL to its hexadecimal
 * representation.
 *
 * The returned string will be allocated in the POOL and be null-terminated.
 */
static const char *
hex_encode(const unsigned char *hashval,
           apr_pool_t *pool)
{
    int i;
    char *hexval = apr_palloc(pool, (APR_MD5_DIGESTSIZE * 2) + 1);
    for (i = 0; i < APR_MD5_DIGESTSIZE; i++) {
        hexval[2 * i] = int_to_hex((hashval[i] >> 4) & 0xf);
        hexval[2 * i + 1] = int_to_hex(hashval[i] & 0xf);
    }
    hexval[APR_MD5_DIGESTSIZE * 2] = '\0';
    return hexval;
}
Exemplo n.º 9
0
void		pointeur(va_list ap, t_env *e)
{
	long int		long_int;

	long_int = 0;
	if (e->type == 'p')
	{
		long_int = va_arg(ap, unsigned long long);
		e->buffer = int_to_hex(long_int, 0);
		if (e->largeur == 0)
		{
			e->buffer = ft_str_add_before(e->buffer, ft_strlen(e->buffer) + 1, 'x');
			e->buffer = ft_str_add_before(e->buffer, ft_strlen(e->buffer) + 1, '0');
		}
	}
Exemplo n.º 10
0
/*
 * For little-endin
 * 0xEA000006 is store like this:
 *
 * high address +----+
 *              | EA |
 *              +----+
 *              | 00 |
 *              +----+
 *              | 00 |
 *              +----+
 *              | 06 |
 * low address  +----+
 *
 * So we get the address value EA000006, and print out: 060000EA
 * This function is used for update program and check for the binary file!
 */
void
uart_print_addr_value(unsigned int data)
{
	char num[9];

	int_to_hex(data, num);
	/* After int_to_hex(), we get num: EA000006 */

	/* EA_00_00_06 -> 06_00_00_EA */
	uart_putc(num[6]);
	uart_putc(num[7]);
	uart_putc(num[4]);
	uart_putc(num[5]);
	uart_putc(num[2]);
	uart_putc(num[3]);
	uart_putc(num[0]);
	uart_putc(num[1]);
}
Exemplo n.º 11
0
// Dans ce test, on va s'assurer que l'utilisateur n'accède pas à la mémoire située après la fin de la chaine de caractères
// @strcasecmp:test_int_to_hex4 => [int_to_hex accède à une adresse mémoire à droite de la zone mémoire de la chaine de caractères passée en argument.]
void test_int_to_hex4(void) {
  unsigned int i = 10601281;
  char* hex1;

  //On cherche à allouer 2 pages de la mémoire, la première avec le droit d'écriture et de lecture
  void *ptr = mmap(NULL, getpagesize()*2, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  if (ptr == MAP_FAILED) {
    CU_FAIL("La mémoire n'a pas pu être allouée pour le test test_int_to_hex6.");
    return;
  }

  // On protège ensuite la deuxième page mémoire en enlevant les droits de lecture et écriture
  mprotect(ptr+getpagesize(), getpagesize(), PROT_NONE);

  // On écrit à la fin de la première page mémoire une chaine de taille 9
  hex1 = (char*) ptr+getpagesize()-9;
  strcpy(hex1, "00000000");

  /* Si le code de l'utilisateur accède à de la mémoire située après le caractère de fin \0,
   * autrement dit la mémoire protégée de la seconde page, un segfault sera envoyé.
   * La mécanique utilisée ici permet d'"attraper" un segfault sans que tout le programme ne plante */

  //On enregistre un signal handler. Cette fonction sera exécutée par le programme lorsque
  //le code produira une segmentation fault (ce qui lance le signal SIGSEGV).
  if (signal(SIGSEGV, sig_handler2) == SIG_ERR) {
      CU_FAIL("Impossible d'enregistrer un signal handler.");
      return;
  }

  //On définit ici un jump avec le label label_test_int_to_hex6 qui attend le paramètre 0 (par défaut)
  if(setjmp(label_test_int_to_hex4)==0) {
      CU_ASSERT_PTR_NOT_NULL(int_to_hex(i,hex1));
  }
  else { //On a reçu un autre paramètre que 0, autrement dit le code a exécuté sig_handler
      //On a donc intercepté une segmentation fault, donc le code de l'utilisateur est fautif.
      CU_ASSERT_TRUE(0);
  }
        
  //On enlève le signal handler précédemment assigné à SIGSEGV
  signal(SIGSEGV, SIG_DFL);

  //On libère la mémoire précédemment allouée
  munmap(ptr, getpagesize()*2);
}
Exemplo n.º 12
0
// Proxy    <--     Client
//
// Triggered when a client sends a message.
RakNet::PluginReceiveResult
CProxy::OnReceive(RakNet::Packet* packet)
{
  if (!packet)
    return RakNet::RR_CONTINUE_PROCESSING;

  ff::fmt(pan::debug, "({0}) Packet<{1}>", packet->systemAddress.ToString(false),
    int_to_hex((int)packet->data[0]));

  std::map<RakNet::SystemAddress, s_clientInfos*>::iterator it = m_mapClientAddr.find(packet->systemAddress);

  if (it != m_mapClientAddr.end())
  {
    s_clientInfos* pInfos = (*it).second;
    return pInfos->m_sendFunc(packet, pInfos);
  }

  return RakNet::RR_CONTINUE_PROCESSING;
}
Exemplo n.º 13
0
void ColorPicker::draw()
{
    Drawable::draw();
    TextRendererTTF tr = text;

    tr.setScreenSize(ge->getSize().x, ge->getSize().y);

    glm::ivec4 col = {r->getValue(), g->getValue(), b->getValue(), a->getValue()};
    std::string str = "#" + int_to_hex(((col.r & 255) << 24) | ((col.g & 255) << 16) | ((col.b & 255) << 8) | (col.a & 255));
    tr.draw(str, pos.x + (width / 2) - (tr.textWidth(str) / 2), ge->getSize().y - 10 - 18, 0);

    if (col != prevColor)
    {
        prevColor = col;
        color->setColor(getColor());
    }

    glUseProgram(GraphicsEngine::defaultShader);
}
/*
 * Set symbols of hex str to value of corresponded bytes(max 16):
 * 
 * '******** ******** ******** ********'
 * 
 * NOTE: Spaces between group of digits is not set by this function.
 * Same for terminated null-character.
 */
static void bytes_to_hex16(char hex[35], const char* bytes, size_t len)
{
    assert(len <= 16);

    int i;
    int addend = -1;
    
    for(i = 0; i < len; i++)
    {
        if(i % 4 == 0) addend++;

        hex[i * 2 + addend] = int_to_hex((bytes[i] & 0xf0) >> 4);
        hex[i * 2 + addend + 1] = int_to_hex(bytes[i] & 0xf);
    }
    for(; i < 16; i++)
    {
        if(i % 4 == 0) addend++;

        hex[i * 2 + addend] = ' ';
        hex[i * 2 + addend + 1] = ' ';
    }
}
Exemplo n.º 15
0
void put_int(uint32_t num)
{
   char output[11];
   int_to_hex(output, num);
   put_str(output);
}
Exemplo n.º 16
0
int nterfacer_line_event(struct esocket *sock, char *newline) {
  struct sconnect *socket = sock->tag;
  char *response, *theirnonceh = NULL, *theirivh = NULL;
  unsigned char theirnonce[16], theiriv[16];
  int number, reason;

  switch(socket->status) {
    case SS_IDLE:
      if(strcasecmp(newline, ANTI_FULL_VERSION)) {
        nterface_log(nrl, NL_INFO, "Protocol mismatch from %s: %s", socket->permit->hostname->content, newline);
        return 1;
      } else {
        unsigned char challenge[32];
        char ivhex[16 * 2 + 1], noncehex[16 * 2 + 1];

        if(!get_entropy(challenge, 32) || !get_entropy(socket->iv, 16)) {
          nterface_log(nrl, NL_ERROR, "Unable to open challenge/IV entropy bin!");
          return 1;
        }

        int_to_hex(challenge, socket->challenge, 32);
        int_to_hex(socket->iv, ivhex, 16);

        memcpy(socket->response, challenge_response(socket->challenge, socket->permit->password->content), sizeof(socket->response));
        socket->response[sizeof(socket->response) - 1] = '\0'; /* just in case */

        socket->status = SS_VERSIONED;
        if(!generate_nonce(socket->ournonce, 1)) {
          nterface_log(nrl, NL_ERROR, "Unable to generate nonce!");
          return 1;
        }
        int_to_hex(socket->ournonce, noncehex, 16);

        if(esocket_write_line(sock, "%s %s %s", socket->challenge, ivhex, noncehex))
           return BUF_ERROR;
        return 0;
      }
      break;
    case SS_VERSIONED:
      for(response=newline;*response;response++) {
        if((*response == ' ') && (*(response + 1))) {
          *response = '\0';
          theirivh = response + 1;
          break;
        }
      }

      if(theirivh) {
        for(response=theirivh;*response;response++) {
          if((*response == ' ') && (*(response + 1))) {
            *response = '\0';
            theirnonceh = response + 1;
            break;
          }
        }
      }

      if(!theirivh || (strlen(theirivh) != 32) || !hex_to_int(theirivh, theiriv, sizeof(theiriv)) ||
         !theirnonceh || (strlen(theirnonceh) != 32) || !hex_to_int(theirnonceh, theirnonce, sizeof(theirnonce))) {
        nterface_log(nrl, NL_INFO, "Protocol error drop: %s", socket->permit->hostname->content);
        return 1;
      }

      if(!memcmp(socket->ournonce, theirnonce, sizeof(theirnonce))) {
        nterface_log(nrl, NL_INFO, "Bad nonce drop: %s", socket->permit->hostname->content);
        return 1;
      }

      if(!strncasecmp(newline, socket->response, sizeof(socket->response))) {
        unsigned char theirkey[32], ourkey[32];

        derive_key(ourkey, socket->permit->password->content, socket->challenge, socket->ournonce, theirnonce, (unsigned char *)"SERVER", 6);

        derive_key(theirkey, socket->permit->password->content, socket->response, theirnonce, socket->ournonce, (unsigned char *)"CLIENT", 6);
        nterface_log(nrl, NL_INFO, "Authed: %s", socket->permit->hostname->content);
        socket->status = SS_AUTHENTICATED;
        switch_buffer_mode(sock, ourkey, socket->iv, theirkey, theiriv);

        if(esocket_write_line(sock, "Oauth"))
          return BUF_ERROR;
      } else {
        nterface_log(nrl, NL_INFO, "Bad CR drop: %s", socket->permit->hostname->content);
        
        return 1;
      }
      break;
    case SS_AUTHENTICATED:
      nterface_log(nrl, NL_INFO|NL_LOG_ONLY, "L(%s): %s", socket->permit->hostname->content, newline);
      reason = nterfacer_new_rline(newline, sock, &number);
      if(reason) {
        if(reason == RE_SOCKET_ERROR)
          return BUF_ERROR;
        if(reason != RE_BAD_LINE) {
          if(esocket_write_line(sock, "%d,E%d,%s", number, reason, request_error(reason)))
            return BUF_ERROR;
          return 0;
        } else {
          return 1;
        }
      }
      break;
  }

  return 0;
}
Exemplo n.º 17
0
int vprintf( const char *fmt, va_list arg )
{
    int character_count = 0;
    char temp_buf[64];

    if ( fmt == NULL )
        return -1;

    while ( *fmt )
    {
        if ( *fmt == '@' )
        {
            fmt++;

            // We don't handle any special formatting
            switch ( *fmt )
            {
            case '@':
                putc( '@' );
                break;

            case 'c':
                // single charß
                {

                    char c = (char )va_arg(arg, int);
                    putc(c);
                }
                break;
                
            case 'd':
                // Integer
                {
                    int int_arg = va_arg( arg, int );
                    char *c;

                    int_to_str( int_arg, temp_buf );

                    c = temp_buf;
                    while ( *c )
                    {
                        putc( *c );
                        character_count++;
                        c++;
                    }
                }
                break;

            case 'x':
                // hex
                {
                    unsigned int int_arg = va_arg( arg, unsigned int );
                    char *c;

                    int_to_hex( int_arg, temp_buf );

                    c = temp_buf;
                    while ( *c )
                    {
                        putc( *c );
                        character_count++;
                        c++;
                    }
                }
                break;

            case 'f':
                // Float
                {
                    double float_arg = va_arg( arg, double );
                    char *c;

                    float_to_str( float_arg, temp_buf );

                    c = temp_buf;
                    while ( *c )
                    {
                        putc( *c );
                        character_count++;
                        c++;
                    }
                }
                break;

            case 's':
                // String
                {
                    char *string_arg = va_arg( arg, char * );

                    while ( *string_arg )
                    {
                        putc( *string_arg );
                        character_count++;
                        string_arg++;
                    }

                }
                break;

            case '\0':
                return -1;

            default:
                // Unknown
                return -1;
            }

            fmt++;
        }
        else
        {