From a395909574d1f603417dbe9ede6a4bccc57e7edb Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Fri, 8 Oct 2021 08:36:44 -0700 Subject: [PATCH] Add a couple of funky projects Added a project with a few bad address region definitions, and one to exercise the security sandbox. Also, fiddled with the documentation a little. --- SourceGen/RuntimeData/Help/editors.html | 175 +++++++++--------- SourceGen/RuntimeData/Help/index.html | 10 +- SourceGen/RuntimeData/Help/intro-details.html | 2 +- SourceGen/SGTestData/FunkyProjects/BadExt.cs | 47 +++++ SourceGen/SGTestData/FunkyProjects/README.md | 12 +- .../FunkyProjects/Simple-BadExt.dis65 | 66 +++++++ .../FunkyProjects/Simple-BadRegions.dis65 | 103 +++++++++++ SourceGen/Sandbox/ScriptManager.cs | 2 + 8 files changed, 321 insertions(+), 96 deletions(-) create mode 100644 SourceGen/SGTestData/FunkyProjects/BadExt.cs create mode 100644 SourceGen/SGTestData/FunkyProjects/Simple-BadExt.dis65 create mode 100644 SourceGen/SGTestData/FunkyProjects/Simple-BadRegions.dis65 diff --git a/SourceGen/RuntimeData/Help/editors.html b/SourceGen/RuntimeData/Help/editors.html index e5df43c..c705caf 100644 --- a/SourceGen/RuntimeData/Help/editors.html +++ b/SourceGen/RuntimeData/Help/editors.html @@ -14,6 +14,91 @@

Back to index

+

Define Address Region

+ +

Address regions +may be created, edited, resized, or removed. Which +operation is performed depends on the current selection. You can +specify the start and end points of a region by selecting the entire +region, or by selecting just the first and last lines.

+

In all cases, you can specify the range's initial address +as a hexadecimal value. You can prefix it with '$', but that's not +required. +24-bit addresses may be written with a bank separator, e.g. "12/3456" +would resolve to address $123456. +If you want to set the region to be non-addressable, enter +"NA".

+ +

You can also enter a pre-label +or specify that the operand should be formatted as a +relative address. + +

To delete a region, click the "Delete Region" button.

+ +

Create

+ +

If your selection starts with a code or data line, the editor +will allow to create a new address region. If a single line was +selected, the default behavior will be to create a region with a +floating end point. If multiple lines were selected, the default +behavior will be to create a region with a fixed end point.

+ +

The address field will be initialized to the address of the +first selected line.

+ +

You can create a child region that shares the same start offset +as an existing region by selecting the first code or data line +within that region. Note that regions with floating end points cannot +have the same start offset as another region.

+ +

Edit

+ +

If you select only the address region start line, perhaps by +double-clicking the operand there, you will be able to edit the +current region's properties.

+ +

If the region has a floating end point, you can choose to convert +it to a fixed end. The end doesn't move; it just gets fixed in place. +This is a quick way to "lock down" regions once you've established +their end points.

+ +

Resize

+ +

If you select multiple lines, and the first line is an address +region start directive, you will be able to resize that region to +the selection. By definition, the updated region will have a fixed +end point.

+ +

Other notes

+ +

There is no affordance for moving the start offset of a region. You +must create a new region and then delete the old one.

+ +

Regions may not "straddle" the start or end points of other regions.

+ +

Double-clicking on the pseudo-opcode of a region start or end +declaration will move the selection to the other end, rather than +opening the editor.

+ +

To see detailed information about an address region in the "Info" +window, select the region start or end directive. You can see the +current arrangement of address regions across your entire +project with Navigate > View Address Map.

+ + + +

Override Status Flags

+ +

The state of the processor status flags are tracked for every +instruction. Each individual flag is recorded as zero, one, or +"indeterminate", meaning it could hold either value at the start of +that instruction. You can override the value of individual flags.

+

The 65816 emulation bit, which is not part of the processor status +register, may also be set in the editor.

+

The M, X, and E flags will not be editable unless your CPU configuration +is set to 65816.

+ +

Edit Label

Sets or clears a label at the selected offset. The label must have the proper form, and not have the same @@ -34,7 +119,7 @@ be imported by other projects (see Working With Multiple Binaries).

-

Edit Instruction Operand

+

Edit Operand (Instruction)

Operands can be formatted explicitly, or you can let the disassembler select the format for you. By default, immediate constants and addresses with no matching symbol are formatted as hex. Symbols @@ -131,7 +216,8 @@ and comment fields. If not, a new entry with a generic name and pre-filled value field will be created in the nearest table.

-

Edit Data Operand

+

Edit Operand (Data)

+

This dialog offers a variety of choices, and can be used to apply a format to multiple lines. You must select all of the bytes you want to format. For example, to format two bytes as a 16-bit word, you must @@ -275,91 +361,6 @@ comment will have one fewer character per line in cc65 output.

not associated with a file offset. If you delete it, you can get it back by using Edit > Edit Header Comment.

- -

Define Address Region

- -

Address regions may be created, edited, resized, or removed. Which -operation is performed depends on the current selection. You can -specify the start and end points of a region by selecting the entire -region, or by selecting just the first and last lines.

-

In all cases, you can specify the range's initial address -as a hexadecimal value. You can prefix it with '$', but that's not -required. -24-bit addresses may be written with a bank separator, e.g. "12/3456" -would resolve to address $123456. -If you want to set the region to be non-addressable, enter -"NA".

- -

You can also enter a pre-label -or specify that the operand should be formatted as a -relative address. - -

To delete a region, click the "Delete Region" button.

- -

Create

- -

If your selection starts with a code or data line, the editor -will allow to create a new address region. If a single line was -selected, the default behavior will be to create a region with a -floating end point. If multiple lines were selected, the default -behavior will be to create a region with a fixed end point.

- -

The address field will be initialized to the address of the -first selected line.

- -

You can create a child region that shares the same start offset -as an existing region by selecting the first code or data line -within that region. Note that regions with floating end points cannot -have the same start offset as another region.

- -

Edit

- -

If you select only the address region start line, perhaps by -double-clicking the operand there, you will be able to edit the -current region's properties.

- -

If the region has a floating end point, you can choose to convert -it to a fixed end. The end doesn't move; it just gets fixed in place. -This is a quick way to "lock down" regions once you've established -their end points.

- -

Resize

- -

If you select multiple lines, and the first line is an address -region start directive, you will be able to resize that region to -the selection. By definition, the updated region will have a fixed -end point.

- -

Other notes

- -

There is no affordance for moving the start offset of a region. You -must create a new region and then delete the old one.

- -

Regions may not "straddle" the start or end points of other regions.

- -

Double-clicking on the pseudo-opcode of a region start or end -declaration will move the selection to the other end, rather than -opening the editor.

- -

To see detailed information about an address region in the "Info" -window, select the region start or end directive. You can see the -current arrangement of address regions across your entire -project with Navigate > View Address Map.

- - - -

Override Status Flags

- -

The state of the processor status flags are tracked for every -instruction. Each individual flag is recorded as zero, one, or -"indeterminate", meaning it could hold either value at the start of -that instruction. You can override the value of individual flags.

-

The 65816 emulation bit, which is not part of the processor status -register, may also be set in the editor.

-

The M, X, and E flags will not be editable unless your CPU configuration -is set to 65816.

- -

Edit Data Bank (65816 only)

Sets the Data Bank Register (DBR) value for 65816 code. This is used diff --git a/SourceGen/RuntimeData/Help/index.html b/SourceGen/RuntimeData/Help/index.html index 627fd1e..5c1d9c3 100644 --- a/SourceGen/RuntimeData/Help/index.html +++ b/SourceGen/RuntimeData/Help/index.html @@ -83,22 +83,22 @@ and 65816 code. The official web site is

  • Editors
  • Visualizations diff --git a/SourceGen/RuntimeData/Help/intro-details.html b/SourceGen/RuntimeData/Help/intro-details.html index 23eb97b..743cc77 100644 --- a/SourceGen/RuntimeData/Help/intro-details.html +++ b/SourceGen/RuntimeData/Help/intro-details.html @@ -527,7 +527,7 @@ The source code starts with a directive that tells the assembler what the initial address is, and the code and data statements that follow are placed appropriately. More complicated programs might relocate parts of themselves to other parts of memory, or be comprised of multiple -"overlay" segments that, through disk loading or bank-switching, all execute +"overlay" segments that, through disk I/O or bank-switching, all execute at the same address.

    Consider the code in the first tutorial. It loads at $1000, copies diff --git a/SourceGen/SGTestData/FunkyProjects/BadExt.cs b/SourceGen/SGTestData/FunkyProjects/BadExt.cs new file mode 100644 index 0000000..0ad60fe --- /dev/null +++ b/SourceGen/SGTestData/FunkyProjects/BadExt.cs @@ -0,0 +1,47 @@ +// Copyright 2021 faddenSoft. All Rights Reserved. +// See the LICENSE.txt file for distribution terms (Apache 2.0). + +using System; +//using System.Collections.Generic; +using System.IO; + +using PluginCommon; + +namespace FunkyTest { + ///

    + /// Extension script that tries to violate the security sandbox. + /// + public class BadExt: MarshalByRefObject, IPlugin { + private IApplication mAppRef; + private byte[] mFileData; + + public string Identifier { + get { + return "Bad test"; + } + } + + public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans) { + mAppRef = appRef; + mFileData = fileData; + + mAppRef.DebugLog("BadTest(id=" + AppDomain.CurrentDomain.Id + "): prepare()"); + + // The behavior should be either "found" or "not found" depending on whether or + // not the security sandbox is enabled. The output is visible in the analyzer + // output window. + mAppRef.DebugLog("Testing file access..."); + string testDir = @"C:\"; + if (Directory.Exists(testDir)) { + mAppRef.DebugLog("Found " + testDir); + } else { + mAppRef.DebugLog("No such file " + testDir); + } + } + + public void Unprepare() { + mAppRef = null; + mFileData = null; + } + } +} diff --git a/SourceGen/SGTestData/FunkyProjects/README.md b/SourceGen/SGTestData/FunkyProjects/README.md index cab0a4b..64a4c09 100644 --- a/SourceGen/SGTestData/FunkyProjects/README.md +++ b/SourceGen/SGTestData/FunkyProjects/README.md @@ -19,8 +19,11 @@ The files are: not match the data file contents. The program should tell you this and offer to let you locate the correct file. * Simple-BadDescLen.dis65 : An operand format descriptor covers a range - off the end of the file. THe program should tell you that it's discarding + off the end of the file. The program should tell you that it's discarding the bad format and continuing. + * Simple-BadExt.dis65 : The project has an extension script that attempts + to perform some basic file I/O that should be blocked by the security + sandbox. (Must look at analyzer output to see the failure.) * Simple-BadJSON.dis65 : Garbage has been inserted into the JSON data stream. The project load should fail with an appropriate message. * Simple-BadLen.dis65 : The data file length stored in the project file @@ -29,6 +32,10 @@ The files are: * Simple-BadMagic.dis65 : The "magic number" at the start of the project file has been damaged. The project load should fail with an appropriate message. + * Simple-BadRegions.dis65 : The project has three correct regions, and + three bad regions: one is zero-length, one is an exact duplicate of + another region, and one straddles two regions. The bad regions should + be discarded with warning messages. * Simple-DupLabel.dis65 : More than one line has the same label. You should be warned that the duplicates are being stripped away. * Simple-FutureVersion.dis65 : The project has a content-version higher @@ -36,10 +43,9 @@ The files are: * Simple-MissingPlatSym.dis65 : One of the platform symbol files listed in the project file does not exist. You should be notified of the problem and loading should continue. (Furthermore, if you look in the project - settings, the missing project file should still be present.) + settings, the missing project file should still be listed.) * Simple-TooShort.dis65 : Same as Simple-BadMagic, but tests to see if we choke when the file is shorter than the magic string. * ZeroLengthFile : This is intended for use with "new project". The application should refuse to create a new project for a zero-length file. - diff --git a/SourceGen/SGTestData/FunkyProjects/Simple-BadExt.dis65 b/SourceGen/SGTestData/FunkyProjects/Simple-BadExt.dis65 new file mode 100644 index 0000000..3c8f6e2 --- /dev/null +++ b/SourceGen/SGTestData/FunkyProjects/Simple-BadExt.dis65 @@ -0,0 +1,66 @@ +### 6502bench SourceGen dis65 v1.0 ### +{ +"_ContentVersion":5, +"FileDataLength":6, +"FileDataCrc32":35051720, +"ProjectProps":{ +"CpuName":"6502", +"IncludeUndocumentedInstr":false, +"TwoByteBrk":false, +"EntryFlags":33489103, +"AutoLabelStyle":"Simple", +"AnalysisParams":{ +"AnalyzeUncategorizedData":true, +"DefaultTextScanMode":"LowHighAscii", +"MinCharsForString":4, +"SeekNearbyTargets":true, +"UseRelocData":false, +"SmartPlpHandling":true, +"SmartPlbHandling":true}, + +"PlatformSymbolFileIdentifiers":[], +"ExtensionScriptFileIdentifiers":["PROJ:BadExt.cs"], +"ProjectSyms":{ +}}, + +"AddressMap":[{ +"Offset":0, +"Addr":4096, +"Length":-1024, +"PreLabel":"", +"IsRelative":false}], +"TypeHints":[{ +"Low":0, +"High":0, +"Hint":"Code"}], +"StatusFlagOverrides":{ +}, + +"Comments":{ +}, + +"LongComments":{ +}, + +"Notes":{ +}, + +"UserLabels":{ +}, + +"OperandFormats":{ +}, + +"LvTables":{ +}, + +"Visualizations":[], +"VisualizationAnimations":[], +"VisualizationSets":{ +}, + +"RelocList":{ +}, + +"DbrValues":{ +}} diff --git a/SourceGen/SGTestData/FunkyProjects/Simple-BadRegions.dis65 b/SourceGen/SGTestData/FunkyProjects/Simple-BadRegions.dis65 new file mode 100644 index 0000000..7661354 --- /dev/null +++ b/SourceGen/SGTestData/FunkyProjects/Simple-BadRegions.dis65 @@ -0,0 +1,103 @@ +### 6502bench SourceGen dis65 v1.0 ### +{ +"_ContentVersion":5, +"FileDataLength":6, +"FileDataCrc32":35051720, +"ProjectProps":{ +"CpuName":"6502", +"IncludeUndocumentedInstr":false, +"TwoByteBrk":false, +"EntryFlags":33489103, +"AutoLabelStyle":"Simple", +"AnalysisParams":{ +"AnalyzeUncategorizedData":true, +"DefaultTextScanMode":"LowHighAscii", +"MinCharsForString":4, +"SeekNearbyTargets":true, +"UseRelocData":false, +"SmartPlpHandling":true, +"SmartPlbHandling":true}, + +"PlatformSymbolFileIdentifiers":[], +"ExtensionScriptFileIdentifiers":[], +"ProjectSyms":{ +}}, + +"AddressMap":[{ +"Offset":0, +"Addr":4096, +"Length":2, +"PreLabel":"", +"IsRelative":false}, + +{ +"Offset":2, +"Addr":4098, +"Length":0, +"PreLabel":"invalid-zero", +"IsRelative":false}, + +{ +"Offset":2, +"Addr":4098, +"Length":3, +"PreLabel":"", +"IsRelative":false}, + +{ +"Offset":2, +"Addr":4098, +"Length":3, +"PreLabel":"invalid-dup", +"IsRelative":false}, + +{ +"Offset":5, +"Addr":4101, +"Length":-1024, +"PreLabel":"", +"IsRelative":false}, + +{ +"Offset":3, +"Addr":4098, +"Length":3, +"PreLabel":"invalid-cross", +"IsRelative":false} +], + +"TypeHints":[{ +"Low":0, +"High":0, +"Hint":"Code"}], +"StatusFlagOverrides":{ +}, + +"Comments":{ +}, + +"LongComments":{ +}, + +"Notes":{ +}, + +"UserLabels":{ +}, + +"OperandFormats":{ +}, + +"LvTables":{ +}, + +"Visualizations":[], +"VisualizationAnimations":[], +"VisualizationSets":{ +}, + +"RelocList":{ +}, + +"DbrValues":{ +}} diff --git a/SourceGen/Sandbox/ScriptManager.cs b/SourceGen/Sandbox/ScriptManager.cs index 06a0023..daddb1a 100644 --- a/SourceGen/Sandbox/ScriptManager.cs +++ b/SourceGen/Sandbox/ScriptManager.cs @@ -275,6 +275,8 @@ namespace SourceGen.Sandbox { int spanLength; List addrEnts = mProject.AddrMap.GetEntryList(out spanLength); + // TODO: if Prepare() throws an exception, we should catch it and report + // it to the user. DomainMgr.PluginMgr.PreparePlugins(appRef, spanLength, addrEnts, plSyms); } }