aboutsummaryrefslogtreecommitdiff
path: root/python/weenix/userland_new.py
blob: 7d4ff552f6596cdde5c7b3dc731a1bb58c2e0974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import subprocess
from os import path

# Define the command and arguments
command = [
    "objdump",
    "--headers",
    "--section=.text",
    "user/usr/bin/s5fstest.exec"
]


class NewUserland(gdb.Command):
    def __init__(self):
      super(NewUserland, self).__init__("new-userland", gdb.COMMAND_USER)

    def invoke(self, arg, from_tty):
        directory = 'user/usr/bin/'
        filename = directory + arg + '.exec'
        if not path.exists(filename):
            filename = 'user/bin/' + arg + '.exec'
        if arg == 'init':
            filename = 'user/sbin/init.exec'
        

        command = f"objdump --headers --section='.text' {filename} | grep .text | awk '{{print $4}}'"

        result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)

        if result.returncode == 0:
            print("VMA of the .text section:")
            text_section = result.stdout.strip()

            gdb.execute(f"add-symbol-file {filename} 0x{text_section}")
            gdb.execute(f"break main")
        else:
            print("Command failed with error:")
            print(result.stderr)
        
        
NewUserland()