コード例 #1
0
void TUserIniFile::LoadValues()
{
  TStringList* ASections, *AValues;
  if ((FileName != "") && FileExists(FileName)) {
    ClearObjects();
    ASections = new TStringList();
    try {
      ReadSections(ASections);
      for(int i=0; i < ASections->Count; i++) {
        AValues = new TStringList();
        ReadSectionValues(ASections->Strings[i], AValues);
        Sections->AddObject(ASections->Strings[i], (TObject*)AValues);
      };
    }
    __finally {
      delete ASections;
    };
  };
コード例 #2
0
ファイル: RawDataReader.cpp プロジェクト: guozanhua/CodeXL
// ---------------------------------------------------------------------------
// Name:        RawDataReader::RawDataInitialize
// Description: This function will open the raw file and read the configuration records.
// Author:      Rajeeb Barman
// Date:        26/09/2013
// ---------------------------------------------------------------------------
AMDTResult RawDataReader::RawDataInitialize(const wchar_t* pFileName, bool isOnline)
{
    pFileName = pFileName;

    AMDTInt32 ret = 0;
    g_isOnline = isOnline;

    if (!g_isOnline)
    {
#if 0 //File support
        //Open the raw data file
        ret = OpenFile(&m_hRawFile, pFileName, L"rb");

        if (m_hRawFile == NULL)
        {
            ret = AMDT_ERROR_FAIL;
        }

        if (AMDT_STATUS_OK == ret)
        {
            //read file to a buffer
            SeekFile(m_hRawFile, 0, SEEK_SET);
            size = ReadFile(m_hRawFile, (AMDTUInt8*) m_fileBuffer, FILE_BUFFER_SIZE);
        }

#endif
    }
    else
    {
        //If online, read from buffer
        AMDTUInt32 clientIdx = 0;
        FILE_HEADER header;
        AMDTUInt32 res = 0;

        ret = GetPowerDriverClientId(&clientIdx);

        if (AMDT_STATUS_OK == ret)
        {
            header.ulClientId = clientIdx;
            header.ulBufferId = 0;
            header.uliBuffer = reinterpret_cast<uint64>(m_pBufferHeader);
            ret = CommandPowerDriver(DRV_CMD_TYPE_IN_OUT,
                                     IOCTL_GET_FILE_HEADER_BUFFER,
                                     &header,
                                     sizeof(FILE_HEADER),
                                     &header,
                                     sizeof(FILE_HEADER),
                                     &res);
        }
    }

    if (AMDT_STATUS_OK == ret)
    {
        //First section of the raw data file is file header
        ret = ReadFileHeader();
    }

    if (AMDT_STATUS_OK == ret)
    {
        //Allocate memory for a raw buffer chunk.
        m_offset = m_rawDataHdl.m_fileHdr.m_rawDataOffset;

        //Read section headers
        ret = ReadSections();
    }

    if (AMDT_STATUS_OK == ret)
    {
        if (!g_isOnline)
        {
            //Calculate the length of the file
            PwrSeekFile(m_hRawFile, 0, SEEK_END);
            m_fileLen = ftell(m_hRawFile);

            //Raw record offset;
            m_curr = m_offset = m_rawDataHdl.m_fileHdr.m_rawDataOffset;
            m_onlineOffset = m_offset;
        }
    }

    return ret;
}
コード例 #3
0
ファイル: Method.cpp プロジェクト: secdec/codepulse
	/// <summary>Read in a method body and any section handlers.</summary>
	/// <remarks>Also converts all short branches to long branches and calls <c>RecalculateOffsets</c></remarks>
	void Method::ReadBody()
	{
		_ASSERTE(m_header.CodeSize != 0);
		_ASSERTE(GetPosition() == 0);

		while (GetPosition() < m_header.CodeSize)
		{
			Instruction* pInstruction = new Instruction();
			pInstruction->m_offset = GetPosition();
			pInstruction->m_origOffset = pInstruction->m_offset;

			BYTE op1 = REFPRE;
			BYTE op2 = Read<BYTE>();
			if (STP1 == op2)
			{
				op1 = STP1;
				op2 = Read<BYTE>();
			}

			OperationDetails &details = Operations::m_mapOpsOperationDetails[MAKEWORD(op1, op2)];
			pInstruction->m_operation = details.canonicalName;
			switch (details.operandSize)
			{
			case Null:
				break;
			case Byte:
				pInstruction->m_operand = Read<BYTE>();
				break;
			case Word:
				pInstruction->m_operand = Read<USHORT>();
				break;
			case Dword:
				pInstruction->m_operand = Read<ULONG>();
				break;
			case Qword:
				pInstruction->m_operand = Read<ULONGLONG>();
				break;
			default:
				break;
			}

			// are we a branch or a switch
			pInstruction->m_isBranch = (details.controlFlow == BRANCH || details.controlFlow == COND_BRANCH);

			if (pInstruction->m_isBranch && pInstruction->m_operation != CEE_SWITCH)
			{
				if (details.operandSize == 1)
				{
					pInstruction->m_branchOffsets.push_back(static_cast<char>(static_cast<BYTE>(pInstruction->m_operand)));
				}
				else
				{
					pInstruction->m_branchOffsets.push_back(static_cast<ULONG>(pInstruction->m_operand));
				}
			}

			if (pInstruction->m_operation == CEE_SWITCH)
			{
				auto numbranches = static_cast<DWORD>(pInstruction->m_operand);
				while (numbranches-- != 0) pInstruction->m_branchOffsets.push_back(Read<long>());
			}

			m_instructions.push_back(pInstruction);
		}

		ReadSections();

		SetBuffer(nullptr);

		ResolveBranches();

		ConvertShortBranches();

		RecalculateOffsets();
	}
コード例 #4
0
ファイル: DefFile.cpp プロジェクト: doniexun/OrangeC
bool DefFile::Read()
{
    stream = new std::fstream(fileName.c_str(), std::ios::in);
    if (stream != NULL)
    {
        try
        {
            lineno = 0;
            NextToken();
            while (!stream->eof())
            {
                if (token->IsEnd())
                {
                    NextToken();
                }
                else if (!token->IsKeyword())
                {
                    throw new std::runtime_error("Invalid directive");
                }
                else
                {
                    switch(token->GetKeyword())
                    {
                        case edt_name:
                            ReadName();
                            break;
                        case edt_library:
                            ReadLibrary();
                            break;
                        case edt_exports:
                            ReadExports();
                            break;
                        case edt_imports:
                            ReadImports();
                            break;
                        case edt_description:
                            ReadDescription();
                            break;
                        case edt_stacksize:
                            ReadStacksize();
                            break;
                        case edt_heapsize:
                            ReadHeapsize();
                            break;
                        case edt_code:
                            ReadCode();
                            break;
                        case edt_data:
                            ReadData();
                            break;
                        case edt_sections:
                            ReadSections();
                            break;
                        default:
                            throw new std::runtime_error("Invalid directive");
                    }
                }
            }
        }
        catch (std::runtime_error *e)
        {
            std::cout << fileName << "(" << lineno << "): " << e->what() << std::endl ;
            delete e;
        }
        delete stream;
    }
    else
    {
        std::cout << "File '" << name << "' not found." << std::endl;
    }
    return true;
}