Added Module.__ReadDataFromRVA() to make it more convenient to read data based on rva.

This commit is contained in:
jfrijters 2011-03-18 05:49:05 +00:00
Родитель 87c2970ea8
Коммит dbfb677b7b
3 изменённых файлов: 25 добавлений и 12 удалений

Просмотреть файл

@ -207,6 +207,11 @@ namespace IKVM.Reflection
throw new NotSupportedException();
}
public virtual int __ReadDataFromRVA(int rva, byte[] data, int offset, int length)
{
throw new NotSupportedException();
}
public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
throw new NotSupportedException();

Просмотреть файл

@ -87,18 +87,7 @@ namespace IKVM.Reflection.Reader
Array.Clear(data, offset, length);
return;
}
module.SeekRVA(rva);
while (length > 0)
{
int read = module.stream.Read(data, offset, length);
if (read == 0)
{
// C++ assemblies can have fields that have an RVA that lies outside of the file
break;
}
offset += read;
length -= read;
}
module.__ReadDataFromRVA(rva, data, offset, length);
}
public override int __FieldRVA

Просмотреть файл

@ -1044,6 +1044,25 @@ namespace IKVM.Reflection.Reader
return peFile.GetSectionInfo(rva, out name, out characteristics);
}
public override int __ReadDataFromRVA(int rva, byte[] data, int offset, int length)
{
SeekRVA(rva);
int totalBytesRead = 0;
while (length > 0)
{
int read = stream.Read(data, offset, length);
if (read == 0)
{
// C++ assemblies can have fields that have an RVA that lies outside of the file
break;
}
offset += read;
length -= read;
totalBytesRead += read;
}
return totalBytesRead;
}
public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
peKind = 0;