sailor__eda
January 23rd, 2008, 00:07
I'm facing a really strange problem that i wanted to share with everyone.
I'm trying to patch a series of bytes in a linux dynamic library. I'm patching a function call in two locations in identical ways.
Here is a code snippet
.text:084E165B 8B 0D 04 DE D7 09 mov ecx, var1
.text:084E1661 89 0C 24 mov [esp+68h+var_68], ecx
.text:084E1664 E8 E7 3A 00 00 call Func1 <= patching this
.text:084E1669 A3 08 DE D7 09 mov var2, eax
.text:084E166E 8B 1D 08 DE D7 09 mov ebx, var2
.text:084E1674 85 DB test ebx, ebx
.text:084E1676 74 3A jz short loc_84E16B2
Func1 returns the results in eax so I wanted to patch the call to be mov eax, 0h instead.
Hence I was patching E8 E7 3A 00 00 with B8 00 00 00 00.
I fire up my favourite hex editor, look for my byte sequence and make the necessary changes. In fact, I have to do this patch in 2 locations, fairly close to each other.
Here's when the fun starts. If disassemble my modified file after my changes, the 2nd patch location has mov eax, 0h exactly as I intended. The first patch location has mov eax, 383Eh!
I did this several times just to make sure I'm not screwing something up and everytime I have the same problem. In fact, after much trial and error, I realized that whatever immediate value I patched in, seemed to have a offset of 383Eh added to it. I fixed the problem by finding 0h-383Eh and using that value instead and that gave me mov eax, 0h.
So my question is what his happening here? Why is it that making the same change a few bytes below works correctly but not for the first location?
I was thinking it might have something to do with the relocation stuff in a dynamic library but that doesn't make sense for immediate values.
So what gives?
Sailor
I'm trying to patch a series of bytes in a linux dynamic library. I'm patching a function call in two locations in identical ways.
Here is a code snippet
.text:084E165B 8B 0D 04 DE D7 09 mov ecx, var1
.text:084E1661 89 0C 24 mov [esp+68h+var_68], ecx
.text:084E1664 E8 E7 3A 00 00 call Func1 <= patching this
.text:084E1669 A3 08 DE D7 09 mov var2, eax
.text:084E166E 8B 1D 08 DE D7 09 mov ebx, var2
.text:084E1674 85 DB test ebx, ebx
.text:084E1676 74 3A jz short loc_84E16B2
Func1 returns the results in eax so I wanted to patch the call to be mov eax, 0h instead.
Hence I was patching E8 E7 3A 00 00 with B8 00 00 00 00.
I fire up my favourite hex editor, look for my byte sequence and make the necessary changes. In fact, I have to do this patch in 2 locations, fairly close to each other.
Here's when the fun starts. If disassemble my modified file after my changes, the 2nd patch location has mov eax, 0h exactly as I intended. The first patch location has mov eax, 383Eh!
I did this several times just to make sure I'm not screwing something up and everytime I have the same problem. In fact, after much trial and error, I realized that whatever immediate value I patched in, seemed to have a offset of 383Eh added to it. I fixed the problem by finding 0h-383Eh and using that value instead and that gave me mov eax, 0h.
So my question is what his happening here? Why is it that making the same change a few bytes below works correctly but not for the first location?
I was thinking it might have something to do with the relocation stuff in a dynamic library but that doesn't make sense for immediate values.
So what gives?
Sailor