It looks like dark times ahead for this “Flash Boy.”

A New York state appeals judge upheld a conviction against former Goldman Sachs programmer Sergey Aleynikov on Thursday — likely ending a nine-year court saga over the theft of “secret sauce” trading code used by the banking giant.

The decision, written by Judge Eugene M. Fahey, strikes at the heart of Aleynikov’s argument — that he couldn’t possibly have broken larceny laws, because those laws only apply to physical things. The code, he argued, was exempt from the definition written in the law.

The judge didn’t buy it.

“Ideas begin in the mind,” Fahey wrote in his 28-page decision. “By its very nature, an idea, be it a symphony or computer source code, begins as intangible property. However, the medium upon which an idea is stored is generally physical, whether it is represented on a computer hard drive, vinyl record, or compact disc.”

The ruling comes a week after a New Jersey court dealt another blow to the ex-Wall Street computer whiz, and ruled that Goldman Sachs doesn’t have to pay his legal bills — which have risen to about $10 million.

Kevin Marino, a lawyer for Aleynikov, said he was “disappointed” in the ruling, and vowed to file a motion to set aside a previous jury’s guilty verdict.

The decision is a stark turnaround from three years ago, when a New York judge ruled in Aleynikov’s favor.

“Aleynikov doubtless acted wrongfully,” Justice Daniel Conviser said in his sprawling, 72-page opinion then. “But in this Court’s view, the People did not prove he committed this particular obscure crime.”

The 48-year-old Russian-born programmer has been convicted twice of theft charges — once in federal court and once in state court — and spent 11 months in jail.

Aleynikov worked as a programmer for Goldman’s high-frequency trading operation until 2009, when he left to take a similar job at a Chicago firm, Teza Technologies.

Aleynikov made a copy of the bank’s source code. Goldman complained to the FBI, which arrested Aleynikov at Newark Airport.

DA Cyrus Vance Jr., who jumped into the case after the federal conviction was tossed, has claimed that the code Aleynikov took was Goldman’s “secret sauce” for its ultra-fast trading computers.

Aleynikov doesn’t dispute he took the code, but claims he wanted to study it. His lawyer says he didn’t break any criminal laws, and the matter should be a civil dispute.