2

I want to generate call graph from Ida pro but I want to do it automatically. I wrote these two scripts but they did not work. Could you help me what is the problem?

1:

#include ida.idc;
#include idc.idc;
static main()
{
cur = MinEA()
end = MaxEA()
auto str_gdlpath;
str_gdlpath = GetIdbPath();
str_gdlpath = substr(str_gdlpath,0,strlen(str_gdlpath)-4)+".gdl";
GenCallGdl(str_gdlpath, "Call Gdl",cur, end, CHART_WINGRAPH);
Message("Gdl file have been saved to %s",str_gdlpath);
}

2:

#include ida.idc;
#include idc.idc;
static main ()
 {
 auto str_gdlpath;
 str_gdlpath = GetIdbPath ();
 str_gdlpath = substr (str_gdlpath, 0, strlen (str_gdlpath) - 4) + ".gdl";
 GenCallGdl (str_gdlpath, "Call Gdl", CHART_WINGRAPH);
 Message ("Gdl file have been saved to% s", str_gdlpath);
 } 

The command I am using to run is:

./idal -c -A -Sgdlscript.idc test.exe

Is it possible to do this in IDAPython too?

  • Do you want to get the GDL, or looking for a way to draw the graph? – tmr232 Jul 16 '15 at 21:26
  • I need the GDL one – Ben Richards Jul 16 '15 at 21:45
1

Most of the functionality from IDC is provided by IDA's idc.py module. You can read the docs here.

The following code should work the same way your IDC did:

import idc

cur = idc.MinEA()
end = idc.MaxEA()
path = idc.GetIdbPath().rsplit('.')[0] + '.gdl'
idc.GenCallGdl(path, 'Call Gdl', idc.CHART_GEN_GDL)
idc.Message('Gdl file has been saved to {}\n'.format(path))
| improve this answer | |
  • I did this. I do not get any problem but i could not find the generated file? Where would be the location of generated file? I also search for it but i did not find – Ben Richards Jul 16 '15 at 21:46
  • Should be right next to the IDB. Does it not work? You can try running it inside IDA instead of using the command-line. – tmr232 Jul 16 '15 at 21:50
  • It does not work. I need to run it outside ida.. Why it is not working? Even it does not work inside IDA – Ben Richards Jul 16 '15 at 21:59
  • I am not sure. I don't have IDA available at the moment to check. Will try and give a better answer on Sunday. For now - if a NetworkX graph is good enough (it can export to several formats, but I don't think it supports GDL) you can use Sark to do it. – tmr232 Jul 16 '15 at 22:05
  • tnx. I will waiting for you. NetworkX does not support GDL. – Ben Richards Jul 16 '15 at 22:19
1

The following works for me:

#include "ida.idc";
#include "idc.idc";   
static main()
{
    auto retval;
    auto cur;
    auto end;
    auto str_gdlpath;
    cur = MinEA();
    end = MaxEA();
    //str_gdlpath = GetIdbPath();
    //str_gdlpath = substr(str_gdlpath,0,strlen(str_gdlpath)-4)+".gdl";
    str_gdlpath = "D:\\temp\\callgraph";
    retval = GenFuncGdl(str_gdlpath, "Call Gdl",cur, end, CHART_NOLIBFUNCS);

    //necessary for ida to exit in batch mode
    exit(0);
}

And the command line:

D:\temp>"C:\Program Files (x86)\IDA\idaw" -c -A -SD:\temp\autogengraph2.idc D:\temp\testdll.dll > NUL

The trailing NUL is necessary to run the batch without ida showing up. Note that in the idc script ida has to be terminated by exit() in order for the script to return to the command prompt.

The GenCallGdl function may work as well, but the documentation is erroneous as the function works with less parameters than the Ida Help indicates.

In the output file, the .gdl extension is appended automatically. As I have no independent .gdl reader, I have not been able to control the output file if it shows the correct graph.

As a general rule for debugging such things, first let Ida show up when running the cmdline batch (i.e. without the -c -A parameters), to be able to see its errors. When everything works, run it silently.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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