Skip to content

Commit 8de3dd0

Browse files
vb: COM descriptors described
1 parent 2f67a0c commit 8de3dd0

File tree

8 files changed

+259
-124
lines changed

8 files changed

+259
-124
lines changed

SunFlower.Test/UnitTest1.vb

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Namespace SunFlower.Test
1111
<SetUp>
1212
Public Sub Setup()
1313
End Sub
14-
1514
''' Failed. Half of pointers are points to non-allocated space
1615
<Test(Author := "CoffeeLake", Description := "Checks internal nested structures of Objects and procedures")>
1716
Public Sub ModuleStructTest()
18-
Dim path = "C:\Program Files (x86)\Semi VB Decompiler\SemiVBDecompiler.EXE"
17+
Dim path = "D:\VB3TOOLS\VBDIS3.67e_Reloaded_Rev3_DoDi_s_VB3Decompiler\VBDIS3.67e\VBDIS3.exe"
18+
' Dim path = "C:\Program Files (x86)\Semi VB Decompiler\SemiVBDecompiler.EXE"
1919
Dim common = New CommonDumpingService(path)
2020

2121
Dim vbParamsOption As Some = common.Dump()
@@ -27,51 +27,23 @@ Namespace SunFlower.Test
2727
Dim entryPointManager = New VbEntryPointManager(reader, vbParam, vbParam.Sections)
2828
Dim headerResult As Some = entryPointManager.Vb5Header
2929
Dim header = headerResult.Cast(Of Vb5Header)()
30+
Dim proj = New Vb5ProjectParser(
31+
vbParam.ImageBase,
32+
header,
33+
reader,
34+
vbParam.Sections,
35+
entryPointManager.RuntimeHeaderOffset
36+
)
37+
Dim objOption = DirectCast(proj.ObjectTable, Some)
38+
Dim objTable = DirectCast(objOption.Data, Vb5ObjectTable)
3039

31-
Dim projectInfo = New Vb5ProjectParser(vbParam.ImageBase, header, reader, vbParam.Sections, entryPointManager.RuntimeHeaderOffset)
32-
33-
Dim objOption = DirectCast(projectInfo.ObjectTable, Some)
34-
Dim obj = DirectCast(objOption.Data, Vb5ObjectTable)
35-
36-
'Dim impParser = New VbImportParser(reader, vbParam.Sections, vbParam.ImageBase)
37-
'Dim imps = impParser.ParseImports(info.ExternalTablePointer, info.ExternalTableCount)
38-
39-
Dim objParser = New Vb5ObjectsParser(reader, vbParam.Sections, vbParam.ImageBase)
40-
Dim objs = objParser.ParseObjects(obj.ObjectsArrayPointer, obj.TotalObjectsCount)
41-
42-
objs.Clear()
43-
End Using
44-
End Using
45-
Assert.Pass()
46-
End Sub
47-
<Test(Author := "CoffeeLake")>
48-
Public Sub ModuleImportsTest
49-
Dim path = "C:\Program Files (x86)\Semi VB Decompiler\SemiVBDecompiler.EXE"
50-
' Dim path = "D:\VB3TOOLS\VBDIS3.67e_Reloaded_Rev3_DoDi_s_VB3Decompiler\VBDIS3.67e\VBDIS3.exe"
51-
Dim common = New CommonDumpingService(path)
52-
53-
Dim vbParamsOption As Some = common.Dump()
54-
55-
Dim vbParam As Vb5ServiceParameters = vbParamsOption.Data
56-
57-
Using stream = New FileStream(path, FileMode.Open, FileAccess.Read)
58-
Using reader = New BinaryReader(stream)
59-
Dim entryPointManager = New VbEntryPointManager(reader, vbParam, vbParam.Sections)
60-
Dim headerResult As Some = entryPointManager.Vb5Header
61-
Dim header = headerResult.Cast(Of Vb5Header)()
62-
63-
Dim projectInfo = New Vb5ProjectParser(vbParam.ImageBase, header, reader, vbParam.Sections, entryPointManager.RuntimeHeaderOffset)
64-
Dim infoOption = DirectCast(projectInfo.ProjectInfo, Some)
65-
Dim info = DirectCast(infoOption.Data, Vb5ProjectInfo)
66-
Dim objOption = DirectCast(projectInfo.ObjectTable, Some)
67-
Dim obj = DirectCast(objOption.Data, Vb5ObjectTable)
68-
Dim impParser = New VbImportParser(reader, vbParam.Sections, vbParam.ImageBase)
69-
Dim imps = impParser.ParseImports(info.ExternalTablePointer, info.ExternalTableCount)
40+
Dim comParser = New Vb5ComRegistrationParser(vbParam.ImageBase, header, reader, vbParam.Sections)
41+
Dim comData = comParser.ParseComRegistrationData()
7042

7143
Dim objParser = New Vb5ObjectsParser(reader, vbParam.Sections, vbParam.ImageBase)
72-
Dim objs = objParser.ParseObjects(obj.ObjectsArrayPointer, obj.TotalObjectsCount)
44+
Dim obj = objParser.ParseObjects(objTable.ObjectsArrayPointer, objTable.TotalObjectsCount)
7345

74-
objs.Clear()
46+
comData.GetType()
7547
End Using
7648
End Using
7749
Assert.Pass()

SunFlower.Vb/Headers/Vb5ComInfoOffsets.vb

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
Imports System.Runtime.InteropServices
22

33
Namespace Headers
4-
<StructLayout(LayoutKind.Sequential, Pack := 1)>
4+
<StructLayout(LayoutKind.Sequential, Pack:=1)>
55
Public Structure Vb5ComData
6-
''' Offset from the COM registration data ENDS
7-
Public RegInfoOffset As UInteger
8-
Public ProjectNameOffset As UInteger
9-
Public HelpDirectoryOffset As UInteger
10-
Public ProjectDescriptionOffset As UInteger
11-
Public UuidProjectClsId As ULong
12-
Public TypeLibraryLanguageId As UInteger
13-
Public Unknown As UInteger
14-
Public TypeLibraryMajor As UShort
15-
Public TypeLibraryMinor As UShort
6+
Public RegInfoOffset As UInteger ' bRegInfo
7+
Public ProjectNameOffset As UInteger ' bSZProjectName
8+
Public HelpDirectoryOffset As UInteger ' bSZHelpDirectory
9+
Public ProjectDescriptionOffset As UInteger ' bSZProjectDescription
10+
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)>
11+
Public UuidProjectClsId As Byte() ' uuidProjectClsId
12+
Public TlbLcid As UInteger ' dwTlbLcid
13+
Public Unknown As UShort ' wUnknown
14+
Public TlbVerMajor As UShort ' wTlbVerMajor
15+
Public TlbVerMinor As UShort ' wTlbVerMinor
1616
End Structure
17+
1718

18-
<StructLayout(LayoutKind.Sequential, Pack := 1)>
19+
<StructLayout(LayoutKind.Sequential, Pack:=1)>
1920
Public Structure Vb5ComInfo
20-
''' If not zero -> another COM information structure goes next
21-
Public NextObjectOffset As UInteger
22-
Public ObjectNameOffset As UInteger
23-
Public ObjectDescriptionOffset As UInteger
24-
Public InstancingMode As UInteger
25-
Public ObjectId As UInteger
26-
Public UuidObject As ULong
27-
Public IsInterface As UInteger
28-
Public UuidObjectInterfaceOffset As UInteger
29-
Public UuidEventsInterfaceOffset As UInteger
30-
Public HasEvents As UInteger
31-
Public MiscStatus As UInteger
32-
Public ClassType As Byte
33-
Public ObjectType As Byte
34-
Public ToolBoxBitmap32 As UShort
35-
Public DefaultIcon As UShort
36-
Public IsDesigner As UShort
37-
Public DesignerDataOffset As UInteger
21+
Public NextObjectOffset As UInteger ' bNextObject
22+
Public ObjectNameOffset As UInteger ' bObjectName
23+
Public ObjectDescriptionOffset As UInteger ' bObjectDescription
24+
Public InstancingMode As UInteger ' dwInstancing
25+
Public ObjectId As UInteger ' dwObjectId
26+
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)>
27+
Public UuidObject As Byte() ' uuidObject
28+
Public IsInterface As UInteger ' fIsInterface
29+
Public UuidObjectInterfaceOffset As UInteger ' bUuidObjectIFace
30+
Public UuidEventsInterfaceOffset As UInteger ' bUuidEventsIFace
31+
Public HasEvents As UInteger ' fHasEvents
32+
Public MiscStatus As UInteger ' dwMiscStatus
33+
Public ClassType As Byte ' fClassType
34+
Public ObjectType As Byte ' fObjectType
35+
Public ToolboxBitmap32 As UShort ' wToolboxBitmap32
36+
Public DefaultIcon As UShort ' wDefaultIcon
37+
Public IsDesigner As UShort ' fIsDesigner
38+
Public DesignerDataOffset As UInteger ' bDesignerData
3839
End Structure
3940
End Namespace

SunFlower.Vb/Managers/MemoryManager.vb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ Namespace Managers
4141
Return $"![{ex.Message}]"
4242
End Try
4343
End Function
44+
45+
Protected Function ReadStringAtOffset(offset As UInteger) As String
46+
Dim bytes As New List(Of Byte)()
47+
Dim b As Integer
48+
49+
Do
50+
b = _reader.ReadByte()
51+
If b = 0 Then Exit Do
52+
bytes.Add(CByte(b))
53+
Loop While bytes.Count < 256
54+
55+
Return Encoding.Default.GetString(bytes.ToArray())
56+
End Function
4457
Protected Function VaToFileOffset(va As UInteger) As Long
4558
Dim rva = If(va - imageBase > 0,
4659
va - imageBase,

SunFlower.Vb/Services/Vb5ComRegistrationManager.vb

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)