Пример #1
0
/* static */
void XDataAllocator::Unregister(XDataAllocation * xdataInfo)
{
#ifndef _WIN32
    Assert(ReadHead(xdataInfo->address));  // should be non-empty .eh_frame
    __DEREGISTER_FRAME(xdataInfo->address);
#endif
}
Пример #2
0
void fmms::Run(string base)
{
    
    // Collect mms info
    for ( int i = 0; i < mms.size(); i++ )
    {
        print mmsFile(mms[i].c_str(), base);
        string link("<A href=\"" + mms[i] 
                + "\" target=\"mmsframe\">" 
                + mms[i] + "</A><BR>\n");
        file->Write(link.c_str());
        string path = strPath + "/" + mms[i];
        string slm = slmPath + "/" + mms[i];
        
        // Header
        ReadHead(path, &mmsFile);

        // Attachment links
       string base;
        Attached(path, slm, &mmsFile);

        // Message
        ReadText(path, &mmsFile);

        mmsFile.CloseTable(0,1);
        mmsFile.Close();
    }
}
Пример #3
0
/* static */
void XDataAllocator::Register(XDataAllocation * xdataInfo, ULONG_PTR functionStart, DWORD functionSize)
{
#ifdef _WIN32
    ULONG_PTR baseAddress = functionStart;
    xdataInfo->pdata.BeginAddress = (DWORD)(functionStart - baseAddress);
    xdataInfo->pdata.UnwindData = (DWORD)((intptr_t)xdataInfo->address - baseAddress);

    NTSTATUS status = NtdllLibrary::Instance->AddGrowableFunctionTable(&xdataInfo->functionTable,
        &xdataInfo->pdata,
        /*MaxEntryCount*/ 1,
        /*Valid entry count*/ 1,
        /*RangeBase*/ functionStart,
        /*RangeEnd*/ functionStart + functionSize);
    BOOLEAN success = NT_SUCCESS(status);
    Assert(!success || xdataInfo->functionTable != nullptr);

    if (!success)
    {
        Js::Throw::XDataRegistrationError(status, functionStart);
    }

#if DBG
    // Validate that the PDATA registration succeeded
    ULONG64            imageBase = 0;
    RUNTIME_FUNCTION  *runtimeFunction = RtlLookupFunctionEntry((DWORD64)functionStart, &imageBase, nullptr);
    Assert(runtimeFunction != NULL);
#endif

#else  // !_WIN32
    Assert(ReadHead(xdataInfo->address));  // should be non-empty .eh_frame
    __REGISTER_FRAME(xdataInfo->address);
#endif
}
Пример #4
0
void TCPConnection::CallBack_Read_Body(const boost::system::error_code &ec, size_t size)
{
    if ( ! ec )
    {
        Server  *srv = Server::GetInstance();
        char *buf = (char*)srv->malloc();
        memcpy(buf,m_buf,size + sizeof(STR_PackHead));
        //srv->RunTask(boost::bind(&CommandParse,&m_socket,buf));
        CommandParse(shared_from_this(),buf);
        srv->free(buf);

        //至此,已处理完一个完整数据包
        m_read_lock.unlock();
        ReadHead();
    }
    else if ( size == 0 || ec == boost::asio::error::eof || ec == boost::asio::error::shut_down)
    {
        Logger::GetLogger()->Debug("Client body Disconnected");
//        int fd = m_socket.native_handle();
        Server::GetInstance()->GetPlayerLogin()->SavePlayerOfflineData(shared_from_this() );
        Server::GetInstance()->GetPlayerLogin()->DeleteNameSock(shared_from_this() );
        SessionMgr::Instance()->RemoveSession(shared_from_this());
        m_read_lock.unlock();
    }
}
Пример #5
0
/* static */
void XDataAllocator::Unregister(XDataAllocation * xdataInfo)
{
#ifdef _WIN32
    // Delete the table
    if (AutoSystemInfo::Data.IsWin8OrLater())
    {
        NtdllLibrary::Instance->DeleteGrowableFunctionTable(xdataInfo->functionTable);
    }
    else
    {
        BOOLEAN success = RtlDeleteFunctionTable(&xdataInfo->pdata);
        Assert(success);
    }

#else  // !_WIN32
    Assert(ReadHead(xdataInfo->address));  // should be non-empty .eh_frame
    __deregister_frame(xdataInfo->address);
#endif
}
Пример #6
0
/* static */
void XDataAllocator::Register(XDataAllocation * xdataInfo, ULONG_PTR functionStart, DWORD functionSize)
{
#ifdef _WIN32
    ULONG_PTR baseAddress = functionStart;
    xdataInfo->pdata.BeginAddress = (DWORD)(functionStart - baseAddress);
    xdataInfo->pdata.EndAddress = (DWORD)(xdataInfo->pdata.BeginAddress + functionSize);
    xdataInfo->pdata.UnwindInfoAddress = (DWORD)((intptr_t)xdataInfo->address - baseAddress);

    BOOLEAN success = FALSE;
    if (AutoSystemInfo::Data.IsWin8OrLater())
    {
        DWORD status = NtdllLibrary::Instance->AddGrowableFunctionTable(&xdataInfo->functionTable,
            &xdataInfo->pdata,
            /*MaxEntryCount*/ 1,
            /*Valid entry count*/ 1,
            /*RangeBase*/ functionStart,
            /*RangeEnd*/ functionStart + functionSize);
        success = NT_SUCCESS(status);
        if (success)
        {
            Assert(xdataInfo->functionTable != nullptr);
        }
    }
    else
    {
        success = RtlAddFunctionTable(&xdataInfo->pdata, 1, functionStart);
    }
    Js::Throw::CheckAndThrowOutOfMemory(success);

#if DBG
    // Validate that the PDATA registration succeeded
    ULONG64            imageBase = 0;
    RUNTIME_FUNCTION  *runtimeFunction = RtlLookupFunctionEntry((DWORD64)functionStart, &imageBase, nullptr);
    Assert(runtimeFunction != NULL);
#endif

#else  // !_WIN32
    Assert(ReadHead(xdataInfo->address));  // should be non-empty .eh_frame
    __register_frame(xdataInfo->address);
#endif
}
Пример #7
0
/*
 *	Initializer
 */
void
InitArchiveFmt_Files(ArchiveHandle *AH)
{
	lclContext *ctx;

	/* Assuming static functions, this can be copied for each format. */
	AH->ArchiveEntryPtr = _ArchiveEntry;
	AH->StartDataPtr = _StartData;
	AH->WriteDataPtr = _WriteData;
	AH->EndDataPtr = _EndData;
	AH->WriteBytePtr = _WriteByte;
	AH->ReadBytePtr = _ReadByte;
	AH->WriteBufPtr = _WriteBuf;
	AH->ReadBufPtr = _ReadBuf;
	AH->ClosePtr = _CloseArchive;
	AH->PrintTocDataPtr = _PrintTocData;
	AH->ReadExtraTocPtr = _ReadExtraToc;
	AH->WriteExtraTocPtr = _WriteExtraToc;
	AH->PrintExtraTocPtr = _PrintExtraToc;

	AH->StartBlobsPtr = _StartBlobs;
	AH->StartBlobPtr = _StartBlob;
	AH->EndBlobPtr = _EndBlob;
	AH->EndBlobsPtr = _EndBlobs;

	/*
	 * Set up some special context used in compressing data.
	 */
	ctx = (lclContext *) calloc(1, sizeof(lclContext));
	AH->formatData = (void *) ctx;
	ctx->filePos = 0;

	/* Initialize LO buffering */
	AH->lo_buf_size = LOBBUFSIZE;
	AH->lo_buf = (void *) malloc(LOBBUFSIZE);
	if (AH->lo_buf == NULL)
		die_horribly(AH, modulename, "out of memory\n");

	/*
	 * Now open the TOC file
	 */
	if (AH->mode == archModeWrite)
	{

		write_msg(modulename, "WARNING:\n"
				  "  This format is for demonstration purposes; it is not intended for\n"
				  "  normal use. Files will be written in the current working directory.\n");

		if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
			AH->FH = fopen(AH->fSpec, PG_BINARY_W);
		else
			AH->FH = stdout;

		if (AH->FH == NULL)
			die_horribly(NULL, modulename, "could not open output file: %s\n", strerror(errno));

		ctx->hasSeek = checkSeek(AH->FH);

		if (AH->compression < 0 || AH->compression > 9)
			AH->compression = Z_DEFAULT_COMPRESSION;


	}
	else
	{							/* Read Mode */

		if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
			AH->FH = fopen(AH->fSpec, PG_BINARY_R);
		else
			AH->FH = stdin;

		if (AH->FH == NULL)
			die_horribly(NULL, modulename, "could not open input file: %s\n", strerror(errno));

		ctx->hasSeek = checkSeek(AH->FH);

		ReadHead(AH);
		ReadToc(AH);
		/* Nothing else in the file... */
		if (fclose(AH->FH) != 0)
			die_horribly(AH, modulename, "could not close TOC file: %s\n", strerror(errno));
	}
}
Пример #8
0
int UnzipFile(const char *sourceFileName, const char *targetFileName)
{
    FILE *sourceFp = NULL, *targetFp = NULL;
    DataCode dataCodeArr[CODE_SIZE];
    HuffmanTreeNode *pTreeHead = NULL, *pTreeNode = NULL;
    UCHAR codeStream[CODE_SIZE], codeStr[CHAR_BIT], readData, writeData, lastBtyeLen;
    int codeStreamLen, i;

    if((sourceFp = fopen(sourceFileName, "rb")) == NULL)
    {
        printf("Error! ");
        return 1;
    }
    if((targetFp = fopen(targetFileName, "w+b")) == NULL)
    {
        printf("Error ! ");
        fclose(sourceFp);
        return 1;
    }

    ReadHead(sourceFp, dataCodeArr);
    fread(&lastBtyeLen,UCHAR_SIZE, 1, sourceFp);
    RebuildHuffmanTree(&pTreeHead, dataCodeArr);
    codeStreamLen = 0;
    while(!feof(sourceFp) || codeStreamLen > 0)
    {
        while(!feof(sourceFp) && codeStreamLen < CODE_SIZE - CHAR_BIT)
        {
            fread(&readData, UCHAR_SIZE, 1, sourceFp);
            ConvertToCodeStr(readData, codeStr);
            memcpy(codeStream+codeStreamLen, codeStr, CHAR_BIT);
            codeStreamLen += CHAR_BIT;
            if(feof(sourceFp))
                codeStreamLen -= lastBtyeLen + CHAR_BIT;
        }

        /* 通过编码查找原数据 */
        pTreeNode = pTreeHead;
        for(i = 0; i < codeStreamLen; i++)
        {
            if(codeStream[i] == 0)
            {
                pTreeNode = pTreeNode->leftChild;
                if(pTreeNode->leftChild == NULL)
                    break;
            }
            else
            {
                pTreeNode = pTreeNode->rightChild;
                if(pTreeNode->leftChild == NULL)
                    break;
            }
        }

        if(pTreeNode->rightChild != NULL) return 1;/* 对当前节点进行判断,若其左右孩子不为空,则为非节点,有错 */
        writeData = pTreeNode->data;
        fwrite(&writeData, UCHAR_SIZE, 1, targetFp);

        /* 读取之后要删除 */
        codeStreamLen -= i + 1;
        memcpy(codeStream, codeStream+i+1, codeStreamLen);
    }

    /* 清理 */
    FreeTree(&pTreeHead);
    for(i = 0; i < CODE_SIZE; ++i)
    {
        if(dataCodeArr[i].pCode != NULL)
        {
            free(dataCodeArr[i].pCode);
            dataCodeArr[i].pCode = NULL;
        }
    }
    fclose(sourceFp);
    fclose(targetFp);
    return 0;
}
Пример #9
0
void TCPConnection::Start()
{
    ReadHead();
}