让我们grep
用来进入球场。我不会费心搜索,default
因为我会得到太多结果,但我会尝试Type "Help"
,它不应该出现太多次。如果是 C 字符串,引号将被转义。我们应该先查找 C 字符串,然后再查找 Python 字符串。
Python $ grep 'Type \\"help\\"' . -Ir
./Modules/main.c: "Type \"help\", \"copyright\", \"credits\" or \"license\" " \
它在Modules/main.c
,在Py_Main()
。更多的挖掘给了我们这条线:
fprintf(stderr, "Python %s on %s\n",
Py_GetVersion(), Py_GetPlatform());
因为“on”在格式字符串中,Py_GetPlatform()
必须是linux
而且Py_GetVersion()
必须给出我们想要的字符串...
Python $ grep Py_GetVersion . -Irl
...
./Python/getversion.c
...
看起来很有希望...
PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
我们必须要Py_GetBuildInfo()
,因为它在括号内...
Python $ grep Py_GetBuildInfo . -Irl
...
./Modules/getbuildinfo.c
...
这看起来有点太明显了。
const char *
Py_GetBuildInfo(void)
{
static char buildinfo[50 + sizeof(HGVERSION) +
((sizeof(HGTAG) > sizeof(HGBRANCH)) ?
sizeof(HGTAG) : sizeof(HGBRANCH))];
const char *revision = _Py_hgversion();
const char *sep = *revision ? ":" : "";
const char *hgid = _Py_hgidentifier();
if (!(*hgid))
hgid = "default";
PyOS_snprintf(buildinfo, sizeof(buildinfo),
"%s%s%s, %.20s, %.9s", hgid, sep, revision,
DATE, TIME);
return buildinfo;
}
所以,default
是 Mercurial 分支的名称。通过检查 makefile,我们可以确定这来自宏HGTAG
。名为 makefile 的变量HGTAG
会生成该变量,并且该变量作为命令运行。所以,
简单的解决方案
在构建 Python 时,
Python $ ./configure
Python $ make HGTAG='echo awesome'
Python $ ./python
Python 3.2.3 (awesome, May 1 2013, 21:33:27)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>