Print assembler hex in one pass

Jason Geffner posted a piece of code to demonstrate how to print out a bulk of assembler hex in one pass,
    http://blogs.msdn.com/geffner/archive/2006/02/10/529320.aspx, i managed to work out another way to 
    accomplish the same work:

#include "stdafx.h"

typedef unsigned char __u8;

void __declspec(naked) shellcode(void)
{
 __asm {
        mov eax, 0x15db  
        rol eax, 0x13
        xor eax, 0xdeadbeef
        shr eax, 0x10
        mov ebx, eax
        shl eax, 0x2
        add eax, ebx
        add eax, ebx
        add eax, ebx
        add eax, 0x4
 }
}

void __declspec(naked) stub(void)
{
}

int __cdecl main(int argc, char* argv[])
{
    int i;
    for (i  =  0;  i  <  (__u8 *)stub - (__u8 *)shellcode;  i++)
    {
        printf ("//x%02x", ((__u8*)shellcode)[i]);
    }
    printf("/n");
    return 0;
}

don't forget to turn on Minimize Size optimization option in Visual C++ compiler, missing this option will make the compiler align the machine code with 4 bytes, so for the sample code, there're 2 byte nop instruction in tail.
Jason is a Virus Analyst of Microsoft Anti Malware team, his blog is worth of a reading.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值