konrad-kruczynski / elfsharp

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

Fix Section.GetContents Method #62

Closed rollrat closed 4 years ago

rollrat commented 4 years ago

GetContents function prints the wrong bytes.

var elf = ELFReader.Load("test/1. Hello World/a.out", false);
var code = (ProgBitsSection<ulong>)elf.GetSection(".text");
var test1 = code.GetContents();

fs.Seek((long)code.Offset, SeekOrigin.Begin);
var test2 = new byte[999999];
fs.Read(test, 0, (int)code.Size);

test1 and test2 arrays are definitely different.

konrad-kruczynski commented 4 years ago

Hi @rollrat! Thanks for the catch. It turns out it's a regression after this commit. I'd like to propose some modifications though. I'll comment on them in the PR content directly.

rollrat commented 4 years ago

Thanks for reviewing my code! As you suggested, I changed the code and added contributions!

rollrat commented 4 years ago

I changed the version to suit your requirements. Thank you

konrad-kruczynski commented 4 years ago

Merged, thanks! I'll post a new version on NuGet today.