コード例 #1
0
bool InstructionContext::TranslateEvmFile(LPCTSTR szInFile, LPCTSTR szOutFile)
{
    MemoryMappedFile mmf;
    if (!mmf.MapFlie(szInFile))
    {
        cerr << "Cannot open evm file.\n";
        return false;
    }

    Header* header = (Header*) mmf.data();
    trace("Header codeSize = %u, dataSize = %u, initialDataSize = %u\n", 
        header->codeSize, header->dataSize, header->initialDataSize);
    // verify
    if (header->signature != SIGNATURE_ESET_VM1 
        || header->dataSize < header->initialDataSize
        || header->codeSize * 3 + header->initialDataSize + 20 != mmf.size())
    {
        cerr << "Invalid evm file.\n";
        return false;
    }

    Instruction* instruction = (Instruction*)(header + 1);

    //section.push_back(0xCC); // Debug

    vector<size_t> instructionOffsets;
    instructionOffsets.resize(header->codeSize);
    for (uint32_t i = 0; i < header->codeSize; ++i, ++instruction)
    {
        instructionOffsets[i] = section.size();
        if (!AddInstruction(
                instruction->Opcode, 
                instruction->Destination, 
                instruction->Source, 
                i, 
                header->dataSize))
        {
            return false;
        }
    }

    // Handle jumps
    for (auto it(jumps.begin()), itEnd(jumps.end()); it != itEnd; ++it)
    {
        for each(auto offset in it->second)
        {
            uint32_t* pos = (uint32_t*) &section[offset];
            size_t instructionIndex = it->first + 1;
            if (instructionIndex >= instructionOffsets.size())
            {
                cerr << "Error: Jump address out of bounds\n";
                return false;
            }
            *pos = instructionOffsets[instructionIndex] - sizeof(uint32_t) - offset;
        }
    }

    return MakeExecutable(szOutFile, instruction, header->initialDataSize, header->dataSize);
}
コード例 #2
0
ファイル: win32_bitmap.cpp プロジェクト: dubhater/zimg
	impl(const char *path, int width, int height, int bit_count) : m_writable{ true }
	{
		size_t file_size = 0;

		if (width < 0 || height < 0)
			throw std::invalid_argument{ "invalid bitmap dimensions" };
		if (bit_count != 24 && bit_count != 32)
			throw std::invalid_argument{ "unsupported biBitCount" };

		file_size += sizeof(BITMAPFILEHEADER);
		file_size += sizeof(BITMAPINFOHEADER);
		file_size += height * bitmap_row_size(width, bit_count);

		m_mmap = MemoryMappedFile{ path, file_size, MemoryMappedFile::CREATE_TAG };

		m_bitmap = BitmapFileData{ m_mmap.size(), m_mmap.write_ptr(), true };
		m_bitmap.init(m_mmap.size(), width, height, bit_count);
	}