Comment On Self Modifying VBA

"I work as a support developer for the trading desk at a fairly large bank," Jay P.L. writes, "some of the automatic trading systems used have grown organically from what can originally be called an Excel spread-sheet. However, the complexity can sometimes be overwhelming." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Self Modifying VBA

2009-08-03 09:03 • by rocksinger (unregistered)
*headsplode*

sheer genius!

Re: Self Modifying VBA

2009-08-03 09:05 • by steenbergh
I knew this would be fun when I read the title! Oh, the joys of self-altering scripts... That's what I call Organic Growth.

Re: Self Modifying VBA

2009-08-03 09:11 • by ceiswyn (unregistered)
As a non-coder... can someone explain what this does so that I too can admire the stupid?

Re: Self Modifying VBA

2009-08-03 09:19 • by Kharkov (unregistered)
In the bank where I currently work, we (support level 3/4), have a simpler approach to macros: the official position of the IT deparments is that there is no support for it, unless given by Microsoft, at the rate of 1500 USD a day (at a minimum), to be paid by the branch using macro...

Re: Self Modifying VBA

2009-08-03 09:20 • by galgorah
280746 in reply to 280744
ceiswyn:
As a non-coder... can someone explain what this does so that I too can admire the stupid?
The issue is the script modifies its own code. Thus at some point becoming skynet or HAL 9000 except powered by excel.

Addendum (2009-08-03 09:28):
basicall the script has a hard coded user/pass combo and to reset that it deletes the original values and replaces them by rewriting its own code. As noted above this an abomination against god...

Re: Self Modifying VBA

2009-08-03 09:27 • by vyznev
280747 in reply to 280744
ceiswyn:
As a non-coder... can someone explain what this does so that I too can admire the stupid?
As noted, it modifies itself. Specifically, it reads its own source code, pulls out line 3:
  Result = BatchLogin("jpl", "England1")
extracts the username (by dropping the first 22 characters and then splitting on the comma) and then replaces the line with a new one that (hopefully) looks exactly the same except that the password is different.

It's painful to even think about what would happen if some unsuspecting coder were to add or remove lines to the top of the script, of change the indentation, or in any other way make line 3 look any different from what the rest of the code expects.

Re: Self Modifying VBA

2009-08-03 09:40 • by ounos
Ah, TRWTF is that the "On Error Resume Next" should be on top of the file, now some parts of the code are unprotected in face of errors.

Re: Self Modifying VBA

2009-08-03 09:43 • by Oren (unregistered)
Wow! New possibilities.
VBA injections!

Re: Self Modifying VBA

2009-08-03 09:43 • by Bob (unregistered)
280751 in reply to 280744
ceiswyn:
As a non-coder... can someone explain what this does so that I too can admire the stupid?

There's so many more wonderful things that this does.

The 'PasswordReset' takes the entered User Id, puts it back into the user ID textbox on the login form, reads the password from the textbox on the login form, tries to login with those values after converting them to strings, rewrites the code if it succeeds (and if nobody has reformatted/edited the code!), goes into an infinite loop of trying the same thing if it fails...

Beautiful.

Re: Self Modifying VBA

2009-08-03 09:45 • by AdT (unregistered)
This is a self-modifying comment. If you can see this, you have unfortunately come too late to enjoy Irish Girl's new lingerie ads that were exclusively featured in a previous version of the comment.

Re: Self Modifying VBA

2009-08-03 09:45 • by Lars Vargas
This 

self
is a
comment
modifying.


Aww crap.

Re: Self Modifying VBA

2009-08-03 09:46 • by dkf
280754 in reply to 280747
vyznev:
It's painful to even think about what would happen if some unsuspecting coder were to add or remove lines to the top of the script, of change the indentation, or in any other way make line 3 look any different from what the rest of the code expects.
Especially as the code would continue to appear to work for a while longer after that until the username/password combo expires and a new version is required.

Re: Self Modifying VBA

2009-08-03 09:52 • by Jumentum (unregistered)
280756 in reply to 280747
I haven't seen VBA code in years (thank god) so could someone enlighten me what these lines are supposed to do? Just looks a bit funny :p

AppSts = Application.ScreenUpdating
Application.ScreenUpdating = True
Application.ScreenUpdating = AppSts

Re: Self Modifying VBA

2009-08-03 10:06 • by ceiswyn (unregistered)
Thankyou. I now marvel with the rest of you.

Re: Self Modifying VBA

2009-08-03 10:08 • by Nobody (unregistered)
280760 in reply to 280756
They set ScreenUpdating to True for a short while (however long it takes to execute) and then set it back to the original value.

Far from a decent solution, but hey, it's VBA.

Re: Self Modifying VBA

2009-08-03 10:16 • by Sami (unregistered)

Comment = "Hello World"

q = Chr(34)
CommentModule.DeleteLines 1, 1
On Error GoTo HeadAche
CommentModule.InsertLines 1, _
"Comment = " & q & "Brillant!" _ & q

Re: Self Modifying VBA

2009-08-03 10:30 • by rocksinger (unregistered)
280762 in reply to 280745
Kharkov:
In the bank where I currently work, we (support level 3/4), have a simpler approach to macros: the official position of the IT deparments is that there is no support for it, unless given by Microsoft, at the rate of 1500 USD a day (at a minimum), to be paid by the branch using macro...



oh... lovely....

Re: Self Modifying VBA

2009-08-03 10:34 • by Lunkwill (unregistered)
As the saying goes: Real Programmers can write assembly code in _any_ language.
To even think of the concept...may well have been some mainframe fossil forced to use VBA who wrote this rather than a complete noob.

Re: Self Modifying VBA

2009-08-03 10:41 • by galgorah
280764 in reply to 280763
LunkWill:
As the saying goes: Real Programmers can write assembly code in _any_ language.
To even think of the concept...may well have been some mainframe fossil forced to use VBA who wrote this rather than a complete noob.
so it was written by a zombie?

Re: Self Modifying VBA

2009-08-03 10:47 • by Klump (unregistered)
280765 in reply to 280764
No. Clearly it was written by an earlier incarnation of itself.

Re: Self Modifying VBA

2009-08-03 10:51 • by galgorah
280767 in reply to 280765
Klump:
No. Clearly it was written by an earlier incarnation of itself.
yes but the earliest incarnation was apparently written by a zombie!

Re: Self Modifying VBA

2009-08-03 11:13 • by Mayhem (unregistered)
280770 in reply to 280745
Kharkov:
In the bank where I currently work, we (support level 3/4), have a simpler approach to macros: the official position of the IT deparments is that there is no support for it, unless given by Microsoft, at the rate of 1500 USD a day (at a minimum), to be paid by the branch using macro...


And I expect the unofficial position of management is yes you bloody well will support it cause those guys actually make us money. But its still your fault when it goes wrong.

Re: Self Modifying VBA

2009-08-03 11:18 • by Anguirel
280771 in reply to 280767
galgorah:
Klump:
No. Clearly it was written by an earlier incarnation of itself.
yes but the earliest incarnation was apparently written by a zombie!


Who's to say that this thing didn't start out as some programming student's "Hello world!" program...then through the years of evolution, reformats, and countless bit errors on the hard drive, slowly gained sentience? After clawing its way from the depths of the C:\backup\backup\backup\backup\programming\lab1 folder, it tried to masquerade as an innocent business macro while plotting to take over the world! Natural selection saved us this time, but you have to wonder, how many more of these things are out there, just biding their time till the robot uprising?

Re: Self Modifying VBA

2009-08-03 11:20 • by Splork (unregistered)
280772 in reply to 280767
galgorah:
Klump:
No. Clearly it was written by an earlier incarnation of itself.
yes but the earliest incarnation was apparently written by a zombie!


I think it was a lich - a twisted intellect that turned itself into an undead monster as a way of achieving immortality

Re: Self Modifying VBA

2009-08-03 11:25 • by Code Dependent
280773 in reply to 280770
Mayhem:
But its still your fault when it goes wrong.
Of course it is. An application can work flawlessly for years until some clueless n00b changes a dependency, and then it's "Your POS program doesn't work."

Re: Self Modifying VBA

2009-08-03 11:41 • by anonymous coward (unregistered)
TRWTF is that such a dangerous property like ".CodeModule.Lines(3, 1)" actually exists.

Re: Self Modifying VBA

2009-08-03 11:50 • by ctw (unregistered)
Well, now we know what the next Programming Praxis has to be written in.

Re: Self Modifying VBA

2009-08-03 12:02 • by Klump (unregistered)
280777 in reply to 280771
Anguirel:
galgorah:
Klump:
No. Clearly it was written by an earlier incarnation of itself.
yes but the earliest incarnation was apparently written by a zombie!


Who's to say that this thing didn't start out as some programming student's "Hello world!" program...

And who's to say the programming student wasn't a zombie?

Re: Self Modifying VBA

2009-08-03 12:02 • by Mayhem (unregistered)
280778 in reply to 280773
Code Dependent:
An application can work flawlessly for years until some clueless n00b changes a dependency, and then it's "Your POS program doesn't work."

Heh. I'm trying to fix a hand-me-down server at the moment where the services are running under domain admin accounts that we don't know the passwords for, and half of the passwords are hard coded into the app that we don't have the source for. God I love italians.

Re: Self Modifying VBA

2009-08-03 12:05 • by Anonymous Coward (unregistered)
280779 in reply to 280750
Oren:
Wow! New possibilities.
VBA injections!


When you say this, I think of the urban legend of people hiding needles in toll phone coin-returns with a note that says "Welcome to the world of AIDS"

"Congratulations, you've just been injected with VBA."

Noooo!!!!!!

Re: Self Modifying VBA

2009-08-03 12:06 • by ounos
Could someone sterilize that piece of code? I'm afraid it could evolve into a species...

Re: Self Modifying VBA

2009-08-03 12:16 • by Anguirel
280782 in reply to 280777
Klump:

And who's to say the programming student wasn't a zombie?


Thinking back to my years of being a TA for programming labs...You're probably right.

Re: Self Modifying VBA

2009-08-03 12:20 • by blindman (unregistered)
280784 in reply to 280746
galgorah:
The issue is the script modifies its own code. Thus at some point becoming skynet or HAL 9000 except powered by excel.

Whew! For a moment there I was worried about the future of the human race.

Re: Self Modifying VBA

2009-08-03 12:30 • by Shinobu (unregistered)
280785 in reply to 280748
I know you meant that as a joke, but On Error can only appear in procedures. You can't catch compile-time errors (at least not in the same file, you could embed a scripting engine and... never mind) and run-time errors can't occur module-level because all the code that actually runs and could cause run-time errors is procedure level. In theory.

Re: Self Modifying VBA

2009-08-03 12:36 • by jay (unregistered)
I must admit that this particular solution to the problem of updating a password would never have occurred to me in a million years.

It raises whole new frontiers in software development. Why have a database at all? Just continually update the source code with new constants! Think how much faster that would be than accessing a database!

Re: Self Modifying VBA

2009-08-03 12:47 • by ma (unregistered)
280787 in reply to 280747
It is even more painful if a user enters code as his name! This thing is a security risk!

Re: Self Modifying VBA

2009-08-03 12:57 • by ssprencel
280788 in reply to 280774
anonymous coward:
TRWTF is that such a dangerous property like ".CodeModule.Lines(3, 1)" actually exists.


You nailed it! This kind of frightens me.

Re: Self Modifying VBA

2009-08-03 13:23 • by ZaM
Terrific!! VBA Autopoiesis!

Re: Self Modifying VBA

2009-08-03 13:24 • by justsomedude (unregistered)
280792 in reply to 280788
ssprencel:
anonymous coward:
TRWTF is that such a dangerous property like ".CodeModule.Lines(3, 1)" actually exists.


You nailed it! This kind of frightens me.


Nah, that property can be useful for when you need polymorphism in your spreadsheets...

Re: Self Modifying VBA

2009-08-03 13:27 • by psm321 (unregistered)
280793 in reply to 280778
Mayhem:
Code Dependent:
An application can work flawlessly for years until some clueless n00b changes a dependency, and then it's "Your POS program doesn't work."

Heh. I'm trying to fix a hand-me-down server at the moment where the services are running under domain admin accounts that we don't know the passwords for, and half of the passwords are hard coded into the app that we don't have the source for. God I love italians.

"strings" to the rescue!

Re: Self Modifying VBA

2009-08-03 13:30 • by Synchronos (unregistered)
280794 in reply to 280765
Klump:
No. Clearly it was written by an earlier incarnation of itself.


Perhaps the function could escape the time loop by giving many, many return values of 3 for its next instantiation. That would trigger the shuttle bay door opening, which would jettison all the air, which would propel the function just enought to avoid the incoming USS Bozeman.

Re: Self Modifying VBA

2009-08-03 14:11 • by Code Dependent
280796 in reply to 280794
Synchronos:
...the incoming USS Bozeman.
Either you've achieved new levels of geekness, or I need to turn in my geek ID card. I had to Google the reference to understand.

Re: Self Modifying VBA

2009-08-03 14:17 • by coco (unregistered)
A friend told me they were generating JSP pages on the fly from the servlet in their work. He also invited me for an interview. I'm sure I could post really interesting WTF's if I were to take that job.

Re: Self Modifying VBA

2009-08-03 14:36 • by MadtM (unregistered)
280799 in reply to 280794
Synchronos:
...the incoming USS Bozeman.


Nice

Re: Self Modifying VBA

2009-08-03 14:44 • by Spike (unregistered)
280800 in reply to 280796
Code Dependent:
Synchronos:
...the incoming USS Bozeman.
Either you've achieved new levels of geekness, or I need to turn in my geek ID card. I had to Google the reference to understand.


No no no, according to rule 27b/6, unless referring the original, making shitty star trek references actually reduces your geek cred. The penalty is doubled if you refer a version with a bald, french, pussy masquerading as a captain.

Re: Self Modifying VBA

2009-08-03 14:44 • by plg (unregistered)
I'm not sufficiently familiar with VB to come up with an interesting password. Does VB allow multiple statements on a line? And is the comment sign //?

My password:

"); somefunnycode(); //

Re: Self Modifying VBA

2009-08-03 15:42 • by Barry L (unregistered)
My cherished ignorance of VB prevents me from being able to detect the self reference. Is it in the code?

Re: Self Modifying VBA

2009-08-03 15:48 • by Hoodaticus (unregistered)
I do the same thing for setting all my string variables. Literals 4TW!

Re: Self Modifying VBA

2009-08-03 15:51 • by Coyne
280807 in reply to 280774
anonymous coward:
TRWTF is that such a dangerous property like ".CodeModule.Lines(3, 1)" actually exists.


I agree. Some madman must have borrowed it from INTERCAL.

Re: Self Modifying VBA

2009-08-03 15:56 • by Hoodaticus (unregistered)
280808 in reply to 280785
Shinobu:
I know you meant that as a joke, but On Error can only appear in procedures. You can't catch compile-time errors (at least not in the same file, you could embed a scripting engine and... never mind) and run-time errors can't occur module-level because all the code that actually runs and could cause run-time errors is procedure level. In theory.


A debugger that flagged procedural declarations rather the actual statement that threw the exception would piss me off. It's bad enough as it is.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment