在ELF文件中编辑变量值? [英] Edit variable values in ELF file?

查看:215
本文介绍了在ELF文件中编辑变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在已编译的ELF文件中更改几个变量。为了清楚地说明这一点,我将使用一个简单的C结构作为示例。

I need to change a couple of variables in a compiled ELF file. Trying to explain this clearly I'll use a simple C struct as an example.

将单个源文件编译并从MyFile链接(@ 0x1000)到MyFile.elf中.c:

The single source file is compiled and linked (@ 0x1000) into MyFile.elf from MyFile.c:

typedef struct {
    uint32_t SerialNumber;      /* Increments for every time it's programmed */
    uint32_t PartNumber;        /* Always the same */
    char     ProdDateTime[32];  /* "YYYY-MM-DD HH:MM:SS" date/time when programmed */
    uint32_t CalcCrc32;         /* Checksum of the above data */
} MyData_T;

const MyData_T MyData = {
    /* SerialNumber      */ 0x11111111,
    /* PartNumber        */ 0x12345678,
    /* ProdDateTime[32]  */ "2013-11-10 12:49:30",
    /* CalcCrc32         */ 0xC0CAC01A
                        };

现在我需要一个控制台工具(无需编译):

Now I need a "console-tool" that (without compiling):


  1. 将新序列号写入0x1000

  2. 将新字符串写入0x1008

  3. 将校验和更新为0x1028。

我什至找不到第一个( 1)任务。似乎这应该是一个相当普遍的情况?我现在已经编写了自己的工具,但是更喜欢使用开源工具或类似工具。

I have not been able to find a tool (objcopy etc?) that even does the first (1) task. Seems this should be a rather common scenario? I've written my own tool for now but would prefer a open source tool or similar.

任何建议/想法/评论/批评都非常感激:D谢谢! !

Any suggestions / ideas / comments / criticisms are highly appreciated :D Thanks you!!

推荐答案

gdb --write / your / application / binary应该能够更改初始化数据的值并将其写入返回到可执行文件。

"gdb --write /your/application/binary" should be able to change value of initialized data and write it back to the executable.

添加 -batch和 -x command_file,您应该能够使它执行所需的操作。

Add "-batch" and "-x command_file" and you should be able to get it to do what you want.

这篇关于在ELF文件中编辑变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆