update to ida 7.6, add builds
This commit is contained in:
227
idasdk76/plugins/hexview/hexplace.cpp
Normal file
227
idasdk76/plugins/hexview/hexplace.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
//--------------------------------------------------------------------------
|
||||
// hex place methods
|
||||
|
||||
typedef hex_place_t hp_t;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Short information about the current location.
|
||||
// It will be displayed in the status line
|
||||
void ida_export hex_place_t__print(const hp_t *, qstring *, void *)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Convert current location to 'uval_t'
|
||||
uval_t ida_export hex_place_t__touval(const hp_t *ths, void *)
|
||||
{
|
||||
return ths->n;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Make a copy
|
||||
place_t *ida_export hex_place_t__clone(const hp_t *ths)
|
||||
{
|
||||
return new hp_t(*ths);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Copy from another hex_place_t object
|
||||
void ida_export hex_place_t__copyfrom(hp_t *ths, const place_t *from)
|
||||
{
|
||||
hp_t *s = (hp_t *)from;
|
||||
ths->d = s->d;
|
||||
ths->n = s->n;
|
||||
ths->lnnum = s->lnnum;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Create a hex_place_t object at the specified address
|
||||
// with the specified data
|
||||
place_t *ida_export hex_place_t__makeplace(const hp_t *ths, void *, uval_t x, int lnnum)
|
||||
{
|
||||
hex_place_t *p = new hex_place_t();
|
||||
p->d = ths->d;
|
||||
p->n = x;
|
||||
p->lnnum = lnnum;
|
||||
return p;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
int ida_export hex_place_t__compare(const hp_t *ths, const place_t *t2)
|
||||
{
|
||||
hp_t *s = (hp_t *)t2;
|
||||
return compare(ths->n, s->n);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Compare two hex_place_t objects
|
||||
// Return -1, 0, 1
|
||||
int ida_export hex_place_t__compare2(const hp_t *ths, const place_t *t2, void *)
|
||||
{
|
||||
return hex_place_t__compare(ths, t2);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Check if the location data is correct and if not, adjust it
|
||||
void ida_export hex_place_t__adjust(hp_t *ths, void *)
|
||||
{
|
||||
if ( ths->n > ths->d->maxline() )
|
||||
{
|
||||
ths->n = 0;
|
||||
ths->lnnum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Move to the previous location
|
||||
bool ida_export hex_place_t__prev(hp_t *ths, void *)
|
||||
{
|
||||
if ( ths->n == 0 )
|
||||
return false;
|
||||
ths->n--;
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Move to the next location
|
||||
bool ida_export hex_place_t__next(hp_t *ths, void *)
|
||||
{
|
||||
if ( ths->n >= ths->d->maxline() )
|
||||
return false;
|
||||
ths->n++;
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Are we at the beginning of the data?
|
||||
bool ida_export hex_place_t__beginning(const hp_t *ths, void *)
|
||||
{
|
||||
return ths->n == 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Are we at the end of the data?
|
||||
bool ida_export hex_place_t__ending(const hp_t *ths, void *)
|
||||
{
|
||||
return ths->n == ths->d->maxline();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Generate text for the current location
|
||||
int ida_export hex_place_t__generate(
|
||||
const hp_t *ths,
|
||||
qstrvec_t *out,
|
||||
int *default_lnnum,
|
||||
color_t *,
|
||||
bgcolor_t *,
|
||||
void *,
|
||||
int maxsize)
|
||||
{
|
||||
int idx = ths->n;
|
||||
if ( idx > ths->d->maxline() || maxsize <= 0 )
|
||||
return 0;
|
||||
uint alignment = ths->d->alignment();
|
||||
uchar *data = (uchar *)qalloc(alignment);
|
||||
if ( !ths->d->read(alignment * ths->n, data, alignment) )
|
||||
{
|
||||
qfree(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define HEX_ASCII_SEP 2
|
||||
size_t bufsize = 4 * alignment + HEX_ASCII_SEP + 20;
|
||||
char *str = (char *)qalloc(bufsize);
|
||||
if ( str == NULL )
|
||||
nomem("hexplace");
|
||||
str[0] = 0;
|
||||
|
||||
// add hex values
|
||||
static const char hexstr[] = "0123456789ABCDEF";
|
||||
size_t pos = qstrlen(str);
|
||||
for ( uint i = 0; i < alignment; i++ )
|
||||
{
|
||||
str[pos++] = ' ';
|
||||
uchar c = data[i];
|
||||
str[pos++] = hexstr[c >> 4];
|
||||
str[pos++] = hexstr[c & 0xF];
|
||||
}
|
||||
|
||||
memset(&str[pos], ' ', HEX_ASCII_SEP);
|
||||
pos += HEX_ASCII_SEP;
|
||||
|
||||
// add ascii values
|
||||
char *ptr = str + pos;
|
||||
char *end = str + bufsize;
|
||||
APPCHAR(ptr, end, COLOR_ON);
|
||||
APPCHAR(ptr, end, COLOR_NUMBER);
|
||||
for ( uint i = 0; i < alignment; i++ )
|
||||
APPCHAR(ptr, end, qisprint(data[i]) ? (char)data[i] : '.');
|
||||
APPCHAR(ptr, end, COLOR_OFF);
|
||||
APPCHAR(ptr, end, COLOR_NUMBER);
|
||||
APPZERO(ptr, end);
|
||||
|
||||
qfree(data);
|
||||
out->push_back(str);
|
||||
*default_lnnum = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void ida_export hex_place_t__serialize(const hex_place_t *_this, bytevec_t *out)
|
||||
{
|
||||
place_t__serialize(_this, out);
|
||||
out->pack_ea(_this->n);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
bool ida_export hex_place_t__deserialize(hex_place_t *_this, const uchar **pptr, const uchar *end)
|
||||
{
|
||||
if ( !place_t__deserialize(_this, pptr, end) || *pptr >= end )
|
||||
return false;
|
||||
_this->n = unpack_ea(pptr, end);
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// this var is static because it is not database specific
|
||||
static int hex_place_id = -1;
|
||||
static const hex_place_t _template;
|
||||
void register_hex_place()
|
||||
{
|
||||
hex_place_id = register_place_class(&_template, PCF_MAKEPLACE_ALLOCATES, &PLUGIN);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
int ida_export hex_place_t__id(const hex_place_t *)
|
||||
{
|
||||
return hex_place_id;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
const char *ida_export hex_place_t__name(const hex_place_t *)
|
||||
{
|
||||
return "hexview:hex_place_t";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
ea_t ida_export hex_place_t__toea(const hex_place_t *)
|
||||
{
|
||||
return BADADDR;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
place_t *ida_export hex_place_t__enter(const hex_place_t *, uint32 *)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void ida_export hex_place_t__leave(const hex_place_t *, uint32)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
bool ida_export hex_place_t__rebase(hex_place_t *, const segm_move_infos_t &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
190
idasdk76/plugins/hexview/hexview.cpp
Normal file
190
idasdk76/plugins/hexview/hexview.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
//---------------------------------------------------------------------------
|
||||
// Hex view sample plugin
|
||||
|
||||
#include <ida.hpp>
|
||||
#include <idp.hpp>
|
||||
#include <loader.hpp>
|
||||
#include <kernwin.hpp>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// hex data
|
||||
class hex_data_t : public plugmod_t, public event_listener_t
|
||||
{
|
||||
TWidget *cv = nullptr;
|
||||
TWidget *hexview = nullptr;
|
||||
|
||||
FILE *f = nullptr;
|
||||
uint64 sz = 10000;
|
||||
const uint align = 16;
|
||||
|
||||
public:
|
||||
|
||||
hex_data_t()
|
||||
{
|
||||
hook_event_listener(HT_VIEW, this);
|
||||
}
|
||||
~hex_data_t()
|
||||
{
|
||||
// listeners are uninstalled automatically
|
||||
// when the owner module is unloaded
|
||||
close();
|
||||
}
|
||||
|
||||
virtual bool idaapi run(size_t) override;
|
||||
virtual ssize_t idaapi on_event(ssize_t code, va_list va) override;
|
||||
|
||||
bool open(const char *fname)
|
||||
{
|
||||
close();
|
||||
f = qfopen(fname, "rb");
|
||||
if ( f == NULL )
|
||||
return false;
|
||||
// 64 bit functions could be used instead
|
||||
qfseek(f, 0, SEEK_END);
|
||||
sz = qftell(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
cv = nullptr;
|
||||
hexview = nullptr;
|
||||
if ( f != nullptr )
|
||||
{
|
||||
qfclose(f);
|
||||
f = nullptr;
|
||||
sz = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool read(uint64 pos, void *buf, size_t bufsize)
|
||||
{
|
||||
// 64 bit functions could be used instead
|
||||
if ( qfseek(f, pos, SEEK_SET) != 0 )
|
||||
return false;
|
||||
return qfread(f, buf, bufsize) == bufsize;
|
||||
}
|
||||
|
||||
uint64 size() const
|
||||
{
|
||||
return sz;
|
||||
}
|
||||
|
||||
int alignment() const
|
||||
{
|
||||
return align;
|
||||
}
|
||||
|
||||
uval_t pos_to_line(uint64 pos) const
|
||||
{
|
||||
return pos / align;
|
||||
}
|
||||
|
||||
uval_t maxline() const
|
||||
{
|
||||
return pos_to_line(sz - 1);
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// hex place
|
||||
define_place_exported_functions(hex_place_t)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
class hex_place_t : public place_t
|
||||
{
|
||||
public:
|
||||
hex_data_t *d;
|
||||
uval_t n;
|
||||
hex_place_t() : d(nullptr), n(0) { lnnum = 0; }
|
||||
hex_place_t(hex_data_t *_d, uint64 pos = 0) : d(_d)
|
||||
{
|
||||
n = d->pos_to_line(pos);
|
||||
lnnum = 0;
|
||||
}
|
||||
define_place_virtual_functions(hex_place_t)
|
||||
};
|
||||
#include "hexplace.cpp"
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ssize_t idaapi hex_data_t::on_event(ssize_t code, va_list va)
|
||||
{
|
||||
switch ( code )
|
||||
{
|
||||
case ui_widget_invisible:
|
||||
{
|
||||
TWidget *w = va_arg(va, TWidget *);
|
||||
if ( w == hexview || w == cv )
|
||||
{
|
||||
close();
|
||||
unhook_event_listener(HT_UI, this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Create a custom view window
|
||||
bool idaapi hex_data_t::run(size_t)
|
||||
{
|
||||
register_hex_place();
|
||||
|
||||
static const char title[] = "Sample hexview";
|
||||
TWidget *widget = find_widget(title);
|
||||
if ( widget != NULL )
|
||||
{
|
||||
warning("Hexview already open. Switching to it.");
|
||||
activate_widget(widget, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ask the user to select a file
|
||||
char *filename = ask_file(false, NULL, "Select a file to display...");
|
||||
if ( filename == NULL || filename[0] == 0 )
|
||||
return true;
|
||||
// open the file
|
||||
if ( !open(filename) )
|
||||
return true;
|
||||
|
||||
// create two place_t objects: for the minimal and maximal locations
|
||||
hex_place_t s1(this);
|
||||
hex_place_t s2(this, size() - 1);
|
||||
// create a custom viewer
|
||||
cv = create_custom_viewer(title, &s1, &s2, &s1, NULL, this, NULL, NULL);
|
||||
// create a code viewer container for the custom view
|
||||
hexview = create_code_viewer(cv);
|
||||
// set the radix and alignment for the offsets
|
||||
set_code_viewer_lines_radix(hexview, 16);
|
||||
set_code_viewer_lines_alignment(hexview, size() > 0xFFFFFFFF ? 16 : 8);
|
||||
// also set the ui event callback
|
||||
hook_event_listener(HT_UI, this);
|
||||
// finally display the form on the screen
|
||||
display_widget(hexview, WOPN_DP_TAB|WOPN_RESTORE);
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static plugmod_t *idaapi init()
|
||||
{
|
||||
return new hex_data_t;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// PLUGIN DESCRIPTION BLOCK
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
plugin_t PLUGIN =
|
||||
{
|
||||
IDP_INTERFACE_VERSION,
|
||||
PLUGIN_MULTI, // The plugin can work with multiple idbs in parallel
|
||||
init, // initialize
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr, // long comment about the plugin
|
||||
nullptr, // multiline help about the plugin
|
||||
"Sample hexview", // the preferred short name of the plugin
|
||||
nullptr, // the preferred hotkey to run the plugin
|
||||
};
|
||||
11
idasdk76/plugins/hexview/makefile
Normal file
11
idasdk76/plugins/hexview/makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
PROC=hexview
|
||||
|
||||
include ../plugin.mak
|
||||
|
||||
# MAKEDEP dependency list ------------------
|
||||
$(F)hexview$(O) : $(I)bitrange.hpp $(I)bytes.hpp $(I)config.hpp $(I)fpro.h \
|
||||
$(I)funcs.hpp $(I)ida.hpp $(I)idp.hpp $(I)ieee.h \
|
||||
$(I)kernwin.hpp $(I)lines.hpp $(I)llong.hpp \
|
||||
$(I)loader.hpp $(I)nalt.hpp $(I)netnode.hpp $(I)pro.h \
|
||||
$(I)range.hpp $(I)segment.hpp $(I)ua.hpp $(I)xref.hpp \
|
||||
hexplace.cpp hexview.cpp
|
||||
Reference in New Issue
Block a user