Question

What is the best way to check and debug if jumping too far?

So I have a var inBuffer which contains a BYTE lenght of 115. I move that into bufSize and try xor'ing it against a set of 3 keys to decrypt the message. My code compiles but I am unable to to build except this part where it says I am jumping too far.

bufSize DWORD ?
mov eax,115
mov bufSize,eax

;-------------------------------------------------
AnalyzeBuffer PROC
;receives nothing
;returns nothing
;-------------------------------------------------
pushad          ; pushes all data in this method into a stack
mov ecx,bufSize ; loop count
mov esi,0       ; start at index 0 in translated buffer

top:
    cmp buffer[esi],20h    ; checks if character is space which is ok
    je yes

    cmp buffer[esi],2ch    ; checks if character is comma wich is okay
    je yes

    cmp buffer[esi],2eh    ; checks if character is period which is okay
    je yes

    cmp buffer[esi],41h     ; checks if character is above A in the ascii chart
    jb no

    ;the following are all unacceptable characters
    cmp buffer[esi],5bh     ;checks if character is [
    je no
    cmp buffer[esi],5ch     ; checks if character is \
    je no
    cmp buffer[esi],5dh     ;checks if character is ]
    je no
    cmp buffer[esi],5eh      ; checks if character is ^
    je no
    cmp buffer[esi],5fh     ; checks if character is _
    je no
    cmp buffer[esi],60h     ; checks if character is `
    je no
    cmp buffer[esi],7bh     ; checks if characre is {
    je no
    cmp buffer[esi],7ch     ; checks if character is |
    je no
    cmp buffer[esi],7dh     ; checks if }
    je no
    cmp buffer[esi],7eh     ; checks if ~
    je no
    cmp buffer[esi],7fh     ; checks if 
    je no



    yes:
        inc esi             ; going to next character
        loop top
        ;getting to this step means these keys worked for all characters in buffer

        mov edx,OFFSET goodMsg
        call WriteString
        call DisplayAllKeys ; shows 3 keys used
        call Crlf
        call Crlf
        mov edx,OFFSET buffer   ; displays decrypted message
        call WriteString
        call Crlf
        call Crlf

    no:
    ;the current character wasnt good so trying next key
    popad
    ret

AnalyzeBuffer ENDP
Was it helpful?

Solution

Next time you should tell which line is causing the error. I am guessing it is the loop instruction, because that only exists with a 8 bit offset. Due to optimization reasons, it's it's recommended to avoid using it anyway, and that will solve your jump range problem too. So, just replace it with a dec ecx; jnz top.

You could also optimize your checks, but that's another story.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top