神话系列之一 C 程序不能反编译

 网上流传很多C和C# 神话

 我听了以后,决定打破这些美丽的神话。。给大家开开眼界,更希望能说明一个神话,。,,

 

解开我 最神秘的等待 

 

 

C 程序能不能反编译成 C 语言的程序?

 

神话:无法反编译的,,只能通过汇编来解释。

详细:

C语言源程序经过编译、优化,得到目标格式,但由目标格式不能逆推得到C源码,因为目标码可能是经过优化的,谁也不能说这些优化做到了哪样的程度,因而没 有算法进行这样的逆推,所以不可能从目标格式得到C源码。

 

 

 

今天我反编译的是我自己写的

小东西,其实就是MSDN找的例子。

 

// crt_printf.c
// This program uses the printf and wprintf functions
// to produce formatted output.

#include <stdio.h>

int main( void )
{
   char     ch = 'h',
            *string = "computer";
   wchar_t  wch = L'w',
            *wstring = L"Unicode";
   int      count = -9234;


   // Display integers
   printf( "Integer formats:/n"
           "   Decimal: %d  Justified: %.6d  "
           "Unsigned: %u/n",
           count, count, count, count );

   // Display decimals
   printf( "Decimal %d as:/n   Hex: %Xh  "
           "C hex: 0x%x  Octal: %o/n",
            count, count, count, count );

   // Display in different radixes
   printf( "Digits 10 equal:/n   Hex: %i  "
           "Octal: %i  Decimal: %i/n",
            0x10, 010, 10 );

   // Display characters
   printf("Characters in field (1):/n"
          "%10c%5hc%5C%5lc/n",
          ch, ch, wch, wch);
   wprintf(L"Characters in field (2):/n"
           L"%10C%5hc%5c%5lc/n",
           ch, ch, wch, wch);

   // Display strings
   printf("Strings in field (1):/n%25s/n"
          "%25.4hs/n   %S%25.3ls/n",
          string, string, wstring, wstring);
   wprintf(L"Strings in field (2):/n%25S/n"
           L"%25.4hs/n   %s%25.3ls/n",
           string, string, wstring, wstring);

   // Display real numbers


   // Display pointer
   printf( "/nAddress as:   %p/n", &count);
}

用的是VC2010 (应该没有什么疑问吧)

编译模式 release (VC默认那个)

 

首先要明白,如果直接全部反编译是不明智的,

因为编译器 会产生很多信息

我们知道 程序要从 Main 函数入口

我们就只需要反编译这个就可以了

你们看看反编译结果:

 

int __cdecl main()
{
  signed int v1; // [sp+8h] [bp-4h]@1                                        

  v1 = -9234;
  _printf("Integer formats:/n   Decimal: %d  Justified: %.6d  Unsigned: %u/n", -9234, -9234, -9234, -9234);
  _printf("Decimal %d as:/n   Hex: %Xh  C hex: 0x%x  Octal: %o/n", v1, v1, v1, v1);
  _printf("Digits 10 equal:/n   Hex: %i  Octal: %i  Decimal: %i/n", 16, 8, 10);
  _printf("Characters in field (1):/n%10c%5hc%5C%5lc/n", 104, 104, 119, 119);
  _wprintf(L"Characters in field (2):/n%10C%5hc%5c%5lc/n", 104, 104, 119, 119);
  _printf("Strings in field (1):/n%25s/n%25.4hs/n   %S%25.3ls/n", "computer", "computer", L"Unicode", L"Unicode");
  _wprintf(L"Strings in field (2):/n%25S/n%25.4hs/n   %s%25.3ls/n", "computer", "computer", L"Unicode", L"Unicode");
  _printf("/nAddress as:   %p/n", &v1);
  return 0;
}

 

这段代码简单修改以后可以编译通过的!

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值