Replies: 5 comments
-
下面给出一个简单的示意图 ![]() 最后一列显示了另外一种情况,就是将 ipc_trans 放在一个固定的地方,然后进行二进制重写将 svc 只转换为 bl 指令即可(不可超过 128M 的范围。) |
Beta Was this translation helpful? Give feedback.
-
在使用 lief 的过程中出现问题,一旦扩大 .text 段的大小,再运行会出现 sigsegv sig_code=2 的错误信号。可能还需要其他代码进行配合修改某些地址。 代码如下 #!/usr/bin/env python
#
# 文档在 https://lief.re/doc/latest/api/binary_abstraction/python.html
#
# Function Examples:
#
# # Assemble and patch the provided assembly code at the specified address.
# bin.assemble(0x12000440, """
# xor rax, rbx;
# mov rcx, rax;
# """)
#
# # Disassemble code starting a the given virtual address.
# insts = binary.disassemble(0xacde, 100);
# for inst in insts:
# print(inst)
#
# # Disassemble code for the given symbol name
# insts = binary.disassemble("__libc_start_main");
# for inst in insts:
# print(inst)
#
# # Disassemble code from the provided bytes
# raw = bytes(binary.get_section(".text").content)
# insts = binary.disassemble_from_bytes(raw);
# for inst in insts:
# print(inst)
#
# # exported_functions
# 其中还提供了一个 tutorial: https://lief.re/doc/stable/tutorials/
# 需要注意的事情是 一些功能只有在 extend version 中提供
# 比如:Disassembler,Assembler
# https://lief.re/doc/latest/extended/intro.html
import lief
import os
import stat
INST_SVC_BYTES = b'\x01\x00\x00\xd4' # Aarch64 Instruction "svc #0"
elf = lief.ELF.parse("a.elf")
target_file = "new.elf"
# 遍历所有的段信息
# for section in elf.sections:
# print(section.name, section.virtual_address)
text_section = elf.get_section(".text")
elf.extend(text_section, 0x4)
# 查找 svc #0 指令所在地,并尝试重写
for pos in text_section.search_all(INST_SVC_BYTES):
print("find svc #0: " + hex(text_section.virtual_address + pos))
print("finded text function position", hex(elf.offset_to_virtual_address(pos + text_section.offset)))
# elf.patch_address(text_section.virtual_address + pos, [0x11, 0x22, 0x33, 0x44])
# for func in elf.exported_functions:
# print("find function: " + func.name)
# elf.remove_section("")
elf.write(target_file)
# 为目标文件添加可执行权限
st = os.stat(target_file)
os.chmod(target_file, st.st_mode | stat.S_IEXEC) |
Beta Was this translation helpful? Give feedback.
-
在 #4 中采用了新的设计,使用 |
Beta Was this translation helpful? Give feedback.
-
基于 Hello World 来构建一个简单的测例,来实验简单的方案。目前 https://rel4team.github.io/zh/docs/monolithic/funcs/func2ipc/ 已经提出了一些问题,但是需要实践来检验,在此基础上构建一个 hello world 来实践 IPC 到函数的转换比较合适。大概使用一周的时间 |
Beta Was this translation helpful? Give feedback.
-
本周遇到了一些问题,比起一套自动化的工具来说,是否符合一定规则的编程方式更加重要。下面给出一些参考信息:
Questions:
这部分可能需要手动填写,目前来看,是否真的有一套机制可以让 IPC 和函数调用更加自然的转换。 rust lib and main in same crate 一些介绍,如何让一个程序同时作为 Lib 和 main 存在。https://doc.rust-lang.org/book/ch12-03-improving-error-handling-and-modularity.html#splitting-code-into-a-library-crate 主要的修改就是需要在一个 crate 里同时创建一个 lib.rs 和 main.rs ,lib.rs 中只编写需要使用的代码不包含主要的执行逻辑。在 main.rs 中创建主要的执行逻辑。这样就不需要考虑 main.rs 和 lib.rs 互相转换的问题了,但是对于编程来说就会有一定的限制。不过好处就是代码更加容易得复用。 这种做法的目标是,让自己既可以作为程序去运行,也可以作为库向外部提供信息,和我们的想法不谋而合。 目前 rel4_kernel 中也采用了这种设计,但是使用的方式不是很一样,目的不一样。rCore-tutorial 中也使用了这个设计。 越来越觉得这些事情是一个系统工程的问题,而不是一个单独的插件可以完成的。 ![]() |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
目标
在用户态使用动态或者静态的方式将 SysCall 指令转换为 IPC。
思路
在 aarch64 上没有 riscv64 jalr 这类方便的指令,只能使用 bl 指令进行跳转,不过 bl 指令有 26 bit 表示地址偏移,也就是 aarch64 的 bl 跳转范围为 +/- 128M。所以理论可行的做法是对 text 段进行扩充,然后将 text 段中插入 syscall 转 ipc 的函数,然后使用工具(目前计划是 lief)将 syscall 指令 (svc #0) 转换为 跳转指令(bl 指令) 跳转到我们新插入的地址,理论上来说,代码段的长度很难超过 +/- 128M。
Beta Was this translation helpful? Give feedback.
All reactions