Skip to content

Commit 9f73a9e

Browse files
all upd
1 parent 8de3dd0 commit 9f73a9e

15 files changed

+3315
-62
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ Target toolchain is an experimental SunFlower build
2323
In the early commits you can see `3.1.0` contract attribute
2424
because SunFlower stays at the alpha-stage. New adapters and support
2525
schemes are incoming soon in 4.0 build.
26+
27+
### Example of result
28+
29+
File with full report for VB Semi Decompiler pinned [here](vbartefacts.md)
30+

SunFlower.Test/UnitTest1.vb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Imports System.IO
22
Imports NUnit.Framework
33
Imports Microsoft.VisualBasic
4+
Imports SunFlower.Vb
45
Imports SunFlower.Vb.Handlers
56
Imports SunFlower.Vb.Headers
67
Imports SunFlower.Vb.Services
@@ -48,5 +49,12 @@ Namespace SunFlower.Test
4849
End Using
4950
Assert.Pass()
5051
End Sub
52+
53+
<Test>
54+
Public Sub EntryPointTest()
55+
Dim path = "D:\VB3TOOLS\VBDIS3.67e_Reloaded_Rev3_DoDi_s_VB3Decompiler\VBDIS3.67e\VBDIS3.exe"
56+
Dim entry = New VisualBasicClassicSeed()
57+
entry.Main(path)
58+
End Sub
5159
End Class
5260
End Namespace

SunFlower.Vb.sln.DotSettings.user

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=D_003A_005CLocals_005CSunFlower_005Csrc_005CSunFlower_002EAbstractions_005Cbin_005CDebug_005Cnet8_002E0_005CSunFlower_002EAbstractions_002Edll/@EntryIndexedValue">True</s:Boolean>
3-
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=6a5742a1_002D5103_002D4f39_002D9ffb_002D512d4565debf/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="ModuleStructTest #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
3+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=0ee0162e_002D69e2_002D4d6f_002D895c_002D3119dc53f33b/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="ModuleStructTest #4" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
4+
&lt;TestAncestor&gt;&#xD;
5+
&lt;TestId&gt;NUnit3x::361555DF-8642-403D-98CE-8A5236DE1BCE::net8.0::SunFlower.Test.SunFlower.Test.Tests.ModuleStructTest&lt;/TestId&gt;&#xD;
6+
&lt;TestId&gt;NUnit3x::361555DF-8642-403D-98CE-8A5236DE1BCE::net8.0::SunFlower.Test.SunFlower.Test.Tests.EntryPointTest&lt;/TestId&gt;&#xD;
7+
&lt;/TestAncestor&gt;&#xD;
8+
&lt;/SessionState&gt;</s:String>
9+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=6a5742a1_002D5103_002D4f39_002D9ffb_002D512d4565debf/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="ModuleStructTest #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
410
&lt;TestAncestor&gt;&#xD;
511
&lt;TestId&gt;NUnit3x::361555DF-8642-403D-98CE-8A5236DE1BCE::net8.0::SunFlower.Test.SunFlower.Test.Tests.ModuleStructTest&lt;/TestId&gt;&#xD;
612
&lt;/TestAncestor&gt;&#xD;
@@ -25,10 +31,17 @@
2531
&lt;TestAncestor&gt;&#xD;
2632
&lt;TestId&gt;NUnit3x::361555DF-8642-403D-98CE-8A5236DE1BCE::net8.0::SunFlower.Test.SunFlower.Test.Tests.ModuleImportsTest&lt;/TestId&gt;&#xD;
2733
&lt;/TestAncestor&gt;&#xD;
34+
&lt;/SessionState&gt;</s:String>
35+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=e8f4c70d_002Df9aa_002D489b_002Dbc62_002D186ca027c024/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="ModuleStructTest #5" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
36+
&lt;TestAncestor&gt;&#xD;
37+
&lt;TestId&gt;NUnit3x::361555DF-8642-403D-98CE-8A5236DE1BCE::net8.0::SunFlower.Test.SunFlower.Test.Tests.ModuleStructTest&lt;/TestId&gt;&#xD;
38+
&lt;TestId&gt;NUnit3x::361555DF-8642-403D-98CE-8A5236DE1BCE::net8.0::SunFlower.Test.SunFlower.Test.Tests.EntryPointTest&lt;/TestId&gt;&#xD;
39+
&lt;/TestAncestor&gt;&#xD;
2840
&lt;/SessionState&gt;</s:String>
2941
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fd913fb5_002D90d6_002D4e25_002Dad6b_002D3df66b9397d8/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="ModuleStructTest #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
3042
&lt;TestAncestor&gt;&#xD;
3143
&lt;TestId&gt;NUnit3x::361555DF-8642-403D-98CE-8A5236DE1BCE::net8.0::SunFlower.Test.SunFlower.Test.Tests.ModuleStructTest&lt;/TestId&gt;&#xD;
44+
&lt;TestId&gt;NUnit3x::361555DF-8642-403D-98CE-8A5236DE1BCE::net8.0::SunFlower.Test.SunFlower.Test.Tests.EntryPointTest&lt;/TestId&gt;&#xD;
3245
&lt;/TestAncestor&gt;&#xD;
3346
&lt;/SessionState&gt;</s:String>
3447

SunFlower.Vb/Managers/TableManager.vb

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Namespace Services
2+
' EXEOCXINFO structure creates by vb6.exe!CreateOcxDefFromExe
3+
' while application is compiling
4+
Public Class Vb5ActiveXInfoParser
5+
6+
End Class
7+
End Namespace

SunFlower.Vb/Services/Vb5ImportsParser.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Imports System.Text
33
Imports SunFlower.Vb.Headers
44

55
Namespace Services
6-
Public Class VbImportParser
6+
Public Class Vb5ImportsParser
77
Private ReadOnly _reader As BinaryReader
88
Private ReadOnly _sections As List(Of PeSection)
99
Private ReadOnly _imageBase As UInteger

SunFlower.Vb/Services/Vb5ProjectParser.vb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ Namespace Services
88
Inherits MemoryManager
99

1010
Private ReadOnly _header As Vb5Header
11-
Private ReadOnly _reader As BinaryReader
12-
1311
''' Some(size_t)
1412
''' None(default)
1513
Public Property ProjectInfoOffset As [Option]
Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,81 @@
1+
Imports System.IO
12
Imports SunFlower.Abstractions
3+
Imports SunFlower.Abstractions.Types
4+
Imports SunFlower.Vb.Handlers
5+
Imports SunFlower.Vb.Headers
6+
Imports SunFlower.Vb.Services
7+
Imports SunFlower.Vb.Visualizers
28

3-
<FlowerSeedContract(3, 0,0)>
9+
<FlowerSeedContract(4, 0,0)>
410
Public Class VisualBasicClassicSeed
511
Implements IFlowerSeed
612

7-
Public ReadOnly Property Seed As String = "MSVBVM.dll 5.0+ Runtime walker" _
13+
Public ReadOnly Property Seed As String = "Visual Basic 5.0+ Runtime walker" _
814
Implements IFlowerSeed.Seed
915
Public ReadOnly Property Status As FlowerSeedStatus =
1016
New FlowerSeedStatus() _
1117
Implements IFlowerSeed.Status
1218

1319
Public Function Main(path As String) As Integer Implements IFlowerSeed.Main
20+
Try
21+
Status.Results = New List(Of FlowerSeedResult)()
22+
Dim common = New CommonDumpingService(path)
23+
24+
Dim vbParamsOption As Some = common.Dump()
25+
26+
Dim vbParam As Vb5ServiceParameters = vbParamsOption.Data
27+
28+
Using stream = New FileStream(path, FileMode.Open, FileAccess.Read)
29+
Using reader = New BinaryReader(stream)
30+
Dim entryPointManager = New VbEntryPointManager(reader, vbParam, vbParam.Sections)
31+
Dim headerResult As Some = entryPointManager.Vb5Header
32+
Dim header = headerResult.Cast(Of Vb5Header)()
33+
Dim proj = New Vb5ProjectParser(
34+
vbParam.ImageBase,
35+
header,
36+
reader,
37+
vbParam.Sections,
38+
entryPointManager.RuntimeHeaderOffset
39+
)
40+
Dim projInfoOption = DirectCast(proj.ProjectInfo, Some)
41+
Dim projInfo = DirectCast(projInfoOption.Data, Vb5ProjectInfo)
42+
Dim objOption = DirectCast(proj.ObjectTable, Some)
43+
Dim objTable = DirectCast(objOption.Data, Vb5ObjectTable)
44+
45+
Dim comParser = New Vb5ComRegistrationParser(vbParam.ImageBase, header, reader, vbParam.Sections)
46+
Dim comData = comParser.ParseComRegistrationData()
47+
48+
Dim objParser = New Vb5ObjectsParser(reader, vbParam.Sections, vbParam.ImageBase)
49+
Dim obj = objParser.ParseObjects(objTable.ObjectsArrayPointer, objTable.TotalObjectsCount)
50+
51+
Dim impParser = New Vb5ImportsParser(reader, vbParam.Sections, vbParam.ImageBase)
52+
Dim imps = impParser.ParseImports(projInfo.ExternalTablePointer, projInfo.ExternalTableCount)
53+
54+
Dim headv = New Vb5HeaderVisualizer(header).ToRegion()
55+
Dim projv = New Vb5ProjectInfoVisualizer(projInfo).ToRegion()
56+
Dim imptv = New Vb5ExternalApiVisualizer(imps).ToRegion()
57+
Dim objsv = Vb5ObjectsIterator.Iterate(obj)
58+
59+
Dim reg = New List(Of Region)()
60+
reg.Add(headv)
61+
reg.Add(projv)
62+
reg.Add(imptv)
63+
64+
Status.Results.Add(New FlowerSeedResult(FlowerSeedEntryType.Regions) With {
65+
.BoxedResult = reg
66+
})
67+
Status.Results.Add(New FlowerSeedResult(FlowerSeedEntryType.Regions) With {
68+
.BoxedResult = objsv
69+
})
70+
Status.IsEnabled = True
71+
reader.Close()
72+
End Using
73+
End Using
74+
75+
Catch e As Exception
76+
Status.LastError = e
77+
End Try
1478

15-
Return -1
79+
Return 1 'https://t.me/overfriends/1087
1680
End Function
1781
End Class
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Imports System.Data
2+
Imports SunFlower.Abstractions
3+
Imports SunFlower.Abstractions.Types
4+
Imports SunFlower.Vb.Services
5+
Namespace Visualizers
6+
Public Class Vb5ExternalApiVisualizer
7+
Inherits AbstractStructVisualizer(Of List(Of VbImportInfo))
8+
9+
Public Sub New(struct As List(Of VbImportInfo))
10+
MyBase.New(struct)
11+
End Sub
12+
13+
Public Overrides Function ToDataTable() As DataTable
14+
Return FlowerReflection.ListToDataTable(_struct)
15+
End Function
16+
17+
Public Overrides Function ToString() As String
18+
Return """
19+
Despite the fact that VB5/6 files have no PE import
20+
entries besides runtime library, any program
21+
can freely use WinAPI functions it wants.
22+
This implemented using another internal structure.
23+
```vb
24+
Declare Sub ExitProcess(code As Long) Lib Kernel32.dll
25+
```
26+
"""
27+
End Function
28+
29+
Public Overrides Function ToRegion() As Region
30+
Return New Region("### Declared External API", ToString(), ToDataTable())
31+
End Function
32+
End Class
33+
End Namespace
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1-
Namespace Visualizers
1+
Imports System.Data
2+
Imports SunFlower.Abstractions
3+
Imports SunFlower.Abstractions.Types
4+
Imports SunFlower.Vb.Headers
5+
6+
Namespace Visualizers
27
Public Class Vb5HeaderVisualizer
3-
8+
Inherits AbstractStructVisualizer(Of Vb5Header)
9+
10+
Public Sub New(struct As Vb5Header)
11+
MyBase.New(struct)
12+
End Sub
13+
14+
Public Overrides Function ToDataTable() As DataTable
15+
Return FlowerReflection.GetNameValueTable(_struct)
16+
End Function
17+
18+
Public Overrides Function ToString() As String
19+
Return """
20+
Microsoft Visual Basic virtual machine embed itself
21+
in compiled program/library. This is the first main file structure (starting point), it
22+
contains links to other structures and also some information related to VB project (like user
23+
specified project name and description).
24+
- EntryPoint contains IA32 opcodes and VA address of this structure;
25+
- Generation code is located in `vb6.exe!WriteRubyExeData`;
26+
27+
"""
28+
End Function
29+
30+
Public Overrides Function ToRegion() As Region
31+
Return New Region("## Visual Basic 5.0+ Header", ToString(), ToDataTable())
32+
End Function
433
End Class
534
End Namespace

0 commit comments

Comments
 (0)