本文整理汇总了C#中ImageFileMachine类的典型用法代码示例。如果您正苦于以下问题:C# ImageFileMachine类的具体用法?C# ImageFileMachine怎么用?C# ImageFileMachine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageFileMachine类属于命名空间,在下文中一共展示了ImageFileMachine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: EmitHelloWorldConsoleExeAssembly
private static byte[] EmitHelloWorldConsoleExeAssembly(PortableExecutableKinds peKind, ImageFileMachine machine)
{
byte[] bytes;
var asmName = new AssemblyName { Name = "Dummy" + Guid.NewGuid() };
var asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
asmName,
System.Reflection.Emit.AssemblyBuilderAccess.Save);
var modBuilder = asmBuilder.DefineDynamicModule(asmName.Name, asmName.Name + ".exe");
var programTypeBuilder = modBuilder.DefineType("Program");
var mainMethodBuilder = programTypeBuilder.DefineMethod("Main", MethodAttributes.Static, typeof(void), Type.EmptyTypes);
var il = mainMethodBuilder.GetILGenerator();
il.EmitWriteLine("Hello, World!");
il.Emit(OpCodes.Ret);
asmBuilder.SetEntryPoint(mainMethodBuilder);
programTypeBuilder.CreateType();
asmBuilder.Save(asmName.Name + ".exe", peKind, machine);
try
{
bytes = File.ReadAllBytes(asmName.Name + ".exe");
}
finally
{
File.Delete(asmName.Name);
}
return bytes;
}
开发者ID:BGCX261,项目名称:zoompe-git,代码行数:26,代码来源:EmitSamplePEs.cs
示例2: WriteModule
internal static void WriteModule(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
ResourceSection resources, int entryPointToken, Stream stream)
{
if (stream == null)
{
string fileName = moduleBuilder.FullyQualifiedName;
bool mono = System.Type.GetType("Mono.Runtime") != null;
if (mono)
{
try
{
// Mono mmaps the file, so unlink the previous version since it may be in use
File.Delete(fileName);
}
catch { }
}
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, fs);
}
// if we're running on Mono, mark the module as executable by using a Mono private API extension
if (mono)
{
File.SetAttributes(fileName, (FileAttributes)(unchecked((int)0x80000000)));
}
}
else
{
WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, stream);
}
}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:32,代码来源:ModuleWriter.cs
示例3: AssemblyGen
internal AssemblyGen(AssemblyName name, string outDir, string outFileExtension, bool isDebuggable,
PortableExecutableKinds peKind, ImageFileMachine machine) {
ContractUtils.RequiresNotNull(name, "name");
#if SILVERLIGHT // AssemblyBuilderAccess.RunAndSave, Environment.CurrentDirectory
_myAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
_myModule = _myAssembly.DefineDynamicModule(name.Name, isDebuggable);
#else
if (outFileExtension == null) {
outFileExtension = ".dll";
}
if (outDir != null) {
try {
outDir = Path.GetFullPath(outDir);
} catch (Exception) {
throw Error.InvalidOutputDir();
}
try {
Path.Combine(outDir, name.Name + outFileExtension);
} catch (ArgumentException) {
throw Error.InvalidAsmNameOrExtension();
}
_outFileName = name.Name + outFileExtension;
_outDir = outDir;
}
// mark the assembly transparent so that it works in partial trust:
CustomAttributeBuilder[] attributes = new CustomAttributeBuilder[] {
new CustomAttributeBuilder(typeof(SecurityTransparentAttribute).GetConstructor(Type.EmptyTypes), new object[0])
};
if (outDir != null) {
#if CLR4
_myAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave, outDir, false, attributes);
#else
//The API DefineDynamicAssembly is obsolete in Dev10.
_myAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave, outDir,
null, null, null, null, false, attributes);
#endif
_myModule = _myAssembly.DefineDynamicModule(name.Name, _outFileName, isDebuggable);
} else {
_myAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run, attributes);
_myModule = _myAssembly.DefineDynamicModule(name.Name, isDebuggable);
}
_myAssembly.DefineVersionInfoResource();
#endif
_machine = machine;
_peKind = peKind;
_isDebuggable = isDebuggable;
if (isDebuggable) {
SetDebuggableAttributes();
}
}
开发者ID:techarch,项目名称:ironruby,代码行数:58,代码来源:AssemblyGen.cs
示例4: WriteModule
internal static void WriteModule(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
ResourceSection resources, int entryPointToken, Stream stream)
{
if (stream == null)
{
using (FileStream fs = new FileStream(moduleBuilder.FullyQualifiedName, FileMode.Create))
{
WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, fs);
}
}
else
{
WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, stream);
}
}
开发者ID:ztzg,项目名称:mono,代码行数:16,代码来源:ModuleWriter.cs
示例5: EmitLibraryAssembly
private static byte[] EmitLibraryAssembly(PortableExecutableKinds peKind, ImageFileMachine machine)
{
byte[] bytes;
var asmName = new AssemblyName { Name = "Dummy" + Guid.NewGuid() };
var asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
asmName,
System.Reflection.Emit.AssemblyBuilderAccess.Save);
asmBuilder.Save(asmName.Name, peKind, machine);
try
{
bytes = File.ReadAllBytes(asmName.Name);
}
finally
{
File.Delete(asmName.Name);
}
return bytes;
}
开发者ID:BGCX261,项目名称:zoompe-git,代码行数:18,代码来源:EmitSamplePEs.cs
示例6: CompilerOptions
public CompilerOptions(){
this.autoRef = true;
this.PEFileKind = PEFileKinds.ConsoleApplication;
this.PEKindFlags = PortableExecutableKinds.ILOnly;
this.PEMachineArchitecture = ImageFileMachine.I386;
this.fFast = true;
this.fPrint = true;
this.nWarningLevel = 4;
this.SourceFileNames = new ArrayList();
this.ImportFileNames = new ArrayList();
this.ManagedResourceFileNames = new Hashtable(10);
this.ManagedResources = new Hashtable(10);
this.Defines = new Hashtable();
string libpath = System.Environment.GetEnvironmentVariable("LIB");
if (libpath != null)
this.libpath = libpath;
else
this.libpath = "";
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:19,代码来源:jsc.cs
示例7: AssemblyGen
public AssemblyGen(string moduleName, string outDir, string outFile, bool emitDebugInfo,
bool staticTypes, PortableExecutableKinds peKind, ImageFileMachine machine)
{
this.outFileName = outFile;
this.outDir = outDir;
this.emitDebugInfo = emitDebugInfo;
this.staticTypes = staticTypes;
this.peKind = peKind;
this.machine = machine;
AssemblyName asmname = new AssemblyName();
AppDomain domain = System.Threading.Thread.GetDomain();
asmname.Name = Path.GetFileNameWithoutExtension(outFileName);
if (outFileName == null) {
myAssembly = domain.DefineDynamicAssembly(
asmname,
AssemblyBuilderAccess.Run,
outDir,
null);
myModule = myAssembly.DefineDynamicModule(moduleName);
} else {
myAssembly = domain.DefineDynamicAssembly(
asmname,
AssemblyBuilderAccess.RunAndSave,
outDir,
null);
myModule = myAssembly.DefineDynamicModule(outFileName, outFileName, emitDebugInfo);
}
myAssembly.DefineVersionInfoResource();
if (emitDebugInfo) SetDebuggableAttributes();
}
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:36,代码来源:AssemblyGen.cs
示例8: GetPEKind
public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
ModuleHandle.GetPEKind(GetNativeHandle(), out peKind, out machine);
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:4,代码来源:Module.cs
示例9: Save
[System.Security.SecurityCritical] // auto-generated
internal void Save(String fileName, bool isAssemblyFile, PortableExecutableKinds portableExecutableKind,
ImageFileMachine imageFileMachine)
{
// This is a helper called by AssemblyBuilder save to save information for the persistable modules.
if (m_moduleData.m_embeddedRes != null)
{
// There are embedded resources for this module
ResWriterData resWriter;
// Add each resource content into the to be saved PE file
for (resWriter = m_moduleData.m_embeddedRes; resWriter != null; resWriter = resWriter.m_nextResWriter)
{
if (resWriter.m_resWriter != null)
resWriter.m_resWriter.Generate();
byte[] resBytes = new byte[resWriter.m_memoryStream.Length];
resWriter.m_memoryStream.Flush();
resWriter.m_memoryStream.Position = 0;
resWriter.m_memoryStream.Read(resBytes, 0, resBytes.Length);
AddResource(GetNativeHandle(),
resWriter.m_strName,
resBytes,
resBytes.Length,
m_moduleData.FileToken,
(int)resWriter.m_attribute,
(int)portableExecutableKind,
(int)imageFileMachine);
}
}
DefineNativeResource(portableExecutableKind, imageFileMachine);
PEFileKinds pekind = isAssemblyFile ? ContainingAssemblyBuilder.m_assemblyData.m_peFileKind : PEFileKinds.Dll;
SavePEFile(GetNativeHandle(), fileName, m_EntryPoint.Token, (int)pekind, isAssemblyFile);
m_moduleData.m_isSaved = true;
}
开发者ID:crummel,项目名称:dotnet_coreclr,代码行数:40,代码来源:ModuleBuilder.cs
示例10: DefineNativeResource
[System.Security.SecurityCritical] // auto-generated
internal void DefineNativeResource(PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
{
string strResourceFileName = m_moduleData.m_strResourceFileName;
byte[] resourceBytes = m_moduleData.m_resourceBytes;
if (strResourceFileName != null)
{
DefineNativeResourceFile(GetNativeHandle(),
strResourceFileName,
(int)portableExecutableKind, (int)imageFileMachine);
}
else
if (resourceBytes != null)
{
DefineNativeResourceBytes(GetNativeHandle(),
resourceBytes, resourceBytes.Length,
(int)portableExecutableKind, (int)imageFileMachine);
}
}
开发者ID:crummel,项目名称:dotnet_coreclr,代码行数:20,代码来源:ModuleBuilder.cs
示例11: GetPEKind
public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
peKind = 0;
if ((cliHeader.Flags & CliHeader.COMIMAGE_FLAGS_ILONLY) != 0)
{
peKind |= PortableExecutableKinds.ILOnly;
}
switch (cliHeader.Flags & (CliHeader.COMIMAGE_FLAGS_32BITREQUIRED | CliHeader.COMIMAGE_FLAGS_32BITPREFERRED))
{
case CliHeader.COMIMAGE_FLAGS_32BITREQUIRED:
peKind |= PortableExecutableKinds.Required32Bit;
break;
case CliHeader.COMIMAGE_FLAGS_32BITREQUIRED | CliHeader.COMIMAGE_FLAGS_32BITPREFERRED:
peKind |= PortableExecutableKinds.Preferred32Bit;
break;
default:
// COMIMAGE_FLAGS_32BITPREFERRED by itself is illegal, so we ignore it
// (not setting any flag is ok)
break;
}
if (peFile.OptionalHeader.Magic == IMAGE_OPTIONAL_HEADER.IMAGE_NT_OPTIONAL_HDR64_MAGIC)
{
peKind |= PortableExecutableKinds.PE32Plus;
}
machine = (ImageFileMachine)peFile.FileHeader.Machine;
}
开发者ID:kenasogoo,项目名称:ikvm-fork,代码行数:27,代码来源:ModuleReader.cs
示例12: AssemblyGen
public AssemblyGen(string moduleName,
string outDir,
string outFile,
AssemblyGenAttributes generationAttributes,
PortableExecutableKinds peKind,
ImageFileMachine machine)
{
Contract.Requires(!String.IsNullOrEmpty(moduleName), "moduleName", "Module name cannot be a null reference or an empty string.");
Contract.Requires(outFile != null || !SaveAndReloadAssemblies, "outFile", "SaveAssemblies mode requires non-null output file name.");
_genAttrs = generationAttributes;
AssemblyName asmname = new AssemblyName();
AppDomain domain = AppDomain.CurrentDomain; //System.Threading.Thread.GetDomain();
_machine = machine;
_peKind = peKind;
_outFileName = outFile;
#if SILVERLIGHT // AssemblyBuilderAccess.RunAndSave, Environment.CurrentDirectory
asmname.Name = moduleName;
_myAssembly = domain.DefineDynamicAssembly(asmname, AssemblyBuilderAccess.Run);
_myModule = _myAssembly.DefineDynamicModule(moduleName, EmitDebugInfo);
#else
try {
outDir = Path.GetFullPath(String.IsNullOrEmpty(outDir) ? Environment.CurrentDirectory : outDir);
} catch (Exception e) {
throw new ArgumentException("Invalid output directory", e);
}
if (SaveAndReloadAssemblies
#if PEVERIFY
|| VerifyAssemblies
#endif
) {
_outDir = outDir;
}
if (moduleName == "ironscheme.boot.new")
{
_outDir = outDir = Path.Combine(outDir, "build");
_outFileName = "ironscheme.boot.dll";
}
// SymbolWriter fails on Mono for some reason
if (SaveAndReloadAssemblies) {
asmname.Name = moduleName == "ironscheme.boot.new" ? "ironscheme.boot" : moduleName;
if (File.Exists("DEVELOPMENT.snk"))
{
asmname.KeyPair = new StrongNameKeyPair(File.ReadAllBytes("DEVELOPMENT.snk"));
}
asmname.Version = new Version("1.0.0.0");
#pragma warning disable 0618
_myAssembly = domain.DefineDynamicAssembly(asmname, moduleName == "ironscheme.boot.new" ? AssemblyBuilderAccess.Save : AssemblyBuilderAccess.Save, outDir, null);
#pragma warning restore 0618
_myModule = _myAssembly.DefineDynamicModule( moduleName == "ironscheme.boot.new" ? "ironscheme.boot.dll" : _outFileName,
_outFileName, EmitDebugInfo);
} else {
asmname.Name = moduleName;
_myAssembly = domain.DefineDynamicAssembly(asmname, AssemblyBuilderAccess.Run);
_myModule = _myAssembly.DefineDynamicModule(moduleName, EmitDebugInfo);
}
_myAssembly.DefineVersionInfoResource();
#endif
if (EmitDebugInfo) SetDebuggableAttributes();
}
开发者ID:robertlj,项目名称:IronScheme,代码行数:70,代码来源:AssemblyGen.cs
示例13: CalculateProcArchIndex
internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags)
{
if (((uint)flags & 0xF0) == 0x70)
return ProcessorArchitecture.None;
if ((pek & System.Reflection.PortableExecutableKinds.PE32Plus) == System.Reflection.PortableExecutableKinds.PE32Plus)
{
switch (ifm)
{
case System.Reflection.ImageFileMachine.IA64:
return ProcessorArchitecture.IA64;
case System.Reflection.ImageFileMachine.AMD64:
return ProcessorArchitecture.Amd64;
case System.Reflection.ImageFileMachine.I386:
if ((pek & System.Reflection.PortableExecutableKinds.ILOnly) == System.Reflection.PortableExecutableKinds.ILOnly)
return ProcessorArchitecture.MSIL;
break;
}
}
else
{
if (ifm == System.Reflection.ImageFileMachine.I386)
{
if ((pek & System.Reflection.PortableExecutableKinds.Required32Bit) == System.Reflection.PortableExecutableKinds.Required32Bit)
return ProcessorArchitecture.X86;
if ((pek & System.Reflection.PortableExecutableKinds.ILOnly) == System.Reflection.PortableExecutableKinds.ILOnly)
return ProcessorArchitecture.MSIL;
return ProcessorArchitecture.X86;
}
if (ifm == System.Reflection.ImageFileMachine.ARM)
{
return ProcessorArchitecture.Arm;
}
}
return ProcessorArchitecture.None;
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:38,代码来源:AssemblyName.cs
示例14: GetPEKind
void GetPEKind (out PortableExecutableKinds peKind, out ImageFileMachine machine) {
ModuleHandle.GetPEKind (out peKind, out machine);
}
开发者ID:LevNNN,项目名称:mono,代码行数:3,代码来源:MonoModule.cs
示例15: GetPEKind
public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
throw new NotSupportedException();
}
开发者ID:nestalk,项目名称:mono,代码行数:4,代码来源:Module.cs
示例16: GetPEKind
// making this internal, used by Module.GetPEKind
internal void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
int _peKind;
int _machine;
_GetPEKind(out _peKind, out _machine);
peKind = (PortableExecutableKinds)_peKind;
machine = (ImageFileMachine)_machine;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:11,代码来源:runtimehandles.cs
示例17: SetProcArchIndex
internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm)
{
ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _Flags);
}
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:4,代码来源:AssemblyName.cs
示例18: StackWalkEx
private static extern bool StackWalkEx(
ImageFileMachine MachineType,
IntPtr hProcess,
IntPtr hThread,
ref STACKFRAME_EX StackFrame,
IntPtr ContextRecord,
ReadProcessMemoryProc64 ReadMemoryRoutine,
FunctionTableAccessProc64 FunctionTableAccessRoutine,
GetModuleBaseProc64 GetModuleBaseRoutine,
TranslateAddressProc64 TranslateAddress,
uint Flags);
开发者ID:southpolenator,项目名称:WinDbgCs,代码行数:11,代码来源:DbgEngDll.cs
示例19: GetPEKind
public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
throw new MissingModuleException(this);
}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:4,代码来源:Missing.cs
示例20: __Save
public void __Save(Stream stream, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
{
if (!stream.CanRead || !stream.CanWrite || !stream.CanSeek || stream.Position != 0)
{
throw new ArgumentException("Stream must support read/write/seek and current position must be zero.", "stream");
}
if (modules.Count != 1)
{
throw new NotSupportedException("Saving to a stream is only supported for single module assemblies.");
}
SaveImpl(modules[0].fileName, stream, portableExecutableKind, imageFileMachine);
}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:12,代码来源:AssemblyBuilder.cs
注:本文中的ImageFileMachine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论