本文整理汇总了C#中IMemory.ReadWord方法的典型用法代码示例。如果您正苦于以下问题:C# IMemory.ReadWord方法的具体用法?C# IMemory.ReadWord怎么用?C# IMemory.ReadWord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMemory
的用法示例。
在下文中一共展示了IMemory.ReadWord方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyRelocations
protected void ApplyRelocations( BinaryReader reader, IMemory memory, ElfSection section, uint baseAddress )
{
List<HiReloc> hiRelocs = new List<HiReloc>();
ElfSection linked = section.Reference;
if( ( linked.Flags & ElfSectionFlags.Alloc ) != ElfSectionFlags.Alloc )
return;
Debug.WriteLine( string.Format( "Relocating section {0} using {1}, {2} relocations total", linked.Name, section.Name, section.Length / 8 ) );
ElfSection textSection = _sectionLookup[ ".text" ];
ElfSection dataSection = _sectionLookup[ ".data" ];
Debug.Assert( textSection != null );
Debug.Assert( dataSection != null );
for( int n = 0; n < section.Length / 8; n++ )
{
reader.BaseStream.Seek( section.ElfOffset + ( 8 * n ), SeekOrigin.Begin );
NativeElfRel rel = new NativeElfRel( reader );
ElfRelocation relocation = new ElfRelocation();
//relocation.Section = section;
relocation.Offset = rel.Offset;
relocation.BaseAddress = ( rel.Info >> 16 ) & 0xFF;
relocation.Symbol = ( rel.Info >> 8 ) & 0xFF;
relocation.RelocationType = ( ElfRelocationType )( byte )( rel.Info & 0xFF );
uint pointer = relocation.Offset;
//ElfSection offsetBase = null;
//ElfSection addressBase = null;
if( ( relocation.Symbol & ( uint )RelocationOffset.Data ) == ( uint )RelocationOffset.Data )
{
//offsetBase = dataSection;
pointer += dataSection.Address;
}
//else if( relocation.BaseAddress == 0x1 )
//{
// offsetBase = textSection;
// pointer += textSection.Address;
//}
else
{
//offsetBase = textSection;
pointer += baseAddress;
}
//ElfSection offsetBase = _sections[ ( int )relocation.Symbol ];
//ElfSection addressBase = _sections[ ( int )relocation.BaseAddress ];
// Happens sometime
if( _symbols.Count == 0 )
{
Debug.WriteLine( "Unable to relocate symbol; symbol table is empty - possibly no .symtab section?" );
return;
}
ElfSymbol symbol = _symbols[ ( int )relocation.Symbol ];
uint symbolValue = symbol.Value;
// !!! This could be bogus
if( ( ( rel.Info >> 8 ) & RelocationRelativeData ) == RelocationRelativeData )
symbolValue += dataSection.Address;
else
symbolValue += baseAddress;
//if( addressBase.Address == 0 )
// symbolValue += baseAddress;
//else
// symbolValue += addressBase.Address;
uint value = ( uint )memory.ReadWord( ( int )pointer );
//Debug.WriteLine( string.Format( " Relocation pointer 0x{0:X8} (elf {1:X8}), value {2:X8}, type {3}, existing memory value {4:X8}",
// pointer, relocation.Offset, symbolValue, relocation.RelocationType, value ) );
bool writeMemory = false;
switch( relocation.RelocationType )
{
case ElfRelocationType.None:
break;
case ElfRelocationType.Mips32:
value += symbolValue;
writeMemory = true;
break;
case ElfRelocationType.Mips26:
Debug.Assert( symbolValue % 4 == 0 );
value = ( uint )( ( value & ~0x03FFFFFF ) | ( ( value + ( symbolValue >> 2 ) ) & 0x03FFFFFF ) );
writeMemory = true;
break;
case ElfRelocationType.Hi16:
{
HiReloc hiReloc = new HiReloc();
hiReloc.Address = pointer;
hiReloc.Value = symbolValue;
hiRelocs.Add( hiReloc );
}
break;
case ElfRelocationType.Lo16:
{
uint vallo = ( ( value & 0x0000FFFF ) ^ 0x00008000 ) - 0x00008000;
while( hiRelocs.Count > 0 )
//.........这里部分代码省略.........