"Practical Reverse Engineering" 中的代码清单是否包含错误,或者我误解了循环结构?

Does the code listing in "Practical Reverse Engineering" contain an error, or do I misunderstand loop constructs?

我最近为了做逆向工程开始学习汇编。我正在阅读 Practical Reverse Engineering 并在那里看到了这段汇编代码:

loop_start:    
  mov eax, [edi+4]
  mov eax, [eax+ebx*4]
  test eax, eax
  ... //They also did the dots here
  jz short loc_7F627F
loc_7F627F:
  inc ebx
  cmp ebx, [edi]
  jl short loop_start

然后他们告诉我们这个信息应该给我们一个想法,把它反编译成这个(我在他们做的地方做所有的点):

typedef struct _Foo
{
  DWORD size;
  DWORD array[...];} FOO, *PFOO;

  PFOO bar= ...;

  for(i= ...; i < bar->size; i++)
  {
    if(bar->array[i] != 0){
    ...
  }
}

但是因为 jz short loc_7F627F 只有在 eax 的内容为零时才会跳转,所以 ... 不应该在 jz 之后而不是在 jz 之前吗?否则这将意味着我测试 eax 的内容,它是否为零,然后做一些未知的事情,如果它是零则稍后跳转(前提是 ... 中没有其他指令影响 ZF 标志),这似乎与他们编写的 C 代码不匹配。

这部分:

loc_7F627F:
inc ebx
cmp ebx, [edi]
jl short loop_start

转换为:

for(i= ?; i < bar->size; i++){
    //do something
    }
}

这部分

mov eax, [edi+4]
mov eax, [eax+ebx*4]
test eax, eax
... //They also did the dots here
jz short loc_7F627F

(不)转换为:

if(bar->array[i] != 0){
  ...
}

你是对的。
... 只应在 array[i] <> 0 时执行,因此汇编语句中的 ... 应在 [=17= 之后,而不是之前。

通常在...之后也应该无条件跳转到loc_7F627F;但是在这种情况下,第一个 ... 之后的代码可以直接进入 for 循环。