Пример #1
0
void AuthenticationError::encode(Bytes& data) const
{
    appendUINT24(data, seqNum);
    appendUINT8(data, userNum);
    appendUINT8(data, errorReason);

    appendBytes(data, errorText);
}
Пример #2
0
void SessionKeyStatus::encode(Bytes& data) const
{
    appendUINT24(data, keyChangeSeqNum);
    appendUINT8(data, userNum);
    appendUINT8(data, keyWrapAlgorithm);
    appendUINT8(data, keyStatus);
    appendBytes(data, challengeData);
}
Пример #3
0
void Challenge::encode(Bytes& data) const
{
    appendUINT24(data, seqNum);
    appendUINT8(data, userNum);
    appendUINT8(data, hmacAlgorithm);
    appendUINT8(data, challengeReason);
    appendBytes(data, challengeData);
}
Пример #4
0
void Outstation::control(AppHeader::FunctionCode fn)
{
    initResponse( 1, 1, 0, 0);
    // append a copy of the control request (which happens to be the
    // remaining portion of the request)
    appendBytes( txFragment, session.rxFragment);

    transmit();

    if (fn == AppHeader::SELECT)
        stats.increment(TX_SELECT_RESP);
    else if (fn == AppHeader::OPERATE)
        stats.increment(TX_OPERATE_RESP);
    else
        assert(0);
}
Пример #5
0
void loadFile ( fudge_byte * * bytes, fudge_i32 * numbytes, const char * filename )
{
    FILE * file;
    fudge_byte buffer [ 1024 ];

    /* Load in the file in 1K blocks */
    if ( ! ( file = fopen ( filename, "rb" ) ) )
        fatalError ( "Failed to open input file" );
    *numbytes = 0;
    while ( ! feof ( file ) )
    {
        fudge_i32 bytesread = fread ( buffer, 1, sizeof ( buffer ), file );
        if ( bytesread )
            appendBytes ( bytes, numbytes, buffer, bytesread );
    }
    fclose ( file );
}
Пример #6
0
/*
 * initWithBytes:
 *
 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
 * The descriptor's length and capacity are set to the input buffer's size.
 */
bool IOBufferMemoryDescriptor::initWithBytes(const void * inBytes,
                                             vm_size_t    inLength,
                                             IODirection  inDirection,
                                             bool         inContiguous)
{
    if (!initWithPhysicalMask(kernel_task, inDirection | kIOMemoryUnshared
			      | (inContiguous ? kIOMemoryPhysicallyContiguous : 0),
			      inLength, inLength, (mach_vm_address_t)0))
        return false;

    // start out with no data
    setLength(0);

    if (!appendBytes(inBytes, inLength))
        return false;

    return true;
}
//==============================================================================
// IOHIDEvent::readBytes
//==============================================================================
IOByteCount IOHIDEvent::readBytes(void * bytes, IOByteCount withLength)
{
    IOHIDSystemQueueElement *   queueElement= NULL;

    queueElement    = (IOHIDSystemQueueElement *)bytes;

    queueElement->timeStamp         = *((uint64_t *)&_timeStamp);
    queueElement->creationTimeStamp = *((uint64_t *)&_creationTimeStamp);
    queueElement->options           = _options;
    queueElement->eventCount        = _eventCount;
    queueElement->senderID          = _senderID;
    queueElement->attributeLength   = 0;

    //bytes += sizeof(IOHIDSystemQueueElement);
    withLength -= sizeof(IOHIDSystemQueueElement);

    return appendBytes((UInt8 *)queueElement->payload, withLength);
}
Пример #8
0
static void appendTextMetadata(variableBuffer *udtaBuffer, char *str, char *atomID)
{
    int tmp;
    int length = strlen(str);
    tmp = 24 + length;
    tmp = SWAP32(tmp);
    appendBytes(udtaBuffer,&tmp,4);
    appendBytes(udtaBuffer,atomID,4);
    tmp = 16 + length;
    tmp = SWAP32(tmp);
    memcpy(atomID,"data",4);
    appendBytes(udtaBuffer,&tmp,4);
    appendBytes(udtaBuffer,atomID,4);
    tmp = 1;
    tmp = SWAP32(tmp);
    appendBytes(udtaBuffer,&tmp,4);
    tmp = 0;
    appendBytes(udtaBuffer,&tmp,4);
    appendBytes(udtaBuffer,str,length);
}
Пример #9
0
void SessionKeyChange::encode(Bytes& data) const
{
    appendUINT24(data, keyChangeSeqNum);
    appendUINT8(data, userNum);
    appendBytes(data, wrappedKeyData);
}
Пример #10
0
void Reply::encode(Bytes& data) const
{
    appendUINT24(data, seqNum);
    appendUINT8(data, userNum);
    appendBytes(data, hmacValue);
}
Пример #11
0
void CCData::appendData(CCData* data) {
    appendBytes(data->getBytes(), data->getSize());
}
Пример #12
0
static unsigned char *setupUdta(mp4Metadata_t *metadata, int bitrate, int mode, int modeQuality, int padding, SInt64 frames, int codecVersion, int *udtaSize)
{
    int tmp;
    short tmp2;
    char atomID[4];

    variableBuffer udtaBuffer;
    udtaBuffer.maxSize = DEFAULT_UDTA_SIZE;
    udtaBuffer.contentSize = 0;
    udtaBuffer.buffer = (unsigned char *)malloc(DEFAULT_UDTA_SIZE);

    /* udta atom */
    tmp = 0;
    memcpy(atomID,"udta",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);

    /* meta atom */
    tmp = 0;
    memcpy(atomID,"meta",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    appendBytes(&udtaBuffer,&tmp,4);

    /* hdlr atom */
    tmp = 0x22;
    tmp = SWAP32(tmp);
    memcpy(atomID,"hdlr",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 0;
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,&tmp,4);
    memcpy(atomID,"mdir",4);
    appendBytes(&udtaBuffer,atomID,4);
    memcpy(atomID,"appl",4);
    appendBytes(&udtaBuffer,atomID,4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,&tmp,4);
    tmp2 = 0;
    tmp2 = SWAP16(tmp2);
    appendBytes(&udtaBuffer,&tmp2,2);

    /* ilst atom */
    tmp = 0;
    memcpy(atomID,"ilst",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);

    /* encoder info */
    char attr[128];
    char str[256];
    long version = 0;
    Gestalt(gestaltQuickTime,&version);
    attr[0] = 0;
    if(mode > 3) strcpy_s(attr,128,"High Efficiency, ");
    switch(mode) {
    case kConfigCBR:
    case kConfigCBR_HE:
        sprintf_s(attr,128,"%sCBR %d kbps",attr,modeQuality);
        break;
    case kConfigABR:
    case kConfigABR_HE:
        sprintf_s(attr,128,"%sABR %d kbps",attr,modeQuality);
        break;
    case kConfigConstrainedVBR:
    case kConfigConstrainedVBR_HE:
        sprintf_s(attr,128,"%sConstrained VBR %d kbps",attr,modeQuality);
        break;
    case kConfigTrueVBR:
        sprintf_s(attr,128,"%sTrue VBR Quality %d",attr,modeQuality);
        break;
    }
    sprintf_s(str,256,"qtaacenc %d, QuickTime %d.%d.%d, %s",VERSION,(version>>24)&0xF,(version>>20)&0xF,(version>>16)&0xF,attr);
    tmp = 24 + strlen(str);
    tmp = SWAP32(tmp);
    atomID[0] = (char)0xa9;
    memcpy(atomID+1,"too",3);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 16 + strlen(str);
    tmp = SWAP32(tmp);
    memcpy(atomID,"data",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 1;
    tmp = SWAP32(tmp);
    appendBytes(&udtaBuffer,&tmp,4);
    tmp = 0;
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,str,strlen(str));

    /* gapless info */
    tmp = 0xBC;
    tmp = SWAP32(tmp);
    memcpy(atomID,"----",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 0x1C;
    tmp = SWAP32(tmp);
    memcpy(atomID,"mean",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 0;
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,"com.apple.iTunes",16);
    tmp = 0x14;
    tmp = SWAP32(tmp);
    memcpy(atomID,"name",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 0;
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,"iTunSMPB",8);
    tmp = 0x84;
    tmp = SWAP32(tmp);
    memcpy(atomID,"data",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 1;
    tmp = SWAP32(tmp);
    appendBytes(&udtaBuffer,&tmp,4);
    tmp = 0;
    appendBytes(&udtaBuffer,&tmp,4);

    appendBytes(&udtaBuffer," 00000000 00000840 ",19);
    char gaplessInfo[32];
    sprintf_s(gaplessInfo,32,"%08X %016llX",(unsigned int)padding,(unsigned long long)frames);
    appendBytes(&udtaBuffer,gaplessInfo,25);
    appendBytes(&udtaBuffer," 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000",72);

    /* bitrate info */
    tmp = 0x6f;
    tmp = SWAP32(tmp);
    memcpy(atomID,"----",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 0x1C;
    tmp = SWAP32(tmp);
    memcpy(atomID,"mean",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 0;
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,"com.apple.iTunes",16);
    tmp = 0x1B;
    tmp = SWAP32(tmp);
    memcpy(atomID,"name",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 0;
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,"Encoding Params",15);
    tmp = 0x30;
    tmp = SWAP32(tmp);
    memcpy(atomID,"data",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);
    tmp = 0;
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,&tmp,4);

    tmp = 1;
    tmp = SWAP32(tmp);
    appendBytes(&udtaBuffer,"vers",4);
    appendBytes(&udtaBuffer,&tmp,4);

    mode = (mode<4) ? mode : mode-4;
    tmp = SWAP32(mode);
    appendBytes(&udtaBuffer,"acbf",4);
    appendBytes(&udtaBuffer,&tmp,4);

    tmp = SWAP32(bitrate);
    appendBytes(&udtaBuffer,"brat",4);
    appendBytes(&udtaBuffer,&tmp,4);

    tmp = SWAP32(codecVersion);
    appendBytes(&udtaBuffer,"cdcv",4);
    appendBytes(&udtaBuffer,&tmp,4);

    /* title */
    if(metadata->title) {
        atomID[0] = (char)0xa9;
        memcpy(atomID+1,"nam",3);
        appendTextMetadata(&udtaBuffer,metadata->title,atomID);
    }
    /* artist */
    if(metadata->artist) {
        atomID[0] = (char)0xa9;
        memcpy(atomID+1,"ART",3);
        appendTextMetadata(&udtaBuffer,metadata->artist,atomID);
    }
    /* album */
    if(metadata->album) {
        atomID[0] = (char)0xa9;
        memcpy(atomID+1,"alb",3);
        appendTextMetadata(&udtaBuffer,metadata->album,atomID);
    }
    /* album artist */
    if(metadata->albumArtist) {
        memcpy(atomID,"aART",4);
        appendTextMetadata(&udtaBuffer,metadata->albumArtist,atomID);
    }
    /* composer */
    if(metadata->composer) {
        atomID[0] = (char)0xa9;
        memcpy(atomID+1,"wrt",3);
        appendTextMetadata(&udtaBuffer,metadata->composer,atomID);
    }
    /* group */
    if(metadata->group) {
        atomID[0] = (char)0xa9;
        memcpy(atomID+1,"grp",3);
        appendTextMetadata(&udtaBuffer,metadata->group,atomID);
    }
    /* genre */
    if(metadata->genre) {
        atomID[0] = (char)0xa9;
        memcpy(atomID+1,"gen",3);
        appendTextMetadata(&udtaBuffer,metadata->genre,atomID);
    }
    /* date */
    if(metadata->date) {
        atomID[0] = (char)0xa9;
        memcpy(atomID+1,"day",3);
        appendTextMetadata(&udtaBuffer,metadata->date,atomID);
    }
    /* comment */
    if(metadata->comment) {
        atomID[0] = (char)0xa9;
        memcpy(atomID+1,"cmt",3);
        appendTextMetadata(&udtaBuffer,metadata->comment,atomID);
    }
    /* track */
    if(metadata->track > 0 || metadata->totalTrack > 0) {
        tmp = 0x20;
        tmp = SWAP32(tmp);
        memcpy(atomID,"trkn",4);
        appendBytes(&udtaBuffer,&tmp,4);
        appendBytes(&udtaBuffer,atomID,4);
        tmp = 0x18;
        tmp = SWAP32(tmp);
        memcpy(atomID,"data",4);
        appendBytes(&udtaBuffer,&tmp,4);
        appendBytes(&udtaBuffer,atomID,4);
        tmp = 0;
        appendBytes(&udtaBuffer,&tmp,4);
        appendBytes(&udtaBuffer,&tmp,4);
        tmp2 = 0;
        appendBytes(&udtaBuffer,&tmp2,2);
        if(metadata->track > 0) {
            tmp2 = metadata->track;
            tmp2 = SWAP16(tmp2);
        }
        appendBytes(&udtaBuffer,&tmp2,2);
        tmp2 = 0;
        if(metadata->totalTrack > 0) {
            tmp2 = metadata->totalTrack;
            tmp2 = SWAP16(tmp2);
        }
        appendBytes(&udtaBuffer,&tmp2,2);
        tmp2 = 0;
        appendBytes(&udtaBuffer,&tmp2,2);
    }
    /* disc */
    if(metadata->disc > 0 || metadata->totalDisc > 0) {
        tmp = 0x20;
        tmp = SWAP32(tmp);
        memcpy(atomID,"disk",4);
        appendBytes(&udtaBuffer,&tmp,4);
        appendBytes(&udtaBuffer,atomID,4);
        tmp = 0x18;
        tmp = SWAP32(tmp);
        memcpy(atomID,"data",4);
        appendBytes(&udtaBuffer,&tmp,4);
        appendBytes(&udtaBuffer,atomID,4);
        tmp = 0;
        appendBytes(&udtaBuffer,&tmp,4);
        appendBytes(&udtaBuffer,&tmp,4);
        tmp2 = 0;
        appendBytes(&udtaBuffer,&tmp2,2);
        if(metadata->disc > 0) {
            tmp2 = metadata->disc;
            tmp2 = SWAP16(tmp2);
        }
        appendBytes(&udtaBuffer,&tmp2,2);
        tmp2 = 0;
        if(metadata->totalDisc > 0) {
            tmp2 = metadata->totalDisc;
            tmp2 = SWAP16(tmp2);
        }
        appendBytes(&udtaBuffer,&tmp2,2);
        tmp2 = 0;
        appendBytes(&udtaBuffer,&tmp2,2);
    }

    /* compilation */
    if(metadata->compilation) {
        tmp = 0x19;
        tmp = SWAP32(tmp);
        memcpy(atomID,"cpil",4);
        appendBytes(&udtaBuffer,&tmp,4);
        appendBytes(&udtaBuffer,atomID,4);
        tmp = 0x11;
        tmp = SWAP32(tmp);
        memcpy(atomID,"data",4);
        appendBytes(&udtaBuffer,&tmp,4);
        appendBytes(&udtaBuffer,atomID,4);
        tmp = 0x15;
        tmp = SWAP32(tmp);
        appendBytes(&udtaBuffer,&tmp,4);
        tmp = 0;
        appendBytes(&udtaBuffer,&tmp,4);
        char tmp3 = 1;
        appendBytes(&udtaBuffer,&tmp3,1);
    }

    /* update length of ilst atom */
    tmp = SWAP32(udtaBuffer.contentSize-54);
    memcpy(udtaBuffer.buffer+54,&tmp,4);

    /* padding */
    memset(udtaBuffer.buffer+udtaBuffer.contentSize,0,udtaBuffer.maxSize-udtaBuffer.contentSize);

    tmp = SWAP32(udtaBuffer.maxSize-udtaBuffer.contentSize);
    memcpy(atomID,"free",4);
    appendBytes(&udtaBuffer,&tmp,4);
    appendBytes(&udtaBuffer,atomID,4);

    /* update length of udta atom */
    tmp = SWAP32(udtaBuffer.maxSize);
    memcpy(udtaBuffer.buffer,&tmp,4);

    /* update length of meta atom */
    tmp = SWAP32(udtaBuffer.maxSize-8);
    memcpy(udtaBuffer.buffer+8,&tmp,4);

    *udtaSize = udtaBuffer.maxSize;

    return udtaBuffer.buffer;
}