Re: Location of VBA code in MDB file

Ross Knudsen <[email protected]> Sun, 5 Jan 2014 10:04:26 +1300
Newsgroups gmane.comp.db.mdb-tools.devel
Message-ID <CAMTnqfK9NT6=4ybT=nEskbP2abG8YCL_EdKqN7OV=s_6ZnM7xQ@mail.gmail.com>
--===============2373288495410171846==
Content-Type: multipart/alternative; boundary=001a11c2d3ac2b2a5a04ef2b5fb7

--001a11c2d3ac2b2a5a04ef2b5fb7
Content-Type: text/plain; charset=ISO-8859-1

Hi Tony,

Thanks for the reply, I managed to find it.  Here are the details for a
MDB-2000 file format:

There is a system table called MSysAccessObjects.  This table has an ID
field (autoincrement) and a Data field (binary data).  All the binary data
is of a fixed length (3992 bytes from memory).  The first entry (ID=0)
appears to be some sort of header but the rest of the Data fields contain
an OLE Compound file similar to what was used in the legacy Office file
formats.

So if you concatenate the Data fields in ID order for ID>0 and write to a
file you can extract the VBA contents amongst other information.  You can
inspect the file contents using 7zip.  Here is the VB.net code I used to
extract the information:

Sub Main()

Const Sql As String = "Select * from MSysAccessObjects where ID > 0 order
by ID ASC;"
Const DatabasePath As String = "c:\users\ross\desktop\Copy 1st Mech
JobCosting.mdb"
Const OutputFilePath As String = "c:\users\ross\desktop\compoundfile"

Using conn As New OleDbConnection()

With New OleDbConnectionStringBuilder()
.DataSource = DatabasePath
.Provider = "Microsoft.ACE.OLEDB.12.0"
conn.ConnectionString = .ConnectionString
End With

conn.Open()

Dim table As New DataTable
Using adapter As New OleDbDataAdapter()
adapter.SelectCommand = New OleDbCommand(Sql, conn)
adapter.Fill(table)
End Using

conn.Close()

Using writer As New BinaryWriter(New FileStream(OutputFilePath,
FileMode.Create, FileAccess.Write))
For Each row As DataRow In table.Rows
writer.Write(row.Item("Data"))
Next row

writer.Close()
End Using

End Using

End Sub



On Sat, Jan 4, 2014 at 2:52 PM, Tony Toews <[email protected]> wrote:

>  At 06:34 PM 2014-01-03, Ross Knudsen wrote:
>
> I see on the TODO list that there is a task to extract the VBA code from
> the database.  I'm quite keen on giving this a go but I wanted to know
> where in the database it is actually stored?  Is it a record in a table
> somewhere?
>
>
> I have a vague memory that, starting in Access 2000, all VBA code was
> placed in a BLOB/Memo field in one record.   I'm not at all sure if
> compiled VBA code was placed in the same BLOB.   That said the code won't
> be that useful without the forms and reports.
>
> Tony
>
>  -----
> Tony Toews, Microsoft Access MVP
> Tony's Main Microsoft Access pages - http://www.granite.ab.ca/accsmstr.htm
> Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
> Granite Fleet Manager http://www.granitefleet.com/
>

--001a11c2d3ac2b2a5a04ef2b5fb7
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi Tony,<div><br></div><div>Thanks for the reply, I manage=
d to find it. =A0Here are the details for a MDB-2000 file format:</div><div=
><br></div><div>There is a system table called MSysAccessObjects. =A0This t=
able has an ID field (autoincrement) and a Data field (binary data). =A0All=
 the binary data is of a fixed length (3992 bytes from memory). =A0The firs=
t entry (ID=3D0) appears to be some sort of header but the rest of the Data=
 fields contain an OLE Compound file similar to what was used in the legacy=
 Office file formats.</div>
<div><br></div><div>So if you concatenate the Data fields in ID order for I=
D&gt;0 and write to a file you can extract the VBA contents amongst other i=
nformation. =A0You can inspect the file contents using 7zip. =A0Here is the=
 VB.net code I used to extract the information:</div>
<div><br></div><div><div>Sub Main()</div><div><br></div><div><span class=3D=
"" style=3D"white-space:pre">	</span>Const Sql As String =3D &quot;Select *=
 from MSysAccessObjects where ID &gt; 0 order by ID ASC;&quot;</div><div><s=
pan class=3D"" style=3D"white-space:pre">	</span>Const DatabasePath As Stri=
ng =3D &quot;c:\users\ross\desktop\Copy 1st Mech JobCosting.mdb&quot;</div>
<div><span class=3D"" style=3D"white-space:pre">	</span>Const OutputFilePat=
h As String =3D &quot;c:\users\ross\desktop\compoundfile&quot;</div><div><b=
r></div><div><span class=3D"" style=3D"white-space:pre">	</span>Using conn =
As New OleDbConnection()</div>
<div><br></div><div><span class=3D"" style=3D"white-space:pre">		</span>Wit=
h New OleDbConnectionStringBuilder()</div><div><span class=3D"" style=3D"wh=
ite-space:pre">			</span>.DataSource =3D DatabasePath</div><div><span class=
=3D"" style=3D"white-space:pre">			</span>.Provider =3D &quot;Microsoft.ACE=
.OLEDB.12.0&quot;</div>
<div><span class=3D"" style=3D"white-space:pre">			</span>conn.ConnectionSt=
ring =3D .ConnectionString</div><div><span class=3D"" style=3D"white-space:=
pre">		</span>End With</div><div><br></div><div><span class=3D"" style=3D"w=
hite-space:pre">		</span>conn.Open()</div>
<div><br></div><div><span class=3D"" style=3D"white-space:pre">		</span>Dim=
 table As New DataTable</div><div><span class=3D"" style=3D"white-space:pre=
">		</span>Using adapter As New OleDbDataAdapter()</div><div><span class=3D=
"" style=3D"white-space:pre">			</span>adapter.SelectCommand =3D New OleDbC=
ommand(Sql, conn)</div>
<div><span class=3D"" style=3D"white-space:pre">			</span>adapter.Fill(tabl=
e)</div><div><span class=3D"" style=3D"white-space:pre">		</span>End Using<=
/div><div><br></div><div><span class=3D"" style=3D"white-space:pre">		</spa=
n>conn.Close()</div>
<div><br></div><div><span class=3D"" style=3D"white-space:pre">		</span>Usi=
ng writer As New BinaryWriter(New FileStream(OutputFilePath, FileMode.Creat=
e, FileAccess.Write))</div><div><span class=3D"" style=3D"white-space:pre">=
			</span>For Each row As DataRow In table.Rows</div>
<div><span class=3D"" style=3D"white-space:pre">				</span>writer.Write(row=
.Item(&quot;Data&quot;))</div><div><span class=3D"" style=3D"white-space:pr=
e">			</span>Next row</div><div><br></div><div><span class=3D"" style=3D"wh=
ite-space:pre">			</span>writer.Close()</div>
<div><span class=3D"" style=3D"white-space:pre">		</span>End Using</div><di=
v><br></div><div><span class=3D"" style=3D"white-space:pre">	</span>End Usi=
ng</div><div><br></div><div>End Sub</div></div><div><br></div></div><div cl=
ass=3D"gmail_extra">
<br><br><div class=3D"gmail_quote">On Sat, Jan 4, 2014 at 2:52 PM, Tony Toe=
ws <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_b=
lank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"gmai=
l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left=
:1ex">

<div><div class=3D"im">
<font size=3D"3">At 06:34 PM 2014-01-03, Ross Knudsen wrote:<br>
<blockquote type=3D"cite">I see on the TODO list that
there is a task to extract the VBA code from the database.=A0 I&#39;m
quite keen on giving this a go but I wanted to know where in the database
it is actually stored?=A0 Is it a record in a table
somewhere?</blockquote><br>
</font></div>I have a vague memory that, starting in Access 2000, all VBA c=
ode
was placed in a BLOB/Memo field in one record.=A0=A0 I&#39;m not at all
sure if compiled VBA code was placed in the same BLOB.=A0=A0 That
said the code won&#39;t be that useful without the forms and
reports.=A0=A0=A0=A0=A0 <br><br>
Tony<br><br>
<u></u><p><u></u>
<font size=3D"3">-----<br>
Tony Toews, Microsoft Access MVP<br>
Tony&#39;s Main Microsoft Access pages -
<a href=3D"http://www.granite.ab.ca/accsmstr.htm" target=3D"_blank">
http://www.granite.ab.ca/accsmstr.htm<br>
</a>Tony&#39;s Microsoft Access Blog -
<a href=3D"http://msmvps.com/blogs/access/" target=3D"_blank">
http://msmvps.com/blogs/access/<br>
</a>Granite Fleet Manager
<a href=3D"http://www.granitefleet.com/" target=3D"_blank">
http://www.granitefleet.com/<br>
</a></font></p></div>

</blockquote></div><br></div>

--001a11c2d3ac2b2a5a04ef2b5fb7--


--===============2373288495410171846==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
--===============2373288495410171846==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
mdbtools-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mdbtools-dev

--===============2373288495410171846==--