Skip to content

Commit 3caba59

Browse files
authored
Add GetNativeChecksum() to access native checksum (#70)
***NO_CI***
1 parent 49b93d6 commit 3caba59

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

source/MetadataProcessor.Core/nanoAssemblyBuilder.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,34 @@ private void ShowDependencies(MetadataToken token, HashSet<MetadataToken> set, H
239239
}
240240
}
241241

242+
/// <summary>
243+
/// Returns the native checksum of the assembly.
244+
/// </summary>
245+
/// <returns>Native checksum of the assembly.</returns>
246+
/// <remarks>
247+
/// Need to call <see cref="Minimize()"/> before calling this method otherwise the checksum is not available.
248+
/// </remarks>
249+
public string GetNativeChecksum()
250+
{
251+
if(_tablesContext.MinimizeComplete)
252+
{
253+
// check if there are any native methods
254+
if (_tablesContext.MethodDefinitionTable.Items.Any(method => method.RVA == 0 && !method.IsAbstract))
255+
{
256+
return $"0x{_tablesContext.NativeMethodsCrc.Current.ToString("X")}";
257+
}
258+
else
259+
{
260+
// this assembly doesn't have native implementation
261+
return "0x00000000";
262+
}
263+
}
264+
else
265+
{
266+
throw new InvalidOperationException("Error: can't provide checksum without compiling the assembly first.");
267+
}
268+
}
269+
242270
private void ShowDependencies(int token, HashSet<int> set, HashSet<int> setTmp)
243271
{
244272
var tokenFrom = TokenToString(token);

0 commit comments

Comments
 (0)