I am trying to recreate a segment of assembly back into the C code. Below is the progress I've made so far, but I'm getting stumped on a specific section.
00000000000010049 <mysteryFunc>:
10049: f3 0f 1e fa endbr64
1004d: 55 push rbp
1004e: 48 89 e5 mov rbp,rsp
10051: 48 89 7d d8 mov QWORD PTR [rbp-0x28],rdi ; This is the function call with a unsigned char ptr as input s
10055: 66 c7 45 e8 00 00 mov WORD PTR [rbp-0x18],0x0 ; Declaring h -- unsigned short h = 0;
1005b: c7 45 ec 00 00 00 00 mov DWORD PTR [rbp-0x14],0x0 ; Declaring length -- unsigned long length = 0;
10062: 48 8b 45 d8 mov rax,QWORD PTR [rbp-0x28] ; Declaring a temp char pointer -- unsigned char *temp = s;
10066: 48 89 45 f0 mov QWORD PTR [rbp-0x10],rax
1006a: eb 5f jmp 100cb <mysteryFunc+0x82> ; This seems to be a goto call to the end of a do-while loop
1006c: 48 8b 45 f0 mov rax,QWORD PTR [rbp-0x10]
10070: 48 89 45 f8 mov QWORD PTR [rbp-0x8],rax
10074: 8b 45 ec mov eax,DWORD PTR [rbp-0x14] ; if(!(length & 1)) {
10077: 83 e0 01 and eax,0x1
1007a: 85 c0 test eax,eax
1007c: 75 22 jne 100a0 <mysteryFunc+0x57>
I don't know what instructions in C would cause this kind of repositioning.
1006c: 48 8b 45 f0 mov rax,QWORD PTR [rbp-0x10] ; What's happening here?
10070: 48 89 45 f8 mov QWORD PTR [rbp-0x8],rax
The function does some processing of a string and checks for null within a do-while loop. I get the feeling it's shifting to a next character, but a lot of the ways I can think to do something like that in C don't produce an assembly instruction like that.
The function does some things in less than conventional ways, like a goto call to the end of a do-while loop to check if the input string is null, instead of just using a regular while loop.