Skip to content

Commit

Permalink
More work on Relocations, adding computation of RVA for some relocati…
Browse files Browse the repository at this point in the history
…on types.
  • Loading branch information
lkinsella committed Jan 22, 2016
1 parent 3091284 commit 096b058
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
45 changes: 32 additions & 13 deletions Src/Workshell.PE/Relocations/Relocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Workshell.PE
{

public enum RelocationType
public enum RelocationType : byte
{
[EnumAnnotationAttribute("IMAGE_REL_BASED_ABSOLUTE")]
Absolute = 0,
Expand Down Expand Up @@ -42,8 +42,9 @@ public class Relocation : ILocationSupport

private RelocationBlock block;
private RelocationType type;
private int offset;
private ushort offset;
private ushort value;
private uint computed_rva;
private StreamLocation location;

internal Relocation(RelocationBlock relocBlock, long relocOffset, ushort relocValue)
Expand All @@ -52,22 +53,32 @@ internal Relocation(RelocationBlock relocBlock, long relocOffset, ushort relocVa

int reloc_type = relocValue >> 12;
int reloc_offset = relocValue & 0xFFF;

type = (RelocationType)reloc_type;
offset = reloc_offset;
offset = Convert.ToUInt16(reloc_offset);
value = relocValue;
location = new StreamLocation(relocOffset,size);
}
computed_rva = block.PageRVA;

#region Methods
switch (type)
{
case RelocationType.Absolute:
break;
case RelocationType.HighLow:
computed_rva += offset;
break;
case RelocationType.Dir64:
computed_rva += offset;
break;
case RelocationType.High:
case RelocationType.Low:
default:
computed_rva = 0;
break;
}

public override string ToString()
{
return String.Format("{0} (0x{0:X4})",value);
location = new StreamLocation(relocOffset,size);
}

#endregion

#region Static Properties

public static int Size
Expand Down Expand Up @@ -106,7 +117,7 @@ public RelocationType Type
}
}

public int Offset
public ushort Offset
{
get
{
Expand All @@ -122,6 +133,14 @@ public ushort Value
}
}

public uint ComputedRVA
{
get
{
return computed_rva;
}
}

#endregion

}
Expand Down
14 changes: 14 additions & 0 deletions Src/Workshell.PE/Relocations/RelocationBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Workshell.PE
public class RelocationBlock : IEnumerable<Relocation>, ILocationSupport
{

private static readonly int size = Utils.SizeOf<IMAGE_BASE_RELOCATION>();

private RelocationContent content;
private StreamLocation location;
private IMAGE_BASE_RELOCATION relocation;
Expand Down Expand Up @@ -52,6 +54,18 @@ public override string ToString()

#endregion

#region Static Properties

public static int Size
{
get
{
return size;
}
}

#endregion

#region Properties

public StreamLocation Location
Expand Down

0 comments on commit 096b058

Please sign in to comment.