int main( int inNumArgs, char **inArgs ) { if( inNumArgs != 2 ) { usage(); } char *otherPublicKeyHex = inArgs[1]; if( strlen( otherPublicKeyHex ) != 64 ) { usage(); } unsigned char *otherPublicKey = hexDecode( otherPublicKeyHex ); if( otherPublicKey == NULL ) { usage(); } unsigned char secretKey[32]; unsigned char ourPublicKey[32]; unsigned char sharedSecretKey[32]; char gotRandom = getCryptoRandomBytes( secretKey, 32 ); if( !gotRandom ) { delete [] otherPublicKey; printf( "Failed to generate crypto-secure random bytes.\n" ); return 1; } curve25519_genPublicKey( ourPublicKey, secretKey ); curve25519_genSharedSecretKey( sharedSecretKey, secretKey, otherPublicKey ); char *ourPublicKeyHex = hexEncode( ourPublicKey, 32 ); char *sharedSecretKeyHex = hexEncode( sharedSecretKey, 32 ); printf( "%s\n%s\n", ourPublicKeyHex, sharedSecretKeyHex ); delete [] otherPublicKey; delete [] ourPublicKeyHex; delete [] sharedSecretKeyHex; return 0; }
bool Reply::nextWrappedContentBuffers(std::vector<asio::const_buffer>& result) { std::vector<asio::const_buffer> contentBuffers; int originalSize; int encodedSize; bool lastData = encodeNextContentBuffer(contentBuffers, originalSize, encodedSize); contentSent_ += encodedSize; contentOriginalSize_ += originalSize; if (chunkedEncoding_) { if (encodedSize || lastData) { buf_ << hexEncode(encodedSize); buf_ << "\r\n"; buf_.asioBuffers(result); if (encodedSize) { result.insert(result.end(), contentBuffers.begin(), contentBuffers.end()); postBuf_ << "\r\n"; if (lastData) { postBuf_ << "0\r\n\r\n"; } } else { postBuf_ << "\r\n"; } postBuf_.asioBuffers(result); } else buf_.asioBuffers(result); return lastData; } else { buf_.asioBuffers(result); result.insert(result.end(), contentBuffers.begin(), contentBuffers.end()); return lastData; } }
void insertPacket(uint8_t s2c, uint64_t time, uint16_t opcode, uint8_t *data, uint32_t data_len, void* arg) { sqlite3 *db = (sqlite3*) arg; const char* insertFormat = "insert into packets (timestamp, direction, opcode, data) " "values (datetime(%u,'unixepoch'), %u, %u, X'%s');"; uint32_t allocSize = 3/*s2c*/+10 /*time*/+5/*opcode*/+data_len*2+strlen(insertFormat); char* queryBuffer = malloc(allocSize); if(!queryBuffer) { printf("Failed to allocate %u bytes for insert query\n", allocSize); exit(1); } sprintf(queryBuffer, insertFormat, (uint32_t)(time/1000000), s2c, opcode, hexEncode(data, data_len)); executeSql(db, queryBuffer); free(queryBuffer); if(opcode == 0x3000) //CMSG_AUTH_SESSION //493) insertClientBuild(data, data_len, db); }
gboolean my_foreach_func(GQuark field_id, const GValue *value, gpointer user_data) { my_foreach_state &state = *((my_foreach_state *)user_data); QString name = QString::fromLatin1(g_quark_to_string(field_id)); if(G_VALUE_TYPE(value) == G_TYPE_STRING && state.whitelist->contains(name)) { QString svalue = QString::fromLatin1(g_value_get_string(value)); // FIXME: is there a better way to detect when we should do this conversion? if(name == "configuration" && (state.out->name == "THEORA" || state.out->name == "VORBIS")) { QByteArray config = QByteArray::fromBase64(svalue.toLatin1()); svalue = hexEncode(config); } PPayloadInfo::Parameter i; i.name = name; i.value = svalue; state.list->append(i); } return TRUE; }
STDMETHODIMP OutputCallback::Output( THIS_ IN ULONG mask, IN PCWSTR text ) { if (m_recording) m_recorded.append(text); // Do not unconditionally output ourselves here, as this causes an endless // recursion. Suppress prompts (note that sequences of prompts may mess parsing up) if (!m_wrapped || mask == DEBUG_OUTPUT_PROMPT) return S_OK; // Wrap debuggee output in gdbmi such that creator recognizes it if (mask != DEBUG_OUTPUT_DEBUGGEE) { m_wrapped->Output(mask, text); return S_OK; } // Base encode as GDBMI is not really made for wide chars std::ostringstream str; hexEncode(str, reinterpret_cast<const unsigned char *>(text), sizeof(wchar_t) * std::wcslen(text)); ExtensionContext::instance().reportLong('E', 0, "debuggee_output", str.str().c_str()); return S_OK; }
int main( int inNumArgs, char **inArgs ) { if( inNumArgs != 2 ) { usage( inArgs[0] ); } FILE *file = fopen( inArgs[1], "rb" ); if( file == NULL ) { printf( "Failed to open file %s for reading\n\n", inArgs[1] ); usage( inArgs[0] ); } SHA_CTX shaContext; SHA1_Init( &shaContext ); int bufferSize = 5000; unsigned char *buffer = new unsigned char[ bufferSize ]; int numRead = bufferSize; char error = false; // read bytes from file until we run out while( numRead == bufferSize && !error ) { numRead = fread( buffer, 1, bufferSize, file ); if( numRead > 0 ) { SHA1_Update( &shaContext, buffer, numRead ); } else{ error = true; } } fclose( file ); delete [] buffer; if( error ) { printf( "Error reading from file %s\n", inArgs[1] ); } else { unsigned char *rawDigest = new unsigned char[ SHA1_DIGEST_LENGTH ]; SHA1_Final( rawDigest, &shaContext ); // else hash is correct char *digestHexString = hexEncode( rawDigest, SHA1_DIGEST_LENGTH ); printf( "%s %s\n", digestHexString, inArgs[1] ); delete [] rawDigest; delete [] digestHexString; } return 0; }
void Packed::listStringItem(const std::string& data) { m_socket << '$' << hexEncode(data); }
void Packed::mapStringItem(const std::string& name, const std::string& data) { m_socket << '$' << hexEncode(name) << '=' << hexEncode(data); }
void Packed::mapFloatItem(const std::string& name, double data) { m_socket << '#' << hexEncode(name) << '=' << data; }
void Packed::mapIntItem(const std::string& name, long data) { m_socket << '@' << hexEncode(name) << '=' << data; }
void Packed::mapListItem(const std::string& name) { m_socket << '(' << hexEncode(name) << '='; }
void Packed::mapMapItem(const std::string& name) { m_socket << '[' << hexEncode(name) << '='; }