安全中国首页 > 文章中心 > 逆向工程技术
 
安全中国网友投稿专用上传FTP空间:
Ftp服务器:download.anqn.com
Ftp端口:21
用户名:anqn
密 码:anqn.com
 

易语言核心runtime的loader和部分services的逆向工程

更新时间:2007-12-20 1:03:56
责任编辑:流火
热 点:

      switch(dwParam1)
      {
        case 1:
          strcpy((char*)dwParam2, FileName_Path);
          return (INT)FileName_Path;
          break;
        case 2001:
          strcpy((char*)dwParam2, FileName_Path);
          return (INT)FileName_Path;
          break;
        case 2002:
          strcpy((char*)dwParam2, FileName_Name);
          return (INT)FileName_Name;
          break;
        default:
          return NULL;    
      }
    case NRS_UNIT_DESTROIED:
      //通知系统指定的单元已经被销毁。
      //和窗口组建相关,不处理。
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_UNIT_DESTROIED);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_CONVERT_NUM_TO_INT:
      //转换其它数值格式到整数
      ThisDataInfo = (PMDATA_INF)dwParam1;
      switch(ThisDataInfo->m_dtDataType)
      {
        case SDT_SHORT:
          return (int)(ThisDataInfo->m_short);
        case SDT_INT:
          return (int)(ThisDataInfo->m_int);
        case SDT_INT64:
          return (int)(ThisDataInfo->m_int64);
        case SDT_FLOAT:
          return (int)(ThisDataInfo->m_float);
        case SDT_DOUBLE:
          return (int)(ThisDataInfo->m_double);
        default:
          return 0;
      }
      break;
    case NRS_GET_CMD_LINE_STR:
      //取当前命令行文本
      return (INT)ThisCmdLine;
    case NRS_GET_EXE_PATH_STR:
      //取当前执行文件所处目录名称
      return (INT)FileName_Path;
    case NRS_GET_EXE_NAME:
      //取当前执行文件名称
      return (INT)FileName_Name;
    case NRS_GET_UNIT_PTR:
      //取单元对象指针
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_GET_UNIT_PTR);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_GET_AND_CHECK_UNIT_PTR:
      //取单元对象指针
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_GET_AND_CHECK_UNIT_PTR);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_EVENT_NOTIFY:
      //通知系统产生了事件
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_EVENT_NOTIFY);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    /*
    在新版本的支持库中不支持
    case NRS_STOP_PROCESS_EVENT_NOTIFY:
      //通知系统暂停处理事件通知
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_STOP_PROCESS_EVENT_NOTIFY);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_CONTINUE_PROCESS_EVENT_NOTIFY:
      //通知系统继续处理事件通知
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_CONTINUE_PROCESS_EVENT_NOTIFY);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    */
    case NRS_DO_EVENTS:
      //通知Windows系统处理所有已有事件
      //我不觉得这种处理方式很好,确定的说,是一种很差的处理方式
      Sleep(1);
      break;
    case NRS_GET_UNIT_DATA_TYPE:
      //成功返回有效的 DATA_TYPE
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_GET_UNIT_DATA_TYPE);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;  
    case NRS_FREE_ARY:
      //释放指定数组数据
      //不会处理T_T,:(
      MessageBoxA(0, ERROR_020, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_MALLOC:
      //分配指定空间的内存,所有与易程序交互的内存都必须使用本通知分配
      temppoint = HeapAlloc(ThisHeap, 0, dwParam1);
      if(temppoint == NULL)
      {
        if(dwParam2 == 0)
        {
          MessageBoxA(0, ERROR_017, "error", MB_ICONERROR);
          ServerFunction_09(0);
          return 0;
        }
        else
        {
          return 0;
        }
      }
      return (INT)temppoint;
    case NRS_MFREE:
      //释放已分配的指定内存
      if(dwParam1 != NULL)
      {
        HeapFree(ThisHeap, 0, (void *)dwParam1);
      }
      break;
    case NRS_MREALLOC:
      //重新分配内存
      temppoint = HeapReAlloc(ThisHeap, 0, (void *)dwParam1, dwParam2);
      if(temppoint == NULL)
      {
        MessageBoxA(0, ERROR_018, "error", MB_ICONERROR);
        ServerFunction_09(0);
        return 0;
      }
      return (INT)temppoint;
    case NRS_RUNTIME_ERR:
      //通知系统已经产生运行时错误
      sprintf(ErrorString, "%s\n\nError String is %s", ERROR_019, (char*)dwParam1);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_EXIT_PROGRAM:
      //通知系统退出用户程序
      ServerFunction_09(dwParam1);
      break;
    case NRS_EVENT_NOTIFY2:
      //以第二类方式通知系统产生了事件
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_EVENT_NOTIFY2);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_GET_WINFORM_COUNT:
      //返回当前程序的窗体数目
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_GET_WINFORM_COUNT);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_GET_WINFORM_HWND:
      //返回指定窗体的窗口句柄,如果该窗体尚未被载入,返回NULL
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_GET_WINFORM_HWND);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_GET_BITMAP_DATA:
      //返回指定HBITMAP的图片数据,成功返回包含BMP图片数据的HGLOBAL句柄,失败返回NULL
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_GET_BITMAP_DATA);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;
    case NRS_FREE_COMOBJECT:
      //通知系统释放指定的DTP_COM_OBJECT类型COM对象
      //不支持COM对象,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_FREE_COMOBJECT);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;  
    case NRS_CHK_TAB_VISIBLE:
      //当选择夹子夹被切换后, 使用本消息通知易系统
      //和窗口组建相关,不处理
      sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_016, NRS_CHK_TAB_VISIBLE);
      MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
      ServerFunction_09(0);
      break;      
    case NRS_GET_PRG_TYPE:
      //返回当前用户程序的类型,为PT_DEBUG_RUN_VER(调试版)或PT_RELEASE_RUN_VER(发布版)
      return PT_RELEASE_RUN_VER;
    default:
      //如果发生例外,不处理
      break;
  }
  
  return 0;
}

bool Init(void)
{
  ThisHeap = HeapCreate(0, 0x1000, 0);
  if(ThisHeap == NULL)
  {
    return false;
  }

  MyNotifySys = ThisNotifySys;

  return true;
}

void _cdecl ServerFunction_00(UINT32 Param1)
{
  
  sprintf(ErrorString, "%s\n\nIntra error number is %d.", ERROR_006, Param1);
  MessageBoxA(0, ErrorString, "error", MB_ICONERROR);
  
  ServerFunction_09(0);
  
  return;
}

__declspec(naked) void _stdcall ServerFunction_01(void)
{

  __asm
  {
    pop temp
    push eax
    pop DllCmdNO
  }

  ThisDllCmd = DllCmdHead;
  ThisDllCmd += DllCmdNO;

  if((* ThisDllCmd->DllFileName) == NULL)
  {
    i = 0;
    while((* DefaultSystemAPI[i]) != NULL)
    {
      ThisLibrary = LoadLibrary(DefaultSystemAPI[i]);
      UnKnowFun = (UNKNOWFUN)GetProcAddress(ThisLibrary, ThisDllCmd->DllCmdName);
      if(UnKnowFun != NULL)
      {
        __asm
        {
          //call UnKnowFun
          //这个地方可能会引起杀毒软件的误报,如果有必要的话,需要处理一下
          push temp
          jmp UnKnowFun
        }
        break;
      }
      else
      {
        FreeLibrary(ThisLibrary);
        i++;
      }

    }

    if(UnKnowFun == NULL)
    {
      ServerFunction_00(0);
    }
    
  }
  else
  {
    ThisLibrary = LoadLibrary(ThisDllCmd->DllFileName);
    UnKnowFun = (UNKNOWFUN)GetProcAddress(ThisLibrary, ThisDllCmd->DllCmdName);
    if(UnKnowFun != NULL)
    {
      __asm
      {
        //call UnKnowFun
        push temp
        jmp UnKnowFun
      }
    }
    else
    {
      ServerFunction_00(0);
    }    
  }
  
  __asm
  {
    push eax
  }
  
  FreeLibrary(ThisLibrary);
  
  __asm
  {
    pop eax
    push temp
    ret
  }
  
}

__declspec(naked) void _cdecl ServerFunction_02(void)
{
  
  __asm
  {
    push ebp
    mov ebp,esp
    mov LibCmdNO,eax
  }
  ThisLibInfo = LibInfoHead;
  ThisLibInfo += LibCmdNO;
  if(ThisLibInfo->ThisLibHandle == NULL || ThisLibInfo->ThisLibInfo == NULL)
  {
    sprintf(ErrorString, "%s\n\nIntra error string is \"%s\".", ERROR_014, ThisLibInfo->ThisLibName);
    MessageBoxA(0, ErrorString, "error", MB_ICONERROR);  
    ServerFunction_09(0);  
  }
  ThisCmdsFuncHead = &(ThisLibInfo->ThisLibInfo->m_pCmdsFunc);
  __asm
  {
    mov edx,[ThisCmdsFuncHead]
    add ebx,[edx]
    lea edx,dword ptr ss:[esp+0x0c]
    sub esp,0x0c
    push edx
    push dword ptr ss:[esp+0x18]
    mov dword ptr ss:[esp+0x08],0
    mov dword ptr ss:[esp+0x0c],0
    mov dword ptr ss:[esp+0x10],0
    lea edx,dword ptr ss:[esp+0x08]
    push edx
    call dword ptr ds:[ebx]
    mov eax,dword ptr ss:[esp+0x0c]
    mov edx,dword ptr ss:[esp+0x10]
    mov ecx,dword ptr ss:[esp+0x14]
    mov esp,ebp
    pop ebp
    retn
  }
}

上一页 1 2 3 4 5 下一页

 
相关文章
一日一文章
 
一日一软件
一日一动画