Exemplo n.º 1
0
 bool readBytes(size_t size, const uint8_t** begin) {
     return waitForBytes(size) &&
            d_.readBytes(size, begin);
 }
Exemplo n.º 2
0
 size_t currentOffset() const {
     return d_.currentOffset();
 }
Exemplo n.º 3
0
 bool readVarU32(uint32_t* u32) {
     return waitForBytes(MaxVarU32DecodedBytes) &&
            d_.readVarU32(u32);
 }
Exemplo n.º 4
0
 void read_payload(Decoder& decoder, const std::string& data)
 {
     std::vector<uint8_t> payload(data.length());
     std::copy(data.c_str(), data.c_str() + data.length(), payload.data());
     decoder.read_payload(payload.data());
 }
Exemplo n.º 5
0
void LinkedDecoder::linkParent()
{
	Decoder *parent = getParent();
	if (parent) m_linkedIdx = parent->linkChild(this);
}
Exemplo n.º 6
0
void *event_listener_loop(void *arg) {
    bool decodingOver;
    event *ev;
    blackadder *ba = (blackadder *) arg;
    DecodingState *ds;
    string information_identifier;
    //string algorithmic_identifier;
    int seed;
    unsigned int sizeOfData = 0;
    //char *symbol;
    //cout << "event_listener_loop started " << endl;
    while (true) {
        ev = new event();
        ba->get_event(*ev);
        if (ev->type == PUBLISHED_DATA) {
            counter++;
            memcpy(&seed, ev->id.c_str() + ev->id.length() - PURSUIT_ID_LEN, sizeof (seed));
            memcpy(&sizeOfData, ev->id.c_str() + ev->id.length() - PURSUIT_ID_LEN + sizeof (seed), sizeof (sizeOfData));
            ds = decoder.getState(information_identifier);
            if (ds == NULL) {
                gettimeofday(&start_tv, &tz);
                ds = decoder.initState(information_identifier, sizeOfData, sizeOfSymbol, true);
            }
            decodingOver = decoder.decodeNext(ds, ev, seed);
            //cout << "identifier: " << chararray_to_hex(ev->id) << ", size of data: " << sizeOfData << ", seed: " << seed << endl;
            if (decodingOver == true) {
                //cout << "/*decoding is over*/" << endl;
                /*******************************DEBUG********************************************/
                gettimeofday(&end_tv, &tz);
                duration.tv_sec = end_tv.tv_sec - start_tv.tv_sec;
                if (end_tv.tv_usec - start_tv.tv_usec > 0) {
                    duration.tv_usec = end_tv.tv_usec - start_tv.tv_usec;
                } else {
                    duration.tv_usec = end_tv.tv_usec + 1000000 - start_tv.tv_usec;
                    duration.tv_sec--;
                }
                double left = counter * ((double) sizeOfSymbol / (double) (1024 * 1024));
                double right = ((double) ((duration.tv_sec * 1000000) + duration.tv_usec)) / 1000000;
                throughput = (left / right);
                cout << "Throughput (MB/sec): " << throughput << endl;
                left = (sizeOfData / sizeOfSymbol) * ((double) sizeOfSymbol / (double) (1024 * 1024));
                right = ((double) ((duration.tv_sec * 1000000) + duration.tv_usec)) / 1000000;
                goodput = (left / right);
                //                for (int i = 0; i < ds->numberOfInputSymbols - 1; i++) {
                //                    for (int j = 0; j < ds->symbolSize; j++) {
                //                        myfile << ((char *) ds->inputSymbols[i]->data)[j];
                //                    }
                //                }
                //                for (int j = 0; j < ds->sizeOfLastInputSymbol; j++) {
                //                    myfile << ((char *) ds->inputSymbols[ds->numberOfInputSymbols - 1]->data)[j];
                //                }
                //                myfile.close();
                /**********************************************************************************/
                
                cout << "Goodput (MB/sec): " << goodput << endl;
                cout << "Average Degree: " << ds->getAverageDegree() << endl;
                cout << "Median Degree: " << ds->getMedianDegree() << endl;
                cout << "#Symbols: " << counter << endl;
                delete ds;
                break;
            }
        }
    }
    return NULL;
}
Exemplo n.º 7
0
void MessageRecorder::recordIncomingMessage(Connection& connection, Decoder& decoder)
{
    if (!isEnabled() || !connection.isValid())
        return;

    WebKitMessageRecord record;
    record.sourceProcessType = static_cast<uint64_t>(connection.client()->remoteProcessType());
    record.destinationProcessType = static_cast<uint64_t>(connection.client()->localProcessType());
    record.destinationID = decoder.destinationID();
    record.isSyncMessage = decoder.isSyncMessage();
    record.shouldDispatchMessageWhenWaitingForSyncReply = decoder.shouldDispatchMessageWhenWaitingForSyncReply();
    record.sourceProcessID = connection.remoteProcessID();
    record.destinationProcessID = getpid();
    record.isIncoming = true;

    record.messageReceiverName = MallocPtr<char>::malloc(sizeof(char) * (decoder.messageReceiverName().size() + 1));
    strncpy(record.messageReceiverName.get(), decoder.messageReceiverName().data(), decoder.messageReceiverName().size());
    record.messageReceiverName.get()[decoder.messageReceiverName().size()] = 0;

    record.messageName = MallocPtr<char>::malloc(sizeof(char) * (decoder.messageName().size() + 1));
    strncpy(record.messageName.get(), decoder.messageName().data(), decoder.messageName().size());
    record.messageName.get()[decoder.messageName().size()] = 0;

    uuid_copy(record.UUID, decoder.UUID());

    decoder.setMessageProcessingToken(std::make_unique<MessageProcessingToken>(WTFMove(record)));
}
Exemplo n.º 8
0
int main(int argc, char** argv)
{
	(void) argc;
	(void) argv;
	signal(SIGCHLD, SIG_IGN);
	int iSocket = socket(AF_INET, SOCK_STREAM, 0);
	if (iSocket < 0) {
		fprintf(stderr, "socket failed %d, errno %d\n", 
				iSocket, errno);
		return 0;
	}
	struct sockaddr_in servAddr, cliAddr;
	socklen_t iCliLen = sizeof(cliAddr);
	memset(&servAddr, 0, sizeof(servAddr));
	servAddr.sin_family = AF_INET;
	servAddr.sin_addr.s_addr = inet_addr(*(argv + 1));
	servAddr.sin_port = htons(atoi(*(argv + 2)));
	int option = 1;
	setsockopt(iSocket, SOL_SOCKET, SO_REUSEADDR, (const void *)&option, sizeof(option));
	bind(iSocket, (struct sockaddr *)&servAddr, sizeof(servAddr));
	listen(iSocket, 512);
	while(1) {
		int iCliFd;
		iCliFd = accept(iSocket, (struct sockaddr *)&cliAddr, &iCliLen);
		if (iCliFd < 0) {
			fprintf(stderr, "accept failed %d, errno %d\n",
					iCliFd, errno);
			return 0;
		}

		pid_t pid = fork();
		if (pid == 0)
		{

#define USERID 1
			char sBuf[10240];
			ssize_t size;
			uint64_t iMsgId = 1ull;
			Encoder encoder(sBuf, sizeof(sBuf));
			Decoder decoder;
			{
				ConnSvrConnectChallenge req;
				char sRandomStr[256];
				memset(sRandomStr, 'z', sizeof(sRandomStr));
				req.set_random_msg(sRandomStr, 256);
				Header header;
				header.set_type(kMsgTypeConnSvrConnectChallenge);
				header.set_msg_id(iMsgId++);
				encoder.EncodeHeader(header);
				encoder.Encode(req);
				size = send(iCliFd, encoder.Data(), encoder.DataLen(), 0);
				printf("send %ld\n", size);
			}
			{
				Header header;
				size = recv(iCliFd, sBuf, sizeof(sBuf), 0);
				decoder.DecodeHeader(sBuf, size, &header);
				ConnSvrConnectReq resp;
				decoder.DecodePayload(&resp);
				unsigned char sUserAgentBuf[1024];
				UserAgent userAgent;
				if (resp.has_user_agent()) {
					const std::string &sUserAgent = resp.user_agent();
					memcpy(sUserAgentBuf, sUserAgent.c_str(), sUserAgent.size());
					if (sUserAgent.size()) {
						unsigned char inputKey = sUserAgentBuf[0];
						unsigned char outputKey;
						for(int i = 1, n = sUserAgent.size(); i != n; i++) {
							outputKey = sUserAgentBuf[i];
							sUserAgentBuf[i] ^= inputKey;
							inputKey = outputKey;
						}
					}
					userAgent.ParseFromArray(sUserAgentBuf + 1, sUserAgent.size() - 1);
				}
				printf("type %d, msgid %lu, phonenum %s, role %d, secretchap %s, ostype %s, osver %s, model %s, clientver %s, network %s, location %s operator %s\n",
						header.type(), header.has_msg_id() ? header.msg_id() : 0,
						resp.phone_num().c_str(), resp.role(), resp.secret_chap().c_str(),
						userAgent.has_os_type() ? userAgent.os_type().c_str() : "",
						userAgent.has_os_ver() ? userAgent.os_ver().c_str() : "",
						userAgent.has_model() ? userAgent.model().c_str() : "",
						userAgent.has_client_ver() ? userAgent.client_ver().c_str() : "",
						userAgent.has_network() ? userAgent.network().c_str() : "",
						userAgent.has_location() ? userAgent.location().c_str() : "",
						userAgent.has_carrier_operator() ? userAgent.carrier_operator().c_str() : "");
			}
			{
				ConnSvrConnectRsp req;
				RspMsg* pRspMsg = req.mutable_rsp_msg();
				pRspMsg->set_rsp_code(0);
				pRspMsg->set_rsp_msg("OK");
				Header header;
				header.set_type(kMsgTypeConnSvrConnectRsp);
				header.set_msg_id(iMsgId++);
				encoder.EncodeHeader(header);
				encoder.Encode(req);
				size = send(iCliFd, encoder.Data(), encoder.DataLen(), 0);
				printf("send %ld\n", size);
			}
			int number = 0;
			while(number < 100) {
				size = recv(iCliFd, sBuf, sizeof(sBuf), 0);
				if (size == 0) {
					break;
				}
				Header header;
				decoder.DecodeHeader(sBuf, size, &header);
				printf("type %d, msgid %lu, ",
						header.type(), header.has_msg_id() ? header.msg_id() : 0);
				if (header.type() == kMsgTypeConnSvrHeartbeatReq) {
					ConnSvrHeartbeatReq resp;
					decoder.DecodePayload(&resp);
					printf("heartbeat\n");
				} else if (header.type() == kMsgTypeCdntSvrUpReq) {
					Coordinate resp;
					decoder.DecodePayload(&resp);
					printf("x %lf, y %lf, coordinatetype %d\n",
							resp.x(), resp.y(), resp.type());
				} else if (header.type() == kMsgTypeDispatchSvrNoRspReq) {
					BinaryMsg req;
					decoder.DecodePayload(&req);
					if (req.type() == kDispatchMessageTypeDriverOrderGetReq) {
						DriverOrderGetReq getReq;
						getReq.ParseFromArray(req.payload().data(), req.payload().size());
						const DriverOrderGetReq::LastStatus &lastStatus = getReq.laststatus();
						printf("type %d, phone %s, token %s, oid %s, down %d, play %d, cancel %d\n",
								req.type(), getReq.phone().c_str(), getReq.token().c_str(),
								lastStatus.oid().c_str(), lastStatus.down(), lastStatus.play(), 
								lastStatus.cancel());
					}
				} else {
					printf("unkown type %d\n", header.type());
				}
				number++;
				if (number == 4) {
					ConnSvrHeartbeatReq req;
					Header header;
					header.set_type(kMsgTypeConnSvrHeartbeatReq);
					header.set_msg_id(iMsgId++);
					encoder.EncodeHeader(header);
					encoder.Encode(req);
					size = send(iCliFd, encoder.Data(), encoder.DataLen(), 0);
					printf("send %ld\n", size);
				}
				/* else if (number == 7) {
					CdntSvrDownReq req;
					Header header;
					header.set_type(kMsgTypeCdntSvrDownReq);
					header.set_msg_id(iMsgId++);
					{
						PeerCoordinateInfo* pPeerCoordinateInfo = req.add_peer_coordinate_infos();
						Coordinate* pCoordinate = pPeerCoordinateInfo->mutable_coordinate();
						pCoordinate->set_x(1.0f);
						pCoordinate->set_y(1.0f);
						pCoordinate->set_type(DidiPush::BD_09);
						pPeerCoordinateInfo->set_distance(10);
						pPeerCoordinateInfo->set_wait_time(10);
						pPeerCoordinateInfo->set_local_id("aslkdjflajk");
					}
					{
						PeerCoordinateInfo* pPeerCoordinateInfo = req.add_peer_coordinate_infos();
						Coordinate* pCoordinate = pPeerCoordinateInfo->mutable_coordinate();
						pCoordinate->set_x(2.0f);
						pCoordinate->set_y(2.0f);
						pCoordinate->set_type(DidiPush::BD_09);
						pPeerCoordinateInfo->set_distance(20);
						pPeerCoordinateInfo->set_wait_time(20);
						pPeerCoordinateInfo->set_local_id("lkjlkjlkj");
					}
					encoder.EncodeHeader(header);
					encoder.Encode(req);
					size = send(iCliFd, encoder.Data(), encoder.DataLen(), 0);
					printf("send %ld\n", size);
				} else if (number == 9) {
					Header header;
					header.set_type(kMsgTypeConnSvrDisconnectReq);
					header.set_msg_id(iMsgId++);
					ConnSvrDisconnectReq req;
					encoder.EncodeHeader(header);
					encoder.Encode(req);
					size = send(iCliFd, encoder.Data(), encoder.DataLen(), 0);
					printf("send %ld\n", size);
				} else if (number == 4) {
					BinaryMsg msg;
					msg.set_type(kPushMessageTypeDriverOrderStrivedReq);
					char sBuf[10240];
					DriverOrderStrivedReq req;
					req.set_oid("asldkjfa");
					req.set_dinfo("alskjdflakj");
					req.set_msg("msg");
					req.set_showtype(DriverMessageTipShowTypeWindow);
					req.SerializeToArray(sBuf, req.ByteSize());
					msg.set_payload(sBuf, req.ByteSize());
					msg.SerializeToArray(sBuf, msg.ByteSize());
					Header header;
					header.set_type(kMsgTypeAppPushMessageReq);
					header.set_msg_id(iMsgId++);
					encoder.EncodeHeader(header);
					encoder.Encode(msg);
					size = send(iCliFd, encoder.Data(), encoder.DataLen(), 0);
					printf("send %ld\n", size);
				}
				*/
			}
			close(iCliFd);
			return 0;
		} else if (pid > 0) {
			close(iCliFd);
		} else {
			fprintf(stderr, "Fork failed\n");
		}
	}
	return 0;
}
Exemplo n.º 9
0
int w_Decoder_getChannels(lua_State *L)
{
	Decoder *t = luax_checkdecoder(L, 1);
	lua_pushinteger(L, t->getChannels());
	return 1;
}
Exemplo n.º 10
0
PassRefPtr<HistoryItem> HistoryItem::decodeBackForwardTree(const String& topURLString, const String& topTitle, const String& topOriginalURLString, Decoder& decoder)
{
    // Since the data stream is not trusted, the decode has to be non-recursive.
    // We don't want bad data to cause a stack overflow.

    uint32_t version;
    if (!decoder.decodeUInt32(version))
        return 0;
    if (version != backForwardTreeEncodingVersion)
        return 0;

    String urlString = topURLString;
    String title = topTitle;
    String originalURLString = topOriginalURLString;

    Vector<DecodeRecursionStackElement, 16> recursionStack;

recurse:
    RefPtr<HistoryItem> node = create(urlString, title, 0);

    node->setOriginalURLString(originalURLString);

    title = String();

    uint64_t size;
    if (!decoder.decodeUInt64(size))
        return 0;
    size_t i;
    RefPtr<HistoryItem> child;
    for (i = 0; i < size; ++i) {
        if (!decoder.decodeString(originalURLString))
            return 0;

        if (!decoder.decodeString(urlString))
            return 0;

        recursionStack.append(DecodeRecursionStackElement(node.release(), i, size));
        goto recurse;

resume:
        node->m_children.append(child.release());
    }

    if (!decoder.decodeInt64(node->m_documentSequenceNumber))
        return 0;

    if (!decoder.decodeUInt64(size))
        return 0;
    for (i = 0; i < size; ++i) {
        String state;
        if (!decoder.decodeString(state))
            return 0;
        node->m_documentState.append(state);
    }

    if (!decoder.decodeString(node->m_formContentType))
        return 0;

    bool hasFormData;
    if (!decoder.decodeBool(hasFormData))
        return 0;
    if (hasFormData) {
        node->m_formData = FormData::decode(decoder);
        if (!node->m_formData)
            return 0;
    }

    if (!decoder.decodeInt64(node->m_itemSequenceNumber))
        return 0;

    if (!decoder.decodeString(node->m_referrer))
        return 0;

    int32_t x;
    if (!decoder.decodeInt32(x))
        return 0;
    int32_t y;
    if (!decoder.decodeInt32(y))
        return 0;
    node->m_scrollPoint = IntPoint(x, y);
    
    if (!decoder.decodeFloat(node->m_pageScaleFactor))
        return 0;

    bool hasStateObject;
    if (!decoder.decodeBool(hasStateObject))
        return 0;
    if (hasStateObject) {
        Vector<uint8_t> bytes;
        if (!decoder.decodeBytes(bytes))
            return 0;
        node->m_stateObject = SerializedScriptValue::adopt(bytes);
    }

    if (!decoder.decodeString(node->m_target))
        return 0;

    // Simulate recursion with our own stack.
    if (!recursionStack.isEmpty()) {
        DecodeRecursionStackElement& element = recursionStack.last();
        child = node.release();
        node = element.node.release();
        i = element.i;
        size = element.size;
        recursionStack.removeLast();
        goto resume;
    }

    return node.release();
}
static bool decodeElement(Decoder& decoder, FormDataElement& element)
{
    uint32_t type;
    if (!decoder.decodeUInt32(type))
        return false;

    switch (type) {
    case FormDataElement::data: {
        element.m_type = FormDataElement::data;
        Vector<uint8_t> data;
        if (!decoder.decodeBytes(data))
            return false;
        size_t size = data.size();
        element.m_data.resize(size);
        memcpy(element.m_data.data(), data.data(), size);
        return true;
    }

    case FormDataElement::encodedFile:
#if ENABLE(FILE_SYSTEM)
    case FormDataElement::encodedURL:
#endif
    {
        element.m_type = static_cast<FormDataElement::Type>(type);
        String filenameOrURL;
        if (!decoder.decodeString(filenameOrURL))
            return false;
        if (type == FormDataElement::encodedFile) {
            if (!decoder.decodeString(element.m_generatedFilename))
            return false;
        if (!decoder.decodeBool(element.m_shouldGenerateFile))
            return false;
        }
        int64_t fileStart;
        if (!decoder.decodeInt64(fileStart))
            return false;
        if (fileStart < 0)
            return false;
        int64_t fileLength;
        if (!decoder.decodeInt64(fileLength))
            return false;
        if (fileLength != BlobDataItem::toEndOfFile && fileLength < fileStart)
            return false;
        double expectedFileModificationTime;
        if (!decoder.decodeDouble(expectedFileModificationTime))
            return false;

#if ENABLE(FILE_SYSTEM)
        if (type == FormDataElement::encodedURL)
            element.m_url = KURL(KURL(), filenameOrURL);
        else
#endif
        element.m_filename = filenameOrURL;

#if ENABLE(BLOB)
        element.m_fileStart = fileStart;
        element.m_fileLength = fileLength;
        element.m_expectedFileModificationTime = expectedFileModificationTime;
#endif
        return true;
    }

#if ENABLE(BLOB)
    case FormDataElement::encodedBlob:
        element.m_type = FormDataElement::encodedBlob;
        String blobURLString;
        if (!decoder.decodeString(blobURLString))
            return false;
        element.m_url = KURL(KURL(), blobURLString);
        return true;
#endif

    }

    return false;
}
Exemplo n.º 12
0
/*!
 * \brief Updates a file in the database.
 *
 * \param filename Full path to file.
 *
 * \returns Nothing.
 */
void FileScanner::UpdateFileInDB(const QString &filename)
{
    QString directory = filename;
    directory.remove(0, m_startdir.length());
    directory = directory.section( '/', 0, -2);

    Decoder *decoder = Decoder::create(filename, NULL, NULL, true);

    if (decoder)
    {
        Metadata *db_meta   = decoder->getMetadata();
        Metadata *disk_meta = decoder->readMetadata();

        if (db_meta && disk_meta)
        {
            disk_meta->setID(db_meta->ID());
            disk_meta->setRating(db_meta->Rating());

            QString album_cache_string;

            // Set values from cache
            int did = m_directoryid[QString(directory.toUtf8()).toLower()];
            if (did > 0)
                disk_meta->setDirectoryId(did);

            int aid = m_artistid[QString(disk_meta->Artist().toUtf8()).toLower()];
            if (aid > 0)
            {
                disk_meta->setArtistId(aid);

                // The album cache depends on the artist id
                album_cache_string = disk_meta->getArtistId() + "#" +
                    QString(disk_meta->Album().toUtf8()).toLower();

                if (m_albumid[album_cache_string] > 0)
                    disk_meta->setAlbumId(m_albumid[album_cache_string]);
            }

            int gid = m_genreid[QString(disk_meta->Genre().toUtf8()).toLower()];
            if (gid > 0)
                disk_meta->setGenreId(gid);

            // Commit track info to database
            disk_meta->dumpToDatabase();

            // Update the cache
            m_artistid[QString(disk_meta->Artist().toUtf8()).toLower()]
                = disk_meta->getArtistId();
            m_genreid[QString(disk_meta->Genre().toUtf8()).toLower()]
                = disk_meta->getGenreId();
            album_cache_string = disk_meta->getArtistId() + "#" +
                QString(disk_meta->Album().toUtf8()).toLower();
            m_albumid[album_cache_string] = disk_meta->getAlbumId();
        }

        if (disk_meta)
            delete disk_meta;

        if (db_meta)
            delete db_meta;

        delete decoder;
    }
}
Exemplo n.º 13
0
/*!
 * \brief Insert file details into database.
 *        If it is an audio file, read the metadata and insert
 *        that information at the same time.
 *
 *        If it is an image file, just insert the filename and
 *        type.
 *
 * \param filename Full path to file.
 *
 * \returns Nothing.
 */
void FileScanner::AddFileToDB(const QString &filename)
{
    QString extension = filename.section( '.', -1 ) ;
    QString directory = filename;
    directory.remove(0, m_startdir.length());
    directory = directory.section( '/', 0, -2);

    QString nameFilter = gCoreContext->GetSetting("AlbumArtFilter",
                                              "*.png;*.jpg;*.jpeg;*.gif;*.bmp");

    // If this file is an image, insert the details into the music_albumart table
    if (nameFilter.indexOf(extension.toLower()) > -1)
    {
        QString name = filename.section( '/', -1);

        MSqlQuery query(MSqlQuery::InitCon());
        query.prepare("INSERT INTO music_albumart SET filename = :FILE, "
                      "directory_id = :DIRID, imagetype = :TYPE;");
        query.bindValue(":FILE", name);
        query.bindValue(":DIRID", m_directoryid[
                            QString(directory.toUtf8()).toLower()]);
        query.bindValue(":TYPE", AlbumArtImages::guessImageType(name));

        if (!query.exec() || query.numRowsAffected() <= 0)
        {
            MythDB::DBError("music insert artwork", query);
        }
        return;
    }

    Decoder *decoder = Decoder::create(filename, NULL, NULL, true);

    if (decoder)
    {
        VERBOSE(VB_FILE, QString("Reading metadata from %1").arg(filename));
        Metadata *data = decoder->readMetadata();
        if (data) {

            QString album_cache_string;

            // Set values from cache
            int did = m_directoryid[QString(directory.toUtf8()).toLower()];
            if (did > 0)
                data->setDirectoryId(did);

            int aid = m_artistid[QString(data->Artist().toUtf8()).toLower()];
            if (aid > 0)
            {
                data->setArtistId(aid);

                // The album cache depends on the artist id
                album_cache_string = data->getArtistId() + "#"
                    + QString(data->Album().toUtf8()).toLower();

                if (m_albumid[album_cache_string] > 0)
                    data->setAlbumId(m_albumid[album_cache_string]);
            }

            int gid = m_genreid[QString(data->Genre().toUtf8()).toLower()];
            if (gid > 0)
                data->setGenreId(gid);

            // Commit track info to database
            data->dumpToDatabase();

            // Update the cache
            m_artistid[QString(data->Artist().toUtf8()).toLower()] =
                data->getArtistId();

            m_genreid[QString(data->Genre().toUtf8()).toLower()] =
                data->getGenreId();

            album_cache_string = data->getArtistId() + "#"
                + QString(data->Album().toUtf8()).toLower();
            m_albumid[album_cache_string] = data->getAlbumId();
            delete data;
        }

        delete decoder;
    }
}
Exemplo n.º 14
0
int disasm_main(int argc, char **argv) {
  bool showHelp;
  string outFileName("a.out.s"), archString("8w32/32/8");
  

  /* Get command line arguments. */
  CommandLineArgFlag          fh("-h", "--help", "", showHelp);
  CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
  CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);

  if (argc != 0) CommandLineArg::readArgs(argc-1, argv);

  if (argc == 0 || showHelp) {
    cout << Help::disasmHelp;
    exit(0);
  }

  ifstream objFile(argv[argc-1]);
  ofstream outFile(outFileName.c_str());
  ArchDef arch(archString);

  if (!objFile) {
    cout << "Disassembler could not open \"" << argv[argc-1] 
         << "\" for reading.\n";
    exit(1);
  }

  if (!outFile) {
    cout << "Disassembler could not open \"" << outFileName 
         << "\" for output.\n";
    exit(1);
  }

  HOFReader hr(arch);
  Obj *o = hr.read(objFile);
  objFile.close();
  Decoder *dec;

  switch (arch.getEncChar()) {
    case 'b': dec = new ByteDecoder(arch); break;
    case 'w': dec = new WordDecoder(arch); break;
    default:
      cout << "Unrecognized encoding character for disassembler.\n";
      exit(1);
  }

  /* Decode the chunks read from the object. */
  for (Size j = 0; j < o->chunks.size(); j++) {
    Chunk *&c = o->chunks[j];
    if (c->flags & EX_USR) {
      TextChunk *tc;
      DataChunk *dc;
      if ((dc = dynamic_cast<DataChunk*>(c)) != NULL) {
        TextChunk *tc = new TextChunk(dc->name);
        dec->decodeChunk(*tc, *dc);
        delete dc;
        c = tc;
      }
    }
  }
  delete dec;

  AsmWriter aw(arch);
  aw.write(outFile, *o);
  outFile.close();

  delete o;

  return 0;
}
Exemplo n.º 15
0
 bool finishSection(const SectionRange& range, const char* name) {
     return d_.finishSection(range, name);
 }
Exemplo n.º 16
0
int w_Decoder_getBitDepth(lua_State *L)
{
	Decoder *t = luax_checkdecoder(L, 1);
	lua_pushinteger(L, t->getBitDepth());
	return 1;
}
Exemplo n.º 17
0
static bool decodeDataObject(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
{
    RefPtr<DataObjectGtk> data = DataObjectGtk::create();

    bool hasText;
    if (!decoder.decode(hasText))
        return false;
    if (hasText) {
        String text;
        if (!decoder.decode(text))
            return false;
        data->setText(text);
    }

    bool hasMarkup;
    if (!decoder.decode(hasMarkup))
        return false;
    if (hasMarkup) {
        String markup;
        if (!decoder.decode(markup))
            return false;
        data->setMarkup(markup);
    }

    bool hasURL;
    if (!decoder.decode(hasURL))
        return false;
    if (hasURL) {
        String url;
        if (!decoder.decode(url))
            return false;
        data->setURL(URL(URL(), url), String());
    }

    bool hasURIList;
    if (!decoder.decode(hasURIList))
        return false;
    if (hasURIList) {
        String uriList;
        if (!decoder.decode(uriList))
            return false;
        data->setURIList(uriList);
    }

    bool hasImage;
    if (!decoder.decode(hasImage))
        return false;
    if (hasImage) {
        GRefPtr<GdkPixbuf> image;
        if (!decodeImage(decoder, image))
            return false;
        data->setImage(image.get());
    }

    bool hasUnknownTypeData;
    if (!decoder.decode(hasUnknownTypeData))
        return false;
    if (hasUnknownTypeData) {
        HashMap<String, String> unknownTypes;
        if (!decoder.decode(unknownTypes))
            return false;

        auto end = unknownTypes.end();
        for (auto it = unknownTypes.begin(); it != end; ++it)
            data->setUnknownTypeData(it->key, it->value);
    }

    dataObject = data;

    return true;
}
Exemplo n.º 18
0
int w_Decoder_getSampleRate(lua_State *L)
{
	Decoder *t = luax_checkdecoder(L, 1);
	lua_pushinteger(L, t->getSampleRate());
	return 1;
}
Exemplo n.º 19
0
void scan_image (const char *filename)
{
    scanner.reset();
    // normally scanner would reset associated decoder,
    // but this debug program connects them manually
    // (to make intermediate state more readily available)
    // so decoder must also be reset manually
    decoder.reset();

    Magick::Image image;
    image.read(filename);
    string file = image.baseFilename();
    size_t baseidx = file.rfind('/');
    if(baseidx != string::npos)
        file = file.substr(baseidx + 1, file.length() - baseidx - 1);
    ofstream svg((file + ".svg").c_str());

    unsigned inwidth = image.columns();
    unsigned flush1 = inwidth / 32;
    unsigned flush0 = 2;
    unsigned width = inwidth + flush1 + flush0;
    unsigned height = image.rows();
    unsigned midy = (height + 1) / 2 + 2;
    image.crop(Magick::Geometry(inwidth, 1, 0, midy));
    image.size(Magick::Geometry(width, 1, 0, 0));

    svg << "<?xml version='1.0'?>" << endl
        << "<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'"
        << " 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>" << endl
        << "<svg version='1.1' id='top'"
        << " width='10in' height='6in' preserveAspectRatio='xMinYMid slice'"
        << " overflow='visible' viewBox='0,0 " << width * 2 << ",384'"
        << " xmlns:xlink='http://www.w3.org/1999/xlink'"
        << " xmlns='http://www.w3.org/2000/svg'>" << endl
        << "<defs><style type='text/css'><![CDATA[" << endl
        << "  * { stroke-linejoin: round; stroke-linecap: round;"
        <<      " stroke-width: .1; text-anchor: middle;"
        <<      " image-rendering: optimizeSpeed;"
        <<      " font-size: 6; font-weight: bold }" << endl
        << "  path { fill: none }" << endl
        << "  #zero { stroke: #00f }" << endl
        << "  #edges { stroke: #f00 }" << endl
        << "  #cur-edge { stroke: #f44 }" << endl
        << "  #raw { stroke: orange }" << endl
        << "  #y0 { stroke: yellow }" << endl
        << "  #y1 { stroke: #0c0 }" << endl
        << "  #y2 { stroke: #0aa }" << endl
        << "  .y1thr { stroke: #f0f }" << endl
        << "  rect.bar { fill: black }" << endl
        << "  text.bar { fill: white }" << endl
        << "  rect.space { fill: white }" << endl
        << "  text.space { fill: black }" << endl
        << "  text.data { fill: #44f; font-size: 16 }" << endl
        << "]]></style></defs>" << endl
        << "<image width='" << width * 2 << "' height='384'"
        << " preserveAspectRatio='none'"
        << " xlink:href='" << file << ".png'/>" << endl
        << "<g transform='translate(1,384) scale(2,-.5)'>" << endl;

    // brute force
    unsigned raw[width];
    {
        // extract scan from image pixels
        image.modifyImage();
        Magick::Pixels view(image);
        Magick::PixelPacket *pxp = view.get(0, 0, width, 1);
        Magick::ColorYUV y;
        double max = 0;
        svg << "<path id='raw' d='M";
        unsigned i;
        for(i = 0; i < inwidth; i++, pxp++) {
            y = *pxp;
            if(max < y.y())
                max = y.y();
            raw[i] = (unsigned)(y.y() * 0x100);
            svg << ((i != 1) ? " " : " L ") << i << "," << raw[i];
            y.u(0);
            y.v(0);
            *pxp = y;
        }
        y.y(max); /* flush scan FIXME? */
        for(; i < inwidth + flush1; i++) {
            raw[i] = (unsigned)(y.y() * 0x100);
            svg << " " << i << "," << raw[i];
            *pxp++ = y;
        }
        y.y(0);
        for(; i < width; i++) {
            raw[i] = (unsigned)(y.y() * 0x100);
            svg << " " << i << "," << raw[i];
            *pxp++ = y;
        }
        view.sync();
        svg << "'/>" << endl
            << "</g>" << endl;
    }
    image.depth(8);
    image.write(file + ".png");

    // process scan and capture calculated values
    unsigned cur_edge[width], last_edge[width];
    int y0[width], y1[width], y2[width], y1_thr[width];

    svg << "<g transform='translate(-3)'>" << endl;
    for(unsigned i = 0; i < width; i++) {
        int edge = scanner.scan_y(raw[i]);
        unsigned x;
        zbar_scanner_get_state(scanner.get_c_scanner(), &x,
                                &cur_edge[i], &last_edge[i],
                                &y0[i], &y1[i], &y2[i], &y1_thr[i]);
#ifdef DEBUG_SCANNER
        cerr << endl;
#endif
        cur_edge[i] += i - x;
        if(edge) {
            last_edge[i] += i - x;
            unsigned w = scanner.get_width();
            svg << "<rect x='" << (2. * (last_edge[i] - w) / ZBAR_FRAC)
                << "' width='" << (w * 2. / ZBAR_FRAC)
                << "' height='32' class='"
                << (scanner.get_color() ? "space" : "bar") << "'/>" << endl
                << "<text transform='translate("
                << ((2. * last_edge[i] - w) / ZBAR_FRAC) - 3
                << ",16) rotate(90)' class='"
                << (scanner.get_color() ? "space" : "bar") << "'>" << endl
                << w << "</text>" << endl;
            zbar_symbol_type_t sym = decoder.decode_width(w);
            if(sym > ZBAR_PARTIAL) {
                svg << "<text transform='translate("
                    << (2. * (last_edge[i] + w) / ZBAR_FRAC)
                    << ",208) rotate(90)' class='data'>"
                    << decoder.get_data_string() << "</text>" << endl;
            }
        }
        else
            last_edge[i] = 0;
    }

    svg << "</g>" << endl
        << "<g transform='translate(-3,384) scale(2,-.5)'>" << endl
        << "<path id='edges' d='";
    for(unsigned i = 0; i < width; i++)
        if(last_edge[i])
            svg << " M" << ((double)last_edge[i] / ZBAR_FRAC) << ",0v768";
    svg << "'/>" << endl
        << "</g>" << endl
        << "<g transform='translate(-1,384) scale(2,-.5)'>" << endl
        << "<path id='y0' d='M";
    for(unsigned i = 0; i < width; i++)
        svg << ((i != 1) ? " " : " L ") << i << "," << y0[i];
    svg << "'/>" << endl
        << "</g>" << endl;

    svg << "<g transform='translate(-1,128) scale(2,-1)'>" << endl
        << "<line id='zero' x2='" << width << "'/>" << endl
        << "<path id='cur-edge' d='";
    for(unsigned i = 1; i < width - 1; i++)
        if(!last_edge[i + 1] && (cur_edge[i] != cur_edge[i + 1]))
            svg << " M" << ((double)cur_edge[i] / ZBAR_FRAC) - 1 << ",-32v64";
    svg << "'/>" << endl
        << "<path class='y1thr' d='M";
    for(unsigned i = 0; i < width; i++)
        svg << ((i != 1) ? " " : " L ") << i << "," << y1_thr[i];
    svg << "'/>" << endl
        << "<path class='y1thr' d='M";
    for(unsigned i = 0; i < width; i++)
        svg << ((i != 1) ? " " : " L ") << i << "," << -y1_thr[i];
    svg << "'/>" << endl
        << "<path id='y1' d='M";
    for(unsigned i = 0; i < width; i++)
        svg << ((i != 1) ? " " : " L ") << (i - 0.5) << "," << y1[i];
    svg << "'/>" << endl
        << "<path id='y2' d='M";
    for(unsigned i = 0; i < width; i++)
        svg << ((i != 1) ? " " : " L ") << i << "," << y2[i];
    svg << "'/>" << endl
        << "</g>" << endl;

    svg << "</svg>" << endl;
}
Exemplo n.º 20
0
 bool fail(const char* msg) {
     return d_.fail(msg);
 }
void mexFunction(	int nlhs, mxArray *plhs[], 
				 int nrhs, const mxArray*prhs[] ) 
{ 
	/* retrive arguments */
	if( nrhs<4 ) 
		mexErrMsgTxt("4 input arguments are required."); 
    if( nlhs!=1 ) 
        mexErrMsgTxt("1 output arguments are required."); 
	// first argument : input array
	int n = mxGetM(prhs[0]); 
	int p = mxGetN(prhs[0]);
    if( p>1 )
        mexErrMsgTxt("Works only for vector arrays."); 
    int dir = (int) *mxGetPr(prhs[1]);
    double* x = mxGetPr(prhs[0]);

    if( mxGetM(prhs[3])!=2 && mxGetN(prhs[3])!=2 )
        mexErrMsgTxt("known_bounds must be of size 2."); 
    int known_size = (int) *mxGetPr(prhs[2]);

    // lower and upper bounds on the int to code
    int known_a = (int) mxGetPr(prhs[3])[0];
    int known_b = (int) mxGetPr(prhs[3])[1];
    bool coding_size = true;
    if( known_size>0 )          // the decoder will know the size and provide it
        coding_size = false;
    bool coding_bounds = false;
    if( known_a==known_b && known_b==-1 )
        coding_bounds = true;  // the decoder will not know the bounds and pr

    // create encoderovide it    
    int capacity = HISTO_CAPACITY;       // capacity of histogram for arithmetic coder  
    EscapeCoder* entropy = new EscapeCoder(capacity);

    if( dir==1 )
    {
        // compute range of the data
        int a = 1<<20, b = -(1<<20); 
        for( int i=0; i<n; ++i )
        {
            if( x[i]<a )
                a = (int) x[i];
            if( x[i]>b )
                b = (int) x[i];
        }
        int subrange = b-a+1;
		if( subrange>=HISTO_CAPACITY )
			mexErrMsgTxt( "Too much symbols." );

        // Open output file
        ofstream outfile(filename, ios::out | ios::trunc | ios::binary);
        if( !outfile )
            mexErrMsgTxt("Cannot open file."); 
        // Create I/O interface object for arithmetic coder
        Encoder* encoder = new Encoder( outfile );

        // set the number of symbols
        entropy->setNSym( subrange );

        // code the size of the image and range
        if( coding_size )
            encoder->writePositive(n);
        else if( known_size!=n )
            mexErrMsgTxt("The provided size does not match the real size."); 
        if( coding_bounds )
            encoder->writeInt(a);
        else if( known_a>a )
            mexErrMsgTxt("The provided bound does not match the real size."); 
        if( coding_bounds )
            encoder->writeInt(b);
        else if( known_b<b )
            mexErrMsgTxt("The provided bound does not match the real size."); 

        // perform coding
        for( int i=0; i<n; i++ ) 
        {
            // rescale to positive integers
            int symbol = (int) (x[i]-a);
            assert( symbol>=0 && symbol<subrange );
            entropy->write(encoder, symbol, TRUE);
        }
        // finish encoding
        encoder->flush();
        delete encoder;
        outfile.close();

        // reopen output file
        FILE* fin = fopen( filename, "rb" );
        if( fin==NULL )
            mexErrMsgTxt("Cannot open file."); 
        int nbr_bytes = 0;
        // compute number of bytes
        while( getc(fin)!=EOF )
            nbr_bytes++;
        fclose(fin);
        // retrieve results in byte
        fin = fopen( filename, "rb" );
        plhs[0] = mxCreateNumericMatrix( nbr_bytes, 1, mxDOUBLE_CLASS, mxREAL );
        double* y = mxGetPr( plhs[0] );
        for( int i=0; i<nbr_bytes; ++i )
        {
            y[i] = (double) getc(fin);
        }
        fclose(fin);
    }
    else
    {
        // write data to a file byte by byte
        FILE* fin = fopen( filename, "wb" );
        if( fin==NULL )
            mexErrMsgTxt("Cannot open file."); 
        for( int i=0; i<n; ++i )
        {
            char c = (char) x[i];
            fwrite( &c, sizeof(char), 1, fin );
        }
        fclose(fin);

        // open compressed image file
        ifstream infile( filename, ios::in | ios::nocreate | ios::binary);
        if( !infile )
            error( "Unable to open file %s", filename );
        // Create I/O interface object for arithmetic decoder
        Decoder *decoder = new Decoder( infile );

        // retrieve size of the data
        int a, b;
        if( coding_size )
            n = decoder->readPositive();
        else
            n = known_size;
        if( coding_bounds )
            a = decoder->readInt();
        else
            a = known_a;
        if( coding_bounds )
            b = decoder->readInt();
        else
            b = known_b;
        int subrange = b-a+1;

        // set the number of symbols
        entropy->setNSym( subrange );

        // retrieve the data
        plhs[0] = mxCreateNumericMatrix( n, 1, mxDOUBLE_CLASS, mxREAL );
        double* y = mxGetPr( plhs[0] );

        for( int i=0; i<n; ++i ) 
        {
            int symbol = entropy->read( decoder, TRUE );
            assert( symbol<subrange && symbol >= 0);
            y[i] = a + symbol;
        }
    }
}
Exemplo n.º 22
0
 bool done() const {
     return d_.done();
 }
Exemplo n.º 23
0
static bool
DecodeSignatureSection(JSContext* cx, Decoder& d, ModuleGeneratorData* init)
{
    if (!d.readCStringIf(SigLabel))
        return true;

    uint32_t sectionStart;
    if (!d.startSection(&sectionStart))
        return Fail(cx, d, "expected signature section byte size");

    uint32_t numSigs;
    if (!d.readVarU32(&numSigs))
        return Fail(cx, d, "expected number of signatures");

    if (numSigs > MaxSigs)
        return Fail(cx, d, "too many signatures");

    if (!init->sigs.resize(numSigs))
        return false;
    if (!init->sigToTable.resize(numSigs))
        return false;

    SigSet dupSet(cx);
    if (!dupSet.init())
        return false;

    for (uint32_t sigIndex = 0; sigIndex < numSigs; sigIndex++) {
        uint32_t numArgs;
        if (!d.readVarU32(&numArgs))
            return Fail(cx, d, "bad number of signature args");

        if (numArgs > MaxArgsPerFunc)
            return Fail(cx, d, "too many arguments in signature");

        ExprType result;
        if (!DecodeExprType(cx, d, &result))
            return false;

        ValTypeVector args;
        if (!args.resize(numArgs))
            return false;

        for (uint32_t i = 0; i < numArgs; i++) {
            if (!DecodeValType(cx, d, &args[i]))
                return false;
        }

        init->sigs[sigIndex] = Sig(Move(args), result);

        SigSet::AddPtr p = dupSet.lookupForAdd(init->sigs[sigIndex]);
        if (p)
            return Fail(cx, d, "duplicate signature");

        if (!dupSet.add(p, &init->sigs[sigIndex]))
            return false;
    }

    if (!d.finishSection(sectionStart))
        return Fail(cx, d, "decls section byte size mismatch");

    return true;
}
Exemplo n.º 24
0
LinkedDecoder::~LinkedDecoder()
{
	Decoder *parent = getParent();
	if (parent) parent->unlinkChild(m_linkedIdx);
}