Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmds/alias: add relative base address support #347

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions cmds/alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static addr_t aliasBase = 0;

static void cmd_aliasInfo(void)
{
lib_printf("sets alias to file, usage: alias [-b <base> | [-r] <name> <offset> <size>]");
lib_printf("sets alias to file, usage: alias [-[r]b <base> | [-r] <name> <offset> <size>]");
}


Expand All @@ -36,7 +36,7 @@ static int cmd_alias(int argc, char *argv[])
size_t sz = 0;
addr_t addr = 0;
int c, relative = 0;
addr_t newBase;
long newBase;

if (argc == 1) {
if (aliasBase != 0) {
Expand Down Expand Up @@ -64,15 +64,20 @@ static int cmd_alias(int argc, char *argv[])
return CMD_EXIT_FAILURE;
}

newBase = lib_strtoul(optarg, &end, 0);
newBase = lib_strtol(optarg, &end, 0);
if (*end != '\0') {
log_error("\n%s: Invalid base.\n", argv[0]);
cmd_aliasInfo();
return CMD_EXIT_FAILURE;
}

aliasBase = newBase;
lib_printf("\n%s: Setting relative base address to 0x%p", argv[0], newBase);
if (relative) {
aliasBase += newBase;
}
else {
aliasBase = newBase;
}
lib_printf("\n%s: Setting relative base address to 0x%p", argv[0], aliasBase);

/* Ignore everything else, this is a separate function */
return CMD_EXIT_SUCCESS;
Expand Down
Loading