0
    public void run() throws Exception {
        var cp = currentProgram;
        var nsSymbols = ghidra.app.util.NamespaceUtils.getSymbols("myNameSpace", cp);
        var glNS = nsSymbols.get(0);
        var st = cp.getSymbolTable();
        var childs = st.getChildren(glNS);
        Map<String, Integer> map = new HashMap<String, Integer>();
        println("Test");
        while (childs.hasNext())
        {
            var next = childs.next();
            var func = (Function)next.getObject();
            var body = func.getBody();
            var lbcu = cp.getListing().getCodeUnits(body, true);
            var i = 0;
            while (lbcu.hasNext())
            {
                lbcu.next();
                i++;
            }
            println("Name: " + next.getName() + ", count: " + i);
        }

Results I get:

NewScript.java> Name: CreateTypeInstance, count: 1
NewScript.java> Name: Deserialize, count: 1

This does not make any sense to me. The listing clearly show more instructions and I can see whole decompiled view yet API return some garbage?

1 Answer 1

1

I do not have a java env to check your code before you edited you had a screenshot with a selection of a symbol in Namespaces in SymbolTree

when you click such a symbol the listing window is synchronized to the Address of such Symbol see screen shot enter image description here

the following python script will print 10 instructions of this symbol see if this is what you are looking for

import ghidra
ns = currentProgram.getSymbolTable().getNamespace(currentAddress)
cs = currentProgram.getListing().getCodeUnits(ns.body,True)
for i in range(0,10,1):
    print(cs.next())

executing this script will print as below compare with screen shot

codeunits4namespace.py> Running...
MOV EDI,EDI
PUSH EBP
MOV EBP,ESP
SUB ESP,0x10
PUSH EBX
PUSH ESI
MOV ESI,ECX
PUSH EDI
MOV EAX,dword ptr [ESI + 0x4]
PUSH dword ptr [EAX]
codeunits4namespace.py> Finished!
1
  • Yeah, your code is the same as mine but I get 1 instruction returned
    – KreonZZ
    Commented Nov 11, 2021 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.