1

我需要在 C# 中处理一些由 OBJCOPY 实用程序提供的转储。

在命令提示符下使用时,我会这样使用它:

objcopy myprogram.elf --dump-section .text=text_section.txt

这就是我将 .text 部分的 RAW 内容获取到文件中的方式。

在 C# 中,我编写了一个小型进程包装器来启动外部程序

public static int RunProcess(string cmd, string args, out string output)
{
    Process proc = new Process();

    try
    {

        proc.StartInfo.CreateNoWindow = true;
        proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        proc.StartInfo.FileName = cmd;

        proc.StartInfo.Arguments = args;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.StartInfo.RedirectStandardError = true;

        proc.Start();
        output = proc.StandardOutput.ReadToEnd();

        proc.WaitForExit(); // wait here, blocking

    }
    catch (Exception ex)
    {
        output = cmd + ": " + ex.Message;
        return 1;
    }

    if (proc.ExitCode != 0)
    {
        output = proc.StandardError.ReadToEnd().Truncate(PROC_TRUNC_OUT).Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ");
        return 1;
    }

    return 0;
}

我不知道如何欺骗 OBJDUMP 并将 RAW 转储直接获取到内存中,而无需外部文件,然后打开并读取该文件的二进制文件。

这篇文章中的一个聪明人
如何在 Linux 上检查 ELF 文件的数据部分的内容?

objcopy file /dev/null --dump-section .text=/dev/stdout | cat

给出了一个 linux 提示以在 stdout 上重定向(我认为我可以捕获),但我无法在 Win 上重现。

那么,聪明的头脑可以想出一个窍门,这可能吗?

先感谢您,

4

1 回答 1

1

在 Windows 上,您可以利用一个设备“CON”。

objcopy file "someFile" --dump-section .text=CON

我没有测试它,因为我没有 OBJCOPY,但它可以与 OpenSSL 一起使用。所以它应该将所有内容输出到控制台。

于 2019-08-07T16:47:03.157 回答