|
11 | 11 |
|
12 | 12 | using Neo.ConsoleService; |
13 | 13 | using Neo.Cryptography.ECC; |
| 14 | +using Neo.Extensions; |
14 | 15 | using Neo.IO; |
15 | 16 | using Neo.SmartContract; |
16 | | -using Neo.VM; |
17 | 17 | using Neo.Wallets; |
18 | 18 | using System; |
19 | 19 | using System.Collections.Generic; |
@@ -56,7 +56,8 @@ private void OnParseCommand(string value) |
56 | 56 |
|
57 | 57 | if (result != null) |
58 | 58 | { |
59 | | - Console.WriteLine($"{pair.Key,-30}\t{result}"); |
| 59 | + ConsoleHelper.Info("", "-----", pair.Key, "-----"); |
| 60 | + ConsoleHelper.Info("", result, Environment.NewLine); |
60 | 61 | any = true; |
61 | 62 | } |
62 | 63 | } |
@@ -417,62 +418,27 @@ private static string Base64Fixed(string str) |
417 | 418 | [ParseFunction("Base64 Smart Contract Script Analysis")] |
418 | 419 | private string? ScriptsToOpCode(string base64) |
419 | 420 | { |
420 | | - Script script; |
421 | 421 | try |
422 | 422 | { |
423 | | - var scriptData = Convert.FromBase64String(base64); |
424 | | - script = new Script(scriptData.ToArray(), true); |
425 | | - } |
426 | | - catch (Exception) |
427 | | - { |
428 | | - return null; |
429 | | - } |
430 | | - return ScriptsToOpCode(script); |
431 | | - } |
| 423 | + var bytes = Convert.FromBase64String(base64); |
| 424 | + var sb = new StringBuilder(); |
| 425 | + var line = 0; |
432 | 426 |
|
433 | | - private string ScriptsToOpCode(Script script) |
434 | | - { |
435 | | - //Initialize all InteropService |
436 | | - var dic = new Dictionary<uint, string>(); |
437 | | - ApplicationEngine.Services.ToList().ForEach(p => dic.Add(p.Value.Hash, p.Value.Name)); |
438 | | - |
439 | | - //Analyzing Scripts |
440 | | - var ip = 0; |
441 | | - Instruction instruction; |
442 | | - var result = new List<string>(); |
443 | | - while (ip < script.Length && (instruction = script.GetInstruction(ip)) != null) |
444 | | - { |
445 | | - ip += instruction.Size; |
446 | | - |
447 | | - var op = instruction.OpCode; |
448 | | - |
449 | | - if (op.ToString().StartsWith("PUSHINT")) |
450 | | - { |
451 | | - var operand = instruction.Operand.ToArray(); |
452 | | - result.Add($"{op} {new BigInteger(operand)}"); |
453 | | - } |
454 | | - else if (op == OpCode.SYSCALL) |
| 427 | + foreach (var instruct in new VMInstruction(bytes)) |
455 | 428 | { |
456 | | - var operand = instruction.Operand.ToArray(); |
457 | | - result.Add($"{op} {dic[BitConverter.ToUInt32(operand)]}"); |
458 | | - } |
459 | | - else |
460 | | - { |
461 | | - if (!instruction.Operand.IsEmpty && instruction.Operand.Length > 0) |
462 | | - { |
463 | | - var operand = instruction.Operand.ToArray(); |
464 | | - var ascii = Encoding.Default.GetString(operand); |
465 | | - ascii = ascii.Any(p => p < '0' || p > 'z') ? operand.ToHexString() : ascii; |
466 | | - |
467 | | - result.Add($"{op} {(operand.Length == 20 ? new UInt160(operand).ToString() : ascii)}"); |
468 | | - } |
| 429 | + if (instruct.OperandSize == 0) |
| 430 | + sb.AppendFormat("L{0:D04}:{1:X04} {2}{3}", line, instruct.Position, instruct.OpCode, Environment.NewLine); |
469 | 431 | else |
470 | | - { |
471 | | - result.Add($"{op}"); |
472 | | - } |
| 432 | + sb.AppendFormat("L{0:D04}:{1:X04} {2,-10}{3}{4}", line, instruct.Position, instruct.OpCode, instruct.DecodeOperand(), Environment.NewLine); |
| 433 | + line++; |
473 | 434 | } |
| 435 | + |
| 436 | + return sb.ToString(); |
| 437 | + } |
| 438 | + catch |
| 439 | + { |
| 440 | + return null; |
474 | 441 | } |
475 | | - return Environment.NewLine + string.Join("\r\n", result.ToArray()); |
476 | 442 | } |
477 | 443 |
|
478 | 444 | /// <summary> |
|
0 commit comments