Hack Forums
[C#] Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ (/showthread.php?tid=5810103)



Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ - gigajew - Mar 10, 2018

Read and write extra data (EoF) of a PE file.

Methods:
public static void SetExtraData(String fileName, Byte[] extraData)
public static Byte[] GetExtraData(String fileName)
public static Int64 GetSizeOfPE(String fileName)




RE: Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ - Ninja - Mar 10, 2018

You can change:
Code
if (information.Exists)
{
    //few lines of code here
}
return -1;
To:
Code
if(!information.Exists)
    return -1
//few lines of code here
Since there is no else statement anyways, and so all the code inside will not be indented anymore. This just makes it a bit nicer to read.


RE: Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ - gigajew - Mar 11, 2018

Yeah that's good advice thanks. Currently working on UDP chat with smileys. Then possibly I'll take on re-creating bahnahnahs netcore project.


RE: Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ - HFDone - Mar 12, 2018

the sizeofoptionalheader is not always 0xE0 its not gonna work with 64bit app.


RE: Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ - gigajew - Mar 12, 2018

(Mar 12, 2018 03:18 AM)HFDone Wrote:  the sizeofoptionalheader is not always 0xE0 its not gonna work with 64bit app.

It reads numberofsections and sizeofheader, adds sizeofheader and raw size of each section to calculate the size. Looking at a 64-bit assembly and a 32-bit assembly in CFF explorer the math seems to add up.


RE: Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ - HFDone - Mar 13, 2018

(Mar 12, 2018 06:47 PM)gigajew Wrote:  It reads numberofsections and sizeofheader, adds sizeofheader and raw size of each section to calculate the size. Looking at a 64-bit assembly and a 32-bit assembly in CFF explorer the math seems to add up.

stream.Seek((e_lfanew + 0xf8 + (i * 40)) + 0x10, SeekOrigin.Begin);


RE: Read/Write EoF (end-of-file) or extra data | NEW CLASS+++ - gigajew - Mar 13, 2018

(Mar 13, 2018 03:08 AM)HFDone Wrote:  stream.Seek((e_lfanew + 0xf8 + (i * 40)) + 0x10, SeekOrigin.Begin);

Ah thanks for the input, I'll change it once i get on my pc