Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions _.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Drivers/WindowsDecompiler/bin/x64/Debug/net6.0-windows/WindowsDecompiler.exe",
"args": [],
"cwd": "${workspaceFolder}/src/Drivers/WindowsDecompiler",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
39 changes: 39 additions & 0 deletions src/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": "0.2.0",
"configurations": [

{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net8.0/astred.dll", "cwd": "${workspaceFolder}",
"args": [],
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "integratedTerminal",
"stopAtEntry": false
},
{
"name": "debug Astred easy", "stopAtEntry": false,
"type": "coreclr", "request": "launch", "console": "integratedTerminal", "preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net8.0/astred.dll", "cwd": "${workspaceFolder}",
"args": [ "-full", "tests/easycpp/easy.cpp", "-treedump", "tests/easycpp/easy.cpp",],
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
"name": "reko li.dcproject", "stopAtEntry": false,
"type": "coreclr", "request": "launch", "console": "integratedTerminal",
"program": "${workspaceFolder}\\..\\..\\LaserType\\LaserImage\\reko-private\\reko.dll",
"cwd": "${workspaceFolder}\\..\\..\\LaserType\\LaserImage",
"args": [ "--env", "ms-dos", "--dasm-bytes", "--dasm-address", "li.dcproject" ],
},
]
}
2 changes: 2 additions & 0 deletions src/Core/Output/AbsynCodeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ private string UnsignedRepresentation(Constant u)
else
{
var sb = new StringBuilder();
#if USE_TILDA_IF_SMALLER
if ((p & msb) != 0 &&
Bits.BitCount(m & p) > Bits.BitCount(m & ~p))
{
sb.Append('~');
p = m & ~p;
hexRep = p.ToString("X", CultureInfo.InvariantCulture);
}
#endif
sb.Append("0x");
int length = hexRep.Length;
int pad;
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Output/Dumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ private void DumpTypedData(SegmentMap map, IProcessorArchitecture arch, ImageMap
{
if (!map.TryFindSegment(item.Address, out var segment) || segment.MemoryArea == null)
return;
if (item.Name != null) {
w.Write("\t\t;;; {0}", item.Name);
w.WriteLine();
}
WriteLabel(item.Address, w);

var rdr = arch.CreateImageReader(segment.MemoryArea, item.Address);
Expand Down
10 changes: 4 additions & 6 deletions src/Core/Output/GlobalDataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,17 @@ public bool VisitArray(ArrayType at)
fmt.Terminate();
fmt.Indent();
fmt.Write("{");
fmt.Terminate();
fmt.Indentation += fmt.TabSize;
fmt.Write(" ");

bool ok = true;
for (int i = 0; i < at.Length; ++i)
{
fmt.Indent();
ok = at.ElementType.Accept(this);
fmt.Terminate(",");
if (i < at.Length - 1) {
fmt.Write(",");
}
}

fmt.Indentation -= fmt.TabSize;
fmt.Indent();
fmt.Write("}");
return ok;
}
Expand Down
109 changes: 103 additions & 6 deletions src/Core/Output/TypedDataDumper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#region License
/*
/*
* Copyright (C) 1999-2024 John Källén.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -31,7 +31,7 @@ public class TypedDataDumper : IDataTypeVisitor
private readonly uint cbSize;
private readonly Formatter fmt;

public TypedDataDumper(EndianImageReader rdr, uint cbSize, Formatter stm)
public TypedDataDumper(EndianImageReader rdr, uint cbSize, Formatter stm)
{
this.rdr = rdr;
this.cbSize = cbSize;
Expand All @@ -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;
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;
}
}
}

Expand Down Expand Up @@ -179,6 +267,8 @@ 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.
Expand All @@ -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)
{
fmt.Write('\'');
}
fmt.WriteLine();
return;
Expand Down
24 changes: 24 additions & 0 deletions src/Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ public uint GetDataSize(IProcessorArchitecture arch, Address addr, DataType dt)
return 0;
while (rdr.IsValid && !rdr.ReadNullCharTerminator(strDt.ElementType))
;
strDt.Length = (int) (rdr.Address - addr);
return (uint) (rdr.Address - addr);
}
else
Expand Down Expand Up @@ -840,6 +841,29 @@ public void AddGlobalField(Address address, DataType dt, string name)
fields.Add(offset, dt, name);
}

public DataType? FindGlobalField(Address address)
{
int offset;
StructureFieldCollection fields;
if (address.Selector.HasValue &&
SegmentMap.TryFindSegment(address, out var seg))
{
offset = (int) address.Offset;
fields = seg.Fields.Fields;
}
else
{
offset = (int) address.ToLinear();
fields = GlobalFields.Fields;
}
var globalField = fields.AtOffset(offset);
if (globalField != null)
{
return globalField.DataType;
}
return null;
}

/// <summary>
/// Add new imported external procedure if there is not one with same
/// import name.
Expand Down
1 change: 1 addition & 0 deletions src/Decompiler/Scanning/GlobalDataWorkItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void VisitString(StringType str)
}

var len = rdr.Offset - offsetStart;
str.Length = (int)len;
program.ImageMap.AddItemWithSize(
addr, new ImageMapItem(addr, (uint) len)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Decompiler/Typing/TypeCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ public void CollectUserGlobalVariableTypes()
{
if (ud.Value.DataType != null)
{
var dt = ud.Value.DataType.Accept(deser);
var dt = program.FindGlobalField(ud.Key);
if (dt == null)
{
dt = ud.Value.DataType.Accept(deser);
}
AddGlobalField(dt, ud.Key, ud.Value.Name);
}
}
Expand Down
Loading