public CodeBlock DecompileCodeBlock(CodeBlockDefinition blockDefinition) { Position = blockDefinition.Offset; var instrBuilder = ImmutableArray.CreateBuilder <Instruction>(); var refCollector = new ReferenceCollector(Module); ImmutableArray <byte> unrecognizedBytes = ImmutableArray <byte> .Empty; do { Instruction currInstruction = null; try { currInstruction = NextInstruction(); if (currInstruction is EndOfScriptInstruction) { break; } if (instrBuilder.Count > 0) { var last = instrBuilder[instrBuilder.Count - 1]; currInstruction.Previous = last; last.Next = currInstruction; } } catch (UnrecognizedInstructionException) { unrecognizedBytes = ModuleReader.ReadBytes(blockDefinition.EndOffset - Position).ToImmutableArray(); break; } instrBuilder.Add(currInstruction); refCollector.Visit(currInstruction); } while (Position < blockDefinition.EndOffset); return(new CodeBlock(blockDefinition) { Instructions = instrBuilder.ToImmutable(), UnrecognizedBytes = unrecognizedBytes, StringReferences = refCollector.Strings, CodeBlockReferences = refCollector.CodeBlocks, ExternalCodeBlockReferences = refCollector.ExternalCodeBlocks, DataBlockReferences = refCollector.DataBlocks }); }
internal CodeBlock(CodeBlockDefinition blockDefinition) { Definition = blockDefinition; }