Beispiel #1
0
/*!
 ************************************************************************
 * \brief
 *   Get an array of (uint16|uint32|rational).
 *
 ************************************************************************
 */
static void getIntArray (Tiff * t, uint32 offset, TiffType type, uint32 a[], int n)
{
    int    i;
    uint8  *mp = t->mp;                           // save memory pointer

    t->mp = t->fileInMemory + offset;
    switch (type)
    {
    case T_SHORT:
        for (i=0; i < n; ++i)
        {
            a[i] = getU16( t);
        }
        break;
    case T_LONG:
        for (i=0; i < n; ++i)
        {
            a[i] = getU32( t);
        }
        break;
    case T_RATIONAL:
        for (i=0; i < 2*n; ++i)
        {
            a[i] = getU32( t);
        }
        break;
    default:
        assert( type == T_SHORT || type == T_LONG || type == T_RATIONAL);
    }
    t->mp = mp;                           // restore memory pointer
}
Beispiel #2
0
/**
 * @brief Get unsigned rational data from raw exif data
 *          This is internal function and is not exposed to client
 * @param [in] offset Offset to entry in bytes inside raw exif data
 * @return Unsigned rational data
 *
 * "rational" means a fractional value, it contains 2 signed/unsigned long integer value,
 *  and the first represents the numerator, the second, the denominator.
 */
u_rational_t ExifReader::getURational(const size_t offset) const
{
    u_rational_t result;
    uint32_t numerator = getU32( offset );
    uint32_t denominator = getU32( offset + 4 );

    return std::make_pair( numerator, denominator );

}
Beispiel #3
0
static void dumpRef( const uint_8 *input, uint length )
{
    const uint_8    *p;
    uint_8          op_code;
    uint_32         tmp;
    int_32          itmp;
    uint_32         unit_length;
    const uint_8    *unit_base;

    p = input;

    while( p - input < length ) {
        unit_length = getU32( (uint_32 *)p );
        p += sizeof( uint_32 );
        unit_base = p;
        printf( "total_length: %08lx\n", getU32( (uint_32 *)p ) );

        while( p - unit_base < unit_length ) {
            op_code = *p++;
            if( op_code < REF_CODE_BASE ) {
                printf( "%s", getReferenceOp( op_code ) );
                switch( op_code ) {
                case REF_BEGIN_SCOPE:
                    printf( " %08lx\n", getU32( (uint_32 *)p ) );
                    p += sizeof( uint_32 );
                    break;
                case REF_END_SCOPE:
                case REF_COPY:
                    printf( "\n" );
                    break;
                case REF_SET_FILE:
                case REF_SET_LINE:
                case REF_SET_COLUMN:
                    p = DecodeULEB128( p, &tmp );
                    printf( " %lu\n", tmp );
                    break;
                case REF_ADD_LINE:
                case REF_ADD_COLUMN:
                    p = DecodeLEB128( p, &itmp );
                    printf( " %ld\n", itmp );
                    break;
                }
            } else {
                op_code -= REF_CODE_BASE;
                printf( "REF line += %d, column += %d, %08lx\n",
                    op_code / REF_COLUMN_RANGE, op_code % REF_COLUMN_RANGE,
                    getU32( (uint_32 *)p )
                );
                p += sizeof( uint_32 );
            }
        }
    }
}
Beispiel #4
0
/**
 * @brief Get string information from raw exif data
 *          This is internal function and is not exposed to client
 * @param [in] offset Offset to entry in bytes inside raw exif data
 * @return string value
 */
std::string ExifReader::getString(const size_t offset) const
{
    size_t size = getU32( offset + 4 );
    size_t dataOffset = 8; // position of data in the field
    if( size > maxDataSize )
    {
        dataOffset = getU32( offset + 8 );
    }
    std::vector<uint8_t>::const_iterator it = m_data.begin() + dataOffset;
    std::string result( it, it + size ); //copy vector content into result

    return result;
}
Beispiel #5
0
static const uint_8 *dumpSegAddr( const uint_8 *input, uint_8 addrsize, uint_8 segsize )
{
    const uint_8    *p;
    uint_32         addr;
    uint_32         seg;

    p = input;

    switch( addrsize ) {
    case 4:
        addr = getU32( (uint_32 *)p );
        p += sizeof( uint_32 );
        break;
    case 2:
        addr = getU16( (uint_16 *)p );
        p += sizeof( uint_16 );
        break;
    default:
        printf( "Unknown address size\n" );
        addr = 0;
        p += addrsize;
        break;
    }
    switch( segsize ) {
    case 4:
        seg = getU32( (uint_32 *)p );
        p += sizeof( uint_32 );
        printf( "%08lx:", seg );
        break;
    case 2:
        seg = getU16( (uint_16 *)p );
        p += sizeof( uint_16 );
        printf( "%04lx:", seg );
        break;
    case 0:
        break;
    default:
        printf( "Unknown address size\n" );
        p += addrsize;
        break;
    }
    switch( addrsize ) {
    case 4:
        printf( "%08lx", addr );
        break;
    case 2:
        printf( "%04lx", addr );
        break;
    }
    return( p );
}
Beispiel #6
0
/*
IndexRow:
		 keySize  |1 byte
		 key	    |
		 page	    |4 byte
*/
int IndexRow::parse(PIndexRow& row,char* pageBuffer,int& offset)
{
	uint8_t keySize;
	char* pKey;
	assert(pageBuffer);
	//////////KeySize
	keySize=*(uint8_t*)(pageBuffer+offset);
	offset+=1;

	assert(keySize>0 && keySize<=MAX_KEY_SIZE);
	if(keySize==0){
		return PTE_KEYSIZE_ZERO;
	}
	else if(keySize > MAX_KEY_SIZE){
		return PTE_KEYSIZE_MAX;
	}
	else{
		pKey=(char*)malloc(keySize);
		if(pKey==NULL){
			return PTE_MEMORY;
		}
		else{
			PageNo pageNo;
			memcpy(pKey,pageBuffer+offset,keySize);
			if(row==NULL)
				row=new IndexRow();
			row->set(pKey,keySize);

			offset+=keySize;
			pageNo=getU32(pageBuffer,offset);
			row->pageNo=pageNo;
		}
	}
	return PFE_SUCESS;
}
float getF32(void){
	unsigned int tmp1;

	tmp1 = getU32();
	
	return *((float*)&tmp1);
}
Beispiel #8
0
/**
 * @brief Get resolution information from raw exif data
 *          This is internal function and is not exposed to client
 * @param [in] offset Offset to entry in bytes inside raw exif data
 * @return resolution value
 */
std::vector<u_rational_t> ExifReader::getResolution(const size_t offset) const
{
    std::vector<u_rational_t> result;
    uint32_t rationalOffset = getU32( offset + 8 );
    result.push_back( getURational( rationalOffset ) );

    return result;
}
void StandardInMessage::doChecksum()
{
	auto givenChecksum = getU32();
	auto size = getRemainingSize();

	if(givenChecksum != crypto::adler32(peekRawChunckAs<uint8_t>(size), size))
		throw PacketException();
}
Beispiel #10
0
/**
 * @brief Get YCbCr Coefficients information from raw exif data
 *          This is internal function and is not exposed to client
 * @param [in] offset Offset to entry in bytes inside raw exif data
 * @return vector with YCbCr coefficients values
 *
 */
std::vector<u_rational_t> ExifReader::getYCbCrCoeffs(const size_t offset) const
{
    std::vector<u_rational_t> result;
    uint32_t rationalOffset = getU32( offset + 8 );
    for( size_t i = 0; i < ycbcrCoeffs; i++ )
    {
        result.push_back( getURational( rationalOffset ) );
        rationalOffset += 8;
    }
    return result;
}
Beispiel #11
0
/**
 * @brief Get Primary Chromaticies information from raw exif data
 *          This is internal function and is not exposed to client
 * @param [in] offset Offset to entry in bytes inside raw exif data
 * @return vector with primary chromaticies values
 *
 */
std::vector<u_rational_t> ExifReader::getPrimaryChromaticies(const size_t offset) const
{
    std::vector<u_rational_t> result;
    uint32_t rationalOffset = getU32( offset + 8 );
    for( size_t i = 0; i < primaryChromaticiesComponents; i++ )
    {
        result.push_back( getURational( rationalOffset ) );
        rationalOffset += 8;
    }
    return result;
}
Beispiel #12
0
/**
 * @brief Get Reference Black&White point information from raw exif data
 *          This is internal function and is not exposed to client
 * @param [in] offset Offset to entry in bytes inside raw exif data
 * @return vector with reference BW points
 *
 * In case of YCbCr format, first 2 show black/white of Y, next 2 are Cb,
 * last 2 are Cr. In case of RGB format, first 2 show black/white of R,
 * next 2 are G, last 2 are B.
 *
 */
std::vector<u_rational_t> ExifReader::getRefBW(const size_t offset) const
{
    const size_t rationalFieldSize = 8;
    std::vector<u_rational_t> result;
    uint32_t rationalOffset = getU32( offset + rationalFieldSize );
    for( size_t i = 0; i < refBWComponents; i++ )
    {
        result.push_back( getURational( rationalOffset ) );
        rationalOffset += rationalFieldSize;
    }
    return result;
}
Beispiel #13
0
/*!
 *****************************************************************************
 * \brief
 *    Read the ImageFileHeader.
 *
 *****************************************************************************
*/
static int readImageFileHeader (Tiff * t)
{
    t->ifh.byteOrder = (uint16) getU16( t);
    t->ifh.arbitraryNumber = (uint16) getU16( t);
    t->ifh.offset = getU32( t);
    if (t->ifh.arbitraryNumber != 42)
    {
        fprintf( stderr, "ImageFileHeader.arbitrary != 42\n");
        return 1;
    }
    t->mp = t->fileInMemory + t->ifh.offset;
    return 0;
}
Beispiel #14
0
	uint32_t getExtLen() const
	{
		return getU32(4);
	}
Beispiel #15
0
static void command_process(int fd, char* command, size_t commandLength) {
    int err = 0; /* syntax or other error, true or false */
    int emptyLine = 0;
    char *token;
    int i;
    uint32_t ui[3];
    uint8_t comm_node = 0xFF; /* undefined */

    char resp[STRING_BUFFER_SIZE];
    int respLen = 0;
    respErrorCode_t respErrorCode = respErrorNone;

    uint32_t sequence = 0;


    /* parse mandatory token '"["<sequence>"]"' */
    if((token = getTok(command, spaceDelim, &err)) == NULL) {
        /* If empty line, respond with empty line. */
        emptyLine = 1;
    }
    if(err == 0) {
        if(token[0] != '[' || token[strlen(token)-1] != ']') {
            err = 1;
            if(token[0] == '#') {
                /* If comment, respond with empty line. */
                emptyLine = 1;
            }
        }
        else {
            token[strlen(token)-1] = '\0';
            sequence = getU32(token+1, 0, 0xFFFFFFFF, &err);
        }
    }


    /* parse optional tokens '[[<net>] <node>]', both numerical. Then follows
     *  mandatory token <command>, which is not numerical. */
    if(err == 0) {
        for(i=0; i<3; i++) {
            if((token = getTok(NULL, spaceDelim, &err)) == NULL) {
                break;
            }
            if(isdigit(token[0]) == 0) {
                break;
            }
            ui[i] = getU32(token, 0, 0xFFFFFFFF, &err);
        }
    }
    if(err == 0) {
        switch(i) {
        case 0: /* only <command> (pointed by token) */
            comm_node = comm_node_default; /* may be undefined */
            break;
        case 1: /* <node> and <command> tokens */
            if(ui[0] < 0 || ui[0] > 127) {
                err = 1;
                respErrorCode = respErrorUnsupportedNode;
            }
            else {
                comm_node = (uint8_t) ui[0];
            }
            break;
        case 2: /* <net>, <node> and <command> tokens */
            if(ui[0] < 1 || ui[0] > 1) {
                err = 1;
                respErrorCode = respErrorUnsupportedNet;
            }
            else if(ui[1] < 0 || ui[1] > 127) {
                err = 1;
                respErrorCode = respErrorUnsupportedNode;
            }
            else {
                comm_net = (uint16_t) ui[0];
                comm_node = (uint8_t) ui[1];
            }
            break;
        case 3: /* <command> token contains digit */
            err = 1;
            break;
        }
    }

    /* Execute command */
    if(err == 0) {

        /* Upload SDO command - 'r[ead] <index> <subindex> <datatype>' */
        if(strcmp(token, "r") == 0 || strcmp(token, "read") == 0) {
            uint16_t idx;
            uint8_t subidx;
            const dataType_t *datatype; /* optional token */
            int errTokDt = 0;
            int errDt = 0;
            uint32_t SDOabortCode = 1;

            uint8_t dataRx[CO_COMMAND_SDO_BUFFER_SIZE]; /* SDO receive buffer */
            uint32_t dataRxLen;  /* Length of received data */

            token = getTok(NULL, spaceDelim, &err);
            idx = (uint16_t)getU32(token, 0, 0xFFFF, &err);

            token = getTok(NULL, spaceDelim, &err);
            subidx = (uint8_t)getU32(token, 0, 0xFF, &err);

            token = getTok(NULL, spaceDelim, &errTokDt);
            datatype = getDataType(token, &errDt);

            /* Datatype must be correct, if present. */
            if(errTokDt == 0 && errDt != 0) {
                err = 1;
            }

            lastTok(NULL, spaceDelim, &err);

            if(err == 0 && (comm_node < 1 || comm_node > 127)) {
                err = 1;
                if(comm_node == 0xFF) {
                    respErrorCode = respErrorNoDefaultNodeSet;
                } else {
                    respErrorCode = respErrorUnsupportedNode;
                }
            }

            /* Make CANopen SDO transfer */
            if(err == 0) {
                err = sdoClientUpload(
                        CO->SDOclient,
                        comm_node,
                        idx,
                        subidx,
                        dataRx,
                        sizeof(dataRx),
                        &dataRxLen,
                        &SDOabortCode,
                        SDOtimeoutTime,
                        blockTransferEnable);

                if(err != 0){
                    respErrorCode = respErrorInternalState;
                }
            }

            /* output result */
            if(err == 0){
                if(SDOabortCode == 0) {
                    respLen = sprintf(resp, "[%d] ", sequence);

                    if(datatype == NULL || (datatype->length != 0 && datatype->length != dataRxLen)) {
                        respLen += dtpHex(resp+respLen, sizeof(resp)-respLen, (char*)dataRx, dataRxLen);
                    }
                    else {
                        respLen += datatype->dataTypePrint(
                                resp+respLen, sizeof(resp)-respLen, (char*)dataRx, dataRxLen);
                    }
                }
                else{
                    respLen = sprintf(resp, "[%d] ERROR: 0x%08X", sequence, SDOabortCode);
                }
            }
        }

        /* Download SDO command - w[rite] <index> <subindex> <datatype> <value> */
        else if(strcmp(token, "w") == 0 || strcmp(token, "write") == 0) {
            uint16_t idx;
            uint8_t subidx;
            const dataType_t *datatype;
            uint32_t SDOabortCode = 1;

            uint8_t dataTx[CO_COMMAND_SDO_BUFFER_SIZE]; /* SDO transmit buffer */
            uint32_t dataTxLen = 0;  /* Length of data to transmit. */

            token = getTok(NULL, spaceDelim, &err);
            idx = (uint16_t)getU32(token, 0, 0xFFFF, &err);

            token = getTok(NULL, spaceDelim, &err);
            subidx = (uint8_t)getU32(token, 0, 0xFF, &err);

            token = getTok(NULL, spaceDelim, &err);
            datatype = getDataType(token, &err);

            if(err == 0) {
                /* take whole string or single token, depending on datatype. Comment may follow. */
                token = getTok(NULL, (datatype->length == 0) ? "\n\r\f" : spaceDelim, &err);
            }

            if(err == 0) {
                dataTxLen = datatype->dataTypeScan((char*)dataTx, sizeof(dataTx), token);

                /* Length must match and must not be zero. */
                if((datatype->length != 0 && datatype->length != dataTxLen) || dataTxLen == 0) {
                    err = 1;
                }
            }

            lastTok(NULL, spaceDelim, &err);

            if(err == 0 && (comm_node < 1 || comm_node > 127)) {
                err = 1;
                if(comm_node == 0xFF) {
                    respErrorCode = respErrorNoDefaultNodeSet;
                } else {
                    respErrorCode = respErrorUnsupportedNode;
                }
            }

            /* Make CANopen SDO transfer */
            if(err == 0) {
                err = sdoClientDownload(
                        CO->SDOclient,
                        comm_node,
                        idx,
                        subidx,
                        dataTx,
                        dataTxLen,
                        &SDOabortCode,
                        SDOtimeoutTime,
                        blockTransferEnable);

                if(err != 0){
                    respErrorCode = respErrorInternalState;
                }
            }

            /* output result */
            if(err == 0){
                if(SDOabortCode == 0) {
                    respLen = sprintf(resp, "[%d] OK", sequence);
                }
                else{
                    respLen = sprintf(resp, "[%d] ERROR: 0x%08X", sequence, SDOabortCode);
                }
            }
        }

        /* NMT start node */
        else if(strcmp(token, "start") == 0) {
            lastTok(NULL, spaceDelim, &err);
            if(err == 0 && comm_node > 127) {
                err = 1;
                respErrorCode = respErrorNoDefaultNodeSet;
            }
            if(err == 0) {
                err = CO_sendNMTcommand(CO, CO_NMT_ENTER_OPERATIONAL, comm_node) ? 1:0;
                if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence);
            }
        }

        /* NMT stop node */
        else if(strcmp(token, "stop") == 0) {
            lastTok(NULL, spaceDelim, &err);
            if(err == 0 && comm_node > 127) {
                err = 1;
                respErrorCode = respErrorNoDefaultNodeSet;
            }
            if(err == 0) {
                err = CO_sendNMTcommand(CO, CO_NMT_ENTER_STOPPED, comm_node) ? 1:0;
                if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence);
            }
        }

        /* NMT Set node to pre-operational */
        else if(strcmp(token, "preop") == 0 || strcmp(token, "preoperational") == 0) {
            lastTok(NULL, spaceDelim, &err);
            if(err == 0 && comm_node > 127) {
                err = 1;
                respErrorCode = respErrorNoDefaultNodeSet;
            }
            if(err == 0) {
                err = CO_sendNMTcommand(CO, CO_NMT_ENTER_PRE_OPERATIONAL, comm_node) ? 1:0;
                if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence);
            }
        }

        /* NMT reset (node or communication) */
        else if(strcmp(token, "reset") == 0) {

            token = getTok(NULL, spaceDelim, &err);
            if(err == 0 && comm_node > 127) {
                err = 1;
                respErrorCode = respErrorNoDefaultNodeSet;
            }
            if(err == 0) {
                if(strcmp(token, "node") == 0) {
                    lastTok(NULL, spaceDelim, &err);
                    if(err == 0) {
                        err = CO_sendNMTcommand(CO, CO_NMT_RESET_NODE, comm_node) ? 1:0;
                        if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence);
                    }
                }
                else if(strcmp(token, "comm") == 0 || strcmp(token, "communication") == 0) {
                    lastTok(NULL, spaceDelim, &err);
                    if(err == 0) {
                        err = CO_sendNMTcommand(CO, CO_NMT_RESET_COMMUNICATION, comm_node) ? 1:0;
                        if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence);
                    }
                }

                else {
                    err = 1;
                }
            }
        }

        /* set command - multiple settings */
        else if(strcmp(token, "set") == 0) {

            token = getTok(NULL, spaceDelim, &err);
            if(err == 0) {
                /* sdo_timeout <value> */
                if(strcmp(token, "sdo_timeout") == 0) {
                    uint16_t tmout;

                    token = getTok(NULL, spaceDelim, &err);
                    tmout = (uint16_t)getU32(token, 0, 10000, &err);

                    lastTok(NULL, spaceDelim, &err);

                    /* Write to variable */
                    if(err == 0) {
                        SDOtimeoutTime = tmout;
                        respLen = sprintf(resp, "[%d] OK", sequence);
                    }
                }

                /* sdo_block <value> */
                else if(strcmp(token, "sdo_block") == 0) {
                    uint8_t blk;

                    token = getTok(NULL, spaceDelim, &err);
                    blk = (uint8_t)getU32(token, 0, 1, &err);

                    lastTok(NULL, spaceDelim, &err);

                    /* Write to variable */
                    if(err == 0) {
                        blockTransferEnable = blk;
                        respLen = sprintf(resp, "[%d] OK", sequence);
                    }
                }

                /* node <value> */
                else if(strcmp(token, "node") == 0) {
                    uint16_t node;

                    token = getTok(NULL, spaceDelim, &err);
                    node = (uint16_t)getU32(token, 1, 127, &err);

                    lastTok(NULL, spaceDelim, &err);

                    /* Write to variable */
                    if(err == 0) {
                        comm_node_default = node;
                        respLen = sprintf(resp, "[%d] OK", sequence);
                    }
                }

                /* Unknown command */
                else {
                    err = 1;
                }
            }
        }

        /* Unknown command */
        else {
            respErrorCode = respErrorReqNotSupported;
            err = 1;
        }
    }


    /* Generate error response (or leave empty line response) */
    if(err != 0 && emptyLine == 0) {
        if(respErrorCode == respErrorNone) {
            respErrorCode = respErrorSyntax;
        }
        respLen = sprintf(resp, "[%d] ERROR: %d", sequence, respErrorCode);
    }


    /* Terminate string and send response */
    resp[respLen++] = '\r';
    resp[respLen++] = '\n';
    resp[respLen++] = '\0';

    if(write(fd, resp, respLen) != respLen) {
        CO_error(0x15200000L);
    }
}
Beispiel #16
0
// message serialization
void LLCategory::packMessage(LLMessageSystem* msg) const
{
	U32 data = getU32();
	msg->addU32Fast(_PREHASH_Category, data);
}
Beispiel #17
0
bool InputMessage::readChecksum()
{
    uint32 receivedCheck = getU32();
    uint32 checksum = stdext::adler32(m_buffer + m_readPos, getUnreadSize());
    return receivedCheck == checksum;
}
Beispiel #18
0
double InputMessage::getDouble()
{
    uint8 precision = getU8();
    int32 v = getU32() - INT_MAX;
    return (v / std::pow((float)10, precision));
}
Beispiel #19
0
static void dumpInfo( const uint_8 *input, uint length ) {

    const uint_8 *p;
    uint_32     abbrev_code;
    uint_32     abbrev_offset;
    uint_8 *    abbrev;
    uint_32     tag;
    uint_32     attr;
    uint_32     form;
    uint_32     len;
    uint_32     tmp;
    int_32      stmp;
    uint_32     unit_length;
    int         address_size;
    const uint_8 *unit_base;

    p = input;
    while( p - input < length ) {
        unit_length = getU32( (uint_32 *)p );
        unit_base = p + sizeof( uint_32 );
        address_size = *(p + 10);
        abbrev_offset = getU32( (uint_32 *)(p + 6) );
        printf( "Length: %08lx\nVersion: %04x\nAbbrev: %08lx\nAddress Size %02x\n",
            unit_length, getU16( (uint_16 *)(p + 4) ), abbrev_offset, address_size );
        p += 11;
        while( p - unit_base < unit_length ) {
            printf( "offset %08x: ", p - input );
            p = DecodeULEB128( p, &abbrev_code );
            printf( "Code: %08lx\n", abbrev_code );
            if( abbrev_code == 0 )
                continue;
            abbrev = findAbbrev( abbrev_code, abbrev_offset );
            if( abbrev == NULL ) {
                printf( "can't find abbreviation %08lx\n", abbrev_code );
                break;
            }
            if( p >= input + length )
                break;
            abbrev = DecodeULEB128( abbrev, &tag );
            printf( "\t%s\n", getTAG( tag ) );
            abbrev++;
            for( ;; ) {
                abbrev = DecodeULEB128( abbrev, &attr );
                abbrev = DecodeULEB128( abbrev, &form );
                if( attr == 0 )
                    break;
                printf( "\t%-20s", getAT( attr ) );
    decode_form:
                switch( form ) {
                case DW_FORM_addr:
                    switch( address_size ) {
                    case 4:
                        tmp = getU32( (uint_32 *)p );
                        p += sizeof( uint_32 );
                        printf( "\t%08lx\n", tmp );
                        break;
                    case 2:
                        tmp = getU16( (uint_16 *)p );
                        p += sizeof( uint_16 );
                        printf( "\t%04lx\n", tmp );
                        break;
                    default:
                        printf( "Unknown address size\n" );
                        p += address_size;
                        break;
                    }
                    break;
                case DW_FORM_block:
                    p = DecodeULEB128( p, &len );
                    printf( "\n" );
                    dumpHex( p, len, 0 );
                    p += len;
                    break;
                case DW_FORM_block1:
                    len = *p++;
                    printf( "\n" );
                    dumpHex( p, len, 0 );
                    p += len;
                    break;
                case DW_FORM_block2:
                    len = getU16( (uint_16 *)p );
                    p += sizeof( uint_16 );
                    printf( "\n" );
                    dumpHex( p, len, 0 );
                    p += len;
                    break;
                case DW_FORM_block4:
                    len = getU32( (uint_32 *)p );
                    p += sizeof( uint_32 );
                    printf( "\n" );
                    dumpHex( p, len, 0 );
                    p += len;
                    break;
                case DW_FORM_data1:
                case DW_FORM_ref1:
                    printf( "\t%02x\n", *p++ );
                    break;
                case DW_FORM_data2:
                case DW_FORM_ref2:
                    printf( "\t%04x\n", getU16( (uint_16 *)p ) );
                    p += sizeof( uint_16 );
                    break;
                case DW_FORM_data4:
                case DW_FORM_ref4:
                    printf( "\t%08lx\n", getU32( (uint_32 *)p ) );
                    p += sizeof( uint_32 );
                    break;
                case DW_FORM_flag:
                    printf( "\t%s\n", *p++ ? "True" : "False" );
                    break;
                case DW_FORM_indirect:
                    p = DecodeULEB128( p, &form );
                    printf( "\t(%s)", getFORM( form ) );
                    goto decode_form;
                case DW_FORM_sdata:
                    p = DecodeLEB128( p, &stmp );
                    printf( "\t%08lx\n", stmp );
                    break;
                case DW_FORM_string:
                    printf( "\t\"%s\"\n", p );
                    p += strlen( (const char *)p ) + 1;
                    break;
                case DW_FORM_strp:  /* 4 byte index into .debug_str */
                    printf_debug_str( getU32( (uint_32 *)p ) );
                    p += 4;
                    break;
                case DW_FORM_udata:
                case DW_FORM_ref_udata:
                    p = DecodeULEB128( p, &tmp );
                    printf( "\t%08lx\n", tmp );
                    break;
                case DW_FORM_ref_addr:  //KLUDGE should really check addr_size
                    printf( "\t%08lx\n", getU32( (uint_32 *)p ) );
                    p += sizeof(uint_32);
                    break;
                default:
                    printf( "unknown form!\n" );
                    return;
                }
            }
        }
    }
}
Beispiel #20
0
// Respond to an Invoke button press
static void onInvokeBtn(HWND win) {
	int idx = ListBox_GetCurSel(GetDlgItem(win, IDC_FUNCTION_LST));
	int id;
	int i;
	char str[256];
	char path[MAX_PATH];
	SSCE_S16 s16, s16_1, s16_2, s16_3;
	SSCE_S32 s32, s32_1, s32_2, s32_3, s32_4;
	SSCE_CHAR word[SSCE_MAX_WORD_SZ];
	SSCE_CHAR otherWord[SSCE_MAX_WORD_SZ];
	SSCE_CHAR *bfr;
	SSCE_CHAR *p;
	const char *fmt, *lang;
	SSCE_S16 scores[16];

	if (LB_ERR == idx) {
		return;
	}

	id = (int)ListBox_GetItemData(GetDlgItem(win, IDC_FUNCTION_LST), idx);

	// Invoke the selected function.
	switch (id) {
	case AddToLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		GetDlgItemText(win, IDC_PARAM3_EDT, otherWord, sizeof(otherWord));
		s16 = SSCE_AddToLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word,
		  getS16(win, IDC_PARAM2_EDT), otherWord);
		displayResult(win, "SSCE_AddToLex", s16);
		break;
	case CheckBlock:
		s16 = SSCE_CheckBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word),
		  otherWord, sizeof(otherWord));
		displayCheckResult(win, "SSCE_CheckBlock", s16);
		if (s16 >= 0) {
			wsprintf(str, "errWord: %s; otherWord: %s", word, otherWord);
		}
		appendMsg(win, str);
		break;
	case CheckBlockDlg:
		s32_1 = getS32(win, IDC_PARAM1_EDT);
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		GetDlgItemText(win, IDC_TEXT_EDT, bfr, (int)s32_1);
		s32 = SSCE_CheckBlockDlg(win, bfr, strlen(bfr), s32_1,
		  getS16(win, IDC_PARAM2_EDT));
		wsprintf(str, "SSCE_CheckBlockDlg returned %ld", s32);
		appendMsg(win, str);
		if (s32 >= 0) {
			SetDlgItemText(win, IDC_TEXT_EDT, bfr);
		}
		free(bfr);
		break;
	case CheckCtrlDlg:
		s16 = SSCE_CheckCtrlDlg(win, GetDlgItem(win, IDC_TEXT_EDT),
		  getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_CheckCtrlDlg", s16);
		break;
	case CheckWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_CheckWord(getS16(win, IDC_SESSION_ID_EDT),
		  word, otherWord, sizeof(otherWord));
		displayCheckResult(win, "SSCE_CheckWord", s16);
		if (s16 >= 0) {
			wsprintf(str, "otherWord: %s", otherWord);
		}
		appendMsg(win, str);
		break;
	case ClearLex:
		s16 = SSCE_ClearLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT));
		displayResult(win, "SSCE_ClearLex", s16);
		break;
	case CloseBlock:
		s16 = SSCE_CloseBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT));
		displayResult(win, "SSCE_CloseBlock", s16);
		break;
	case CloseLex:
		s16 = SSCE_CloseLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT));
		displayResult(win, "SSCE_CloseLex", s16);
		break;
	case CloseSession:
		s16 = SSCE_CloseSession(getS16(win, IDC_SESSION_ID_EDT));
		displayResult(win, "SSCE_CloseSession", s16);
		break;
	case CreateLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_CreateLex(getS16(win, IDC_SESSION_ID_EDT),
		  path, getS16(win, IDC_PARAM2_EDT));
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_LEXICON_ID_EDT, str);
		}
		wsprintf(str, "SSCE_CreateLex(%s) returned %hd", path, s16);
		appendMsg(win, str);
		break;
	case DelBlockText:
		s16 = SSCE_DelBlockText(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), getS32(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_DelBlockText", s16);
		break;
	case DelBlockWord:
		s32 = SSCE_DelBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word));
		wsprintf(str, "SSCE_DelBlockWord returned %ld; deleted text = %s",
		  s32, word);
		appendMsg(win, str);
		break;
	case DelFromLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_DelFromLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word);
		displayResult(win, "SSCE_DelFromLex", s16);
		break;
	case EditLexDlg:
		s16 = SSCE_EditLexDlg(win);
		displayResult(win, "SSCE_EditLexDlg", s16);
		break;
	case FindLexWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_FindLexWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word, otherWord, sizeof(otherWord));
		if (s16 < 0) {
			displayResult(win, "SSCE_FindLexWord", s16);
		}
		else {
			int i;
			const char *actionName = "(unknown)";

			for (i = 0; i < sizeof(actions) / sizeof(actions[0]); ++i) {
				if (actions[i].action == s16) {
					actionName = actions[i].name;
					break;
				}
			}
			wsprintf(str, "SSCE_FindLexWord returned %s", actionName);
			appendMsg(win, str);
			if (otherWord[0] != '\0') {
				wsprintf(str, "otherWord: %s", otherWord);
				appendMsg(win, str);
			}
		}
		break;
	case GetAutoCorrect:
		s16 = SSCE_GetAutoCorrect();
		displayResult(win, "SSCE_GetAutoCorrect", s16);
		break;
	case GetBlock:
		s16 = SSCE_GetBlockInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), &s32_1, NULL, NULL, NULL);
		if (s16 < 0) {
			displayResult(win, "SSCE_GetBlockInfo", s16);
			break;
		}
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1 + 1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		s16 = (SSCE_S16)SSCE_GetBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), bfr, s32_1 + 1);
		bfr[s32_1] = '\0';
		displayResult(win, "SSCE_GetBlock", s16);
		appendMsg(win, "Block contents:");
		appendMsg(win, bfr);
		free(bfr);
		break;
	case GetBlockInfo:
		s16 = SSCE_GetBlockInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), &s32_1, &s32_2, &s32_3, &s32_4);
		displayResult(win, "SSCE_GetBlockInfo", s16);
		wsprintf(str,
		  "textLen = %ld; blkSz = %ld; curPos = %ld; wordCount = %ld",
		  s32_1, s32_2, s32_3, s32_4);
		appendMsg(win, str);
		break;
	case GetBlockWord:
		s16 = SSCE_GetBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word));
		displayResult(win, "SSCE_GetBlockWord", s16);
		wsprintf(str, "word: %s", word);
		appendMsg(win, str);
		break;
	case GetHelpFile:
		SSCE_GetHelpFile(path, sizeof(path));
		wsprintf(str, "help file: %s", path);
		appendMsg(win, str);
		break;
	case GetLex:
		s16 = SSCE_GetLexInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), &s32_1, NULL, NULL);
		if (s16 < 0) {
			displayResult(win, "SSCE_GetLexInfo", s16);
			break;
		}
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		s32 = SSCE_GetLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), bfr, s32_1);
		wsprintf(str, "SSCE_GetLex returned %ld", s32);
		appendMsg(win, str);
		for (p = bfr; *p != '\0'; p += strlen(p) + 1) {
			appendMsg(win, p);
		}
		free(bfr);
		break;
	case GetLexId:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_GetLexId(path);
		displayResult(win, "SSCE_GetLexId", s16);
		break;
	case GetLexInfo:
		s16 = SSCE_GetLexInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), &s32_1, &s16_2, &s16_3);
		displayResult(win, "SSCE_GetLexInfo", s16);
		fmt = "(unknown)";
		for (i = 0; i < sizeof(lexFormats) / sizeof(lexFormats[0]); ++i) {
			if (lexFormats[i].format == s16_2) {
				fmt = lexFormats[i].name;
				break;
			}
		}
		lang = "(unknown)";
		for (i = 0; i < sizeof(languages) / sizeof(languages[0]); ++i) {
			if (languages[i].lang == s16_3) {
				lang = languages[i].name;
				break;
			}
		}
		wsprintf(str, "size = %ld; format = %s; language = %s", s32_1,
		  fmt, lang);
		appendMsg(win, str);
		break;
	case GetMainLexFiles:
		SSCE_GetMainLexFiles(path, sizeof(path));
		wsprintf(str, "MainLexFiles: %s", path);
		appendMsg(win, str);
		break;
	case GetMainLexPath:
		SSCE_GetMainLexPath(path, sizeof(path));
		wsprintf(str, "MainLexPath: %s", path);
		appendMsg(win, str);
		break;
	case GetMinSuggestDepth:
		s16 = SSCE_GetMinSuggestDepth();
		displayResult(win, "SSCE_GetMinSuggestDepth", s16);
		break;
	case GetOption:
		s32 = (SSCE_S32)SSCE_GetOption(getS16(win, IDC_SESSION_ID_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM1_EDT));
		if (s32 < 0) {
			displayResult(win, "SSCE_GetOption", (SSCE_S16)s32);
		}
		else {
			wsprintf(str, "SSCE_GetOption returned %ld", s32);
			appendMsg(win, str);
		}
		break;
	case GetRegTreeName:
		SSCE_GetRegTreeName(path, sizeof(path));
		wsprintf(str, "RegTreeName: %s", path);
		appendMsg(win, str);
		break;
	case GetSid:
		s16 = SSCE_GetSid();
		displayResult(win, "SSCE_GetSid", s16);
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_SESSION_ID_EDT, str);
		}
		break;
	case GetStatistics:
		SSCE_GetStatistics((SSCE_U32 *)&s32_1, (SSCE_U32 *)&s32_2,
		  (SSCE_U32 *)&s32_3);
		wsprintf(str,
		  "wordsChecked = %lu; wordsChanged = %lu; errorsDetected = %lu",
		  s32_1, s32_2, s32_3);
		appendMsg(win, str);
		break;
	case GetStringTableName:
		SSCE_GetStringTableName(path, sizeof(path));
		wsprintf(str, "StringTableName: %s", path);
		appendMsg(win, str);
		break;
	case GetUserLexFiles:
		SSCE_GetUserLexFiles(path, sizeof(path));
		wsprintf(str, "UserLexFiles: %s", path);
		appendMsg(win, str);
		break;
	case GetUserLexPath:
		SSCE_GetUserLexPath(path, sizeof(path));
		wsprintf(str, "UserLexPath: %s", path);
		appendMsg(win, str);
		break;
	case InsertBlockText:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_InsertBlockText(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word);
		displayResult(win, "SSCE_InsertBlockText", s16);
		break;
	case NextBlockWord:
		s16 = SSCE_NextBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT));
		displayResult(win, "SSCE_NextBlockWord", s16);
		break;
	case OpenBlock:
		s32_1 = getS32(win, IDC_PARAM1_EDT);
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		GetDlgItemText(win, IDC_TEXT_EDT, bfr, (int)s32_1);
		s16 = SSCE_OpenBlock(getS16(win, IDC_SESSION_ID_EDT),
		  bfr, strlen(bfr), s32_1, TRUE);
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_BLOCK_ID_EDT, str);
		}
		displayResult(win, "SSCE_OpenBlock", s16);
		free(bfr);
		break;
	case OpenLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_OpenLex(getS16(win, IDC_SESSION_ID_EDT),
		  path, getS32(win, IDC_PARAM2_EDT));
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_LEXICON_ID_EDT, str);
		}
		wsprintf(str, "SSCE_OpenLex(%s) returned %hd", path, s16);
		appendMsg(win, str);
		break;
	case OpenSession:
		s16 = SSCE_OpenSession();
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_SESSION_ID_EDT, str);
		}
		displayResult(win, "SSCE_OpenSession", s16);
		break;
	case OptionsDlg:
		s16 = SSCE_OptionsDlg(win);
		displayResult(win, "SSCE_OptionsDlg", s16);
		break;
	case ReplaceBlockWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_ReplaceBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word);
		displayResult(win, "SSCE_ReplaceBlockWord", s16);
		break;
	case ResetLex:
		s16 = SSCE_ResetLex();
		displayResult(win, "SSCE_ResetLex", s16);
		break;
	case SetAutoCorrect:
		s16 = SSCE_SetAutoCorrect(getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetAutoCorrect", s16);
		break;
	case SetBlockCursor:
		s16 = SSCE_SetBlockCursor(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), getS32(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetBlockCursor", s16);
		break;
	case SetDebugFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		SSCE_SetDebugFile(path);
		wsprintf(str, "Diagnostic file set to %s", path);
		break;
	case SetDialogOrigin:
		SSCE_SetDialogOrigin(getS16(win, IDC_PARAM1_EDT),
		  getS16(win, IDC_PARAM2_EDT));
		appendMsg(win, "Dialog origin set");
		break;
	case SetHelpFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetHelpFile(path);
		displayResult(win, "SSCE_SetHelpFile", s16);
		break;
	case SetIniFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetIniFile(path);
		displayResult(win, "SSCE_SetIniFile", s16);
		break;
	case SetKey:
		s32 = SSCE_SetKey(getU32(win, IDC_PARAM1_EDT));
		wsprintf(str, "SSCE_SetKey returned %ld", s32);
		appendMsg(win, str);
		break;
	case SetMainLexFiles:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetMainLexFiles(path);
		displayResult(win, "SSCE_SetMainLexFiles", s16);
		break;
	case SetMainLexPath:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetMainLexPath(path);
		displayResult(win, "SSCE_SetMainLexPath", s16);
		break;
	case SetMinSuggestDepth:
		s16 = SSCE_SetMinSuggestDepth(getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetMinSuggestDepth", s16);
		break;
	case SetOption:
		s32 = (SSCE_S32)SSCE_SetOption(getS16(win, IDC_SESSION_ID_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM1_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM2_EDT));
		wsprintf(str, "SSCE_SetOption returned %ld", s32);
		appendMsg(win, str);
		break;
	case SetRegTreeName:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetRegTreeName(path);
		displayResult(win, "SSCE_SetRegTreeName", s16);
		break;
	case SetStringTableName:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetStringTableName(path);
		displayResult(win, "SSCE_SetStringTableName", s16);
		break;
	case SetUserLexFiles:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetUserLexFiles(path);
		displayResult(win, "SSCE_SetUserLexFiles", s16);
		break;
	case SetUserLexPath:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetUserLexPath(path);
		displayResult(win, "SSCE_SetUserLexPath", s16);
		break;
	case Suggest:
		s16_1 = SSCE_MAX_WORD_SZ * 16;
		bfr = (SSCE_CHAR *)malloc((size_t)s16_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_Suggest(getS16(win, IDC_SESSION_ID_EDT),
		  word, getS16(win, IDC_PARAM2_EDT), bfr, (SSCE_S32)s16_1,
		  scores, sizeof(scores) / sizeof(scores[0]));
		displayResult(win, "SSCE_Suggest", s16);
		if (s16 >= 0) {
			for (p = bfr, i = 0; *p != '\0'; p += strlen(p) + 1, ++i) {
				wsprintf(str, "%s [%hd]", p, scores[i]);
				appendMsg(win, str);
			}
		}
		free(bfr);
		break;
	case Version:
		SSCE_Version(word, sizeof(word));
		wsprintf(str, "Version: %s", word);
		appendMsg(win, str);
		break;
	}
}
Beispiel #21
0
static void dumpLines( const uint_8 *input, uint length )
{
    const uint_8    *p;
    uint            opcode_base;
    uint            *opcode_lengths;
    uint            u;
    uint            file_index;
    const uint_8    *name;
    uint_32         dir_index;
    uint_32         mod_time;
    uint_32         file_length;
    uint_32         directory;
    uint_8          op_code;
    uint_8          op_len;
    uint_32         tmp;
    uint_16         tmp_seg;
    uint            line_range;
    int             line_base;
    int_32          itmp;
    int             default_is_stmt;
    state_info      state;
    uint            min_instr;
    uint_32         unit_length;
    const uint_8    *unit_base;

    p = input;
    while( p - input < length ) {
        unit_length = getU32( (uint_32 *)p );
        p += sizeof( uint_32 );
        unit_base = p;

        printf( "total_length: 0x%08lx (%u)\n", unit_length, unit_length );

        printf( "=== unit dump start ===\n" );
        dumpHex( unit_base - sizeof( uint_32 ), unit_length + sizeof (uint_32 ), 1 );
        printf( "=== unit dump end ===\n" );

        printf( "version: 0x%04x\n", getU16( (uint_16 *)p ) );
        p += sizeof( uint_16 );

        printf( "prologue_length: 0x%08lx (%u)\n", getU32( (uint_32 *)p ), getU32( (uint_32 *)p ) );
        p += sizeof( uint_32 );

        min_instr = *p;
        printf( "minimum_instruction_length: 0x%02x (%u)\n", min_instr, min_instr );
        p += 1;

        default_is_stmt = *p;
        printf( "default_is_stmt: 0x%02x (%u)\n", default_is_stmt, default_is_stmt );
        p += 1;

        line_base = *(int_8 *)p;
        printf( "line_base: 0x%02x (%d)\n", (unsigned char)line_base, line_base );
        p += 1;

        line_range = *(uint_8 *)p;
        printf( "line_range: 0x%02x (%u)\n", line_range, line_range );
        p += 1;

        opcode_base = *p;
        printf( "opcode_base: 0x%02x (%u)\n", opcode_base, opcode_base );
        p += 1;
        opcode_lengths = alloca( sizeof( uint ) * opcode_base );
        printf( "standard_opcode_lengths:\n" );
        for( u = 0; u < opcode_base - 1; ++u ) {
            opcode_lengths[u] = *p;
            ++p;
            printf( "%4u: %u\n", u + 1, opcode_lengths[u] );
        }

        printf( "-- current_offset = %08x\n", p - input );

        if( p - input >= length )
            return;

        printf( "-- start include paths --\n");
        file_index = 0;
        while( *p != 0 ) {
            ++file_index;
            name = p;
            p += strlen( (const char *)p ) + 1;
            printf( "path %u: '%s'\n", file_index, name );
            if( p - input >= length ) {
                return;
            }
        }
        printf( "-- end include paths --\n");
        p++;
        printf( "-- start files --\n");
        file_index = 0;
        while( *p != 0 ) {
            ++file_index;
            name = p;
            p += strlen( (const char *)p ) + 1;
            p = DecodeULEB128( p, &dir_index );
            p = DecodeULEB128( p, &mod_time );
            p = DecodeULEB128( p, &file_length );
            printf( "file %u: '%s' dir_index %08lx mod_time %08lx length %08lx\n",
                file_index, name, dir_index, mod_time, file_length );
            if( p - input >= length ) {
                return;
            }
        }
        printf( "-- end files --\n");
        p++;
        initState( &state, default_is_stmt );

        while( p - unit_base < unit_length ) {
            op_code = *p;
            ++p;
            if( op_code == 0 ) {
                printf( "EXTENDED 0x%02x: ", op_code );
                /* extended op_code */
                op_len = *p;
                ++p;
                printf( "len: %03d ", op_len );
                op_code = *p;
                ++p;
                switch( op_code ) {
                case DW_LNE_end_sequence:
                    printf( "END_SEQUENCE\n" );
                    state.end_sequence = 1;
                    dumpState( &state );
                    initState( &state, default_is_stmt );
                    break;
                case DW_LNE_set_address:
                    if( op_len == 3 ) {
                        tmp = getU16( (uint_16 *)p );
                        p += sizeof( uint_16 );
                    } else {
                        tmp = getU32( (uint_32 *)p );
                        p += sizeof( uint_32 );
                    }
#if 0   /* Why did they choose 6 byte here?  */
                    tmp_seg = getU16( (uint_16 *)p );
                    p += sizeof( uint_16 );
                    printf( "SET_ADDRESS %04x:%08lx\n", tmp_seg, tmp );
#else
                    tmp_seg = 0;    /* stop warning */
                    printf( "SET_ADDRESS %08lx\n", tmp );
#endif
                    break;
                case DW_LNE_WATCOM_set_segment_OLD:
                case DW_LNE_WATCOM_set_segment:
                    tmp_seg = getU16( (uint_16 *)p );
                    p += sizeof( uint_16 );
                    printf( "SET_ADDRESS_SEG %04x\n", tmp_seg );
                    break;
                case DW_LNE_define_file:
                    ++file_index;
                    name = p;
                    p += strlen( (const char *)p ) + 1;
                    p = DecodeULEB128( p, &directory );
                    p = DecodeULEB128( p, &mod_time );
                    p = DecodeULEB128( p, &file_length );
                    printf( "DEFINE_FILE %u: '%s' directory %ld mod_time %08lx length %08lx\n",
                        file_index, name, directory, mod_time, file_length );
                    break;
                default:
                    printf( "** unknown extended opcode: %02x - %u bytes\n", op_code, op_len );
                    printf( "** losing %u bytes\n", unit_length - ( p - unit_base ));

                    dumpHex( p-3, (unit_length - ( p - unit_base )) + 3, 1 );

                    p = unit_base + unit_length;
                    goto hacky;
//                    return;
                }
            } else if( op_code < opcode_base ) {
                printf( "%s", getStandardOp( op_code ) );
                switch( op_code ) {
                case DW_LNS_copy:
                    printf( "\n" );
                    dumpState( &state );
                    state.basic_block = 0;
                    break;
                case DW_LNS_advance_pc:
                    p = DecodeLEB128( p, &itmp );
                    printf( " %ld\n", itmp );
                    state.address += itmp * min_instr;
                    break;
                case DW_LNS_advance_line:
                    p = DecodeLEB128( p, &itmp );
                    printf( " %ld\n", itmp );
                    state.line += itmp;
                    break;
                case DW_LNS_set_file:
                    p = DecodeLEB128( p, &itmp );
                    printf( " %ld\n", itmp );
                    state.file = itmp;
                    break;
                case DW_LNS_set_column:
                    p = DecodeLEB128( p, &itmp );
                    printf( " %ld\n", itmp );
                    state.column = itmp;
                    break;
                case DW_LNS_negate_stmt:
                    printf( "\n" );
                    state.is_stmt = !state.is_stmt;
                    break;
                case DW_LNS_set_basic_block:
                    printf( "\n" );
                    state.basic_block = 1;
                    break;
                case DW_LNS_const_add_pc:
                    printf( "\n" );
                    state.address += ( ( 255 - opcode_base ) / line_range ) * min_instr;
                    break;
                case DW_LNS_fixed_advance_pc:
                    tmp = getU16( (uint_16 *)p );
                    p += sizeof( uint_16 );
                    printf( " %04x\n", tmp );
                    state.address += tmp;
                    break;
                default:
                    for( u = 0; u < opcode_lengths[op_code - 1]; ++u ) {
                        p = DecodeLEB128( p, &itmp );
                        printf( " %08lx", itmp );
                    }
                    printf( "\n" );
                }
            } else {
                printf( "SPECIAL 0x%02x:", op_code );
                op_code -= opcode_base;
                printf( " addr incr: %d  line incr: %d\n",
                    op_code / line_range,
                    line_base + op_code % line_range );
                state.line += line_base + op_code % line_range;
                state.address += ( op_code / line_range ) * min_instr;
                dumpState( &state );
                state.basic_block = 0;
            }
        }
hacky:
        printf( "-- current_offset = %08x\n", p - input );
    }
}
/**************************************************************** 
SeaNet General Packet Format is;
*	'@'		:	Message Header = '@' (0x40).
*	HHHH	:	Hex Length of whole binary packet (excluding LF Terminator).
*	BB		:	Binary Word of above Hex Length.
*	SID		:	Packet Source Identification (Tx Node number 0 - 255).
*	DID		:	Packet Destination Identification (Rx Node number 0 -255).
*	COUNT	:	Byte Count of attached message that follows this byte.
*	MSG		:	Command / Reply Message (i.e. 'Alive' command, 'Data Reply' message).
*	TERM	:	Message Terminator = Line Feed (0Ah).
* 
*	Returns -1 if failed, 1 if correct first time, 2 if it had to 
* 	stich packets
* 
****************************************************************/
int sortPacket(void)
{

	int packetFlag = 0,
	leFlag = 0,
	buffLen, 		//length of the recieved buffer, output from read_port()
	i,				//counter
	temp[263],
	msgLen,
	binFlag;

	//How long was the msg, according to read() ?
	buffLen = read_port();
	//printf("buffLen = %d\n", buffLen);
	rBptr = &returnBuffer[0];	//set pointer for recieved data

	//Store all packets into temp[]	

	for( i = 0; i < buffLen; i++ )
	{
		leFlag = temp[i];
		temp[i] = getU8();
		if(i >= 1 && temp[i] == 0x40 && temp[i-1] == 0x0a)
		{
			buffLen = i;
		}

	}

	//Store temp stuff into right place

	header = temp[0];
	hLength = getU32(temp[1], temp[2], temp[3], temp[4]);
	bLength = getU16(temp[6], temp[5]);
	sID = temp[7];
	dID = temp[8];
	byteCount = temp[9];
	term = temp[buffLen-1];

	//Clear msg buffer first
	for(i = 0; i < 263; i++)
		msg[i] = NULL;

	msgLen = 0;

	//Store the msg, works for varying lengths
	for( i = 10; i < (buffLen-2); i ++)
	{
		msg[(i-10)] = temp[i];
		msgLen ++;
	}

	//What is prinf?

	if(header == '@' && term == 10 && buffLen == bLength + 6)
	{

		//Prinf the packet
		//printf("<< ");
		//for(i = 0; i < buffLen; i ++)
		//	printf("%x : ", temp[i]);
		//printf("\n");

		packetFlag = 1;


		if(msg[0] == mtHeadData)
		{

//			if(byteCount == 0)
//				printf("Single Packet\n");
//			else
//				printf("Multi Packet\n");
			binFlag = 0;
			//printf("\nBearing: %f\n Bins: ", (float) getU16(temp[41], temp[40]) / 17.775 );
			for(i = 44; i < buffLen-1; i++ )
			{
				
				tempBinArray[i-44] = temp[i];
				//printf("%d, ", temp[i]);
				if(temp[i] >= THRESHOLD && binFlag == 0)
				{
					bins = i-44;
					binFlag = 1;
				}
			}
			//printf("%d\n", bins * 6);

			bearing = getU16(temp[41], temp[40]);

		}

		//printf("%d, %d\n", byteCount, msgLen+1);
	}
	else
	{
		packetFlag = -1;
	}

	return packetFlag; 
}
Beispiel #23
0
/**
 * @brief The utility function for extracting actual offset exif IFD0 info is started from
 *          This is internal function and is not exposed to client
 *
 * @return offset of IFD0 field
 */
uint32_t ExifReader::getStartOffset() const
{
    return getU32( 4 );
}
crypto::Xtea StandardInMessage::getXtea()
{
	return {getU32(), getU32(), getU32(), getU32()};
}
Beispiel #25
0
static void dumpARanges( const uint_8 *input, uint length )
{
    const uint_8    *p;
    const uint_8    *q;
    const uint_8    *cu_ar_end;
    uint_32         cu;
    uint_32         tmp;
    uint_32         tuple_size;
    uint_32         padding;
    arange_header   ar_header;

    p = input;

    if( (input == NULL) || (length == 0) )
        return;

    if( length < sizeof( ar_header ) ) {
        printf( ".debug_aranges section too small!\n" );
        return;
    }

    cu = 0;

    while( p - input < length ) {
        ++cu;
        printf( "Compilation Unit %d\n", cu );

        ar_header.len = getU32( (uint_32 *)p );
        p += sizeof( uint_32 );
        ar_header.version = getU16( (uint_16 *)p );
        p += sizeof( uint_16 );
        ar_header.dbg_pos = getU32( (uint_32 *)p );
        p += sizeof( uint_32 );
        ar_header.addr_size = *p;
        p += sizeof( uint_8 );
        ar_header.seg_size = *p;
        p += sizeof( uint_8 );

        printf( "  length:    %08lx\n", ar_header.len );
        printf( "  version:   %04x\n", ar_header.version );
        printf( "  dbg_pos:   %08lx\n", ar_header.dbg_pos );
        printf( "  addr_size: %02x\n", ar_header.addr_size );
        printf( "  seg_size:  %02x\n", ar_header.seg_size );

        /* tuples should be aligned on twice the size of a tuple; some Watcom
         * versions didn't do this right!
         */
        tuple_size = (ar_header.addr_size + ar_header.seg_size) * 2;
        q = (const uint_8 *)(((uint_32)p + tuple_size - 1) & ~(tuple_size - 1));
        padding = q - p;

        /* check if padding contains non-zero data */
        if( padding ) {
            switch( ar_header.addr_size ) {
            case 4:
                tmp = getU32( (uint_32 *)p );
                break;
            case 2:
                tmp = getU16( (uint_16 *)p );
                break;
            default:
                printf( "Unknown address size\n" );
                return;
            }
            /* padding is missing! */
            if( tmp ) {
                padding = 0;
            }
        }

        p += padding;
        cu_ar_end = p - sizeof( ar_header ) + sizeof( ar_header.len ) + ar_header.len - padding;

        while( p < cu_ar_end ) {
            /* range address */
            printf( "\t" );
            p = dumpSegAddr( p, ar_header.addr_size, ar_header.seg_size );
            /* range length */
            printf( "\t" );
            switch( ar_header.addr_size ) {
            case 4:
                tmp = getU32( (uint_32 *)p );
                p += sizeof( uint_32 );
                printf( "%08lx\n", tmp );
                break;
            case 2:
                tmp = getU16( (uint_16 *)p );
                p += sizeof( uint_16 );
                printf( "%04lx\n", tmp );
                break;
            default:
                printf( "Unknown address size\n" );
                p += ar_header.addr_size;
                return;
            }
        }
    }
}