-
Notifications
You must be signed in to change notification settings - Fork 270
Improve handling of nul-terminated string in Globals. #1350
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
7953bb7
a134333
c680779
9a4086b
0b902e9
a33145c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,11 +41,99 @@ public TypedDataDumper(EndianImageReader rdr, uint cbSize, Formatter stm) | |
| public void VisitArray(ArrayType at) | ||
| { | ||
| var addrEnd = rdr.Address + cbSize; | ||
| for (int i = 0; at.IsUnbounded || i < at.Length; ++i) | ||
|
|
||
| if (at.ElementType.Domain < Domain.Composite) | ||
| { | ||
| if (!rdr.IsValid || addrEnd <= rdr.Address) | ||
| return; | ||
| at.ElementType.Accept(this); | ||
| int offset = 0; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There appears to be a lot of duplication here; could this code and the code in |
||
| bool clean = true; | ||
| for (int i = 0; at.IsUnbounded || i < at.Length; ++i) | ||
| { | ||
| if (!rdr.IsValid || addrEnd <= rdr.Address) | ||
| { | ||
| return; | ||
| } | ||
| if (offset % 16 == 0) | ||
| { | ||
| if (!clean) | ||
| { | ||
| fmt.WriteLine(); | ||
| fmt.Write(" "); | ||
| clean = true; | ||
| } | ||
| switch (at.ElementType.Size) | ||
| { | ||
| default: | ||
| case 1: | ||
| fmt.WriteKeyword("db"); | ||
| fmt.Write("\t"); | ||
| break; | ||
| case 2: | ||
| fmt.WriteKeyword("dw"); | ||
| fmt.Write("\t"); | ||
| break; | ||
| case 4: | ||
| fmt.WriteKeyword("dd"); | ||
| fmt.Write("\t"); | ||
| break; | ||
| case 8: | ||
| fmt.WriteKeyword("dq"); | ||
| fmt.Write("\t"); | ||
| break; | ||
| } | ||
| } | ||
| if (!clean) | ||
| { | ||
| fmt.Write(","); | ||
| } | ||
| switch (at.ElementType.Size) | ||
| { | ||
| default: | ||
| case 1: | ||
| byte b = rdr.ReadByte(); | ||
| if (at.ElementType.Domain == Domain.Character && 0x20 <= b && b < 0x7F) | ||
| { | ||
| fmt.Write(string.Format("'{0}'", (char)b)); | ||
| } | ||
| else | ||
| { | ||
| fmt.Write(string.Format("0x{0:X2}", b)); | ||
| } | ||
| offset += 1; | ||
| break; | ||
| case 2: | ||
| fmt.Write(string.Format("0x{0:X4}", rdr.ReadUInt16())); | ||
| offset += 2; | ||
| break; | ||
| case 4: | ||
| fmt.Write(string.Format("0x{0:X8}", rdr.ReadUInt32())); | ||
| offset += 4; | ||
| break; | ||
| case 8: | ||
| fmt.Write(string.Format("0x{0:X16}", rdr.ReadUInt64())); | ||
| offset += 8; | ||
| break; | ||
| } | ||
| clean = false; | ||
| } | ||
| if (!clean) { | ||
| fmt.WriteLine(); | ||
| clean = true; | ||
| } | ||
| } | ||
| else { | ||
| bool clean = true; | ||
| for (int i = 0; at.IsUnbounded || i < at.Length; ++i) | ||
| { | ||
| if (!rdr.IsValid || addrEnd <= rdr.Address) | ||
| return; | ||
|
|
||
| if (!clean) { | ||
| fmt.Write(" "); | ||
| clean = true; | ||
| } | ||
| at.ElementType.Accept(this); | ||
| clean = false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -179,10 +267,12 @@ public void VisitString(StringType str) | |
| fmt.Write("\t"); | ||
| bool inStringLiteral = false; | ||
| string sep = ""; | ||
| int size = str.Length; | ||
| int i = 0; | ||
| while (rdr.TryReadByte(out byte b)) | ||
| { | ||
| //$REVIEW: assumes ASCII. | ||
| if (0x20 >= b && b < 0x7F) | ||
| if (0x20 <= b && b < 0x7F) | ||
| { | ||
| if (!inStringLiteral) | ||
| { | ||
|
|
@@ -198,13 +288,20 @@ public void VisitString(StringType str) | |
| if (inStringLiteral) | ||
| { | ||
| fmt.Write('\''); | ||
| inStringLiteral = false; | ||
| } | ||
| fmt.Write(sep); | ||
| sep = ","; | ||
| fmt.Write(string.Format("0x{0:X2}", b)); | ||
| if (b == 0) | ||
| break; | ||
| } | ||
| i++; | ||
| Debug.Assert(i < size); | ||
| } | ||
| if (inStringLiteral) | ||
| { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a unit tests to show how this is an improvement. |
||
| fmt.Write('\''); | ||
| } | ||
| fmt.WriteLine(); | ||
| return; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on an enum's value in this way is fragile. Consider exposing a
DataType.IsCompositeproperty in a separate PR` to accomplish this.