Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

two issues with new register calling convention

未关闭
#8,455 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@D0ntPanic 已经在做这个了。

开始于 2026年9月21日。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
64/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp

调研方向

Start in arch/x86/arch_x86.cpp at the x86 register calling-convention implementation, especially IsStackAdjustedOnReturn and GetCallLayout, and compare the proposed layout with GetDefaultCallLayout. Verify callee cleanup and that an indirect result pointer occupies the slot after declared parameters: EAX with none, EDX after one, and the stack after EAX, EDX, and ECX are used.

由索引模型根据 Issue 内容生成。

描述

The x86 register calling convention added in the recent CC refactor needs two core fixes to be laid out
correctly: callee stack cleanup, and the hidden pointer for an indirectly returned result going in the argument slot following the declared parameters (EAX with no parameters, EDX after one, the stack once EAX/EDX/ECX
are taken). Without them, every Delphi prototype with a stack argument or a string/record/variant result has its arguments shifted.

Found this while working on a delphi plugin, it certainly produces better results but haven't validated it fully by hand:

diff --git a/arch/x86/arch_x86.cpp b/arch/x86/arch_x86.cpp
index 35d58a008..966f53c23 100644
--- a/arch/x86/arch_x86.cpp
+++ b/arch/x86/arch_x86.cpp
@@ -4913,11 +4913,56 @@ public:
                return type && !type->IsFloat() && type->GetWidth() > 4;
        }

+       bool IsStackAdjustedOnReturn() override
+       {
+               return true;
+       }
+
        bool AreStackArgumentsPushedLeftToRight() override
        {
                return true;
        }

+       /*! Delphi passes the hidden pointer for an indirectly returned result in the argument slot
+           *following* the declared parameters: EAX for a parameterless function, EDX after one
+           parameter, and the stack once EAX, EDX and ECX are taken. GetIndirectReturnValueLocation
+           cannot express that, because the slot depends on how many parameters precede it, so the
+           whole layout is computed here instead.
+        */
+       CallLayout GetCallLayout(BinaryView* view, const ReturnValue& returnValue, const vector<FunctionParameter>& params,
+               const std::optional<set<uint32_t>>& permittedRegs) override
+       {
+               CallLayout result = GetDefaultCallLayout(view, returnValue, params, permittedRegs);
+               if (!result.returnValue.has_value() || !result.returnValue->indirect)
+                       return result;
+
+               // A caller that has pinned the return value to an explicit location keeps it.
+               // MarkNonDefaultParameterLocations clears defaultLocation and re-runs this until the
+               // layout agrees with the location it recorded, so moving a pinned location never
+               // terminates.
+               if (!returnValue.defaultLocation)
+                       return result;
+
+               // Lay the call out a second time with the hidden pointer appended as an ordinary trailing
+               // parameter and nothing returned, then split that parameter back off as the return value.
+               vector<FunctionParameter> extended = params;
+               extended.push_back(FunctionParameter("", Type::PointerType(GetArchitecture(), Type::VoidType())));
+               CallLayout appended = GetDefaultCallLayout(view, ReturnValue(Type::VoidType()), extended, permittedRegs);
+               if (appended.parameters.size() != extended.size())
+                       return result;
+
+               ValueLocation hidden = appended.parameters.back();
+               hidden.indirect = true;
+               hidden.returnedPointer = result.returnValue->returnedPointer;
+               appended.parameters.pop_back();
+
+               result.parameters = appended.parameters;
+               result.returnValue = hidden;
+               result.stackAdjustment = appended.stackAdjustment;
+               result.registerStackAdjustments = appended.registerStackAdjustments;
+               return result;
+       }
+
主要语言
C++
星标
1.3k
派生
298
平均合并
4 天 13 小时
30 天内合并 PR
20

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Vector35/binaryninja-api 的其他 Issue

查看 Vector35/binaryninja-api 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。