Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/Neo.CLI/CLI/MainService.Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
using Neo.Extensions;
using Neo.IO;
using Neo.SmartContract;
using Neo.VM;
using Neo.Wallets;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
Expand Down Expand Up @@ -441,6 +443,58 @@ private static string Base64Fixed(string str)
}
}

/// <summary>
/// Base64 .nef file Analysis
/// </summary>
[ParseFunction("Base64 .nef file Analysis")]
private string? NefFileAnalyis(string base64)
{
byte[] nefData;
if (File.Exists(base64)) // extension name not considered
nefData = File.ReadAllBytes(base64);
else
{
try
{
nefData = Convert.FromBase64String(base64);
}
catch { return null; }
}
NefFile nef;
Script script;
bool verifyChecksum = false;
bool strictMode = false;
try
{
nef = NefFile.Parse(nefData, true);
verifyChecksum = true;
}
catch (FormatException)
{
nef = NefFile.Parse(nefData, false);
}
catch { return null; }
try
{
script = new Script(nef.Script, true);
strictMode = true;
}
catch (BadScriptException)
{
script = new Script(nef.Script, false);
}
catch { return null; }
string? result = ScriptsToOpCode(Convert.ToBase64String(nef.Script.ToArray()));
if (result == null)
return null;
string prefix = $"\r\n# Compiler: {nef.Compiler}";
if (!verifyChecksum)
prefix += $"\r\n# Warning: Invalid .nef file checksum";
if (!strictMode)
prefix += $"\r\n# Warning: Failed in {nameof(strictMode)}";
return prefix + result;
}

/// <summary>
/// Checks if the string is null or cannot be printed.
/// </summary>
Expand Down