int print_digits(int value, int base, int signed_bool, int width, int pad, int format) { char print_buf[4]; register unsigned int u; register char *s; int neg; int pc; u = value; pc = 0; neg = 0; if (value == 0) { print_buf[0] = '0'; print_buf[1] = '\0'; return (print_string (print_buf, width, pad, 0)); } if (signed_bool && base == 10 && value < 0) { neg = 1; u = -value; } s = print_buf - 4 + 1; s = convert_to_base(u, base, format, s); if (neg) s = print_neg(&width, pad, &pc, s); return (pc + print_string(s, width, pad, 0)); }
// Given a { length, fixed, count } triplet, calculate the internal state of // inc_key_loop() after the specified number of crypt operations. // // Note that the state produced may be a few crypts early due to the // number_cache behaviour. This is unavoidable, john does the same thing with // REC files internally. static bool calculate_number_state(uint8_t *numbers, uint32_t length, uint32_t fixed, uint32_t count, uint64_t crypts) { // Compensate for the number_cache in inc_key_loop() skipping certain // increments of numbers[]. if (fixed != length) crypts = crypts - (crypts % (count + 1)); // Convert number of crypts into a k-digit base-n representation // of crypts. This closely matches how John stores it's internal state, // with the exception of fixed digits. convert_to_base(numbers, kMaxLength, count + 1, crypts); // Move the digits above the fixed digit down one position, because the // fixed digit will displace them. This is the same as partial // multiplication of these digits by base, but moving them is more // efficient than having to convert them to integers. memmove(&numbers[0], &numbers[1], fixed); // Now we can force the fixed digit into the correct position. numbers[fixed] = count; // Finally, we need to adjust the digits above the fixed position // independently. This is because John will never set a digit in those // positions to count, however other arithmetic rules still apply. // // We can interpret this algorithm behaviour as setting these digits to one // base lower than the rest of the digits. Yes, this is confusing. convert_to_base(numbers, fixed, count, convert_from_base(numbers, fixed, count + 1)); // Complete. return true; }
void standard_use_type::do_use() { int result = sqlite_ok; convert_to_base(); switch (m_type) { case x_null: result = sqlite3_bind_null(m_st->m_stmt, m_iparam); break; case x_bool: result = sqlite3_bind_int(m_st->m_stmt, m_iparam, as <bool> (m_data) ? 1 : 0); break; case x_char: result = sqlite3_bind_int(m_st->m_stmt, m_iparam, as <char> (m_data)); break; case x_uchar: result = sqlite3_bind_int(m_st->m_stmt, m_iparam, as <unsigned char> (m_data)); break; case x_short: result = sqlite3_bind_int(m_st->m_stmt, m_iparam, as <short> (m_data)); break; case x_ushort: result = sqlite3_bind_int(m_st->m_stmt, m_iparam, as <unsigned short> (m_data)); break; case x_int: result = sqlite3_bind_int(m_st->m_stmt, m_iparam, as <int> (m_data)); break; case x_uint: result = sqlite3_bind_int64(m_st->m_stmt, m_iparam, as <unsigned int> (m_data)); break; case x_long: result = sqlite3_bind_int(m_st->m_stmt, m_iparam, as <long> (m_data)); break; case x_ulong: result = sqlite3_bind_int64(m_st->m_stmt, m_iparam, as <unsigned long> (m_data)); break; case x_longlong: result = sqlite3_bind_int64(m_st->m_stmt, m_iparam, as <long long> (m_data)); break; case x_ulonglong: result = sqlite3_bind_int64(m_st->m_stmt, m_iparam, as <unsigned long long> (m_data)); break; case x_float: result = sqlite3_bind_double(m_st->m_stmt, m_iparam, as <float> (m_data)); break; case x_double: result = sqlite3_bind_double(m_st->m_stmt, m_iparam, as <double> (m_data)); break; #if 0 case x_longdouble: result = sqlite3_bind_double(m_st->m_stmt, m_iparam, as <long double> (m_data)); break; #endif case x_cstring: result = sqlite3_bind_text(m_st->m_stmt, m_iparam, as <char*> (m_data), -1, sqlite_static); break; case x_cwstring: result = sqlite3_bind_text16(m_st->m_stmt, m_iparam, as <wchar_t*> (m_data), -1, sqlite_static); break; case x_stdstring: { std::string const& s = as <std::string> (m_data); result = sqlite3_bind_text(m_st->m_stmt, m_iparam, s.c_str(), int(s.size() * sizeof(s[0])), sqlite_static); } break; case x_stdwstring: { std::wstring const& s = as <std::wstring> (m_data); result = sqlite3_bind_text16(m_st->m_stmt, m_iparam, s.c_str(), int(s.size() * sizeof(s[0])), sqlite_static); } break; case x_beaststring: { string const& s = as <string> (m_data); result = sqlite3_bind_text(m_st->m_stmt, m_iparam, s.toutf8(), -1, sqlite_static); } break; case x_stdtm: case x_blob: default: throw std::invalid_argument ("bad parameter"); } if (result != sqlite_ok) throw detail::sqliteerror(__file__, __line__, result); }
void standard_use_type::do_use() { int result=SQLITE_OK; convert_to_base(); switch (m_type) { case x_null: result = sqlite3_bind_null (m_st->m_stmt, m_iParam); break; case x_bool: result = sqlite3_bind_int (m_st->m_stmt, m_iParam, as <bool> (m_data)?1:0 ); break; case x_char: result = sqlite3_bind_int (m_st->m_stmt, m_iParam, as <char> (m_data)); break; case x_short: result = sqlite3_bind_int (m_st->m_stmt, m_iParam, as <short> (m_data)); break; case x_int: result = sqlite3_bind_int (m_st->m_stmt, m_iParam, as <int> (m_data)); break; case x_long: result = sqlite3_bind_int (m_st->m_stmt, m_iParam, as <long> (m_data)); break; case x_int64: result = sqlite3_bind_int64 (m_st->m_stmt, m_iParam, as <int64> (m_data)); break; case x_uchar: result = sqlite3_bind_int (m_st->m_stmt, m_iParam, as <unsigned char> (m_data)); break; case x_ushort: result = sqlite3_bind_int (m_st->m_stmt, m_iParam, as <unsigned short> (m_data)); break; case x_uint: result = sqlite3_bind_int64 (m_st->m_stmt, m_iParam, as <unsigned int> (m_data)); break; case x_ulong: result = sqlite3_bind_int64 (m_st->m_stmt, m_iParam, as <unsigned long> (m_data)); break; case x_uint64: result = sqlite3_bind_int64 (m_st->m_stmt, m_iParam, as <sqlite3_uint64, sqlite3_int64> (m_data)); break; case x_float: result = sqlite3_bind_double (m_st->m_stmt, m_iParam, as <float> (m_data)); break; case x_double: result = sqlite3_bind_double (m_st->m_stmt, m_iParam, as <double> (m_data)); break; case x_cstring: result = sqlite3_bind_text (m_st->m_stmt, m_iParam, as <char*> (m_data), -1, SQLITE_STATIC); break; case x_cwstring: result = sqlite3_bind_text16 (m_st->m_stmt, m_iParam, as <wchar_t*> (m_data), -1, SQLITE_STATIC); break; case x_stdstring: { std::string const& s = as <std::string> (m_data); result = sqlite3_bind_text (m_st->m_stmt, m_iParam, s.c_str(), s.size() * sizeof(s[0]), SQLITE_STATIC); } break; case x_stdwstring: { std::wstring const& s = as <std::wstring> (m_data); result = sqlite3_bind_text16 (m_st->m_stmt, m_iParam, s.c_str(), s.size() * sizeof(s[0]), SQLITE_STATIC); } break; case x_juceString: { String const& s = as <String> (m_data); result = sqlite3_bind_text (m_st->m_stmt, m_iParam, s.toUTF8(), -1, SQLITE_STATIC); } break; case x_stdtm: case x_blob: default: Throw (Error().fail (__FILE__, __LINE__, Error::badParameter)); } if (result != SQLITE_OK) Throw (detail::sqliteError(__FILE__, __LINE__, result)); }