| 23 | extern "C" |
| 24 | { |
| 25 | BN_DECLARE_CORE_ABI_VERSION |
| 26 | |
| 27 | void TailCallTranslation(Ref<AnalysisContext> analysisContext) |
| 28 | { |
| 29 | Ref<Function> function = analysisContext->GetFunction(); |
| 30 | Ref<BinaryView> data = function->GetView(); |
| 31 | |
| 32 | bool updated = false; |
| 33 | uint8_t opcode[BN_MAX_INSTRUCTION_LENGTH]; |
| 34 | InstructionInfo iInfo; |
| 35 | |
| 36 | // Look for jumps to other functions |
| 37 | Ref<LowLevelILFunction> llilFunc = analysisContext->GetLowLevelILFunction(); |
| 38 | for (auto& i : llilFunc->GetBasicBlocks()) |
| 39 | { |
| 40 | // if (m_owner->IsAborted()) |
| 41 | // return; |
| 42 | |
| 43 | Ref<Architecture> arch = i->GetArchitecture(); |
| 44 | size_t instrIndex = i->GetEnd() - 1; |
| 45 | LowLevelILInstruction instr = llilFunc->GetInstruction(instrIndex); |
| 46 | if (instr.operation != LLIL_JUMP) |
| 47 | continue; |
| 48 | |
| 49 | uint64_t platformAddr; |
| 50 | LowLevelILInstruction destExpr = instr.GetDestExpr<LLIL_JUMP>(); |
| 51 | RegisterValue target = destExpr.GetValue(); |
| 52 | if (target.IsConstant()) |
| 53 | platformAddr = target.value; |
| 54 | else if (target.state |
| 55 | == ImportedAddressValue) // Call to imported function, look up type from import symbol |
| 56 | platformAddr = target.value; |
| 57 | else if (target.state == ExternalPointerValue && target.offset == 0) |
| 58 | platformAddr = target.value; |
| 59 | else |
| 60 | continue; |
| 61 | |
| 62 | size_t opLen = data->Read(opcode, instr.address, arch->GetMaxInstructionLength()); |
| 63 | if (!opLen || !arch->GetInstructionInfo(opcode, instr.address, opLen, iInfo)) |
| 64 | continue; |
| 65 | Ref<Platform> platform = iInfo.archTransitionByTargetAddr ? |
| 66 | function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) : |
| 67 | function->GetPlatform(); |
| 68 | if (platform) |
| 69 | { |
| 70 | bool canReturn = true; |
| 71 | Ref<Function> targetFunc = nullptr; |
| 72 | if (target.state == ImportedAddressValue) |
| 73 | { |
| 74 | DataVariable var; |
| 75 | if (data->GetDataVariableAtAddress(target.value, var)) |
| 76 | { |
| 77 | if (var.type && (var.type->GetClass() == PointerTypeClass) |
| 78 | && (var.type->GetChildType()->GetClass() == FunctionTypeClass)) |
| 79 | canReturn = var.type->GetChildType()->CanReturn().GetValue(); |
| 80 | } |
| 81 | } |
| 82 | else if (target.state == ExternalPointerValue && target.offset == 0) |
nothing calls this directly
no test coverage detected