forked from trungnt2910/MemoryModule.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElfProgramHeader.cs
More file actions
70 lines (60 loc) · 2.37 KB
/
Copy pathElfProgramHeader.cs
File metadata and controls
70 lines (60 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using MemoryModule.Linux.Elf;
using System;
using System.Collections.Generic;
using System.Text;
namespace MemoryModule.Linux.Elf
{
public unsafe class ElfProgramHeader
{
private byte* memory;
private ElfProgramHeaderNative* obj;
public ElfProgramHeaderType Type
{
get => (Environment.Is64BitProcess) ? obj->Data64.Type : obj->Data32.Type;
}
public ulong Offset
{
get => Environment.Is64BitProcess ? (ulong)obj->Data64.Offset : obj->Data32.Offset;
}
public ulong FileSize
{
get => Environment.Is64BitProcess ? (ulong)obj->Data64.FileSize : obj->Data32.FileSize;
}
public ulong VirtualAddress
{
get => Environment.Is64BitProcess ? (ulong)obj->Data64.VirtualAddress : obj->Data32.VirtualAddress;
}
public ulong MemorySize
{
get => Environment.Is64BitProcess ? (ulong)obj->Data64.MemorySize : obj->Data32.MemorySize;
}
public ulong Align
{
get => Environment.Is64BitProcess ? (ulong)obj->Data64.Align : obj->Data32.Align;
}
public uint Flags => Environment.Is64BitProcess ? obj->Data64.Flags : obj->Data32.Flags;
public ElfProgramHeader(byte* memory, ElfProgramHeaderNative* obj)
{
this.memory = memory;
this.obj = obj;
}
public override string ToString()
{
return Environment.Is64BitProcess ?
$@"ELF Program Header at: 0x{(ulong)obj:x}, owned by 0x{(ulong)memory:x}
- Type: {obj->Data64.Type},
- Size on file: 0x{(ulong)obj->Data64.Offset:x}..0x{(obj->Data64.Offset.ToUInt64() + obj->Data64.FileSize.ToUInt64()):x}, {obj->Data64.FileSize} bytes.
- Virtual address: 0x{(ulong)obj->Data64.VirtualAddress:x}..0x{(obj->Data64.VirtualAddress.ToUInt64() + obj->Data64.MemorySize.ToUInt64()):x}
- Flags: {obj->Data64.Flags}
- Alignment: {obj->Data64.Align}
" :
$@"ELF Program Header at: 0x{(ulong)obj:x}, owned by 0x{(ulong)memory:x}
- Type: {obj->Data32.Type},
- Size on file: 0x{(ulong)obj->Data32.Offset:x}..0x{(obj->Data32.Offset + obj->Data32.FileSize):x}, {obj->Data64.FileSize} bytes.
- Virtual address: 0x{(ulong)obj->Data32.VirtualAddress:x}..0x{(obj->Data32.VirtualAddress + obj->Data32.MemorySize):x}
- Flags: {obj->Data32.Flags}
- Alignment: {obj->Data32.Align}
";
}
}
}