首页
社区
课程
招聘
[旧帖] [求助]IDA反编译的伪代码中如何实现switch语句 0.00雪花
2008-12-22 16:16 8456

[旧帖] [求助]IDA反编译的伪代码中如何实现switch语句 0.00雪花

2008-12-22 16:16
8456
新学ida,拿个有源代码的程序练习。
源代码中含有switch语句,生成的伪代码却是n个 if 语句,头都看晕了。
有办法使伪代码的 if 转换为switch吗?

阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

收藏
点赞0
打赏
分享
最新回复 (3)
雪    币: 2576
活跃值: (447)
能力值: ( LV2,RANK:85 )
在线值:
发帖
回帖
粉丝
wyfe 2008-12-22 16:25
2
0
用Hex-Rays.Decompiler插件,F5执行
雪    币: 230
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
烟灰缸 2008-12-22 17:35
3
0
谢谢wyfe的回答。
我用的就是Hex-Rays插件,v1.0.071108版本。
就是它生成的伪代码,把switch换成了 if 。
能转换回switch吗?如何转换?
雪    币: 230
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
烟灰缸 2008-12-24 09:14
4
0
在哪里操作,才能将伪代码中令人头晕的 if 转换为switch?

源代码:
LRESULT CALLBACK WinSunProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
        switch(uMsg)
        {
        case WM_CHAR:  
                char szChar[20];
                sprintf(szChar,"Char is %d",wParam);
                MessageBox(hwnd,szChar,"字符",0);
                break;
        case WM_LBUTTONDOWN:
                MessageBox(hwnd,"谁让你单击鼠标左键?","鼠标",0);
                HDC hdc;
                hdc=GetDC(hwnd);  
                TextOut(hdc,0,50,"编程",strlen("编程"));
                ReleaseDC(hwnd,hdc);  
                break;
        case WM_PAINT:
                HDC hdcpaint;
                PAINTSTRUCT ps;
                hdcpaint=BeginPaint(hwnd,&ps);  
                TextOut(hdcpaint,0,100,"我爱你",strlen("我爱你"));
                EndPaint(hwnd,&ps);  
                ReleaseDC(hwnd,hdcpaint);
                break;
        case WM_CLOSE:  
                if(IDYES==MessageBox(hwnd,"退出吗?","确认",MB_YESNO))
                {
                        DestroyWindow(hwnd);
                }
                break;
        case WM_DESTROY:
                PostQuitMessage(0);  
                break;
        default:
                return DefWindowProc(hwnd,uMsg,wParam,lParam);  //
        }
        return 0;
}

生成的伪代码:
LRESULT __stdcall WinSunProc(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lparam)
{
  HWND Hwnd; // esi@7
  HWND hWnd; // esi@5
  HDC hdcpaint; // ebx@5
  HWND HWnd; // esi@12
  HDC hdc; // ebx@12
  struct tagPAINTSTRUCT ps; // [sp+20h] [bp-40h]@5
  char szChar; // [sp+Ch] [bp-54h]@13

  if ( uMsg <= (unsigned int)WM_CLOSE )
  {
    if ( uMsg != WM_CLOSE )
    {
      if ( uMsg == WM_DESTROY )
      {
        PostQuitMessage(0);
        return 0;
      }
      if ( uMsg == 15 )
      {
        hWnd = hwnd;                                  // 顺便问一句:这2个变量能合而为一吗?
        hdcpaint = BeginPaint(hwnd, &ps);
        TextOutA(hdcpaint, 0, 100, "我爱你", strlen("我爱你") - 1);
        EndPaint(hWnd, &ps);
        ReleaseDC(hWnd, hdcpaint);
        return 0;
      }
      return DefWindowProcA(hwnd, uMsg, wparam, lparam);
    }
    Hwnd = hwnd;
    if ( MessageBoxA(hwnd, "退出吗?", "确认", MB_YESNO) == IDYES )
    {
      DestroyWindow(Hwnd);
      return 0;
    }
    return 0;
  }
  if ( uMsg == WM_CHAR )
  {
    sprintf(&szChar, "Char is %d", wparam);
    MessageBoxA(hwnd, &szChar, "字符", 0);
    return 0;
  }
  if ( uMsg != 513 )
    return DefWindowProcA(hwnd, uMsg, wparam, lparam);
  HWnd = hwnd;
  MessageBoxA(hwnd, "谁让你单击鼠标左键?", "鼠标", 0);
  hdc = GetDC(HWnd);
  TextOutA(hdc, 0, 50, "编程", strlen("编程") - 1);
  ReleaseDC(HWnd, hdc);
  return 0;
}
游客
登录 | 注册 方可回帖
返回