2

I am using IDA Pro 6 and I'm looking for a way to automatically export an analysed file into a listing (.lst) file.

The interface of IDA enables to do this action using the menu File > Produce File > Create LST file..., but I could not find a way to execute this action in batch mode (by running IDA in a terminal with the -B). The Hex-Rays's help page does not seem to help, as I'm unable to find a switch that matches my needs.

Is there any way I could get the listing out of IDA in an automated way ? Maybe with a IDC/Python script ?

A typical listing I would need is composed of the address location, bytes and assembly for each instruction, such as below (the lines with only comments or variables declaration can be omitted if there is no other possibility):

text:004016B0             ; =============== S U B R O U T I N E =======================================
.text:004016B0
.text:004016B0            ; Attributes: noreturn bp-based frame
.text:004016B0
.text:004016B0            ___report_gsfailure proc near       ; CODE XREF: __security_check_cookie(x):$failure$3j
.text:004016B0
.text:004016B0            var_324         = dword ptr -324h
.text:004016B0            var_8       = dword ptr -8
.text:004016B0            var_4       = dword ptr -4
.text:004016B0
.text:004016B0 8B FF                  mov     edi, edi
.text:004016B2 55                 push    ebp
.text:004016B3 8B EC                  mov     ebp, esp
.text:004016B5 81 EC 24 03 00+            sub     esp, 324h
.text:004016BB A3 40 21 40 00             mov     dword_402140, eax
.text:004016C0 89 0D 3C 21 40+            mov     dword_40213C, ecx
.text:004016C6 89 15 38 21 40+            mov     dword_402138, edx
.text:004016CC 89 1D 34 21 40+            mov     dword_402134, ebx
.text:004016D2 89 35 30 21 40+            mov     dword_402130, esi
.text:004016D8 89 3D 2C 21 40+            mov     dword_40212C, edi
  • Did you try -B option ? (-B batch mode. IDA will generate .IDB and .ASM files automatically") – w s Apr 9 '18 at 10:29
2

The IDAPython API you need is idc.gen_file . The file type is OFILE_LST.

You should run ida as follows:

{your ida executable}  -A -S{full name of the file with script below} {your exe}

The script is

import idc
idc.gen_file(idc.OFILE_LST , your_listing_file_name, 0, idc.BADADDR, 0)
import ida_pro 
ida_pro.qexit()

This script works with IDA 7.1, and you'll probably need to find replacement for ida_pro.qexit which should cause IDA to quit after finishing the script (in IDA 6.95 and probably earlier versions you can use sys.exit instead).

1

contents of directory prior to test

:\>ls -l | awk "{print $5 , $8}"

190 bldwmsgbox.bat
175 dumplst.idc
108 wmsgbox.cpp

compiling and linking src

:\>bldwmsgbox.bat
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.6.4
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
wmsgbox.cpp

contents of idc file

:\>cat dumplst.idc
#include <idc.idc>
static main(void) {
auto fp;
Batch(1);
Wait();
fp = fopen("idclst.lst","w");
GenerateFile(OFILE_LST,fp,MinEA(),MaxEA(),0x0);
fclose(fp);
Exit(0);
}

automatic analysis and creation of lst file

:\>e:\IDA_FREE_5\idag.exe -B -Sdumplst.idc wmsgbox.exe

deleting the idb and reopening the binary in gui to produce a lst file from file->produce file->create lst file

:\>del *.idb

:\>echo "using gui file->producefile to make another lst for comparison"
"using gui file->producefile to make another lst for comparison"

:\>e:\IDA_FREE_5\idag.exe wmsgbox.exe

:\>ls -l *.lst | awk "{print $5 , $8}"
16877 guiidclst.lst
18617 idclst.lst

:\>wc -l *.lst
  574 guiidclst.lst
  580 idclst.lst
 1154 total

:\>echo "appears to be whitespace diff 
just 6 ines bigger but too much byte variation 
appears to be whitespace difference "

diff output ignoring whitespace and case

:\>diff -iw idclst.lst guiidclst.lst
24d23
< .text:00401000 ; IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
33d31
< .text:00401000 ; UUUUUUUUUUUUUUU S U B R O U T I N E UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
66d63
< .idata:00402000       ; IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
71,72c68
< .idata:00402000                       extrn __imp__ExitProcess@4:dword ; DATA XREF: main+19↑r
< .idata:00402000                                               ; ExitProcess(x)↑r
---
> .idata:00402000       extrn __imp__ExitProcess@4:dword
78,79c74
< .idata:00402008                       extrn __imp__MessageBoxA@16:dword ; DATA XREF: main+11↑r
< .idata:00402008                                               ; MessageBoxA(x,x,x,x)↑r
---
> .idata:00402008       extrn __imp__MessageBoxA@16:dword
82d76
< .rdata:00402010       ; IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
90c84
< .rdata:00402010       Caption         db 'test',0             ; DATA XREF: main+5↑o
---
> .rdata:00402010       Caption db 'test',0
93c87
< .rdata:00402018       Text            db 'test',0             ; DATA XREF: main+A↑o
---
> .rdata:00402018       Text db 'test',0

:\>
  • Many thanks @blabb for your very complete and detailed answer! While this answers my question, I subjectively preferred the python approach. If I was able to mark multiple answers as valid, yours would be definitely one! – ZenLulz May 14 '18 at 10:55

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.