| 
14 | 14 | using Neo.Extensions;  | 
15 | 15 | using Neo.IO;  | 
16 | 16 | using Neo.SmartContract;  | 
 | 17 | +using Neo.VM;  | 
17 | 18 | using Neo.Wallets;  | 
18 | 19 | using System;  | 
19 | 20 | using System.Collections.Generic;  | 
20 | 21 | using System.Globalization;  | 
 | 22 | +using System.IO;  | 
21 | 23 | using System.Linq;  | 
22 | 24 | using System.Numerics;  | 
23 | 25 | using System.Reflection;  | 
@@ -441,6 +443,58 @@ private static string Base64Fixed(string str)  | 
441 | 443 |             }  | 
442 | 444 |         }  | 
443 | 445 | 
 
  | 
 | 446 | +        /// <summary>  | 
 | 447 | +        /// Base64 .nef file Analysis  | 
 | 448 | +        /// </summary>  | 
 | 449 | +        [ParseFunction("Base64 .nef file Analysis")]  | 
 | 450 | +        private string? NefFileAnalyis(string base64)  | 
 | 451 | +        {  | 
 | 452 | +            byte[] nefData;  | 
 | 453 | +            if (File.Exists(base64))  // extension name not considered  | 
 | 454 | +                nefData = File.ReadAllBytes(base64);  | 
 | 455 | +            else  | 
 | 456 | +            {  | 
 | 457 | +                try  | 
 | 458 | +                {  | 
 | 459 | +                    nefData = Convert.FromBase64String(base64);  | 
 | 460 | +                }  | 
 | 461 | +                catch { return null; }  | 
 | 462 | +            }  | 
 | 463 | +            NefFile nef;  | 
 | 464 | +            Script script;  | 
 | 465 | +            bool verifyChecksum = false;  | 
 | 466 | +            bool strictMode = false;  | 
 | 467 | +            try  | 
 | 468 | +            {  | 
 | 469 | +                nef = NefFile.Parse(nefData, true);  | 
 | 470 | +                verifyChecksum = true;  | 
 | 471 | +            }  | 
 | 472 | +            catch (FormatException)  | 
 | 473 | +            {  | 
 | 474 | +                nef = NefFile.Parse(nefData, false);  | 
 | 475 | +            }  | 
 | 476 | +            catch { return null; }  | 
 | 477 | +            try  | 
 | 478 | +            {  | 
 | 479 | +                script = new Script(nef.Script, true);  | 
 | 480 | +                strictMode = true;  | 
 | 481 | +            }  | 
 | 482 | +            catch (BadScriptException)  | 
 | 483 | +            {  | 
 | 484 | +                script = new Script(nef.Script, false);  | 
 | 485 | +            }  | 
 | 486 | +            catch { return null; }  | 
 | 487 | +            string? result = ScriptsToOpCode(Convert.ToBase64String(nef.Script.ToArray()));  | 
 | 488 | +            if (result == null)  | 
 | 489 | +                return null;  | 
 | 490 | +            string prefix = $"\r\n# Compiler: {nef.Compiler}";  | 
 | 491 | +            if (!verifyChecksum)  | 
 | 492 | +                prefix += $"\r\n# Warning: Invalid .nef file checksum";  | 
 | 493 | +            if (!strictMode)  | 
 | 494 | +                prefix += $"\r\n# Warning: Failed in {nameof(strictMode)}";  | 
 | 495 | +            return prefix + result;  | 
 | 496 | +        }  | 
 | 497 | + | 
444 | 498 |         /// <summary>  | 
445 | 499 |         /// Checks if the string is null or cannot be printed.  | 
446 | 500 |         /// </summary>  | 
 | 
0 commit comments