Esempio n. 1
0
/** Add color data to an attribute node.
 * @param attr The attribute node.
 * @param col The value to set.
 */
void
data_add_color(AttributeNode attr, const Color *col)
{
  char buffer[1+6+1];
  DataNode data_node;

  buffer[0] = '#';
  convert_to_hex(col->red, &buffer[1]);
  convert_to_hex(col->green, &buffer[3]);
  convert_to_hex(col->blue, &buffer[5]);
  buffer[7] = 0;

  data_node = xmlNewChild(attr, NULL, (const xmlChar *)"color", NULL);
  xmlSetProp(data_node, (const xmlChar *)"val", (xmlChar *)buffer);
}
Esempio n. 2
0
static int l_encrypt(lua_State *L) {
  size_t keyLen, valLen, outLen, bufferSize;

  // TODO Key must be the correct key size
  const char *key = luaL_checklstring(L, 1, &keyLen);
  const char *val = luaL_checklstring(L, 2, &valLen);

  bufferSize = valLen + AES_BLOCK_SIZE;
  unsigned char buffer[bufferSize];

  if (encrypt_str(buffer, val, valLen, key, &outLen) != 1)
    return luaL_error(L, "Error encrypting value");

  size_t hexOutLen = outLen * 2;
  char hexStr[hexOutLen];

  convert_to_hex(buffer, outLen, hexStr);

  luaL_Buffer b;
  luaL_buffinit(L, &b);
  luaL_addlstring(&b, hexStr, hexOutLen);
  luaL_pushresult(&b);

  return 1;
}
Esempio n. 3
0
void MyClass::GOST2012(){
emit set_max(0);
    QFile file(fname);
    emit sendStringFileName(fname);
    CTX = (GOST34112012Context*)(malloc(sizeof(GOST34112012Context)));
    if(sizeHash==64)
        GOST34112012Init(CTX, 512);
    if(sizeHash==32)
        GOST34112012Init(CTX, 256);

     if (file.open(QIODevice::ReadOnly) )
               {
                 while (!file.atEnd()) {
                 QByteArray line = file.read(4096);
                 GOST34112012Update(CTX, (unsigned char*)(line.data()), line.size());
               }
             }
             file.close();
             GOST34112012Final(CTX, &digest[0]);
     convert_to_hex(digest, hexdigest, sizeHash, 1);//eflag=1 (в Госте в таком виде хеш получается)// eflag=0 наоборот развернут
     QString rez = (char*)hexdigest;
    // QString rez = (char*)digest;
    //  rez   = rez.toLocal8Bit().toHex();
             GOST34112012Cleanup(CTX);

    emit sendString(rez);emit set_max(100);emit change_value(100);emit finished();emit sendStringDone("Complete");
}
Esempio n. 4
0
                multipolygon_type multipolygon_finish() {
                    set_size(m_multipolygon_size_offset, m_polygons);
                    std::string data;
                    std::swap(data, m_data);

                    if (m_out_type == out_type::hex) {
                        return convert_to_hex(data);
                    } else {
                        return data;
                    }
                }
Esempio n. 5
0
                linestring_type linestring_finish(size_t num_points) {
                    set_size(m_linestring_size_offset, num_points);
                    std::string data;
                    std::swap(data, m_data);

                    if (m_out_type == out_type::hex) {
                        return convert_to_hex(data);
                    } else {
                        return data;
                    }
                }
Esempio n. 6
0
                point_type make_point(const osmium::geom::Coordinates& xy) const {
                    std::string data;
                    header(data, wkbPoint, false);
                    str_push(data, xy.x);
                    str_push(data, xy.y);

                    if (m_out_type == out_type::hex) {
                        return convert_to_hex(data);
                    } else {
                        return data;
                    }
                }
Esempio n. 7
0
static int l_hash(lua_State *L) {
  size_t len;
  const char *str = luaL_checklstring(L, 1, &len);
  unsigned char encr[SHA256_DIGEST_LENGTH];

  if (hash_str(encr, str, len) != 1)
    return luaL_error(L, "Error hashing value");

  size_t hexOutLen = SHA256_DIGEST_LENGTH * 2;
  char hexStr[hexOutLen];

  convert_to_hex(encr, SHA256_DIGEST_LENGTH, hexStr);

  luaL_Buffer b;
  luaL_buffinit(L, &b);
  luaL_addlstring(&b, hexStr, hexOutLen);
  luaL_pushresult(&b);

  return 1;
}
Esempio n. 8
0
void go(std::ifstream *input_, unsigned int &buff_count, unsigned int &good_buff_count, unsigned int &total_count, 
		bool show_raw, bool convert, bool show_zero, bool do_search, T search_int, T buffer_select){
	bool good_buffer;
	int show_next = 0;
	unsigned int count = 0;
	unsigned int word_count = 0;

	T word;

	if(buffer_select != 0){ good_buffer = false; }
	else{ good_buffer = true; }

	while(true){
		input_->read((char*)&word, sizeof(T));
		if(input_->eof()){ 
			if(buff_count > 1){
				std::cout << " Buffer Size: " << word_count << " words\n";
				std::cout << "============================================================================================================================\n";
			}
			break; 
		}

		if(do_search){
			if(show_next > 0){
				std::cout << convert_to_hex(word) << "  ";
				if(convert){ std::cout << convert_to_hex(word, true) << "  "; }
				show_next = show_next - 1;
				if(show_next <= 0){ std::cout << std::endl; }
			}		
			else if(word == search_int){
				std::cout << convert_to_hex(word) << "  ";
				if(convert){ std::cout << convert_to_hex(word, true) << "  "; }
				show_next = 4;
			}
			total_count++;
			word_count++;
			continue;
		}

		// Check for end of buffer
		/*if(word == ENDBUFF || (!show_zero && word == 0)){
			total_count++;
			continue;
		}*/
		if((!show_zero && word == 0)){
			total_count++;
			word_count++;
			continue;
		}
				
		// Check for a new buffer
		if(word == HEAD || word == DATA || word == SCAL || word == DEAD || word == DIR || word == PAC || word == ENDFILE){ // new buffer
			buff_count++;
			if(buffer_select != 0){
				if(word == buffer_select){ good_buffer = true; }
				else{ good_buffer = false; }
			}
			
			if(good_buffer){
				good_buff_count++;
				if(buff_count > 1){
					if(show_raw){ std::cout << "\n"; }
					std::cout << "\n Buffer Size: " << word_count << " words\n";
					std::cout << "============================================================================================================================\n";
				}
				std::cout << "\n============================================================================================================================\n";
				std::cout << " Buffer Number: " << buff_count << std::endl;
				std::cout << " Buffer Type: " << convert_to_hex(word);
				if(word == HEAD){ std::cout << " \"HEAD\"\n"; }
				else if(word == DATA){ std::cout << " \"DATA\"\n"; }
				else if(word == ENDFILE){ std::cout << " \"EOF \"\n"; }
				else if(word == SCAL){ std::cout << " \"SCAL\"\n"; }
				else if(word == DEAD){ std::cout << " \"DEAD\"\n"; }
				else if(word == DIR){ std::cout << " \"DIR\"\n"; }
				else if(word == PAC){ std::cout << " \"PAC\"\n"; }
				std::cout << " Total Count: " << total_count << " words\n";
				count = 0;
			}
			word_count = 0; // New buffer. Reset the buffer word count
		}
		
		if(!good_buffer){ // We don't care about this buffer
			total_count++;
			word_count++;
			continue; 
		} 

		total_count++;
		word_count++;
		if(show_raw){
			if(count == 0){ std::cout << "\n0000  "; }
			else if(count % 10 == 0){ 
				std::stringstream stream; stream << count;
				std::string temp_string = stream.str();
				std::string padding = "";
				if(temp_string.size() < 4){
					for(unsigned int i = 0; i < (4 - temp_string.size()); i++){ 
						padding += "0";
					}
				}
				std::cout << "\n" << padding << temp_string << "  "; 
			}
			std::cout << convert_to_hex(word) << "  "; count++;
			if(convert){ std::cout << convert_to_hex(word, true) << "  "; count++; }
		}
	}
}
Esempio n. 9
0
int main(int argc, char *argv[]){
	if(argc > 1 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)){
		help(argv[0]);
		return 1;
	}
	else if(argc < 2){
		std::cout << " Error: Invalid number of arguments to " << argv[0] << ". Expected 1, received " << argc-1 << ".\n";
		help(argv[0]);
		return 1;
	}
	
	std::ifstream input(argv[1], std::ios::binary);
	if(!input.is_open()){
		std::cout << " Error: failed to open input file\n";
		return 1;
	}

	std::streampos foffset = 0;

	int buffer_select = 0;
	int search_int = 0;
	int word_size = 4;
	bool show_raw = false;
	bool convert = false;
	bool show_zero = true;
	bool do_search = false;
	int index = 2;
	while(index < argc){
		if(strcmp(argv[index], "--type") == 0){
			if(index + 1 >= argc){
				std::cout << " Error! Missing required argument to '--type'!\n";
				help(argv[0]);
				return 1;
			}
			buffer_select = atoi(argv[++index]);
			std::cout << " Displaying only buffer type " << convert_to_hex(buffer_select) << "\n";
		}
		else if(strcmp(argv[index], "--raw") == 0){
			show_raw = true;
		}
		else if(strcmp(argv[index], "--convert") == 0){
			convert = true;
		}
		else if(strcmp(argv[index], "--search") == 0){
			if(index + 1 >= argc){
				std::cout << " Error! Missing required argument to '--search'!\n";
				help(argv[0]);
				return 1;
			}
			do_search = true; 
			search_int = atoi(argv[++index]);
			std::cout << " Searching for " << search_int << " (" << convert_to_hex(search_int) << ")\n";
		}
		else if(strcmp(argv[index], "--zero") == 0){
			show_zero = false;
		}
		else if(strcmp(argv[index], "--word") == 0){
			if(index + 1 >= argc){
				std::cout << " Error! Missing required argument to '--word'!\n";
				help(argv[0]);
				return 1;
			}
			word_size = atoi(argv[++index]);
			if(word_size != 1 && word_size != 2 && word_size != 4 && word_size != 8){
				std::cout << " Error: Invalid word size (" << word_size << " bytes)!\n";
				return 1;
			}
			std::cout << " Using word size of " << word_size << " bytes\n";
		}
		else if(strcmp(argv[index], "--offset") == 0){
			if(index + 1 >= argc){
				std::cout << " Error! Missing required argument to '--offset'!\n";
				help(argv[0]);
				return 1;
			}
			foffset = strtoll(argv[++index], NULL, 0);
			std::cout << " Starting at word no. " << foffset << " in file.\n";
		}
		else{ 
			std::cout << " Error! Unrecognized option '" << argv[index] << "'!\n";
			help(argv[0]);
			return 1;
		}
		index++;
	}

	input.seekg(foffset*word_size);

	unsigned int good_buff_count = 0;
	unsigned int total_count = 0;
	unsigned int buff_count = 0;

	if(word_size == 1){ go<unsigned char>(&input, buff_count, good_buff_count, total_count, show_raw, convert, show_zero, do_search, search_int, buffer_select); }
	else if(word_size == 2){ go<unsigned short>(&input, buff_count, good_buff_count, total_count, show_raw, convert, show_zero, do_search, search_int, buffer_select); }
	else if(word_size == 4){ go<unsigned int>(&input, buff_count, good_buff_count, total_count, show_raw, convert, show_zero, do_search, search_int, buffer_select); }
	else{ go<unsigned long long>(&input, buff_count, good_buff_count, total_count, show_raw, convert, show_zero, do_search, search_int, buffer_select); }

	input.close();
	
	if(!do_search){
		std::cout << "\n\n Read " << total_count << " " << word_size << " byte words (";
		total_count *= word_size;
		std::cout << total_count << " bytes)\n";
		std::cout << "  Found " << buff_count << " total buffers\n";
		if(buffer_select != 0){ std::cout << "  Found " << good_buff_count << " " << convert_to_hex(buffer_select) << " buffers\n"; }
	}
	
	return 0;
}
Esempio n. 10
0
/****************
 * Print SEXP to buffer using the MODE.  Returns the length of the
 * SEXP in buffer or 0 if the buffer is too short (We have at least an
 * empty list consisting of 2 bytes).  If a buffer of NULL is provided,
 * the required length is returned.
 */
size_t
gcry_sexp_sprint (const gcry_sexp_t list, int mode,
                  void *buffer, size_t maxlength )
{
  static unsigned char empty[3] = { ST_OPEN, ST_CLOSE, ST_STOP };
  const unsigned char *s;
  char *d;
  DATALEN n;
  char numbuf[20];
  size_t len = 0;
  int i, indent = 0;

  s = list? list->d : empty;
  d = buffer;
  while ( *s != ST_STOP )
    {
      switch ( *s )
        {
        case ST_OPEN:
          s++;
          if ( mode != GCRYSEXP_FMT_CANON )
            {
              if (indent)
                len++;
              len += indent;
            }
          len++;
          if ( buffer )
            {
              if ( len >= maxlength )
                return 0;
              if ( mode != GCRYSEXP_FMT_CANON )
                {
                  if (indent)
                    *d++ = '\n';
                  for (i=0; i < indent; i++)
                    *d++ = ' ';
                }
              *d++ = '(';
	    }
          indent++;
          break;
        case ST_CLOSE:
          s++;
          len++;
          if ( buffer )
            {
              if ( len >= maxlength )
                return 0;
              *d++ = ')';
	    }
          indent--;
          if (*s != ST_OPEN && *s != ST_STOP && mode != GCRYSEXP_FMT_CANON)
            {
              len++;
              len += indent;
              if (buffer)
                {
                  if (len >= maxlength)
                    return 0;
                  *d++ = '\n';
                  for (i=0; i < indent; i++)
                    *d++ = ' ';
                }
            }
          break;
        case ST_DATA:
          s++;
          memcpy ( &n, s, sizeof n ); s += sizeof n;
          if (mode == GCRYSEXP_FMT_ADVANCED)
            {
              int type;
              size_t nn;

              switch ( (type=suitable_encoding (s, n)))
                {
                case 1: nn = convert_to_string (s, n, NULL); break;
                case 2: nn = convert_to_token (s, n, NULL); break;
                default: nn = convert_to_hex (s, n, NULL); break;
                }
              len += nn;
              if (buffer)
                {
                  if (len >= maxlength)
                    return 0;
                  switch (type)
                    {
                    case 1: convert_to_string (s, n, d); break;
                    case 2: convert_to_token (s, n, d); break;
                    default: convert_to_hex (s, n, d); break;
                    }
                  d += nn;
                }
              if (s[n] != ST_CLOSE)
                {
                  len++;
                  if (buffer)
                    {
                      if (len >= maxlength)
                        return 0;
                      *d++ = ' ';
                    }
                }
            }
          else
            {
              sprintf (numbuf, "%u:", (unsigned int)n );
              len += strlen (numbuf) + n;
              if ( buffer )
                {
                  if ( len >= maxlength )
		    return 0;
                  d = stpcpy ( d, numbuf );
                  memcpy ( d, s, n ); d += n;
                }
            }
          s += n;
          break;
        default:
          BUG ();
	}
    }
  if ( mode != GCRYSEXP_FMT_CANON )
    {
      len++;
      if (buffer)
        {
          if ( len >= maxlength )
            return 0;
          *d++ = '\n';
        }
    }
  if (buffer)
    {
      if ( len >= maxlength )
        return 0;
      *d++ = 0; /* for convenience we make a C string */
    }
  else
    len++; /* we need one byte more for this */

  return len;
}
Esempio n. 11
0
/*
 * DUID should not change over time so save it to file.
 * See RFC 3315 chapter 9 for details.
 */
static int set_duid(struct connman_service *service,
                    struct connman_network *network,
                    GDHCPClient *dhcp_client, int index)
{
    GKeyFile *keyfile;
    const char *ident;
    char *hex_duid;
    unsigned char *duid;
    int duid_len;

    ident = __connman_service_get_ident(service);

    keyfile = connman_storage_load_service(ident);
    if (keyfile == NULL)
        return -EINVAL;

    hex_duid = g_key_file_get_string(keyfile, ident, "IPv6.DHCP.DUID",
                                     NULL);
    if (hex_duid != NULL) {
        unsigned int i, j = 0, hex;
        size_t hex_duid_len = strlen(hex_duid);

        duid = g_try_malloc0(hex_duid_len / 2);
        if (duid == NULL) {
            g_key_file_free(keyfile);
            g_free(hex_duid);
            return -ENOMEM;
        }

        for (i = 0; i < hex_duid_len; i += 2) {
            sscanf(hex_duid + i, "%02x", &hex);
            duid[j++] = hex;
        }

        duid_len = hex_duid_len / 2;
    } else {
        int ret;
        int type = __connman_ipconfig_get_type_from_index(index);

        ret = g_dhcpv6_create_duid(G_DHCPV6_DUID_LLT, index, type,
                                   &duid, &duid_len);
        if (ret < 0) {
            g_key_file_free(keyfile);
            return ret;
        }

        hex_duid = convert_to_hex(duid, duid_len);
        if (hex_duid == NULL) {
            g_key_file_free(keyfile);
            return -ENOMEM;
        }

        g_key_file_set_string(keyfile, ident, "IPv6.DHCP.DUID",
                              hex_duid);

        __connman_storage_save_service(keyfile, ident);
    }
    g_free(hex_duid);

    g_key_file_free(keyfile);

    g_dhcpv6_client_set_duid(dhcp_client, duid, duid_len);

    return 0;
}