示例#1
0
        private void LoadDataFromFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (File.Exists(path))
            {
                MainForm.targetAVMPath = path;

                var bytes = File.ReadAllBytes(path);

                var mapFileName = path.Replace(".avm", ".neomap");

                debugMode      = DebugMode.Assembly;
                sourceLanguage = SourceLanguageKind.Other;

                if (File.Exists(mapFileName))
                {
                    map = new NeoMapFile();
                    map.LoadFromFile(mapFileName);
                }
                else
                {
                    map = null;
                }

                this.debugger = new NeoDebugger(bytes);
                this.avm_asm  = NeoDisassembler.Disassemble(bytes);

                if (map != null && map.Entries.Any())
                {
                    var srcFile = map.Entries.FirstOrDefault().url;

                    FileName.Text = srcFile;

                    sourceLanguage = LanguageSupport.DetectLanguage(srcFile);

                    debugMode = DebugMode.Source;
                    debugContent[DebugMode.Source] = File.ReadAllText(srcFile);
                }

                debugContent[DebugMode.Assembly] = avm_asm.ToString();
                FileName.Text = Path.GetFileName(path);

                ReloadTextArea();

                StorageLoad();

                UpdateSourceViewMenus();

                shouldReset = true;
            }
        }
示例#2
0
        public override void Execute(string[] args)
        {
            if (args.Length < 2)
            {
                return;
            }

            var filePath = args[1];

            if (File.Exists(filePath))
            {
                Shell.avmPath = filePath;

                var bytes = File.ReadAllBytes(filePath);

                var avmName = Path.GetFileName(filePath);
                Shell.Write($"Loaded {avmName} ({bytes.Length} bytes)");

                string contractName;

                var mapFile = avmName.Replace(".avm", ".debug.json");
                if (File.Exists(mapFile))
                {
                    var map = new NeoMapFile();
                    map.LoadFromFile(mapFile, bytes);

                    contractName = map.contractName;
                }
                else
                {
                    contractName = avmName.Replace(".avm", "");
                }

                var address = Shell.blockchain.FindAddressByName(contractName);

                if (address == null)
                {
                    address = Shell.blockchain.DeployContract(contractName, bytes);
                    Shell.Write($"Deployed {contractName} at address {address.keys.address}");
                }
                else
                {
                    Shell.Write($"Updated {contractName} at address {address.keys.address}");
                }

                Runtime.OnLogMessage = (x => Shell.Write(x));
            }
            else
            {
                Shell.Write("File not found.");
            }
        }
示例#3
0
        public bool LoadDebugInfo(string fileName)
        {
            var debugFile = fileName.Replace(".avm", ".debug.json");

            if (File.Exists(debugFile))
            {
                this.map = new NeoMapFile();
                this.map.LoadFromFile(debugFile);
                return(true);
            }

            return(false);
        }
示例#4
0
        private void LoadDataFromFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (File.Exists(path))
            {
                var bytes = File.ReadAllBytes(path);

                var mapFileName = path.Replace(".avm", ".neomap");

                debugMode = DebugMode.Assembly;

                if (File.Exists(mapFileName))
                {
                    map = new NeoMapFile();
                    map.LoadFromFile(mapFileName);
                }
                else
                {
                    map = null;
                }

                this.debugger = new NeoDebugger(bytes);
                this.avm_asm  = NeoDisassembler.Disassemble(bytes);


                if (map != null && map.Entries.Any())
                {
                    var srcFile = map.Entries.FirstOrDefault().url;
                    FileName.Text = srcFile;
                    debugMode     = DebugMode.Source;
                    debugContent[DebugMode.Source] = File.ReadAllText(srcFile);
                }

                debugContent[DebugMode.Assembly] = avm_asm.ToString();
                FileName.Text = Path.GetFileName(path);

                TextArea.Text     = debugContent[debugMode];
                TextArea.ReadOnly = true;

                shouldReset = true;
            }
        }
示例#5
0
        public bool LoadAvmFile(string avmPath)
        {
            //Decide what we need to open
            if (!String.IsNullOrEmpty(avmPath)) //use the explicit file provided
            {
                _avmFilePath = avmPath;
            }
            else if (!String.IsNullOrEmpty(Settings.lastOpenedFile)) //fallback to last opened
            {
                _avmFilePath = Settings.lastOpenedFile;
            }
            else
            {
                return(false); //We don't know what to open, just let the user specify with another call
            }
            //Housekeeping - let's find out what files we have and make sure we're good
            if (!File.Exists(_avmFilePath))
            {
                Log("File not found. " + avmPath);
                return(false);
            }

            _debugContent.Clear();

            _contractName     = Path.GetFileNameWithoutExtension(_avmFilePath);
            _contractByteCode = File.ReadAllBytes(_avmFilePath);
            _map = new NeoMapFile();
            try
            {
                avmDisassemble = NeoDisassembler.Disassemble(_contractByteCode);
                _disassembles[_contractByteCode] = avmDisassemble;
            }
            catch (DisassembleException e)
            {
                Log($"Disassembler Error: {e.Message}");
                return(false);
            }

            if (File.Exists(_abiFilePath))
            {
                _ABI = new ABI(_abiFilePath);
            }
            else
            {
                _ABI = new ABI();
                Log($"Warning: {_abiFilePath} was not found. Please recompile your AVM with the latest compiler.");
            }

            //Let's see if we have source code we can map
            if (File.Exists(_mapFilePath))
            {
                _map.LoadFromFile(_mapFilePath, _contractByteCode);
            }
            else
            {
                _map = null;

                if (File.Exists(_oldMapFilePath))
                {
                    Log("Old map file format found.  Please recompile your avm with the latest compiler.");
                }
                else
                {
                    Log($"Warning: Could not find {_mapFilePath}");
                }
            }

            if (_map != null)
            {
                foreach (var entry in _map.FileNames)
                {
                    if (string.IsNullOrEmpty(entry))
                    {
                        continue;
                    }

                    if (!File.Exists(entry))
                    {
                        Log($"Warning: Could not load the source code, check that this file exists: {entry}");
                        continue;
                    }

                    var sourceCode = File.ReadAllText(entry);
                    _debugContent[entry] = sourceCode;
                }
            }

            //We always should have the assembly content
            _debugContent[_avmFilePath] = avmDisassemble.ToString();

            //Save the settings
            Settings.lastOpenedFile = avmPath;
            Settings.Save();
            _avmFileLoaded = true;

            //Force a reset now that we're loaded
            _resetFlag = true;

            _currentFilePath = avmPath;

            return(true);
        }
示例#6
0
        public void LoadDataFromFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (!File.Exists(path))
            {
                MessageBox.Show("Can't find '" + (String.IsNullOrEmpty(path) ? "(null)" : path + "'"), this.Text + " - " + Environment.CurrentDirectory);
            }
            else
            {
                MainForm.targetAVMPath = path;

                this.contractName = Path.GetFileNameWithoutExtension(path);

                this.contractBytecode = File.ReadAllBytes(path);

                var oldMapFileName = path.Replace(".avm", ".neomap");
                var newMapFileName = path.Replace(".avm", ".debug.json");

                debugMode      = DebugMode.Assembly;
                sourceLanguage = SourceLanguageKind.Other;

                if (File.Exists(newMapFileName))
                {
                    map = new NeoMapFile();
                    map.LoadFromFile(newMapFileName, contractBytecode);

                    this.contractName = map.contractName;
                }
                else
                {
                    if (File.Exists(oldMapFileName))
                    {
                        MessageBox.Show("Warning: The file format of debug map changed. Please recompile your AVM with the latest compiler.");
                    }
                    map = null;
                }

                string abiFilename = path.Replace(".avm", ".abi.json");
                if (File.Exists(abiFilename))
                {
                    abi = new ABI(abiFilename);
                }
                else
                {
                    MessageBox.Show($"Error: {abiFilename} was not found. Please recompile your AVM with the latest compiler.");
                    return;
                }

                this.debugger = null;
                this.avm_asm  = NeoDisassembler.Disassemble(contractBytecode);

                if (map != null && map.Entries.Any())
                {
                    var srcFile = map.Entries.FirstOrDefault().url;

                    if (string.IsNullOrEmpty(srcFile))
                    {
                        MessageBox.Show("Error: Could not load the debug map correct, no file entries.");
                        return;
                    }

                    if (!File.Exists(srcFile))
                    {
                        MessageBox.Show("Error: Could not load the source code, check that this file exists:" + srcFile);
                        return;
                    }

                    FileName.Text = srcFile;

                    sourceLanguage = LanguageSupport.DetectLanguage(srcFile);

                    debugMode = DebugMode.Source;
                    debugContent[DebugMode.Source] = File.ReadAllText(srcFile);
                }

                debugContent[DebugMode.Assembly] = avm_asm.ToString();
                FileName.Text = Path.GetFileName(path);

                ReloadTextArea();

                BlockchainLoad();

                UpdateSourceViewMenus();

                shouldReset = true;

                settings.lastOpenedFile = path;
                settings.Save();
            }
        }
示例#7
0
        public override void Execute(string[] args, Action <ShellMessageType, string> output)
        {
            if (args.Length < 2)
            {
                return;
            }

            switch (args[1].ToLower())
            {
            case "load":
            {
                var filePath = args[1];

                if (File.Exists(filePath))
                {
                    Shell.avmPath = filePath;

                    var bytes = File.ReadAllBytes(filePath);

                    var avmName = Path.GetFileName(filePath);
                    output(ShellMessageType.Success, $"Loaded {avmName} ({bytes.Length} bytes)");

                    string contractName;

                    var mapFile = avmName.Replace(".avm", ".debug.json");
                    if (File.Exists(mapFile))
                    {
                        var map = new NeoMapFile();
                        map.LoadFromFile(mapFile, bytes);

                        contractName = map.contractName;
                    }
                    else
                    {
                        contractName = avmName.Replace(".avm", "");
                    }

                    var address = Shell.Debugger.Blockchain.FindAddressByName(contractName);

                    if (address == null)
                    {
                        address = Shell.Debugger.Blockchain.DeployContract(contractName, bytes);
                        output(ShellMessageType.Success, $"Deployed {contractName} at address {address.keys.address}");
                    }
                    else
                    {
                        output(ShellMessageType.Default, $"Updated {contractName} at address {address.keys.address}");
                    }

                    Runtime.OnLogMessage = (x => output(ShellMessageType.Default, x));
                }
                else
                {
                    output(ShellMessageType.Error, "File not found.");
                }

                break;
            }

            case "input":
            {
                break;
            }
            }
        }
        public bool LoadAvmFile(string avmPath)
        {
            //Decide what we need to open
            if (!String.IsNullOrEmpty(avmPath)) //use the explicit file provided
            {
                _avmFilePath = avmPath;
            }
            else if (!String.IsNullOrEmpty(_settings.lastOpenedFile)) //fallback to last opened
            {
                _avmFilePath = _settings.lastOpenedFile;
            }
            else
            {
                return(false); //We don't know what to open, just let the user specify with another call
            }
            //Housekeeping - let's find out what files we have and make sure we're good
            if (!File.Exists(_avmFilePath))
            {
                Log("File not found. " + avmPath);
                return(false);
            }
            else if (File.Exists(_oldMapFilePath))
            {
                Log("Old map file format found.  Please recompile your avm with the latest compiler.");
                return(false);
            }

            _debugContent     = new Dictionary <DebugMode, string>();
            _mode             = DebugMode.Assembly;
            _language         = SourceLanguage.Other;
            _contractName     = Path.GetFileNameWithoutExtension(_avmFilePath);
            _contractByteCode = File.ReadAllBytes(_avmFilePath);
            _map = new NeoMapFile();
            try
            {
                _avmAsm = NeoDisassembler.Disassemble(_contractByteCode);
            }
            catch (DisassembleException e)
            {
                Log($"Disassembler Error: {e.Message}");
                return(false);
            }

            if (File.Exists(_abiFilePath))
            {
                _aBI = new ABI(_abiFilePath);
            }
            else
            {
                _aBI = new ABI();
                Log($"Warning: {_abiFilePath} was not found. Please recompile your AVM with the latest compiler.");
            }

            //We always should have the assembly content
            _debugContent[DebugMode.Assembly] = _avmAsm.ToString();

            //Let's see if we have source code we can map
            if (File.Exists(_mapFilePath))
            {
                _map.LoadFromFile(_mapFilePath, _contractByteCode);
            }
            else
            {
                _map = null;
                Log($"Warning: Could not find {_mapFilePath}");
                //return false;
            }

            if (_map != null && _map.Entries.Any())
            {
                _srcFileName = _map.Entries.FirstOrDefault().url;
                if (string.IsNullOrEmpty(_srcFileName))
                {
                    throw new Exception("Error: Could not load the debug map correctly, no source file specified in map.");
                }
                if (!File.Exists(_srcFileName))
                {
                    throw new Exception($"Error: Could not load the source code, check that this file exists: {_srcFileName}");
                }

                _debugContent[DebugMode.Source] = File.ReadAllText(_srcFileName);
                _language = LanguageSupport.DetectLanguage(_srcFileName);
                _mode     = DebugMode.Source;
            }

            //Save the settings
            _settings.lastOpenedFile = avmPath;
            _settings.Save();
            _avmFileLoaded = true;

            //Force a reset now that we're loaded
            _resetFlag = true;

            return(true);
        }