- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我需要获取正在运行的进程中堆栈的基地址。这将使我能够打印 addr2line 可以理解的原始堆栈跟踪(运行二进制文件被剥离,但 addr2line 可以访问符号)。我设法通过检查 argv[0]
的 elf header 来做到这一点:我读取入口点并将其从 &_start
中减去:
#include <stdio.h>
#include <execinfo.h>
#include <unistd.h>
#include <elf.h>
#include <stdio.h>
#include <string.h>
void* entry_point = NULL;
void* base_addr = NULL;
extern char _start;
/// given argv[0] will populate global entry_pont
void read_elf_header(const char* elfFile) {
// switch to Elf32_Ehdr for x86 architecture.
Elf64_Ehdr header;
FILE* file = fopen(elfFile, "rb");
if(file) {
fread(&header, 1, sizeof(header), file);
if (memcmp(header.e_ident, ELFMAG, SELFMAG) == 0) {
printf("Entry point from file: %p\n", (void *) header.e_entry);
entry_point = (void*)header.e_entry;
base_addr = (void*) ((long)&_start - (long)entry_point);
}
fclose(file);
}
}
/// print stacktrace
void bt() {
static const int MAX_STACK = 30;
void *array[MAX_STACK];
auto size = backtrace(array, MAX_STACK);
for (int i = 0; i < size; ++i) {
printf("%p ", (long)array[i]-(long)base_addr );
}
printf("\n");
}
int main(int argc, char* argv[])
{
read_elf_header(argv[0]);
printf("&_start = %p\n",&_start);
printf("base address is: %p\n", base_addr);
bt();
// elf header is also in memory, but to find it I have to already have base address
Elf64_Ehdr * ehdr_addr = (Elf64_Ehdr *) base_addr;
printf("Entry from memory: %p\n", (void *) ehdr_addr->e_entry);
return 0;
}
示例输出:
Entry point from file: 0x10c0
&_start = 0x5648eeb150c0
base address is: 0x5648eeb14000
0x1321 0x13ee 0x29540f8ed09b 0x10ea
Entry from memory: 0x10c0
然后我可以
$ addr2line -e a.out 0x1321 0x13ee 0x29540f8ed09b 0x10ea
/tmp/elf2.c:30
/tmp/elf2.c:45
??:0
??:?
如何在不访问 argv
的情况下获取基址?我可能需要在 main()
(全局变量的初始化)之前打印痕迹。转向 ASLR 或 PIE 不是一个选项。
最佳答案
How can I get base address without access to argv? I may need to print traces before main()
有几种方式:
/proc
(几乎总是这样),您可以从 /proc/self/exe
读取 ELF header 。dladdr1()
,如 Antti Haapala 的回答所示。_r_debug.r_map
,它指向加载的ELF 图像的链表。该列表中的第一个条目对应于 a.out
,其 l_addr
包含您要查找的重定位。此解决方案等效于 dladdr1
,但不需要针对 libdl
进行链接。Could you provide sample code for 3?
当然:
#include <link.h>
#include <stdio.h>
extern char _start;
int main()
{
uintptr_t relocation = _r_debug.r_map->l_addr;
printf("relocation: %p, &_start: %p, &_start - relocation: %p\n",
(void*)relocation, &_start, &_start - relocation);
return 0;
}
gcc -Wall -fPIE -pie t.c && ./a.out
relocation: 0x555d4995e000, &_start: 0x555d4995e5b0, &_start - relocation: 0x5b0
Are both 2 and 3 equally portable?
我认为它们的可移植性差不多:dladdr1
是 GLIBC 扩展,也存在于 Solaris 上。 _r_debug
早于 Linux,也可以在 Solaris 上运行(我还没有实际检查过,但我相信它会)。它也可以在其他 ELF 平台上运行。
关于c - 如何找到 PIE 二进制文件的加载重定位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55066749/
我正在使用 Xcode 4.5,部署目标为 iOS 5.1 当我编译我的应用程序时,我收到以下警告,这些方法与两个大小显着增加的特定方法有关。 ld: warning: PIE disabled. A
我想使用 lief 将可执行文件转换为共享库,我注意到它只支持 pie 可执行文件。所以我想知道是否有一种方法可以将 no-pie 可执行文件转换为 pie 可执行文件。 最佳答案 不,没有,除非在链
我的 Android 项目应该生成原生可执行文件作为构建的一部分,并支持 API 14 (Android 4.0) 的所有设备。 问题是 4.0 仅支持非 pie 可执行文件,而 Android >
我有一个全屏cordova应用程序,我曾经使用下面的css作为iPhone X的缺口, padding-top: 25px; padding-top: env(safe-area-inset-top)
我指的是这个https://ecomfe.github.io/echarts/doc/example/pie1.html#-en例子。我无法隐藏饼图中的相邻标签。我已经圈出了我希望隐藏在附加图像中的标
这是我的代码: function graphDataAllChart(graphData) { $(".dataContentAllPie").empty(); nv.addGrap
这有效: perl -pi -e 's/abc/cba/g' hellofile 但这不会: perl -pie 's/cba/abc/g' hellofile 换句话说 -pi -e 有效但 -pi
在 amcharts v4 中,PIE 切片的颜色在 10 种左右的颜色后重复。就像他们有一系列颜色,他们只使用这些颜色并在完成后重复。我希望所有切片都具有独特的颜色,而无需手动创建颜色。如果可能需要
我在我的应用程序中有一个 15 秒计时器的要求,在圆形进度条动画中将在秒数的中心包含标签 下面的代码给出了从 0.0 到 1.0f 的 labelprogress,但我想将它映射到 15 秒倒计时的平
我有一个在夜间运行后台服务的应用程序。它由 alarm clock app 触发运行. 该应用整夜将手机外部 SD 卡上的数据上传到 Dropbox。它可以在以前的 Android 版本上无缝运行,但
我正在尝试从这里自定义一个饼图: https://canvasjs.com/jquery-charts/pie-chart-index-data-label-inside/ 我使用的代码如下,经过我的
我正在尝试使用 CSS PIE 显示圆 Angular ,但它不起作用。请看my website for reference .您会看到在 IE7 和 IE8 中,顶部的小登录区域没有圆 Angula
我正致力于将我们公司的 Web 应用程序带入 21 世纪,并尝试使用一些新的 CSS3 功能,如 border-radius 和 box-shadow 以获得更现代的视觉效果。然而,我们 90% 以上
有一个简单的例子:http://fsou1.ru/files/verstka_examples/14/index2.html 我在 IE 中使用 PIE.js 附加边框半径,但是当我在悬停事件上添加“
我有一个网站 here ... 在 Chrome/FF 中查看它,您会看到带有圆 Angular 的标签。 IE8 仍然显示方 Angular 。 这是我调用 PIE 的 CSS... .class-
渲染边框的 RGBA 颜色时遇到问题。边框半径的 RGBA 颜色工作正常但不是边框颜色,它不显示任何边框颜色。 CSSPie 中是否有单独的“-pie-”标签用于在边框中使用 RGBA? 我的代码:
我用 gcc -fpie test.c 编译了一个简单的 hello world c 代码,现在使用 objdump 查看二进制文件: Disassembly of section __TEXT,__
我正在使用 CSS3 pie 并在 head 标签之前通过附加的 js 文件调用它。 出于某种原因,我的背景图片出现了。我已经尝试了标准添加 z-index 和位置相对修复,但它没有显示。任何帮助指导
这是我检测和显示性别和年龄的循环。我试图在 matplotlib 饼图上绘制它,但每次它运行循环时,它都会为每个预测打开一个不同的图表。如何实时更新同一个图表。 这里我更新完整的代码 使用 Pytho
我用的是ie8,其他版本不知道。我到处都在使用派,它通常工作正常。但是,我所有的表单输入元素都有框阴影和边框半径,并且没有边框(几乎所有样式)。在 FF/Safari/Chrome 中一切都很好,但在
我是一名优秀的程序员,十分优秀!