MCPcopy Create free account
hub / github.com/AlSch092/UltimateAntiCheat / GetRemoteTextSection

Method GetRemoteTextSection

Process/Process.cpp:928–982  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

926}
927
928bool Process::GetRemoteTextSection(__in const HANDLE hProcess, __out uintptr_t& baseAddress, __out SIZE_T& sectionSize)
929{
930 HMODULE hModule = nullptr;
931 MODULEENTRY32 me32;
932 me32.dwSize = sizeof(MODULEENTRY32);
933
934 HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetProcessId(hProcess));
935 if (hSnapshot == INVALID_HANDLE_VALUE)
936 return false;
937
938 if (Module32First(hSnapshot, &me32))
939 hModule = me32.hModule;
940
941 if(hSnapshot)
942 CloseHandle(hSnapshot);
943
944 if (!hModule)
945 return false;
946
947 IMAGE_DOS_HEADER dosHeader;
948 SIZE_T bytesRead = 0;
949
950 if (!ReadProcessMemory(hProcess, hModule, &dosHeader, sizeof(dosHeader), &bytesRead) || bytesRead != sizeof(dosHeader))
951 return false;
952
953 if (dosHeader.e_magic != IMAGE_DOS_SIGNATURE)
954 return false;
955
956 IMAGE_NT_HEADERS ntHeaders;
957 if (!ReadProcessMemory(hProcess, (LPCVOID)((uintptr_t)hModule + dosHeader.e_lfanew), &ntHeaders, sizeof(ntHeaders), &bytesRead) || bytesRead != sizeof(ntHeaders))
958 return false;
959
960 if (ntHeaders.Signature != IMAGE_NT_SIGNATURE)
961 return false;
962
963 IMAGE_SECTION_HEADER sectionHeader;
964 uintptr_t sectionOffset = (uintptr_t)hModule + dosHeader.e_lfanew + offsetof(IMAGE_NT_HEADERS, OptionalHeader) + ntHeaders.FileHeader.SizeOfOptionalHeader;
965
966 for (WORD i = 0; i < ntHeaders.FileHeader.NumberOfSections; i++)
967 {
968 if (!ReadProcessMemory(hProcess, (LPCVOID)sectionOffset, &sectionHeader, sizeof(sectionHeader), &bytesRead) || bytesRead != sizeof(sectionHeader))
969 return false;
970
971 if (memcmp(sectionHeader.Name, ".text", 5) == 0)
972 {
973 baseAddress = (uintptr_t)hModule + sectionHeader.VirtualAddress;
974 sectionSize = sectionHeader.Misc.VirtualSize;
975 return true;
976 }
977
978 sectionOffset += sizeof(IMAGE_SECTION_HEADER);
979 }
980
981 return false;
982}
983
984
985std::vector<BYTE> Process::ReadRemoteTextSection(__in const DWORD pid)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected