Skip to content

Instantly share code, notes, and snippets.

@SamTebbs33
Created November 1, 2019 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamTebbs33/abe4e544627e3dc1576aff29df1a6f50 to your computer and use it in GitHub Desktop.
Save SamTebbs33/abe4e544627e3dc1576aff29df1a6f50 to your computer and use it in GitHub Desktop.
const std = @import("std");
const ChildProcess = std.ChildProcess;
const File = std.fs.File;
pub fn main() !void {
const args = std.os.argv;
if (args.len != 3) {
std.debug.warn("Usage: {} <elf file> <map file>\n", args[0][0..strlen(args[0])]);
return;
}
const elf_file_path = args[1][0..strlen(args[1])];
const map_file_path = args[2][0..strlen(args[2])];
const elf_file = try File.openRead(elf_file_path);
const map_file = try File.openWrite(map_file_path);
const allocator = std.heap.direct_allocator;
const readelf_proc = try ChildProcess.init([_][]const u8{ "readelf", "-s", elf_file_path }, allocator);
readelf_proc.stdout_behavior = ChildProcess.StdIo.Pipe;
readelf_proc.stdout = map_file;
_ = try readelf_proc.spawn();
}
fn strlen(str: [*]u8) usize {
var i: usize = 0;
while (str[i] != 0) : (i += 1) {}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment