本文整理汇总了C++中MemoryMappedFile::MapFlie方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryMappedFile::MapFlie方法的具体用法?C++ MemoryMappedFile::MapFlie怎么用?C++ MemoryMappedFile::MapFlie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryMappedFile
的用法示例。
在下文中一共展示了MemoryMappedFile::MapFlie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TranslateEvmFile
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*) §ion[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);
}