vgenet
08-07-2008, 07:09 AM
hey VBA people... I already posted this on another forum and talked about it there but I thought I would share it with everyone here sinse it'S all about VBA.
I set myself out on a mission to find a way to encrypt VBA code and decrypt/execute on the "fly" I come across allot of trouble with the code until I come up with this (and still cant exactly be classed as a true encryption of the code) only encrypting half of it. So here it is:
Sub EncryptedCodeSub()
' "1ih" xoBgsM
' "2ih" xoBgsM
' "3ih" xoBgsM
End Sub
Sub Auto_Open()
Dim lines() As String: Dim b As String
With ThisDocument: Set Project = .VBProject
a = Project.VBComponents(1).CodeModule.lines(2, 3)
lines = Split(a, vbCrLf): For i = 0 To UBound( _
lines): b = b & vbCrLf & StrReverse(Replace(lines _
(i), "'", "")): Next: Project.VBComponents(1). _
CodeModule.InsertLines 2, b: EncryptedCodeSub
Project.VBComponents(1).CodeModule.DeleteLines 2, 4
End With: End Sub
Ofcourse I "could" write a DLL in VB6 and add that DLL as a Reference in my project - But that's out of the subject.
ps: yes, I know reversing a string is not encryption ;)
or you could obfuscate the encryption/decrypting sub
Sub Auto_Open()
Dim r1743435449() As String: Dim r17506438749 As String
With ThisDocument: Set r17546434449 = .VBProject
a = r17546434449.VBComponents(((2 Mod 6) * 1) - 1).CodeModule. _
lines(2 Mod 6 * 1, 3): r1743435449 = Split(a, vbCrLf): For i _
= 2 Mod 1 To UBound(r1743435449): r17506438749 = r17506438749 & _
vbCrLf & StrReverse(Replace(r1743435449(i), "'", "")): Next
r17546434449.VBComponents(1).CodeModule.InsertLines (2 Mod 6) * 1 _
, r17506438749: EncryptedCodeSub: r17546434449.VBComponents(((2 _
Mod 6) * 1) - 1).CodeModule.DeleteLines 2 Mod 5, (3 Mod 8) + 1
End With: End Sub
I set myself out on a mission to find a way to encrypt VBA code and decrypt/execute on the "fly" I come across allot of trouble with the code until I come up with this (and still cant exactly be classed as a true encryption of the code) only encrypting half of it. So here it is:
Sub EncryptedCodeSub()
' "1ih" xoBgsM
' "2ih" xoBgsM
' "3ih" xoBgsM
End Sub
Sub Auto_Open()
Dim lines() As String: Dim b As String
With ThisDocument: Set Project = .VBProject
a = Project.VBComponents(1).CodeModule.lines(2, 3)
lines = Split(a, vbCrLf): For i = 0 To UBound( _
lines): b = b & vbCrLf & StrReverse(Replace(lines _
(i), "'", "")): Next: Project.VBComponents(1). _
CodeModule.InsertLines 2, b: EncryptedCodeSub
Project.VBComponents(1).CodeModule.DeleteLines 2, 4
End With: End Sub
Ofcourse I "could" write a DLL in VB6 and add that DLL as a Reference in my project - But that's out of the subject.
ps: yes, I know reversing a string is not encryption ;)
or you could obfuscate the encryption/decrypting sub
Sub Auto_Open()
Dim r1743435449() As String: Dim r17506438749 As String
With ThisDocument: Set r17546434449 = .VBProject
a = r17546434449.VBComponents(((2 Mod 6) * 1) - 1).CodeModule. _
lines(2 Mod 6 * 1, 3): r1743435449 = Split(a, vbCrLf): For i _
= 2 Mod 1 To UBound(r1743435449): r17506438749 = r17506438749 & _
vbCrLf & StrReverse(Replace(r1743435449(i), "'", "")): Next
r17546434449.VBComponents(1).CodeModule.InsertLines (2 Mod 6) * 1 _
, r17506438749: EncryptedCodeSub: r17546434449.VBComponents(((2 _
Mod 6) * 1) - 1).CodeModule.DeleteLines 2 Mod 5, (3 Mod 8) + 1
End With: End Sub