dnlib icon indicating copy to clipboard operation
dnlib copied to clipboard

The precise method for calculating 'RVA'

Open soheil-js opened this issue 2 years ago • 0 comments

In the research I conducted, I realized that the RVA value depends on "DataDirectories.Length" which can be observed in the path "moduleDefMD.Metadata.PEImage.ImageNTHeaders.OptionalHeader".

example :

ModuleContext _modCtx = ModuleDef.CreateModuleContext();
ModuleDefMD _moduleDefMD = ModuleDefMD.Load("path", _modCtx);
...
IImageOptionalHeader _optionalHeader = _moduleDefMD.Metadata.PEImage.ImageNTHeaders.OptionalHeader;
uint _numberOfRvaAndSizes = (uint)_optionalHeader.DataDirectories.Length;
var _options = new ModuleWriterOptions(_moduleDefMD)
{
    MetadataOptions = { Flags = MetadataFlags.PreserveAll },
    PEHeadersOptions = { NumberOfRvaAndSizes = _numberOfRvaAndSizes },
    Logger = DummyLogger.NoThrowInstance,
    WritePdb = true
};
_moduleDefMD.Write("path", _options);

soheil-js avatar Jan 23 '24 06:01 soheil-js