Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions archinfo/arch_pcode.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import logging
from typing import Union
from typing import TYPE_CHECKING, Union

from .arch import Arch, Endness, Register
from .archerror import ArchError
from .tls import TLSArchInfo
from .types import RegisterOffset

if TYPE_CHECKING:
import pypcode

try:
import pypcode

Expand Down Expand Up @@ -64,8 +67,7 @@ def __init__(self, language: Union["pypcode.ArchLanguage", str]):
archinfo_regs[pc_reg.lower()].alias_names = tuple(aliases)

if pc_offset is None:
log.warning("Unknown program counter register offset?")
pc_offset = 0x80000000
log.debug("%s declares no program counter", self.name)

sp_offset = None
ret_offset = RegisterOffset(0)
Expand Down Expand Up @@ -112,7 +114,7 @@ def find_matching_cid(language, desired):
sp_offset = 0x80000008

self.instruction_alignment = 1
self.ip_offset = RegisterOffset(pc_offset)
self.ip_offset = None if pc_offset is None else RegisterOffset(pc_offset)
self.sp_offset = RegisterOffset(sp_offset)
self.bp_offset = RegisterOffset(sp_offset)
self.ret_offset = RegisterOffset(ret_offset)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_pcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ def test_arch_68000(self):
assert arch.instruction_endness == Endness.BE
assert arch.bits == 32

def test_arch_without_program_counter(self):
"""Dalvik and the DATA languages declare no program counter, so archinfo reports none."""
for lang_id in ("Dalvik:LE:32:DEX_Nougat", "DATA:LE:64:default"):
arch = ArchPcode(lang_id)
assert arch.ip_offset is None
assert "ip" not in arch.registers
assert "pc" not in arch.registers

def test_arch_with_program_counter(self):
"""A language that names its program counter keeps naming it, under pc and ip both."""
arch = ArchPcode("x86:LE:64:default")
assert arch.registers["ip"] == arch.registers["rip"]
assert arch.registers["pc"] == arch.registers["rip"]
assert arch.ip_offset == arch.registers["rip"][0]

def test_arch_bad_langid(self):
with self.assertRaises(ArchError):
ArchPcode("invalid")
Expand Down
Loading