首页
社区
课程
招聘
未解决 [求助]IDA一段伪代码关于memcpy看不懂
发表于: 2018-12-23 23:46 3448

未解决 [求助]IDA一段伪代码关于memcpy看不懂

2018-12-23 23:46
3448
int __cdecl OPT(CERPlayer *pPlayer, int nID, int *pnParams, int nMax, const char *str)
{
  COptCommand cmd; // ST1C_8
  int nSize; // ebp
  unsigned int nlen; // kr04_4
  char *v8; // edi
  int iKeyNet; // ST0C_4
  int iIDNet; // eax
  char szCmd[1024]; // [esp+14h] [ebp-400h]

  cmd.m_wID = nID;
  cmd.m_cID = 36;
  cmd.m_byNumberOfInt = nMax;
  *(_DWORD *)&szCmd[4] = 0;
  *(_DWORD *)szCmd = *(_DWORD *)&cmd.m_cID;
//nSize
  nSize = 4 * nMax + 8;
  qmemcpy(&szCmd[8], pnParams, 4 * nMax);
//为啥+1再-1,>>2跟&3是为啥?
//有没有大佬帮忙合并下这个if里面的代码....研究了一天了也没搞懂
// memcpy 的长度不是4的倍数?
  if ( str && strcmp(str, pszName) )
  {
    nlen = strlen(str) + 1;
    qmemcpy(&szCmd[nSize], str, 4 * ((nlen - 1) >> 2));
    v8 = &szCmd[4 * ((nlen - 1) >> 2) + nSize];
    nSize += nlen - 1;
    qmemcpy(v8, &str[4 * ((nlen - 1) >> 2)], ((_BYTE)nlen - 1) & 3);
  }
//
  iKeyNet = CERPlayer::KeyNet(pPlayer);
  iIDNet = CERPlayer::IDNet(pPlayer);
  MessageOpt(szCmd, nSize, iIDNet, iKeyNet);
  return 1;
}
//汇编代码
.text:1008EF60                 sub     esp, 408h
.text:1008EF66                 mov     edx, [esp+408h+nID]
.text:1008EF6D                 mov     eax, [esp+408h+arg_C]
.text:1008EF74                 push    ebx
.text:1008EF75                 push    ebp
.text:1008EF76                 push    esi
.text:1008EF77                 mov     [esp+414h+cmd.m_cID], 24h
.text:1008EF7C                 mov     [esp+414h+cmd.m_wID], dx
.text:1008EF81                 mov     [esp+414h+cmd.m_byNumberOfInt], al
.text:1008EF85                 mov     esi, dword ptr [esp+414h+cmd.m_cID]
.text:1008EF89                 xor     ecx, ecx
.text:1008EF8B                 push    edi
.text:1008EF8C                 mov     dword ptr [esp+418h+szCmd], esi
.text:1008EF90                 mov     esi, [esp+418h+arg_8]
.text:1008EF97                 mov     dword ptr [esp+418h+szCmd+4], ecx
.text:1008EF9B                 mov     ecx, eax
.text:1008EF9D                 lea     edi, [esp+418h+szCmd+8]
.text:1008EFA1                 rep movsd
.text:1008EFA3                 mov     esi, [esp+418h+arg_10]
.text:1008EFAA                 lea     ebp, ds:8[eax*4]
.text:1008EFB1                 test    esi, esi
.text:1008EFB3                 jz      short loc_1008F00B
.text:1008EFB5                 mov     edi, offset pszName
.text:1008EFBA                 mov     eax, esi
.text:1008EFBC
.text:1008EFBC loc_1008EFBC:                           ; CODE XREF: OPT+7A↓j
.text:1008EFBC                 mov     bl, [eax]
.text:1008EFBE                 mov     cl, bl
.text:1008EFC0                 cmp     bl, [edi]
.text:1008EFC2                 jnz     short loc_1008EFE0
.text:1008EFC4                 test    cl, cl
.text:1008EFC6                 jz      short loc_1008EFDC
.text:1008EFC8                 mov     bl, [eax+1]
.text:1008EFCB                 mov     cl, bl
.text:1008EFCD                 cmp     bl, [edi+1]
.text:1008EFD0                 jnz     short loc_1008EFE0
.text:1008EFD2                 add     eax, 2
.text:1008EFD5                 add     edi, 2
.text:1008EFD8                 test    cl, cl
.text:1008EFDA                 jnz     short loc_1008EFBC
.text:1008EFDC
.text:1008EFDC loc_1008EFDC:                           ; CODE XREF: OPT+66↑j
.text:1008EFDC                 xor     eax, eax
.text:1008EFDE                 jmp     short loc_1008EFE5
.text:1008EFE0 ; ---------------------------------------------------------------------------
.text:1008EFE0
.text:1008EFE0 loc_1008EFE0:                           ; CODE XREF: OPT+62↑j
.text:1008EFE0                                         ; OPT+70↑j
.text:1008EFE0                 sbb     eax, eax
.text:1008EFE2                 sbb     eax, 0FFFFFFFFh
.text:1008EFE5
.text:1008EFE5 loc_1008EFE5:                           ; CODE XREF: OPT+7E↑j
.text:1008EFE5                 test    eax, eax
.text:1008EFE7                 jz      short loc_1008F00B
.text:1008EFE9                 mov     edi, esi
.text:1008EFEB                 or      ecx, 0FFFFFFFFh
.text:1008EFEE                 xor     eax, eax
.text:1008EFF0                 repne scasb
.text:1008EFF2                 not     ecx
.text:1008EFF4                 dec     ecx
.text:1008EFF5                 lea     edi, [esp+ebp+418h+szCmd]
.text:1008EFF9                 mov     eax, ecx
.text:1008EFFB                 mov     ebx, ecx
.text:1008EFFD                 shr     ecx, 2
.text:1008F000                 rep movsd
.text:1008F002                 mov     ecx, ebx
.text:1008F004                 and     ecx, 3
.text:1008F007                 add     ebp, eax
.text:1008F009                 rep movsb
.text:1008F00B
.text:1008F00B loc_1008F00B:                           ; CODE XREF: OPT+53↑j
.text:1008F00B                                         ; OPT+87↑j
.text:1008F00B                 push    ebp             ; nSize
.text:1008F00C                 push    edx             ; nID
.text:1008F00D                 call    OPT_SCmd_Update
.text:1008F012                 mov     edi, [esp+420h+arg_0]
.text:1008F019                 add     esp, 8
.text:1008F01C                 or      esi, 0FFFFFFFFh
.text:1008F01F                 or      eax, 0FFFFFFFFh
.text:1008F022                 test    edi, edi
.text:1008F024                 jz      short loc_1008F036
.text:1008F026                 mov     ecx, edi        ; this
.text:1008F028                 call    CERPlayer::IDNet
.text:1008F02D                 mov     ecx, edi        ; this
.text:1008F02F                 mov     esi, eax
.text:1008F031                 call    CERPlayer::KeyNet
.text:1008F036
.text:1008F036 loc_1008F036:                           ; CODE XREF: OPT+C4↑j
.text:1008F036                 push    eax             ; nPlayerKeyNet
.text:1008F037                 push    esi             ; nPlayerIDNet
.text:1008F038                 lea     eax, [esp+420h+szCmd]
.text:1008F03C                 push    ebp             ; nSize
.text:1008F03D                 push    eax             ; szMsg
.text:1008F03E                 call    MessageOptServer
.text:1008F043                 add     esp, 10h
.text:1008F046                 mov     eax, 1
.text:1008F04B                 pop     edi
.text:1008F04C                 pop     esi
.text:1008F04D                 pop     ebp
.text:1008F04E                 pop     ebx
.text:1008F04F                 add     esp, 408h
.text:1008F055                 retn


[培训]科锐逆向工程师培训第53期2025年7月8日开班!

最后于 2018-12-23 23:59 被hackasn编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 591
活跃值: (131)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
解决了
2018-12-24 01:26
0
雪    币: 12
活跃值: (438)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
看看是不是四字节
2018-12-24 09:49
1
游客
登录 | 注册 方可回帖
返回