2

I just tried to convert the asm code shown belown, but I failed to get the same result

00ACDE11  /MOV AL,BYTE PTR DS:[EBX]          
00ACDE13  |MOV EDX,EAX                       
00ACDE15  |ADD DL,0CF                        
00ACDE18  |SUB DL,9                          
00ACDE1B  |JB SHORT 00ACDE46            ;Especially this     
00ACDE1D  |ADD DL,0F9                        
00ACDE20  |SUB DL,0E                         
00ACDE23  |JB SHORT 00ACDE46            ;Especially this     
00ACDE25  |DEC EDX                           
00ACDE26  |SUB DL,0B                         
00ACDE29  |JB SHORT 00ACDE46            ;Especially this     
00ACDE2B  |XOR EAX,EAX                       
00ACDE2D  |MOV AL,BYTE PTR SS:[EBP-310]      
00ACDE33  |DEC EAX                           
00ACDE34  |CALL 009E2D24                     
00ACDE39  |MOV EDI,EAX                       
00ACDE3B  |MOV AL,BYTE PTR SS:[EDI+EBP-30F]  
00ACDE42  |MOV BYTE PTR DS:[EBX],AL          
00ACDE44  |JMP SHORT 00ACDE48                
00ACDE46  |MOV BYTE PTR DS:[EBX],AL          
00ACDE48  |INC EBX                           
00ACDE49  |DEC ESI                           
00ACDE4A  \JNZ SHORT 00ACDE11                

I already does some research effort on the internet and found that carry flag is set when an overflow is caused. This is what I already tried:

for(int i=0; i < n ;i++)
{
    int c = buffer[i] + 0xC6;

    if(c > 0xFF) // <---- this is not producing the same result
    {
        c = ((unsigned char) c) + 0xEB;

        if(c > 0xFF) // <---- this is not producing the same result
        {
            c = ((unsigned char) c) - 0xC;

            if(c > 0xFF) // <---- this is not producing the same result
            {
                //...
                //func_009E2D24(...);

            }
        }
    }

    //...
}
2
  • C has no concept of overflow (unless you call "this is undefined behaviour" a concept), so you can't really translate this to C; you'll have to understand the assembler. Commented May 22, 2016 at 6:41
  • 1
    As checking overflow is "after the fact" and not accessible in C, you can invert it by checking for < 14 before doing the subtraction.
    – Jongware
    Commented May 22, 2016 at 11:05

1 Answer 1

1

This is what I wanted so far, this worked fine for me:

for(int i=0; i < n ;i++)
{
    int c = buffer[i] + 0xCF;
    c = (unsigned char)c;
    c -= 9;
    if (c > 0)
    {
        c += 0xF9;
        c = (unsigned char)c;
        c -= 0xE;
        if (c > 0)
        {
            c = (unsigned char)c;
            c -= 0xC;
            if (c > 0)
            {
                //...
                //func_009E2D24(...);
            }
        }

    }
    //...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.