#include <segment.hpp> // For segment functions
#include <ua.hpp>
// Loop through each executable segment, displaying the mnemonic used in each instruction
for (int s = 0; s < get_segm_qty(); s++)
{
segment_t *seg = getnseg(s);
if (seg->type == SEG_CODE)
{
int bytes = 0;
// a should always be the address of an instruction, which is why bytes is dynamic
// depending on the result of ua_mnem()
for (ea_t a = seg->startEA; a < seg->endEA; a += bytes)
{
char mnem[MAXSTR];
const char *res;
// Get the mnemonic at a, store it in mnem
res = ua_mnem(a, mnem, sizeof(mnem)-1);
// If this was an instruction, display the mnemonic, set the bytes counter
// to cmd.size, so that the next address processed by ua_mnem() is the next instruction.
if (res != NULL)
{
msg("Mnemonic at %a: %s\n", a, mnem);
bytes = cmd.size;
}
else
{
msg ("No code\n");
// If there was no code at this address, increment the byte counter by 1 so that
// ua_mnem() works off the next address.
bytes = 1;
}
}
}
}