Skip to content

Instantly share code, notes, and snippets.

@mykola2312
Created February 26, 2021 05:37
Show Gist options
  • Save mykola2312/b03693603f6ff4048c9e27c62d712e07 to your computer and use it in GitHub Desktop.
Save mykola2312/b03693603f6ff4048c9e27c62d712e07 to your computer and use it in GitHub Desktop.
#include "disas.h"
opcode_t arch[] = {
{'\x90',1},{'\x81',6},{'\xC7',6},{'\xA1',5},
{'\x74',2},{'\x33',2},{'\x89',7},{'\x6A',2},
{'\xE8',5},{'\xE9',5},{'\x50',1},{'\x51',1},
{'\x52',1},{'\x53',1},{'\x54',1},{'\x55',1},
{'\x56',1},{'\x57',1},{'\x0E',1},{'\x1E',1},
{'\x16',1},{'\x06',1},{'\x75',2},{'\xCC',1},
{'\xC2',3},{'\xC3',1},{'\xCD',2},{'\x58',1},
{'\x59',1},{'\x5A',1},{'\x5B',1},{'\x5C',1},
{'\x5D',1},{'\x5E',1},{'\x5F',1},{'\x36',5},
{'\xA9',5},{'\x74',2},{'\x75',2},{'\x83',3},
{'\x8A',2},{'\x84',2},{'\x24',1},{'\x68',5},
{'\x33',2},{'\x00',0}
};
opcode2_t arch2[] = {
{0xEC8B,2},{0x748B,4},{0x458B,3},{0x418B,3},
{0x4C8B,4},{0x518B,3},{0x5D8B,3},{0xFF8B,2},
{0x7E80,4},{0x7E83,4},{0x468D,3},{0x0D8B,6},
{0x118B,2},{0x928B,6},{0xD0FF,2},{0xD1FF,2},
{0xD2FF,2},{0xD3FF,2},{0xD4FF,2},{0xD5FF,2},
{0xD6FF,2},{0xD7FF,2},{0x50FF,3},{0x51FF,3},
{0x52FF,3},{0x53FF,3},{0x54FF,4},{0x55FF,3},
{0x56FF,3},{0x57FF,3},{0xE0FF,2},{0xE1FF,2},
{0xE2FF,2},{0xE3FF,2},{0xE4FF,2},{0xE5FF,2},
{0xE6FF,2},{0xE7FF,2},{0xC1F7,6},{0xC2F7,6},
{0xC3F7,6},{0xC4F7,6},{0xC5F7,6},{0xC6F7,6},
{0xC7F7,6},{0x448B,4},{0x5C8B,4},{0x4C8B,4},
{0x548B,4},{0x748B,4},{0x7C8B,4},{0x6C8B,4},
{0x648B,4},{0x458B,3},{0xC08B,2},{0x0000,0}
};
size_t opcode_size(unsigned char* ptr)
{
//__asm int 3
for(opcode_t* i = arch; i->opsize != 0; i++)
{
if(i->signature == *ptr)
return i->opsize;
}
for(opcode2_t* i = arch2; i->opsize != 0; i++)
{
if(i->signature == *(unsigned short*)ptr)
return i->opsize;
}
return 0;
}
size_t disas_func(unsigned char* begin,unsigned char* end)
{
unsigned char* ptr = begin;
size_t cur = 0,size = 0;
while(ptr!=end&&size<5)
{
if(!(cur=opcode_size(ptr)))
return 0;
else
{
size+=cur;
ptr+=cur;
}
}
return size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment