// -----------------------------------------------------------------------------
// CSdpOriginField::SetAddressL
// Sets address from the buffer
// -----------------------------------------------------------------------------
//
EXPORT_C void CSdpOriginField::SetAddressL(
    const TDesC8& aAddress,
    RStringF aNetType, 
    RStringF aAddressType )
    {
    __TEST_INVARIANT;
     
    __ASSERT_ALWAYS( SdpUtil::IsToken( aNetType.DesC() )  &&
                     SdpUtil::IsToken( aAddressType.DesC() ) &&
                     IsValidAddress( aAddress ) &&
                     TypeMatchesWithFormat( aAddress, 
                                            aAddressType.DesC(), iPool ),
                     User::Leave( KErrSdpCodecOriginField ) );

    iAddress = aAddress;
    iAddressType.Close();
    iAddressType = aAddressType.Copy();

    __TEST_INVARIANT;
    }
// -----------------------------------------------------------------------------
// CSdpOriginField::SetInetAddress
// Sets Internet Address
// -----------------------------------------------------------------------------
//
EXPORT_C void CSdpOriginField::SetInetAddress(
    const TInetAddr& aValue )
	{    
	__TEST_INVARIANT;
    
	if ( IsValidAddress( aValue ) )
        {                       
        TBuf<KMaxIPDesLength> buf;
        aValue.Output( buf );
        // Copy new address to safe
        iAddress.Copy( buf );
    
        // Copy network type and address type        
        SdpUtil::SetDefaultNetTypeAndAddrType( 
            iPool, aValue, iNetType, iAddressType );
        SetIPAddressType( aValue );
        }

    __TEST_INVARIANT;
	}
char * const MemoryManager::CoalesceWithNextBlock(char * const ptr)
{
	if (IsNextBlockFree(ptr) && IsValidAddress(GetNextBlock(ptr)))
	{
		//Remove next block from free blocks
		freeBlocks.remove((Node*)GetNextBlock(ptr));
		
		ForwardIteratationOverFreeBlocks();

		//Update header
		size_t newHeaderData = GetHeader(ptr) + GetHeader(GetNextBlock(ptr));
		SetHeader(ptr, newHeaderData);
		//Update footer
		SetFooter(ptr, newHeaderData);
		return ptr;
	}
	else
	{
		return ptr;
	}
}
// -----------------------------------------------------------------------------
// CSdpConnectionField::SetInetAddressL
// Sets address from TInetAddr
// -----------------------------------------------------------------------------
//
EXPORT_C void CSdpConnectionField::SetInetAddressL(
    const TInetAddr& aAddress,
    TInt aTTL,
    TUint aNumOfAddress )
	{
	__TEST_INVARIANT;

    if ( IsValidAddress( aAddress, aTTL, aNumOfAddress ) == KErrNone )
        {
        TBuf<KMaxAddressLength> addr16;
       	//If aAddress IPv4-Mapped IPv6, result of Output IPv4
         aAddress.Output( addr16 );

        HBufC8* tempBuf = HBufC8::NewL( addr16.Length() );
        tempBuf->Des().Copy( addr16 );

        SdpUtil::SetDefaultNetTypeAndAddrType(
            iPool, aAddress, iNetType, iAddressType );
        if(aAddress.Address() && aAddress.IsV4Mapped())
			{
			iAddressType.Close();
			iAddressType = iPool.StringF( SdpCodecStringConstants::EAddressTypeIP4,
                                      SdpCodecStringConstants::Table ).Copy();
			}
        // Set address
        delete iAddress;
        iAddress = tempBuf;
        // Set attributes for address
        iTTL = aTTL;
        iNumOfAddress = aNumOfAddress;
        }
    else
        {
        User::Leave( KErrSdpCodecConnectionField );
        }

	__TEST_INVARIANT;
	}
Example #5
0
const unsigned char* Analysis::TranslateAddress(duint addr)
{
    return IsValidAddress(addr) ? _data + (addr - _base) : nullptr;
}
Example #6
0
void ControlFlowAnalysis::BasicBlocks()
{
    for(auto i = _blockStarts.begin(); i != _blockStarts.end(); ++i)
    {
        uint start = *i;
        if(!IsValidAddress(start))
            continue;
        uint nextStart = _base + _size;
        auto next = std::next(i);
        if(next != _blockStarts.end())
            nextStart = *next;
        for(uint addr = start, prevaddr = 0; addr < _base + _size;)
        {
            prevaddr = addr;
            if(_cp.Disassemble(addr, TranslateAddress(addr), MAX_DISASM_BUFFER))
            {
                if(_cp.InGroup(CS_GRP_RET) || _cp.GetId() == X86_INS_INT3)
                {
                    insertBlock(BasicBlock(start, addr, 0, 0)); //leaf block
                    break;
                }
                else if(_cp.InGroup(CS_GRP_JUMP) || _cp.IsLoop())
                {
                    uint dest1 = GetReferenceOperand();
                    uint dest2 = _cp.GetId() != X86_INS_JMP ? addr + _cp.Size() : 0;
                    insertBlock(BasicBlock(start, addr, dest1, dest2));
                    insertParent(dest1, start);
                    insertParent(dest2, start);
                    break;
                }
                addr += _cp.Size();
            }
            else
                addr++;
            if(addr == nextStart)   //special case handling overlapping blocks
            {
                insertBlock(BasicBlock(start, prevaddr, 0, nextStart));
                insertParent(nextStart, start);
                break;
            }
        }
    }
    _blockStarts.clear();

#ifdef _WIN64
    int count = 0;
    EnumerateFunctionRuntimeEntries64([&](PRUNTIME_FUNCTION Function)
    {
        const uint funcAddr = _moduleBase + Function->BeginAddress;
        const uint funcEnd = _moduleBase + Function->EndAddress;

        // If within limits...
        if(funcAddr >= _base && funcAddr < _base + _size)
            _functionStarts.insert(funcAddr);
        count++;
        return true;
    });
    dprintf("%u functions from the exception directory...\n", count);
#endif // _WIN64

    dprintf("%u basic blocks, %u function starts detected...\n", _blocks.size(), _functionStarts.size());
}
// -----------------------------------------------------------------------------
// CSdpConnectionField::CopyAddressL
// Copies address after checking that it is valid
// -----------------------------------------------------------------------------
//
void CSdpConnectionField::CopyAddressL(
    const TDesC8& aAddress,
    RStringPool aPool )
    {
    RStringF addrTypeIP4 = aPool.StringF(
        SdpCodecStringConstants::EAddressTypeIP4,
        SdpCodecStringConstants::Table );
    RStringF addrTypeIP6 = aPool.StringF(
        SdpCodecStringConstants::EAddressType,
        SdpCodecStringConstants::Table );
    HBufC8* addr = NULL;

    if ( iAddressType == addrTypeIP4 || iAddressType == addrTypeIP6 )
        {
        User::LeaveIfError(
            IsValidAddress( iAddressType == addrTypeIP4, aAddress ) );

        addr = ParseAddressFieldL( iAddressType == addrTypeIP4, aAddress,
                               iTTL, iNumOfAddress );
  		//If address is IPv4-Mapped IPv6 , it is changed to IPv4
		TInetAddr inetaddr;
		TBuf<KMaxAddressLength> address;
		address.Copy(*addr);
		TInt err = inetaddr.Input(address);
        TBuf16 <KMaxAddressLength> output;
        inetaddr.Output(output);
		if(!err && 
            ( ( inetaddr.Address() && inetaddr.IsV4Mapped() ) || 
              ( inetaddr.IsWildAddr() && output.Match(KWildAddr) != KErrNotFound ) 
            ) )
			{//IPv4-Mapped IPv6 is changed to IPv4 address
			TBuf<KMaxIPDesLength> buf;
			inetaddr.Output( buf );
			// Copy new address to safe
			delete addr;
			addr = NULL;
			addr = HBufC8::NewL(buf.Length());
			addr->Des().Copy(buf);
			iAddressType.Close();
			iAddressType = 
				iPool.StringF(SdpCodecStringConstants::EAddressTypeIP4,
                               SdpCodecStringConstants::Table ).Copy();
			}
	
        }
    else
        {
        // Address not IP4 or IP6, must be then non-ws-string
        if ( SdpUtil::IsNonWhitespace( aAddress ) )
            {
            addr = aAddress.AllocL();
            }
        else
            {
            User::Leave( KErrSdpCodecConnectionField );
            }
        }

    delete iAddress;
    iAddress = addr;
    }
size_t MemoryManager::GetHeader(char * const ptr) const
{
	if (IsValidAddress(ptr - sizeof(size_t*)))
		return *(size_t*)(ptr - sizeof(size_t*));
}