Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29601 Discussions

Extract the .FOR code from a EXE?

GWats1
New Contributor I
337 Views

In my haste to try new code on an old VS19 project, I edited the FOR code and overwrote my .FOR subroutine. Is there an easy way or tool that could take the working EXE and extract the old code?

I had a working project for a version 1. I must have copied the FOR routine to a new project and called it V2 and compiled that. The EXE works fine but I now want to edit some new code into it.

My problem is I can't find a copy of my FOR subroutine the went into the working EXE for V2.

I then took the V2 project and added a lot of code to make a V3 that now works in VS26 with the IFX. The older versions used iFort if that makes any difference. I'll blame Covid since we worked from home for 1.5 years and I got comfortable walking 50 feet to my home office instead of riding a bus 25 miles.

I have the .FOR code for V1 and I have the .FOR code for V3 and I need to reconstruct the .FOR code for the V2. In this day of AI everything, can I just ask a chatbot to look over the two FOR versions and build the missing piece? 

It would likely take me a couple of days comparing the 2 FOR versions to do it manually, but I wanted to see if there could be an easier way. 

GWats1_0-1783730580077.png

 

5 Replies
DavidWhite
Valued Contributor II
308 Views

Reverse engineering compiled code into Fortran is next to impossible, and even if you could do it, it would not look anything like your original code.

 

This is why backups and versioning of code are so important - I learned the hard way many years ago, when I lost about one months' consulting work due to a disc failure.  The only consolation was that having repeated the work (gratis of course), I believe that my second attempt at the coding was probably better than the first.

 

All the best with your manual attempt!

GWats1
New Contributor I
258 Views

Hi David,

Thanks for the reply. I do have a couple of old thumb drives to check at home and at work before I dive in to manually recreate the V2 state of the program. My home PC may have some old files also. The missing/overwritten code has about 600 lines and I think I can figure out the lines added between V2 and V3. 

I only occasionally write and compile Fortran code and dealing with the VS26 environment is daunting. I should have just started a new project and brought in the 5 source files and edited the main routine that I wanted to update, but I'm an engineer and only do Fortran for myself and a few engineers around me. 

I do need to learn the debugging stuff in VS26. I typically put in write statements to print out variables and do a trial run to see if the program is calculating things correctly. All the breakpoint stuff is foreign to me. I guess I need to look at some YouTube videos about debugging code.

I'm about to retire and will have some time to play with it.

 

BTW, I had a typo in my original post and was trying to figure out how to edit my post but never could see where.

0 Kudos
davidwarner344
157 Views

No easy way, unfortunately. A compiled EXE can't be turned back into the original .FOR source. Your best option is to compare the V1 and V3 code and use the V2 EXE to verify behavior as you rebuild it. AI can help compare the two versions, but it can't recover code that only exists in the executable.

 
 
 
0 Kudos
JohnNichols
Honored Contributor I
34 Views

There is a one to one relationship between the Fortran to Executable code, there has to be for each compiler.  

Therefore mathematically there has to be an inverse relationship, because the mathematical steps are embedded on both sides of the relationship.  

The fact that the EXE is almost impossible for a human to read is not a bar.  

A + B = C has to be the same math on both sides of the compiler.  

Strip out all the guff and find the A+B = C

Just a thought.  

0 Kudos
GWats1
New Contributor I
24 Views

HI Guys,

Thanks for the replies. I'm neck deep in trying to remember what I was thinking 10 years ago when I was revising my code. I do tend to put in comments saying what I was doing which is a help. I only drag out my Fortran skills very infrequently and have to remember my IF Then Else Endif syntax. I may have a few ElseIf in there somewhere.   It is tough trying to remember syntax I learned in 1968 and use every few years.

 

I did figure out enough to use WinPrint.F90 to create a PDF output file, but my simple text output file is years behind the times. At some point I wanted to figure out how to add some simple graphics of a circle with other circles around it and a 12-sided polygon inside into the PDF to show the results of a base plate design. Maybe a call to another graphics subroutine?

 

I write programs mostly for me to use to solve engineering problems I encounter so the output is not a huge priority. I share them with others and grudgingly write a user manual.

I have the ASCE 48-19 manual to recreate the equations, and I helped write the ASCE 113 equations which I am deconstructing to get back to 48-19. These are the tall T-Line poles carrying power around from the generator to the substation.

0 Kudos
Reply