Skip to content

Commit 3d0b0ae

Browse files
committed
Make argreg a class member
1 parent 829a924 commit 3d0b0ae

File tree

5 files changed

+18
-38
lines changed

5 files changed

+18
-38
lines changed

qiling/cc/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44

5-
from typing import Callable, Tuple
5+
from typing import Callable, Sequence, Tuple
66

77
from qiling.arch.arch import QlArch
88

@@ -107,19 +107,17 @@ class QlCommonBaseCC(QlCC):
107107
of the QlCC interface.
108108
"""
109109

110-
_argregs = ()
110+
_retreg: int
111+
_argregs: Sequence
111112
_shadow = 0
112113
_retaddr_on_stack = True
113114

114-
def __init__(self, arch: QlArch, retreg: int):
115+
def __init__(self, arch: QlArch):
115116
super().__init__(arch)
116117

117118
# native address size in bytes
118119
self._asize = self.arch.pointersize
119120

120-
# return value register
121-
self._retreg = retreg
122-
123121
def __access_param(self, index: int, stack_access: Callable, reg_access: Callable) -> Tuple[Callable, int]:
124122
"""[private] Generic accessor to function call parameters by their index.
125123

qiling/cc/arm.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
UC_ARM64_REG_X4, UC_ARM64_REG_X5, UC_ARM64_REG_X6, UC_ARM64_REG_X7
99
)
1010

11-
from qiling.arch.arch import QlArch
1211
from qiling.cc import QlCommonBaseCC
1312

1413
class QlArmBaseCC(QlCommonBaseCC):
@@ -29,13 +28,9 @@ def unwind(self, nslots: int) -> int:
2928
return self.arch.stack_pop()
3029

3130
class aarch64(QlArmBaseCC):
31+
_retreg = UC_ARM64_REG_X0
3232
_argregs = (UC_ARM64_REG_X0, UC_ARM64_REG_X1, UC_ARM64_REG_X2, UC_ARM64_REG_X3, UC_ARM64_REG_X4, UC_ARM64_REG_X5, UC_ARM64_REG_X6, UC_ARM64_REG_X7) + (None, ) * 8
3333

34-
def __init__(self, arch: QlArch) -> None:
35-
super().__init__(arch, UC_ARM64_REG_X0)
36-
3734
class aarch32(QlArmBaseCC):
35+
_retreg = UC_ARM_REG_R0
3836
_argregs = (UC_ARM_REG_R0, UC_ARM_REG_R1, UC_ARM_REG_R2, UC_ARM_REG_R3) + (None, ) * 12
39-
40-
def __init__(self, arch: QlArch) -> None:
41-
super().__init__(arch, UC_ARM_REG_R0)

qiling/cc/intel.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,18 @@
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44

55
from unicorn.x86_const import (
6-
UC_X86_REG_AX, UC_X86_REG_EAX, UC_X86_REG_RAX, UC_X86_REG_RCX,
7-
UC_X86_REG_RDI, UC_X86_REG_RDX, UC_X86_REG_RSI, UC_X86_REG_R8,
8-
UC_X86_REG_R9, UC_X86_REG_R10
6+
UC_X86_REG_EAX, UC_X86_REG_RAX, UC_X86_REG_RCX, UC_X86_REG_RDI,
7+
UC_X86_REG_RDX, UC_X86_REG_RSI, UC_X86_REG_R8, UC_X86_REG_R9,
8+
UC_X86_REG_R10
99
)
1010

11-
from qiling.arch.arch import QlArch
1211
from qiling.cc import QlCommonBaseCC
1312

1413
class QlIntelBaseCC(QlCommonBaseCC):
1514
"""Calling convention base class for Intel-based systems.
1615
Supports arguments passing over registers and stack.
1716
"""
1817

19-
def __init__(self, arch: QlArch):
20-
retreg = {
21-
16: UC_X86_REG_AX,
22-
32: UC_X86_REG_EAX,
23-
64: UC_X86_REG_RAX
24-
}[arch.bits]
25-
26-
super().__init__(arch, retreg)
27-
2818
def setReturnAddress(self, addr: int) -> None:
2919
self.arch.stack_push(addr)
3020

@@ -36,6 +26,8 @@ class QlIntel64(QlIntelBaseCC):
3626
"""Calling convention base class for Intel-based 64-bit systems.
3727
"""
3828

29+
_retreg = UC_X86_REG_RAX
30+
3931
@staticmethod
4032
def getNumSlots(argbits: int) -> int:
4133
return max(argbits, 64) // 64
@@ -44,6 +36,8 @@ class QlIntel32(QlIntelBaseCC):
4436
"""Calling convention base class for Intel-based 32-bit systems.
4537
"""
4638

39+
_retreg = UC_X86_REG_EAX
40+
4741
@staticmethod
4842
def getNumSlots(argbits: int) -> int:
4943
return max(argbits, 32) // 32

qiling/cc/mips.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44

55
from unicorn.mips_const import UC_MIPS_REG_V0, UC_MIPS_REG_A0, UC_MIPS_REG_A1, UC_MIPS_REG_A2, UC_MIPS_REG_A3
66

7-
from qiling.arch.arch import QlArch
87
from qiling.cc import QlCommonBaseCC
98

109
class mipso32(QlCommonBaseCC):
10+
_retreg = UC_MIPS_REG_V0
1111
_argregs = (UC_MIPS_REG_A0, UC_MIPS_REG_A1, UC_MIPS_REG_A2, UC_MIPS_REG_A3) + (None, ) * 12
1212
_shadow = 4
1313
_retaddr_on_stack = False
1414

15-
def __init__(self, arch: QlArch):
16-
super().__init__(arch, UC_MIPS_REG_V0)
17-
1815
@staticmethod
1916
def getNumSlots(argbits: int):
2017
return 1

qiling/cc/riscv.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22
#
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44

5-
from qiling.arch.arch import QlArch
65
from qiling.cc import QlCommonBaseCC
76

87
from unicorn.riscv_const import (
9-
UC_RISCV_REG_A0, UC_RISCV_REG_A1, UC_RISCV_REG_A2,
10-
UC_RISCV_REG_A3, UC_RISCV_REG_A4, UC_RISCV_REG_A5,
8+
UC_RISCV_REG_A0, UC_RISCV_REG_A1, UC_RISCV_REG_A2,
9+
UC_RISCV_REG_A3, UC_RISCV_REG_A4, UC_RISCV_REG_A5
1110
)
1211

13-
1412
class riscv(QlCommonBaseCC):
1513
"""Default calling convention for RISCV
16-
First 6 arguments are passed in regs, the rest are passed on the stack.
14+
First 6 arguments are passed in regs, the rest are passed on the stack.
1715
"""
1816

17+
_retreg = UC_RISCV_REG_A0
1918
_argregs = (UC_RISCV_REG_A0, UC_RISCV_REG_A1, UC_RISCV_REG_A2, UC_RISCV_REG_A3, UC_RISCV_REG_A4, UC_RISCV_REG_A5) + (None, ) * 10
2019

21-
def __init__(self, arch: QlArch):
22-
super().__init__(arch, UC_RISCV_REG_A0)
23-
2420
@staticmethod
2521
def getNumSlots(argbits: int):
2622
return 1

0 commit comments

Comments
 (0)