Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333949 - CDT PE Binary Parser does not recognize Borland compiled executable
Summary: CDT PE Binary Parser does not recognize Borland compiled executable
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-11 03:40 EST by VT CLA
Modified: 2020-09-04 15:26 EDT (History)
2 users (show)

See Also:


Attachments
PE parser Borland patch (782 bytes, patch)
2011-01-12 22:58 EST, Marc-André Laperle CLA
no flags Details | Diff
Test binary (46.00 KB, application/octet-stream)
2012-11-17 22:58 EST, Marc-André Laperle CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description VT CLA 2011-01-11 03:40:00 EST
Build Identifier: 20100917-0705

Hi all,

I'm running into a strange problem where eclipse cdt isn't recognizing a binary executable compiled with Borland/CodeGear. However, it has no trouble with executables created with these tools: msvc, digital mars compiler, mingw-gcc, executable created with the PE-Lib API.

After some extensive analysis of the difference in the generated PE file structure, it appears the problem is coming from the e_lfanew data field in the Dos Header. PE executables that the binary parser recognized all had a e_lfanew value <= 0x100h. The compiled PE executable from Borland/CodeGear had a e_lfanew value of 0x200h, which the parser did not recognize as a valid executable.

As an experiment, I hand-modified the Borland executable with CFF Explorer so that the e_lfanew has a value of 0x100h instead of 0x200h. After saving the modifications, a refresh in the Eclipse IDE properly recognizes it as a valid PE executable!

By recognize, I mean when you look in the C/C++ Projects Panel, the executable file shows either a bug icon or the blue circle with a right arrowhead inside it. When it's not recognize, the generic 01010 icon is shown for the executable instead.

Reproducible: Always

Steps to Reproduce:
1. Compile any simple hello world program with Borland/CodeGear compiler toolset.   Can use any version as it seems to happen with all of them.

2. Start a new project in Eclipse CDT and have the root folder point to the location of where the compiled program is located.

3. Make sure the project is set to use the PE Binary Parser and not the ELF parser.

You will see that the icon in the C/C++ projects pane isn't shown correct for that executable file. As a side effect, when you try to debug it or run it by right clicking project name->Run As (or Debug As)->1 Local C/C++ Application it will give the error message: Launch failed. Binary not found.
Comment 1 VT CLA 2011-01-12 20:17:43 EST
Can I get some response on this bug report?
Comment 2 Marc-André Laperle CLA 2011-01-12 21:43:10 EST
Hi, 

Looks like good investigation. Maybe you could try making a patch?
http://wiki.eclipse.org/Getting_started_with_CDT_development

I think the changes would be in the org.eclipse.cdt.core plugin, in the package
org.eclipse.cdt.utils.coff
or
org.eclipse.cdt.utils.coff.parser

And this bug probably belongs to Component : cdt-core :)
Comment 3 Marc-André Laperle CLA 2011-01-12 22:58:26 EST
Created attachment 186700 [details]
PE parser Borland patch

Knowing nothing about PE and just looking at the code...I just increased the hint buffer size and it works. Do you know what the exact hint buffer size should be? I don't want to just put a bigger number and hope for the best ;)
Comment 4 VT CLA 2011-01-13 02:01:25 EST
Actually, I have no idea what the hint buffer size is suppose to signify or represent.

After looking through the documentation and COFF specs, I am unable to find what the max allowable value is for e_lfanew. Since this is a long type, 32-bit value on a typical i386 machine, I would guess e_lfanew could possibly be as high as 4,294,967,295(0xFFFF) -- though unlikely in practice for obvious reasons.

I don't know how qualified I am to submit a patch fix for this though. I program primarily in C/C++ and I don't know any Java really. Add to this the fact that I don't even know the eclipse CDT codebase at all and you're asking for an impossible task.

I can however test if your patch corrects the bug or not. But I'll need a way to get a build of eclipse with the patch applied somehow.
Comment 5 Marc-André Laperle CLA 2012-11-17 22:58:30 EST
Created attachment 223697 [details]
Test binary

Here's a test exe I compiled when I first look at this.