Skip to content

Commit f2e8895

Browse files
committed
Added basic support for function types.
1 parent bd200de commit f2e8895

9 files changed

Lines changed: 581 additions & 255 deletions

NtApiDotNet/NtApiDotNet.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@
293293
<Compile Include="Win32\Debugger\DbgHelpSymbolResolver.cs" />
294294
<Compile Include="Win32\Debugger\EnumProcessModulesFilter.cs" />
295295
<Compile Include="Win32\Debugger\EnumTypeInformation.cs" />
296+
<Compile Include="Win32\Debugger\FunctionParameter.cs" />
297+
<Compile Include="Win32\Debugger\FunctionTypeInformation.cs" />
296298
<Compile Include="Win32\Debugger\IMAGEHLP_MODULE64.cs" />
297299
<Compile Include="Win32\Debugger\IMAGEHLP_SYMBOL_TYPE_INFO.cs" />
298300
<Compile Include="Win32\Debugger\MODULEINFO.cs" />

NtApiDotNet/Win32/Debugger/DbgHelpSymbolResolver.cs

Lines changed: 435 additions & 253 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2020 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace NtApiDotNet.Win32.Debugger
16+
{
17+
/// <summary>
18+
/// Class for a function parameter.
19+
/// </summary>
20+
public sealed class FunctionParameter
21+
{
22+
/// <summary>
23+
/// Name of the parameter.
24+
/// </summary>
25+
public string Name { get; }
26+
/// <summary>
27+
/// Type of the parameter.
28+
/// </summary>
29+
public TypeInformation ParameterType { get; }
30+
31+
internal FunctionParameter(string name, TypeInformation parameter_type)
32+
{
33+
Name = name;
34+
ParameterType = parameter_type;
35+
}
36+
}
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2020 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System.Collections.Generic;
16+
17+
namespace NtApiDotNet.Win32.Debugger
18+
{
19+
/// <summary>
20+
/// Type information for a function.
21+
/// </summary>
22+
public class FunctionTypeInformation : TypeInformation
23+
{
24+
/// <summary>
25+
/// Type for the return type.
26+
/// </summary>
27+
public TypeInformation ReturnType { get; }
28+
29+
/// <summary>
30+
/// List of function parameters.
31+
/// </summary>
32+
public IReadOnlyList<FunctionParameter> Parameters { get; }
33+
34+
internal FunctionTypeInformation(int type_index, SymbolLoadedModule module, string name, TypeInformation return_type, IEnumerable<FunctionParameter> parameters)
35+
: base(SymTagEnum.SymTagFunctionType, 0, type_index, module, name)
36+
{
37+
ReturnType = return_type;
38+
Parameters = new List<FunctionParameter>(parameters).AsReadOnly();
39+
}
40+
}
41+
}

NtApiDotNet/Win32/Debugger/ISymbolTypeResolver.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,19 @@ public interface ISymbolTypeResolver
5151
/// <param name="mask">A mask string for the type name. e.g. mod!ABC*</param>
5252
/// <returns>The list of types.</returns>
5353
IEnumerable<TypeInformation> QueryTypesByName(IntPtr base_address, string mask);
54+
55+
/// <summary>
56+
/// Get the address of a symbol.
57+
/// </summary>
58+
/// <param name="name">The name of the symbol, should include the module name, e.g. modulename!MySymbol.</param>
59+
/// <returns>The symbol type.</returns>
60+
TypeInformation GetTypeForSymbolByName(string name);
61+
62+
/// <summary>
63+
/// Get the address of a symbol.
64+
/// </summary>
65+
/// <param name="address">The address of the symbol.</param>
66+
/// <returns>The symbol type.</returns>
67+
TypeInformation GetTypeForSymbolByAddress(IntPtr address);
5468
}
5569
}

NtApiDotNet/Win32/Debugger/SYMBOL_INFO.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,37 @@
1717
// the original author James Forshaw to be used under the Apache License for this
1818
// project.
1919

20+
using System;
2021
using System.Runtime.InteropServices;
2122

2223
namespace NtApiDotNet.Win32.Debugger
2324
{
25+
[Flags]
26+
enum SYMBOL_INFO_FLAGS
27+
{
28+
SYMFLAG_VALUEPRESENT = 0x00000001,
29+
SYMFLAG_REGISTER = 0x00000008,
30+
SYMFLAG_REGREL = 0x00000010,
31+
SYMFLAG_FRAMEREL = 0x00000020,
32+
SYMFLAG_PARAMETER = 0x00000040,
33+
SYMFLAG_LOCAL = 0x00000080,
34+
SYMFLAG_CONSTANT = 0x00000100,
35+
SYMFLAG_EXPORT = 0x00000200,
36+
SYMFLAG_FORWARDER = 0x00000400,
37+
SYMFLAG_FUNCTION = 0x00000800,
38+
SYMFLAG_VIRTUAL = 0x00001000,
39+
SYMFLAG_THUNK = 0x00002000,
40+
SYMFLAG_TLSREL = 0x00004000,
41+
SYMFLAG_SLOT = 0x00008000,
42+
SYMFLAG_ILREL = 0x00010000,
43+
SYMFLAG_METADATA = 0x00020000,
44+
SYMFLAG_CLR_TOKEN = 0x00040000,
45+
SYMFLAG_NULL = 0x00080000,
46+
SYMFLAG_FUNC_NO_RETURN = 0x00100000,
47+
SYMFLAG_SYNTHETIC_ZEROBASE = 0x00200000,
48+
SYMFLAG_PUBLIC_CODE = 0x00400000,
49+
}
50+
2451
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode), DataStart("Name")]
2552
class SYMBOL_INFO
2653
{
@@ -31,7 +58,7 @@ class SYMBOL_INFO
3158
public int Index;
3259
public int Size;
3360
public long ModBase; // Base Address of module comtaining this symbol
34-
public int Flags;
61+
public SYMBOL_INFO_FLAGS Flags;
3562
public long Value; // Value of symbol, ValuePresent should be 1
3663
public long Address; // Address of symbol including base address of module
3764
public int Register; // register holding value or pointer to value

NtApiDotNet/Win32/Debugger/SymbolInformation.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class SymbolInformation
3939
/// Internal type index.
4040
/// </summary>
4141
internal int TypeIndex { get; }
42+
internal SymTagEnum Tag { get; }
4243

4344
private static SymbolInformationType MapType(SymTagEnum tag)
4445
{
@@ -50,6 +51,10 @@ private static SymbolInformationType MapType(SymTagEnum tag)
5051
return SymbolInformationType.EnumeratedType;
5152
case SymTagEnum.SymTagBaseType:
5253
return SymbolInformationType.BaseType;
54+
case SymTagEnum.SymTagFunction:
55+
return SymbolInformationType.Function;
56+
case SymTagEnum.SymTagPointerType:
57+
return SymbolInformationType.Pointer;
5358
default:
5459
return SymbolInformationType.UndefinedType;
5560
}
@@ -62,6 +67,16 @@ internal SymbolInformation(SymTagEnum tag, long size, int type_index, SymbolLoad
6267
Module = module;
6368
TypeIndex = type_index;
6469
Type = MapType(tag);
70+
Tag = tag;
71+
}
72+
73+
/// <summary>
74+
/// Overridden ToString method.
75+
/// </summary>
76+
/// <returns>Returns the symbol name.</returns>
77+
public override string ToString()
78+
{
79+
return Name;
6580
}
6681
}
6782
}

NtApiDotNet/Win32/Debugger/SymbolInformationType.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public enum SymbolInformationType
3636
/// </summary>
3737
BaseType,
3838
/// <summary>
39+
/// A function type.
40+
/// </summary>
41+
Function,
42+
/// <summary>
43+
/// A pointer type.
44+
/// </summary>
45+
Pointer,
46+
/// <summary>
3947
/// Undefined.
4048
/// </summary>
4149
UndefinedType,

NtApiDotNet/Win32/ISymbolResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public interface ISymbolResolver : IDisposable
7171
/// Get the address of a symbol.
7272
/// </summary>
7373
/// <param name="name">The name of the symbol, should include the module name, e.g. modulename!MySymbol.</param>
74-
/// <returns></returns>
74+
/// <returns>The address of the symbol</returns>
7575
IntPtr GetAddressOfSymbol(string name);
7676
/// <summary>
7777
/// Get the symbol name for an address.

0 commit comments

Comments
 (0)