Log in

View Full Version : Another IDA script: Dump section


OpenRCE_Saphex
November 24th, 2007, 18:50
Hi,

This script can be useful or not useful. It dumps a section to a C style file.

Code:
#include <idc.idc>

static main()
{
auto l_FilePath, l_pFile, l_Address, l_End, l_Iterate, l_Count;

if (ScreenEA() == BADADDR)
return;

SetStatus(IDA_STATUS_WORK);

l_FilePath = AskFile(1, "*.c", "Select output file";

if (l_FilePath != 0) {
l_pFile = fopen(l_FilePath, "wb";

if (l_pFile != 0) {
l_Address = GetSegmentAttr(ScreenEA(), SEGATTR_START);
l_End = GetSegmentAttr(ScreenEA(), SEGATTR_END);

if ((l_Address == BADADDR) || (l_End == BADADDR))
return;

fprintf(l_pFile, "//\n";
fprintf(l_pFile, "// Dump from %s\n", SegName(l_Address));
fprintf(l_pFile, "// Dump len %d bytes\n", (l_End - l_Address));
fprintf(l_pFile, "//\n";
fprintf(l_pFile, "unsigned char g_pCode[] = {\n\t";

l_Count = 1;

for (l_Iterate = l_Address; l_Iterate < l_End; l_Iterate++) {
fprintf(l_pFile, "0x%02X, ", Byte(l_Iterate));

if (l_Count == 15) {
fprintf(l_pFile, "\n\t";
l_Count = 0;
}

l_Count++;
}

fprintf(l_pFile, "\n};";
fclose(l_pFile);
}
}

SetStatus(IDA_STATUS_READY);
}


Best regards,
saphex

https://www.openrce.org/blog/view/887/Another_IDA_script:_Dump_section