From 8fa2477af86aa909a462bc3ea5484ab517042d79 Mon Sep 17 00:00:00 2001 From: Hecate2 <2474101468@qq.com> Date: Thu, 12 Sep 2024 11:08:36 +0800 Subject: [PATCH 1/3] support path input in parse --- src/Neo.CLI/CLI/MainService.Tools.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Neo.CLI/CLI/MainService.Tools.cs b/src/Neo.CLI/CLI/MainService.Tools.cs index 60de31493a..56e23c8d61 100644 --- a/src/Neo.CLI/CLI/MainService.Tools.cs +++ b/src/Neo.CLI/CLI/MainService.Tools.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Numerics; using System.Reflection; @@ -33,6 +34,8 @@ partial class MainService [ConsoleCommand("parse", Category = "Base Commands", Description = "Parse a value to its possible conversions.")] private void OnParseCommand(string value) { + if (File.Exists(value)) + value = Convert.ToBase64String(File.ReadAllBytes(value)); value = Base64Fixed(value); var parseFunctions = new Dictionary>(); From 588d225832a0a7507abd63cb3f51bd19183da19d Mon Sep 17 00:00:00 2001 From: Hecate2 <2474101468@qq.com> Date: Thu, 12 Sep 2024 15:36:13 +0800 Subject: [PATCH 2/3] FilePathToContentBase64 --- src/Neo.CLI/CLI/MainService.Tools.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.Tools.cs b/src/Neo.CLI/CLI/MainService.Tools.cs index 56e23c8d61..9b9ac8150d 100644 --- a/src/Neo.CLI/CLI/MainService.Tools.cs +++ b/src/Neo.CLI/CLI/MainService.Tools.cs @@ -34,8 +34,6 @@ partial class MainService [ConsoleCommand("parse", Category = "Base Commands", Description = "Parse a value to its possible conversions.")] private void OnParseCommand(string value) { - if (File.Exists(value)) - value = Convert.ToBase64String(File.ReadAllBytes(value)); value = Base64Fixed(value); var parseFunctions = new Dictionary>(); @@ -71,6 +69,16 @@ private void OnParseCommand(string value) } } + /// + /// Read file from path and print its content in base64 + /// + [ParseFunction("File path to content base64")] + private string? FilePathToContentBase64(string path) + { + if (!File.Exists(path)) return null; + return Convert.ToBase64String(File.ReadAllBytes(path)); + } + /// /// Little-endian to Big-endian /// input: ce616f7f74617e0fc4b805583af2602a238df63f From 76321d5943a849f7abb0f4af5bcfdc684406c7f6 Mon Sep 17 00:00:00 2001 From: Hecate2 <2474101468@qq.com> Date: Sat, 14 Sep 2024 09:59:03 +0800 Subject: [PATCH 3/3] allow only .nef file --- src/Neo.CLI/CLI/MainService.Tools.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.Tools.cs b/src/Neo.CLI/CLI/MainService.Tools.cs index 9b9ac8150d..1168d50ac0 100644 --- a/src/Neo.CLI/CLI/MainService.Tools.cs +++ b/src/Neo.CLI/CLI/MainService.Tools.cs @@ -70,11 +70,12 @@ private void OnParseCommand(string value) } /// - /// Read file from path and print its content in base64 + /// Read .nef file from path and print its content in base64 /// - [ParseFunction("File path to content base64")] - private string? FilePathToContentBase64(string path) + [ParseFunction(".nef file path to content base64")] + private string? NefPathToContentBase64(string path) { + if (Path.GetExtension(path).ToLower() != ".nef") return null; if (!File.Exists(path)) return null; return Convert.ToBase64String(File.ReadAllBytes(path)); }