MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / RebaseThreadStarts

Method RebaseThreadStarts

view/macho/machoview.cpp:864–942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

862
863
864void MachoView::RebaseThreadStarts(BinaryReader& virtualReader, vector<uint32_t>& threadStarts, uint64_t stepMultiplier)
865{
866 std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
867
868 // create a dummy relocation to handle tagged pointers
869 BNRelocationInfo reloc;
870 memset(&reloc, 0, sizeof(BNRelocationInfo));
871 reloc.type = StandardRelocationType;
872 reloc.size = 8;
873 reloc.nativeType = BINARYNINJA_MANUAL_RELOCATION;
874
875 size_t numReg = 0;
876 size_t numAuth = 0;
877 uint64_t imageBase = GetStart();
878 for (auto threadStart : threadStarts)
879 {
880 if (threadStart == 0xffffffff)
881 break;
882
883 m_logger->LogDebug("Rebasing thread chain start: 0x%x", threadStart);
884 try
885 {
886 uint64_t curAddr = imageBase + threadStart;
887 virtualReader.Seek(curAddr);
888 while (true)
889 {
890 if (!IsOffsetBackedByFile(virtualReader.GetOffset()))
891 {
892 m_logger->LogError("Chained address: 0x%" PRIx64 " in thread start: 0x%x not backed by file!", virtualReader.GetOffset(), threadStart);
893 break;
894 }
895
896 // read tagged pointer
897 uint64_t val = virtualReader.Read64();
898 bool isAuthenticated = (val & (1ULL << 63)) != 0;
899 bool isRebase = (val & (1ULL << 62)) == 0;
900 if (isRebase)
901 {
902 // calculate new target value
903 uint64_t tgtVal;
904 if (isAuthenticated)
905 {
906 numAuth++;
907 tgtVal = (val & 0xFFFFFFFF) + imageBase;
908 }
909 else
910 {
911 numReg++;
912 uint64_t top8Bits = val & 0x0007F80000000000ULL;
913 uint64_t bottom43Bits = val & 0x000007FFFFFFFFFFULL;
914 tgtVal = (top8Bits << 13) | (((int64_t)(bottom43Bits << 21) >> 21) & 0x00FFFFFFFFFFFFFF);
915 tgtVal += m_imageBaseAdjustment;
916 }
917
918 reloc.address = curAddr;
919 DefineRelocation(m_arch, reloc, tgtVal, reloc.address);
920 }
921

Callers

nothing calls this directly

Calls 7

LogDebugMethod · 0.80
LogErrorMethod · 0.80
LogInfoMethod · 0.80
SeekMethod · 0.45
GetOffsetMethod · 0.45
Read64Method · 0.45
countMethod · 0.45

Tested by

no test coverage detected