Exemple #1
0
//==============================================================================
bool CC_UnitDriver::flash_verify_by_read(const DataSectionStore &section_store)
{
    ByteVector data;
    bool result = true;

    pw_.read_start(section_store.actual_size());

    flash_read_start();
    foreach (const DataSection &item, section_store.sections())
    {
        flash_read_block(item.address, item.size(), data);
        if (memcmp(&data[0], &item.data[0], item.size()))
        {
            //binary_file_save("vr.bin", data);
            result = false;
            break;
        }
        data.clear();
    }
    flash_read_end();

    pw_.read_finish();

    return result;
}
	void BufferReader::Clear()
	{
		mReadBitPos = 0;
		mWriteBitPos = 0;
		mDataBitSize = 0;
		mData.clear();
	}
	void BufferReader::SetData(uchar* thePtr, int theCount)
	{
		mData.clear();
		mData.reserve(theCount);
		mData.insert(mData.begin(), thePtr, thePtr + theCount);
		mDataBitSize = mData.size() * 8;
	}
bool Registry::StringListToValue(const StringList& list, ByteVector& value)
{
    value.clear();
    ByteVector::iterator out= value.begin();
    for (StringList::const_iterator i= list.begin() ; i!=list.end() ; ++i)
    {
        value.reserve(value.size() + (*i).size()+1);
        copy((*i).begin(), (*i).end(), out);
        *out++= 0;
    }
    *out++= 0;
    return true;
}
Exemple #5
0
//==============================================================================
static void create_read_proc(size_t count, ByteVector &proc)
{
    uint8_t clr_a[]			= { 0x5E, 0x55, 0xE4 };
    uint8_t mov_c_a_dptr_a[]= { 0x4E, 0x55, 0x93 };
    uint8_t inc_dptr[]		= { 0x5E, 0x55, 0xA3 };

    proc.clear();
    for (size_t i = 0; i < count; i++)
    {
        vector_append(proc, clr_a, sizeof(clr_a));
        if (!((i + 1) % 64) || i == (count - 1))
            mov_c_a_dptr_a[0] |= 0x01;
        vector_append(proc, mov_c_a_dptr_a, sizeof(mov_c_a_dptr_a));
        mov_c_a_dptr_a[0] &= ~0x01;
        vector_append(proc, inc_dptr, sizeof(inc_dptr));
    }
}
Exemple #6
0
void
CryptoProxy::selfTest()
{
    // test HMAC MD 5
    ByteVector key;
    ByteVector data;
    ByteVector digest;
    //   case 1
    key.assign(16, 0x0b);
    data.copy((byte_t*)"Hi There", 8);
    const byte_t dig1[] = { 0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d };
    hmac(CryptoProxy::HMAC_MD5, data, key, digest);
    LOG_LODEBUG << "MD5 1: " << (memcmp(digest.c_ptr(), dig1, 16) == 0 ? "OK" : "FAILED");
    //   case 2
    key.copy((byte_t*)"Jefe", 4);
    data.copy((byte_t*)"what do ya want for nothing?", 28);
    const byte_t dig2[] = { 0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03, 0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38 };
    hmac(CryptoProxy::HMAC_MD5, data, key, digest);
    LOG_LODEBUG << "MD5 2: " << (memcmp(digest.c_ptr(), dig2, 16) == 0 ? "OK" : "FAILED");
    //   case 3
    key.assign(16, 0xaa);
    data.assign(50, 0xdd);
    const byte_t dig3[] = {0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88, 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6};
    hmac(CryptoProxy::HMAC_MD5, data, key, digest);
    LOG_LODEBUG << "MD5 3: " << (memcmp(digest.c_ptr(), dig3, 16) == 0 ? "OK" : "FAILED");

    // test AES CBC 128
    ByteVector plainText;
    ByteVector encryptedText;
    ByteVector decryptedText;
    //   case 1 - one block
    const byte_t key1[] = {0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b, 0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06};
    const byte_t iv1[] = {0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30, 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41};
    const byte_t cipher1[] = {0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8, 0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a};
    plainText.copy((byte_t*)"Single block msg", 16);
    encrypt(ByteVector(key1, 16), ByteVector(iv1, 16), plainText, encryptedText);
    LOG_LODEBUG << "AES 1: length " << (encryptedText.length() == 16 ? "OK" : "FAILED");
    LOG_LODEBUG << "AES 1: content " << (memcmp(encryptedText.c_ptr(), cipher1, 16) == 0 ? "OK" : "FAILED");
    decrypt(ByteVector(key1, 16), ByteVector(iv1, 16), encryptedText, decryptedText);
    LOG_LODEBUG << "AES 1: decrypt " << (memcmp(decryptedText.c_ptr(), plainText.c_ptr(), 16) == 0 ? "OK" : "FAILED");
    //   case 2 - two blocks
    const byte_t key2[] = {0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0, 0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a};
    const byte_t iv2[] = {0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58};
    const byte_t cipher2[] = {0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a, 0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a,
                              0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9, 0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1};
    plainText.clear();
    for (byte_t i = 0; i < 32; plainText += i++);
    encrypt(ByteVector(key2, 16), ByteVector(iv2, 16), plainText, encryptedText);
    LOG_LODEBUG << "AES 2: length " << (encryptedText.length() == 32 ? "OK" : "FAILED");
    LOG_LODEBUG << "AES 2: content " << (memcmp(encryptedText.c_ptr(), cipher2, 32) == 0 ? "OK" : "FAILED");
    decrypt(ByteVector(key2, 16), ByteVector(iv2, 16), encryptedText, decryptedText);
    LOG_LODEBUG << "AES 2: decrypt " << (memcmp(decryptedText.c_ptr(), plainText.c_ptr(), 32) == 0 ? "OK" : "FAILED");
    //   case 3 - three blocks
    const byte_t key3[] = {0x6c, 0x3e, 0xa0, 0x47, 0x76, 0x30, 0xce, 0x21, 0xa2, 0xce, 0x33, 0x4a, 0xa7, 0x46, 0xc2, 0xcd};
    const byte_t iv3[] = {0xc7, 0x82, 0xdc, 0x4c, 0x09, 0x8c, 0x66, 0xcb, 0xd9, 0xcd, 0x27, 0xd8, 0x25, 0x68, 0x2c, 0x81};
    const byte_t cipher3[] = {0xd0, 0xa0, 0x2b, 0x38, 0x36, 0x45, 0x17, 0x53, 0xd4, 0x93, 0x66, 0x5d, 0x33, 0xf0, 0xe8, 0x86,
                              0x2d, 0xea, 0x54, 0xcd, 0xb2, 0x93, 0xab, 0xc7, 0x50, 0x69, 0x39, 0x27, 0x67, 0x72, 0xf8, 0xd5,
                              0x02, 0x1c, 0x19, 0x21, 0x6b, 0xad, 0x52, 0x5c, 0x85, 0x79, 0x69, 0x5d, 0x83, 0xba, 0x26, 0x84};
    plainText.copy((byte_t*)"This is a 48-byte message (exactly 3 AES blocks)", 48);
    encrypt(ByteVector(key3, 16), ByteVector(iv3, 16), plainText, encryptedText);
    LOG_LODEBUG << "AES 3: length " << (encryptedText.length() == 48 ? "OK" : "FAILED");
    LOG_LODEBUG << "AES 3: content " << (memcmp(encryptedText.c_ptr(), cipher3, 48) == 0 ? "OK" : "FAILED");
    decrypt(ByteVector(key3, 16), ByteVector(iv3, 16), encryptedText, decryptedText);
    LOG_LODEBUG << "AES 3: decrypt " << (memcmp(decryptedText.c_ptr(), plainText.c_ptr(), 48) == 0 ? "OK" : "FAILED");
}
void SoftwareBreakpointManager::getOpcode(uint32_t type,
                                          ByteVector &opcode) const {
#if defined(OS_WIN32) && defined(ARCH_ARM)
  if (type == 4) {
    static const uint32_t WinARMBPType = 2;
    DS2LOG(Warning,
           "requesting a breakpoint of size %u on Windows ARM, "
           "adjusting to type %u",
           type, WinARMBPType);
    type = WinARMBPType;
  }
#endif

  opcode.clear();

  // TODO: We shouldn't have preprocessor checks for ARCH_ARM vs ARCH_ARM64
  // because we might be an ARM64 binary debugging an ARM inferior.
  switch (type) {
#if defined(ARCH_ARM)
  case 2: // udf #1
    opcode.push_back('\xde');
#if defined(OS_POSIX)
    opcode.push_back('\x01');
#elif defined(OS_WIN32)
    opcode.push_back('\xfe');
#endif
    break;
  case 3: // udf.w #0
    opcode.push_back('\xa0');
    opcode.push_back('\x00');
    opcode.push_back('\xf7');
    opcode.push_back('\xf0');
    break;
  case 4: // udf #16
    opcode.push_back('\xe7');
    opcode.push_back('\xf0');
    opcode.push_back('\x01');
    opcode.push_back('\xf0');
    break;
#elif defined(ARCH_ARM64)
  case 4:
    opcode.push_back('\xd4');
    opcode.push_back('\x20');
    opcode.push_back('\x20');
    opcode.push_back('\x00');
    break;
#endif
  default:
    DS2LOG(Error, "invalid breakpoint type %d", type);
    DS2BUG("invalid breakpoint type");
    break;
  }

#if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
#error "Target not supported."
#endif

#if defined(ENDIAN_LITTLE)
  std::reverse(opcode.begin(), opcode.end());
#endif
}