Kayaker
October 22nd, 2006, 15:36
Hi
It's challenging but not impossible. I'll give you a few tips to get you started. The new SDK uses a number of functions which i2s uses that need to be modified. Basically you need to recompile ida2sice_408 under the new SDK and "fix" every compiler error.
Most of the errors will be because of the new string-safe or buffer overflow versions of previous functions. I place these into 2 groups.
Group 1: The functions strncpy, sprintf and strcat
have been replaced with their string-safe versions,
qstrncpy, qsnprintf and qstrncat.
Group 2: The following functions were also modified to protect
against buffer overflow and required updating:
get_member_name, get_root_filename, get_input_file_path,
get_true_segm_name, get_struc_name.
Here is an example of modifying a single line in i2s to be compatible with the new version of strcpy (now qstrncpy).
As you can see all we're doing is adding a buffer size element to the function (which is what string-safe functions do). The commented-out code is the *old* i2s function, below it is the new declaration. This is all that is needed:
Code:
// NEW: qstrncpy(char *dst, const char *src, size_t dstsize);
// strcpy( sicePath, pSicePaths[I] );
qstrncpy( sicePath, pSicePaths[I], sizeof sicePath );
Here is an example of modifying one of the functions in the 2nd group. You need to add a buffer and a buffer size element. What I did was to define a buffer with the name 'member_name' and give it a size [MAXNAMELEN]. This could then be used in place of the (char *buf, size_t bufsize) parameters of the new version of the get_member_name function.
Code:
// OLD: get_member_name(tid_t mid);
// NEW: get_member_name(tid_t mid, char *buf, size_t bufsize);
// pMemberName = (WORD*)get_member_name( pMember->id );
char member_name[MAXNAMELEN];
get_member_name(pMember->id, member_name, sizeof member_name);
pMemberName = (WORD*)member_name;
In some cases you will need to combine the modifications in these two groups in creative ways:
Code:
// NEW: qstrncpy(char *dst, const char *src, size_t dstsize);
// NEW: get_member_name(tid_t mid, char *buf, size_t bufsize);
// strcpy( pName_afterDot, get_member_name( pMember->id ) );
char member_name[MAXNAMELEN];
get_member_name(pMember->id, member_name, sizeof member_name);
qstrncpy( pName_afterDot, member_name, strlen (member_name) +1 );
If you're still in the game after all this, there will be a few more changes to make but you should be comfortable enough with the i2s code by that time that you should be able to work with them yourself. The most problematic one will be with the new version of supval, but it too can be fixed if you spend a bit of time on it.
// OLD: char *supval(nodeidx_t alt, char tag=stag)
// NEW: ssize_t supval(sval_t alt, void *buf, size_t bufsize, char tag=stag)
Here is one last modification I found necessary to make to kernwin.hpp before starting it all:
Code:
VC6++
Include files: C:\..\IDA\SDK\INCLUDE
Library files: C:\..\IDA\SDK\LIBVC.W32
============================================================
To compile this plugin the first step is to modify the file
..\sdk\includes\kernwin.hpp
The class linearray_t should be declared as 'public', as in:
class linearray_t
{
public:
DECLARE_LINEARRAY_HELPERS(friend)
...
============================================================
In total there are just over 100 compiler errors of 3 or 4 types which need repairing. It took me a few days to do it but don't be discouraged by them. Be patient and think of it as a great way of learning to work with the IDA SDK and the excellent example of Mostek's Ida2Sice plugin.
If you need further help as you go along I will be glad to help.
Cheers,
Kayaker