xAnalyzer automatically detects loop structures within functions during analysis, providing visual indicators that help you understand code flow and iteration patterns. This feature identifies backward jumps that create loops, marking them clearly in the disassembly.
Loops are only detected within function boundaries (between prolog and epilog/return instructions) to ensure accuracy.
; Standard while loop patternloc_401000: ; ← Loop start cmp ecx, 10 jge short loc_401020 ; Exit condition inc ecx ; ... loop body ... jmp short loc_401000 ; ← Backward jump (loop detected)loc_401020: ; Loop exit
; Classic for loop structure xor eax, eax ; i = 0loc_401050: ; ← Loop start cmp eax, 100 jge short loc_401070 ; i >= 100, exit ; ... loop body ... inc eax ; i++ jmp short loc_401050 ; ← Loop detectedloc_401070:
; Do-while loop (condition at end)loc_401100: ; ← Loop start ; ... loop body ... dec edx test edx, edx jnz short loc_401100 ; ← Conditional backward jump
; Loop with multiple exit conditionsloc_401200: ; ← Loop start test eax, eax jz short loc_401230 ; Early exit cmp ebx, [esi] je short loc_401230 ; Another exit ; ... loop body ... jmp short loc_401200 ; ← Continue looploc_401230:
Loop detection only works within function boundaries. If a function contains a RET instruction in the middle of its code, it will be detected as a function end and the loops stack is cleared.
func_start: push ebp mov ebp, esp test eax, eax jz short early_exit loc_loop: ; Loop here ; ... body ... jmp short loc_loop ; ← Detected early_exit: ; First RET pop ebp ret ; ← Clears loop stack ; Any loops after this point won't be detected
typedef struct stLOOPSTACK { duint dwStartAddress; // Where the loop begins duint dwEndAddress; // Where the backward jump occurs} LOOPSTACK;stack <LOOPSTACK*> stackLoops; // Global stackduint addressFunctionStart; // Current function start reference