Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disassembly view now corrupts at the start of some procedures. MASTER: WindowsDecompiler #1334

Closed
gbody opened this issue Feb 28, 2024 · 2 comments

Comments

@gbody
Copy link
Contributor

gbody commented Feb 28, 2024

Steps are to load sample LinkIIgs, select scan binaries from the menu, select procedure check_error_level.
See attachment for description and example of corruption.

It appears this started after the implementation of the IMemory interface and is still occurring using the most recent commit.

reko - disassembly display issue.docx

@gbody
Copy link
Contributor Author

gbody commented Mar 2, 2024

Additional information.

AbstractMixedCodeDataModel.SpanGenerator.cs
Lines 254 - 260
public override (ModelPosition, LineSpan)? GenerateSpan()
{
Debug.Assert(line.Count == 0);
var addr = this.position.Address;
if (program.TryCreateImageReader(program.Architecture, addr, item.Size, out var rdr))
{
mem.Formatter.RenderLine(rdr, program.TextEncoding, this);

Prior to IMemory Interface
When creating the the Image reader for the item it used the end address, item.EndAddress
var rdr = program.CreateImageReader(program.Architecture, addr, item.EndAddress);

With new IMemory Interface when creating a reader for the current line of hex data, it uses the current address for the hex data to be displayed from and the Item.size to set the reader data size.
If less than one line this works. If more than one line needs to be displayed it will attempt to display the first line correctly, but when it creates a reader for the second line of hex data for an item, it will use the address for the start of hex data to be displayed and use the Item.size to calculate the end of the reader data which is fine for a full line of hex data. But if the last line is a partial line
eg. for an Item starting at 0x00100F58 and Item.size of 18 (decimal)
x00100F58 01 02 03 04 05 06 07 08
x00100F60 09 0a 0b 0c 0d 0e 0f 10 11 12
Line 1 generation with addr passed as x00100F58, Item.size is 18, calculated end address for reader rdr is x00100F6A
Line 2 generation with addr passed as x00100F60, Item.size is 18, calculated end address for reader rdr is 0x00100F72, which is outside of the original Item range.
When generating the hex representation for the current line, it checks to see if it's less than the end address and reads the data, if it is at the end address it should flag it and return invalid data, so it can pad the remainder of the line before adding the ASCII data view at the end of the line.
What is happening during line 2 generation is a full line of hex data is generated as the end address address is now outside of the range of the item and more than a full line. When the next item to show is being processed the current addr is at 0x00100F70, so the data from 00100F6A - 0x001006F was displayed as hex data and not disassembled code as expected.

uxmal added a commit that referenced this issue Mar 5, 2024
Full credit to @gbody for chasing down the root cause.
@uxmal
Copy link
Owner

uxmal commented Mar 5, 2024

Fixed in 74817ce. Thanks for all the hard work digging up the cause of this regression.

@uxmal uxmal closed this as completed Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants