asm command: fix default arch (#2066)

Before this commit, running `asm mov rax, 0xdeadbeef` would not work on amd64 targets because the default arch was set in the argparse default argument value and it was populated once.

Now, this `default=...` kwarg is not set and instead we fetch current arch inside the `asm` command directly when the user did not pass any architecture value.
pull/2070/head
Disconnect3d 2 years ago committed by GitHub
parent d209d9a3b3
commit 638cd45e5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -16,7 +16,6 @@ parser.add_argument(
parser.add_argument( parser.add_argument(
"--arch", "--arch",
default=pwnlib.context.context.arch,
choices=pwnlib.context.context.architectures.keys(), choices=pwnlib.context.context.architectures.keys(),
type=str, type=str,
help="Target architecture", help="Target architecture",
@ -63,6 +62,9 @@ def asm(shellcode, format, arch, avoid, infile) -> None:
with open(infile) as file: with open(infile) as file:
shellcode = [file.read()] shellcode = [file.read()]
if not arch:
arch = pwnlib.context.context.arch
bits_for_arch = pwnlib.context.context.architectures.get(arch, {}).get("bits") bits_for_arch = pwnlib.context.context.architectures.get(arch, {}).get("bits")
assembly = pwnlib.asm.asm(" ".join(shellcode), arch=arch, bits=bits_for_arch) assembly = pwnlib.asm.asm(" ".join(shellcode), arch=arch, bits=bits_for_arch)

Loading…
Cancel
Save