FieldRVA.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * PERWAPI - An API for Reading and Writing PE Files
  3. *
  4. * Copyright (c) Diane Corney, Queensland University of Technology, 2004.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the PERWAPI Copyright as included with this
  8. * distribution in the file PERWAPIcopyright.rtf.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY as is explained in the copyright notice.
  12. *
  13. * The author may be contacted at d.corney@qut.edu.au
  14. *
  15. * Version Date: 26/01/07
  16. */
  17. using System;
  18. using System.IO;
  19. using System.Collections;
  20. using System.Security.Cryptography;
  21. namespace QUT.PERWAPI
  22. {
  23. /**************************************************************************/
  24. /// <summary>
  25. /// Descriptor for the address of a field's value in the PE file
  26. /// </summary>
  27. public class FieldRVA : MetaDataElement
  28. {
  29. FieldDef field;
  30. DataConstant data;
  31. uint rva = 0, fieldIx = 0;
  32. /*-------------------- Constructors ---------------------------------*/
  33. internal FieldRVA(FieldDef field, DataConstant data)
  34. {
  35. this.field = field;
  36. this.data = data;
  37. tabIx = MDTable.FieldRVA;
  38. }
  39. internal FieldRVA(PEReader buff)
  40. {
  41. rva = buff.ReadUInt32();
  42. fieldIx = buff.GetIndex(MDTable.Field);
  43. tabIx = MDTable.FieldRVA;
  44. }
  45. internal static void Read(PEReader buff, TableRow[] fRVAs)
  46. {
  47. for (int i = 0; i < fRVAs.Length; i++)
  48. fRVAs[i] = new FieldRVA(buff);
  49. }
  50. internal sealed override void Resolve(PEReader buff)
  51. {
  52. field = (FieldDef)buff.GetElement(MDTable.Field, fieldIx);
  53. field.AddDataValue(buff.GetDataConstant(rva, field.GetFieldType()));
  54. }
  55. internal sealed override void BuildTables(MetaDataOut md)
  56. {
  57. md.AddToTable(MDTable.FieldRVA, this);
  58. md.AddData(data);
  59. }
  60. internal static uint Size(MetaData md)
  61. {
  62. return 4 + md.TableIndexSize(MDTable.Field);
  63. }
  64. internal sealed override void Write(PEWriter output)
  65. {
  66. output.WriteDataRVA(data.DataOffset);
  67. output.WriteIndex(MDTable.Field, field.Row);
  68. }
  69. }
  70. }