konrad-kruczynski / elfsharp

Pure managed C# library for reading ELF, UImage, Mach-O binaries.
https://elfsharp.it
Other
159 stars 57 forks source link

Program Header Loading #28

Closed Awesomeclaw closed 8 years ago

Awesomeclaw commented 8 years ago

Hello, I'm trying to use ELFSharp to load program binaries for an instruction set simulator. However, part of the program loading sequence involves loading the raw program header data into memory. I see that there are methods to access program header information, but there doesn't seem to be any which allow you to access the data directly. Is this currently possible with ELFSharp? If not, is this something which might be added in the future?

Thanks!

konrad-kruczynski commented 8 years ago

Hi! I'm happy you've found some use for the library. Regarding your question: it can be done, but I have to understand specific requirement. I presume that program header is something that is called Segment by me. In that case I would normally use code like this to load them:

var segmentsToLoad = elf.Segments.Where(x => x.Type == SegmentType.Load);
foreach(var s in segmentsToLoad)
{
    var contents = s.GetContents();
    Load(s.Address, contents); // some method to load
}

Is that something that is not sufficient for you?

Awesomeclaw commented 8 years ago

Hi,

Although I've managed to load the contents of the segments into memory, I'd like to be able to load some of the actual binary ELF data as well. I think the exact data I want is called the 'Segment Header' in the ELFSharp library.

Thanks!

konrad-kruczynski commented 8 years ago

OK, now I get it. I think it won't be a problem. I would first like to finish my initial work on Mach-O support (there is a branch I want to merge) and then I will be able to do it - which should be near the end of the week.

konrad-kruczynski commented 8 years ago

It took some more time than I thought, but I finally have initial Mach-O support and get to your issue. I hope that you're still interested ;)

konrad-kruczynski commented 8 years ago

The necessary function is called GetRawHeader.