bool DefFile::Write() { stream = new std::fstream(fileName.c_str(), std::ios::out); //if (stream != NULL) { WriteName(); WriteLibrary(); WriteExports(); WriteImports(); WriteDescription(); WriteStacksize(); WriteHeapsize(); WriteCode(); WriteData(); WriteSections(); delete stream; } return true; }
/// <summary>Write the method to a supplied buffer</summary> /// <remarks><para>The buffer must be of the size supplied by <c>GetMethodSize</c>.</para> /// <para>Currently only write methods with 'Fat' headers and 'Fat' Sections - simpler.</para> /// <para>The buffer will normally be allocated by a call to <c>IMethodMalloc::Alloc</c></para></remarks> void Method::WriteMethod(IMAGE_COR_ILMETHOD* pMethod) { BYTE* pCode; auto fatImage = static_cast<COR_ILMETHOD_FAT*>(&pMethod->Fat); m_header.Flags &= ~CorILMethod_MoreSects; if (m_exceptions.size() > 0) { m_header.Flags |= CorILMethod_MoreSects; } memcpy(fatImage, &m_header, m_header.Size * sizeof(DWORD)); pCode = fatImage->GetCode(); SetBuffer(pCode); for (auto it = m_instructions.begin(); it != m_instructions.end(); ++it) { auto& details = Operations::m_mapNameOperationDetails[(*it)->m_operation]; if (details.op1 == REFPRE) { Write<BYTE>(details.op2); } else if (details.op1 == MOOT) { continue; } else { Write<BYTE>(details.op1); Write<BYTE>(details.op2); } switch (details.operandSize) { case Null: break; case Byte: Write<BYTE>(static_cast<BYTE>((*it)->m_operand)); break; case Word: Write<USHORT>(static_cast<USHORT>((*it)->m_operand)); break; case Dword: Write<ULONG>(static_cast<ULONG>((*it)->m_operand)); break; case Qword: Write<ULONGLONG>((*it)->m_operand); break; default: break; } if ((*it)->m_operation == CEE_SWITCH) { for (auto offsetIter = (*it)->m_branchOffsets.begin(); offsetIter != (*it)->m_branchOffsets.end(); ++offsetIter) { Write<long>(*offsetIter); } } } WriteSections(); }