2 years ago

#38981

test-img

minima1cha0s

Porting python2 to python3

I have the below line which I assume works in python 2

m = re.search((
            # [Nr] Name              Type             Address           Offset
            r'^\s*(?P<number>\d+)'
            r'\s+(?P<name>[^\s]*)'
            r'\s+(?P<size>{hex_re})'
            r'\s+(?P<address>{hex_re})'
            r'\s+(?P<lma>{hex_re})'
            r'\s+(?P<offset>{hex_re})'
            r'\s+(?P<align>[^\s]+)'
            ).format(hex_re=hex_re), line)

On compilation I had the following error - TypeError: cannot use a string pattern on a bytes-like object

So I tried the following 2 solutions.

  • adding b like br'\s+(?P<name>[^\s]*)' but then it says byte object does not have format function
  • adding b and .decode('utf-8') like br'\s+(?P<name>[^\s]*)'.decode('utf-8'). Reiterates the original error.

I am trying to get this to run using python3.

Link to exact file: https://github.com/minimalchaos/SM-G970F_a12_kernel/blob/main/scripts/rkp_cfp/instrument.py

line object :

proc = subprocess.Popen([OBJDUMP, '--section-headers', vmlinux], stdout=subprocess.PIPE)
f = each_procline(proc)
it = iter(f)
line = next(it)

python

android

linux-kernel

kernel

android-kernel

0 Answers

Your Answer

Accepted video resources