Skip to content

Commit

Permalink
Replace Entrypoint with EntryPoint for consistency with Reflection an…
Browse files Browse the repository at this point in the history
…d other APIs.
  • Loading branch information
Washi1337 committed Sep 16, 2022
1 parent c537bfb commit b6fa3ed
Show file tree
Hide file tree
Showing 28 changed files with 128 additions and 128 deletions.
18 changes: 9 additions & 9 deletions src/AsmResolver.DotNet/Builder/DotNetDirectoryBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public DotNetDirectoryBuildResult CreateDirectory()
{
Metadata = Metadata.CreateMetadata(),
DotNetResources = Resources.Size > 0 ? Resources.CreateDirectory() : null,
Entrypoint = GetEntrypoint(),
EntryPoint = GetEntryPoint(),
Flags = Module.Attributes,
StrongName = StrongNameSize > 0 ? new DataSegment(new byte[StrongNameSize]) : null,
VTableFixups = VTableFixups.Directory.Count > 0 ? VTableFixups.Directory : null
Expand All @@ -152,29 +152,29 @@ public DotNetDirectoryBuildResult CreateDirectory()
return new DotNetDirectoryBuildResult(directory, _tokenMapping);
}

private uint GetEntrypoint()
private uint GetEntryPoint()
{
if (Module.ManagedEntrypoint is null)
if (Module.ManagedEntryPoint is null)
return 0;

var entrypointToken = MetadataToken.Zero;
var entryPointToken = MetadataToken.Zero;

switch (Module.ManagedEntrypoint.MetadataToken.Table)
switch (Module.ManagedEntryPoint.MetadataToken.Table)
{
case TableIndex.Method:
entrypointToken = GetMethodDefinitionToken(Module.ManagedEntrypointMethod!);
entryPointToken = GetMethodDefinitionToken(Module.ManagedEntryPointMethod!);
break;

case TableIndex.File:
entrypointToken = AddFileReference((FileReference) Module.ManagedEntrypoint);
entryPointToken = AddFileReference((FileReference) Module.ManagedEntryPoint);
break;

default:
ErrorListener.MetadataBuilder($"Invalid managed entrypoint {Module.ManagedEntrypoint.SafeToString()}.");
ErrorListener.MetadataBuilder($"Invalid managed entry point {Module.ManagedEntryPoint.SafeToString()}.");
break;
}

return entrypointToken.ToUInt32();
return entryPointToken.ToUInt32();
}

private void AddMethodSemantics(MetadataToken ownerToken, IHasSemantics provider)
Expand Down
2 changes: 1 addition & 1 deletion src/AsmResolver.DotNet/FileReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace AsmResolver.DotNet
public class FileReference :
MetadataMember,
IImplementation,
IManagedEntrypoint,
IManagedEntryPoint,
IOwnedCollectionElement<ModuleDefinition>
{
private readonly LazyVariable<Utf8String?> _name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
/// <summary>
/// Represents a member that is either a method definition or a reference to an external file, that can be used to
/// indicate the managed entrypoint of a .NET module.
/// indicate the managed entry point of a .NET module.
/// </summary>
public interface IManagedEntrypoint : IMetadataMember
public interface IManagedEntryPoint : IMetadataMember
{
}
}
}
2 changes: 1 addition & 1 deletion src/AsmResolver.DotNet/MethodDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MethodDefinition :
IHasGenericParameters,
IMemberForwarded,
IHasSecurityDeclaration,
IManagedEntrypoint
IManagedEntryPoint
{
private readonly LazyVariable<Utf8String?> _name;
private readonly LazyVariable<TypeDefinition?> _declaringType;
Expand Down
40 changes: 20 additions & 20 deletions src/AsmResolver.DotNet/ModuleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ModuleDefinition :
private IList<AssemblyReference>? _assemblyReferences;
private IList<CustomAttribute>? _customAttributes;

private readonly LazyVariable<IManagedEntrypoint?> _managedEntrypoint;
private readonly LazyVariable<IManagedEntryPoint?> _managedEntryPoint;
private IList<ModuleReference>? _moduleReferences;
private IList<FileReference>? _fileReferences;
private IList<ManifestResource>? _resources;
Expand Down Expand Up @@ -269,7 +269,7 @@ protected ModuleDefinition(MetadataToken token)
_mvid = new LazyVariable<Guid>(GetMvid);
_encId = new LazyVariable<Guid>(GetEncId);
_encBaseId = new LazyVariable<Guid>(GetEncBaseId);
_managedEntrypoint = new LazyVariable<IManagedEntrypoint?>(GetManagedEntrypoint);
_managedEntryPoint = new LazyVariable<IManagedEntryPoint?>(GetManagedEntryPoint);
_runtimeVersion = new LazyVariable<string>(GetRuntimeVersion);
_nativeResources = new LazyVariable<IResourceDirectory?>(GetNativeResources);
Attributes = DotNetDirectoryFlags.ILOnly;
Expand Down Expand Up @@ -494,13 +494,13 @@ public bool IsStrongNameSigned
}

/// <summary>
/// Gets or sets a value indicating whether the .NET module has a native entrypoint or not.
/// Gets or sets a value indicating whether the .NET module has a native entry point or not.
/// </summary>
public bool HasNativeEntrypoint
public bool HasNativeEntryPoint
{
get => (Attributes & DotNetDirectoryFlags.NativeEntrypoint) != 0;
set => Attributes = (Attributes & ~DotNetDirectoryFlags.NativeEntrypoint)
| (value ? DotNetDirectoryFlags.NativeEntrypoint : 0);
get => (Attributes & DotNetDirectoryFlags.NativeEntryPoint) != 0;
set => Attributes = (Attributes & ~DotNetDirectoryFlags.NativeEntryPoint)
| (value ? DotNetDirectoryFlags.NativeEntryPoint : 0);
}

/// <summary>
Expand Down Expand Up @@ -744,22 +744,22 @@ public IMetadataResolver MetadataResolver
}

/// <summary>
/// Gets or sets the managed method that is invoked when the .NET module is initialized.
/// Gets or sets the managed method that is invoked after the .NET module is loaded and initialized.
/// </summary>
public MethodDefinition? ManagedEntrypointMethod
public MethodDefinition? ManagedEntryPointMethod
{
get => ManagedEntrypoint as MethodDefinition;
set => ManagedEntrypoint = value;
get => ManagedEntryPoint as MethodDefinition;
set => ManagedEntryPoint = value;
}

/// <summary>
/// Gets or sets the managed entrypoint that is invoked when the .NET module is initialized. This is either a
/// method, or a reference to a secondary module containing the entrypoint method.
/// Gets or sets the managed entry point that is invoked when the .NET module is initialized. This is either a
/// method, or a reference to a secondary module containing the entry point method.
/// </summary>
public IManagedEntrypoint? ManagedEntrypoint
public IManagedEntryPoint? ManagedEntryPoint
{
get => _managedEntrypoint.Value;
set => _managedEntrypoint.Value = value;
get => _managedEntryPoint.Value;
set => _managedEntryPoint.Value = value;
}

/// <summary>
Expand Down Expand Up @@ -1036,13 +1036,13 @@ protected virtual IList<CustomAttribute> GetCustomAttributes() =>
protected virtual string GetRuntimeVersion() => KnownRuntimeVersions.Clr40;

/// <summary>
/// Obtains the managed entrypoint of this module.
/// Obtains the managed entry point of this module.
/// </summary>
/// <returns>The entrypoint.</returns>
/// <returns>The entry point.</returns>
/// <remarks>
/// This method is called upon initialization of the <see cref="ManagedEntrypoint"/> property.
/// This method is called upon initialization of the <see cref="ManagedEntryPoint"/> property.
/// </remarks>
protected virtual IManagedEntrypoint? GetManagedEntrypoint() => null;
protected virtual IManagedEntryPoint? GetManagedEntryPoint() => null;

/// <summary>
/// Obtains the native win32 resources directory of the underlying PE image (if available).
Expand Down
10 changes: 5 additions & 5 deletions src/AsmResolver.DotNet/Serialized/SerializedModuleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,16 @@ protected override IList<ExportedType> GetExportedTypes()
protected override string GetRuntimeVersion() => ReaderContext.Metadata!.VersionString;

/// <inheritdoc />
protected override IManagedEntrypoint? GetManagedEntrypoint()
protected override IManagedEntryPoint? GetManagedEntryPoint()
{
if ((DotNetDirectory.Flags & DotNetDirectoryFlags.NativeEntrypoint) != 0)
if ((DotNetDirectory.Flags & DotNetDirectoryFlags.NativeEntryPoint) != 0)
{
// TODO: native entrypoints.
// TODO: native entry points.
return null;
}

if (DotNetDirectory.Entrypoint != 0)
return LookupMember(DotNetDirectory.Entrypoint) as IManagedEntrypoint;
if (DotNetDirectory.EntryPoint != 0)
return LookupMember(DotNetDirectory.EntryPoint) as IManagedEntryPoint;

return null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/AsmResolver.PE.File/Headers/OptionalHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static OptionalHeader FromReader(ref BinaryStreamReader reader, bool igno
SizeOfCode = reader.ReadUInt32(),
SizeOfInitializedData = reader.ReadUInt32(),
SizeOfUninitializedData = reader.ReadUInt32(),
AddressOfEntrypoint = reader.ReadUInt32(),
AddressOfEntryPoint = reader.ReadUInt32(),
BaseOfCode = reader.ReadUInt32()
};

Expand Down Expand Up @@ -168,9 +168,9 @@ public uint SizeOfUninitializedData
}

/// <summary>
/// Gets or sets the relative virtual address to the entrypoint of the portable executable (PE) file.
/// Gets or sets the relative virtual address to the entry point of the portable executable (PE) file.
/// </summary>
public uint AddressOfEntrypoint
public uint AddressOfEntryPoint
{
get;
set;
Expand Down Expand Up @@ -417,7 +417,7 @@ public override void Write(IBinaryStreamWriter writer)
writer.WriteUInt32(SizeOfCode);
writer.WriteUInt32(SizeOfInitializedData);
writer.WriteUInt32(SizeOfUninitializedData);
writer.WriteUInt32(AddressOfEntrypoint);
writer.WriteUInt32(AddressOfEntryPoint);
writer.WriteUInt32(BaseOfCode);

switch (Magic)
Expand Down
10 changes: 5 additions & 5 deletions src/AsmResolver.PE/Builder/PEFileBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public virtual PEFile CreateFile(IPEImage image)
protected abstract IEnumerable<DataDirectory> CreateDataDirectories(PEFile peFile, IPEImage image, TContext context);

/// <summary>
/// Gets the relative virtual address (RVA) to the entrypoint of the PE file.
/// Gets the relative virtual address (RVA) to the entry point of the PE file.
/// </summary>
/// <param name="peFile">The (incomplete) PE file containing the entrypoint.</param>
/// <param name="peFile">The (incomplete) PE file containing the entry point.</param>
/// <param name="image">The image that the PE file was based on.</param>
/// <param name="context">The object containing the intermediate values used during the PE file construction.</param>
/// <returns>The relative virtual address to the entrypoin.</returns>
protected abstract uint GetEntrypointAddress(PEFile peFile, IPEImage image, TContext context);
/// <returns>The relative virtual address to the entry point.</returns>
protected abstract uint GetEntryPointAddress(PEFile peFile, IPEImage image, TContext context);

/// <summary>
/// Gets the file alignment for the new PE file.
Expand Down Expand Up @@ -144,7 +144,7 @@ protected virtual void ComputeOptionalHeaderFields(PEFile peFile, IPEImage image
header.SizeOfImage += section.GetVirtualSize();
}

header.AddressOfEntrypoint = GetEntrypointAddress(peFile, image, context);
header.AddressOfEntryPoint = GetEntryPointAddress(peFile, image, context);

header.BaseOfCode = peFile.Sections.FirstOrDefault(s => s.IsContentCode)?.Rva ?? 0;
header.BaseOfData = peFile.Sections.FirstOrDefault(s => s.IsContentInitializedData)?.Rva ?? 0;
Expand Down
36 changes: 18 additions & 18 deletions src/AsmResolver.PE/DotNet/Builder/ManagedPEFileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Platform Platform
}

/// <summary>
/// Gets the code segment used as a native entrypoint of the resulting PE file.
/// Gets the code segment used as a native entry point of the resulting PE file.
/// </summary>
/// <remarks>
/// This property might be <c>null</c> if no bootstrapper is to be emitted. For example, since the
Expand Down Expand Up @@ -246,47 +246,47 @@ protected virtual PESection CreateTextSection(IPEImage image, ManagedPEBuilderCo

private static void CreateImportDirectory(IPEImage image, ManagedPEBuilderContext context)
{
bool importEntrypointRequired = context.Platform.IsClrBootstrapperRequired
bool importEntryPointRequired = context.Platform.IsClrBootstrapperRequired
|| (image.DotNetDirectory!.Flags & DotNetDirectoryFlags.ILOnly) == 0;
string entrypointName = (image.Characteristics & Characteristics.Dll) != 0
string entryPointName = (image.Characteristics & Characteristics.Dll) != 0
? "_CorDllMain"
: "_CorExeMain";

var modules = CollectImportedModules(image, importEntrypointRequired, entrypointName, out var entrypointSymbol);
var modules = CollectImportedModules(image, importEntryPointRequired, entryPointName, out var entryPointSymbol);

foreach (var module in modules)
context.ImportDirectory.AddModule(module);

if (importEntrypointRequired)
if (importEntryPointRequired)
{
if (entrypointSymbol is null)
throw new InvalidOperationException("Entrypoint symbol was required but not imported.");
if (entryPointSymbol is null)
throw new InvalidOperationException("Entry point symbol was required but not imported.");

context.Bootstrapper = context.Platform.CreateThunkStub(entrypointSymbol);
context.Bootstrapper = context.Platform.CreateThunkStub(entryPointSymbol);
}
}

private static List<IImportedModule> CollectImportedModules(
IPEImage image,
bool entryRequired,
string mscoreeEntryName,
out ImportedSymbol? entrypointSymbol)
out ImportedSymbol? entryPointSymbol)
{
var modules = new List<IImportedModule>();

IImportedModule? mscoreeModule = null;
entrypointSymbol = null;
entryPointSymbol = null;

foreach (var module in image.Imports)
{
// Check if the CLR entrypoint is already imported.
// Check if the CLR entry point is already imported.
if (module.Name == "mscoree.dll")
{
mscoreeModule = module;

// Find entrypoint in this imported module.
// Find entry point in this imported module.
if (entryRequired)
entrypointSymbol = mscoreeModule.Symbols.FirstOrDefault(s => s.Name == mscoreeEntryName);
entryPointSymbol = mscoreeModule.Symbols.FirstOrDefault(s => s.Name == mscoreeEntryName);

// Only include mscoree.dll if necessary.
if (entryRequired || module.Symbols.Count > 1)
Expand All @@ -308,11 +308,11 @@ private static List<IImportedModule> CollectImportedModules(
modules.Add(mscoreeModule);
}

// Add entrypoint sumbol if it wasn't imported yet.
if (entrypointSymbol is null)
// Add entry point sumbol if it wasn't imported yet.
if (entryPointSymbol is null)
{
entrypointSymbol = new ImportedSymbol(0, mscoreeEntryName);
mscoreeModule.Symbols.Add(entrypointSymbol);
entryPointSymbol = new ImportedSymbol(0, mscoreeEntryName);
mscoreeModule.Symbols.Add(entryPointSymbol);
}
}

Expand Down Expand Up @@ -423,7 +423,7 @@ protected override IEnumerable<DataDirectory> CreateDataDirectories(PEFile peFil
}

/// <inheritdoc />
protected override uint GetEntrypointAddress(PEFile peFile, IPEImage image, ManagedPEBuilderContext context)
protected override uint GetEntryPointAddress(PEFile peFile, IPEImage image, ManagedPEBuilderContext context)
=> context.Bootstrapper?.Segment.Rva ?? 0;

/// <inheritdoc />
Expand Down
6 changes: 3 additions & 3 deletions src/AsmResolver.PE/DotNet/DotNetDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DotNetDirectoryFlags Flags
}

/// <inheritdoc />
public uint Entrypoint
public uint EntryPoint
{
get;
set;
Expand Down Expand Up @@ -116,7 +116,7 @@ public override uint GetPhysicalSize() =>
+ 2 * sizeof(ushort) // version
+ DataDirectory.DataDirectorySize // metadata
+ sizeof(uint) // flags
+ sizeof(uint) // entrypoint
+ sizeof(uint) // entry point
+ 6 * DataDirectory.DataDirectorySize; // data directories.

/// <inheritdoc />
Expand All @@ -127,7 +127,7 @@ public override void Write(IBinaryStreamWriter writer)
writer.WriteUInt16(MinorRuntimeVersion);
CreateDataDirectoryHeader(Metadata).Write(writer);
writer.WriteUInt32((uint) Flags);
writer.WriteUInt32(Entrypoint);
writer.WriteUInt32(EntryPoint);
CreateDataDirectoryHeader(DotNetResources).Write(writer);
CreateDataDirectoryHeader(StrongName).Write(writer);
CreateDataDirectoryHeader(CodeManagerTable).Write(writer);
Expand Down
Loading

0 comments on commit b6fa3ed

Please sign in to comment.