Flag: Tornado! Hurricane!

 Forums >>  IDA Pro  >>  # solution: how to load two or more files into single IDA Pro database

Topic created on: May 1, 2008 00:27 CDT by nezumi .

a man asked me: is it possible to load two or more files into the same single IDA Pro database. for example, we have NOTEPAD.EXE and want to load two additional files: KERNEL32.DLL and NTDLL.DLL to see how they interact with each other.

as an author of "thinking in IDA Pro", knowing her internals like my own pocket (IDA Pro is a female name and, yep, I don't know what I might find in my pocket next time), I said: yep, it's simple. no problem, man!

IDA Pro has linear address space emulates x86 CPU flat memory model (well, not only x86, it works with other CPUs too). the loader loads a file into virtual memory and does everything has to be done.

there is two solutions to load more files

first: we load the next file as an additional binary file (menu File, Load file, Additional binary file...). IDA Pro does nothing, just load the file, leaves us to parse all internal PE/ELF structures (I saw some IDC-scripts, written by Symantec team, but don't remember the link). this is tedious job, so, thanks, but no thanks!

second: we use IDA Pro function: bool ida_export load_nonbinary_file (const char *original_file_name, const char *real_file_name, const char *sysdlldir,  ushort _neflags, load_info_t *loader), where "loader" - result returned by load_info_t *ida_export build_loaders_list( const char *filename), - see \IDA\SDK\include\ loader.hpp. of course, we have to free the pointer with qfree function (see file pro.h).

this is all. well... since we have linear address space, we must avoid file overlapping, that means all files are supposed to have different base addresses. if they are match - we must to re-base one of them before loading (if files have relocations it's very simple, otherwise, extremely tricky, however, it's possible).

so, we come to plug-in, looking like this one:


void idaapi run(int arg)
{
       load_info_t *ld;
       warning("plugin \"dual-load\" is called!");

        /* NOTE: KERNEL32.DLL and NTDLL.DLL has to be in the current directory!!! */
       ld = build_loaders_list("KERNEL32.DLL");
       load_nonbinary_file("KERNEL32.DLL", "KERNEL32.DLL", ".", NEF_SEGS | NEF_RSCS | NEF_NAME | NEF_IMPS | NEF_CODE, ld);
       /* qfree(ld);

       ld = build_loaders_list("NTDLL.DLL"); */
       load_nonbinary_file("NTDLL.DLL", "NTDLL.DLL", ".", NEF_SEGS | NEF_RSCS | NEF_NAME | NEF_IMPS | NEF_CODE, ld);
       qfree(ld);
}


ok, we load notepad.exe into IDA Pro, call our plug-in and... have a fun!!! notepad.exe, kernel32.dll and ntdll.dll are loaded into the same idb-database! the only problem is: IDA Pro doesn't create cross-references between them. I mean, if you analyze notepad.exe, move the cursor to call ds:GetModuleHandleA, press "enter" and... nothing happens! you're into the import table of notepad.exe. and where is the export? somewhere... but, this is not a problem, really, since, we can find GetModuleHandleA in the "Names Windows" (called by Shift-F4) or write a simple IDC-script to create cross-reference between import and export, it's like to build a bridge :-]



I think, we all have to ask Ilfak for this feature, why just don't add it to user menu? it would be _very_ usefully.

  nezumi     May 1, 2008 16:42.26 CDT
# other solutions: how to load two or more files into the same IDA-Pro database:

Ilfak describes three ways how to load several files in one IDB.

first solution: use pe_dlls.idc IDC-script, written by Atli Mar Gudmundsson (the original link is broken, was fixed, and then broken again. so, download it from OpenRCE). this is a really good script. guess what it does? well, it loads all dlls using by the main file and supporting recursive loading. wow! it's easy-to-use and reliable. but... it works with PE files only and what if I want to load ELF or two NT-drivers or linux kernel modules?! my plug-in handles this, coz it uses IDA loaders, so it supports all formant supported by IDA. however, I recommend you pe_dlls.idc, since, I just love it.

second solution: Ilfak tell us: use the debugger and take the memory snapshot. very well! everyone knows about this trick and does it almost everyday. this is best way to analyze packed file - just run the program, dump it with your favorite dumper and disassemble the dump. don't care about restoring import table or something like that. dumped program might be unable to run, but it's quite enough to analyze it. however, this strategy doesn't work with trickily protections as well as drivers

third solution : IDA Debugger are involved. what I can say?! theoretically, we can get accurate dump, including only those DLLs we need, however, IDA has _extremely_ "weak" debugger and almost any protection is able to defeat it. how we're supposed to analyze malware packed with modern protectors?! I simple don't know. this is not my way. this is very restricted way (is it possible to load drivers or something like that?!). the answer is no.

so, use my plug-in. it's really simple, useful and supports every file-format, supported by IDA. it also allow to load user-land and kernel-land files at the same time

  zarulshahrin     May 18, 2008 00:55.25 CDT
This works on 5.2:

#include <loader.hpp>
#include <diskio.hpp>
#include <kernwin.hpp>

void idaapi run(int arg)
{
load_info_t *ld;

// Prompt the user for a file
char *file = askfile_cv(0, "", "File to open", NULL);

// Open the file
linput_t *myfile = open_linput(file, false);

if (myfile == NULL)
    msg("Failed to open or corrupt file.\n");

else
{
ld = build_loaders_list(myfile);
load_nonbinary_file(file,myfile,".", NEF_SEGS|NEF_RSCS|NEF_NAME|NEF_IMPS|NEF_CODE,ld);
qfree(ld);

close_linput(myfile);
}

}

Note: Registration is required to post to the forums.

There are 31,322 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
hi!
Jul/01
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit