md-modules icon indicating copy to clipboard operation
md-modules copied to clipboard

MD Debugger: Add a failsafe against charset pollution (AS)

Open vladikcomper opened this issue 1 year ago • 0 comments

The AS macro assembler has a charset directive, which allows to re-map ASCII-characters to non-standard values. AS projects that aren't careful with this macro may easily corrupt MD Debugger's string output if charset is not restored to the default one.

Per AS documentation, using charset directive without arguments should restore the default charset. MD Debugger macros can always do so before outputting strings unless there are performance concerns against this. Alternatively, charset may be called once before generating texts for exception handlers.

Example of charset pollution

The following was the output of _ErrorMessage macro in one the project that reported this bug:

1906D4 : =$0                          .__lpos:        set             0               ; start position
1906D4 :                             ; Write part of "ADDRESS ERROR" before the end
1906D4 : 1C44 4452 1653              dc.b    substr("ADDRESS ERROR", .__lpos, 0), 0
1906DA : 53FF 1652 524F 
1906E0 : 5200             

Actual bytes it outputs for "ADDRESS ERROR" string:

1C44 4452 1653 53FF 1652 524F 5200

However, here's how "ADDRESS ERROR" ASCII-string should look like:

$ echo ADDRESS ERROR | xxd
4144 4452 4553 5320 4552 524f 5200       ADDRESS ERROR.

This was caused by charset pollution earlier in the project's code.

vladikcomper avatar Dec 27 '24 16:12 vladikcomper