tianna0370 Posted August 13, 2010 Posted August 13, 2010 Hello:I am developing a plugin for Ollydbg now, but I am struggled to modify the assembly code by Ollydbg API. For example, in the main windows, there is an instruction "PUSH EAX". I'd like to change it to "PUSH EBX". I have tried two APIs: Assemble() and Writememory(), but didn't success. Am I right? Could anyone write a piece of sample code for me?thanks a lot in advance.Fan
ragdog Posted August 13, 2010 Posted August 13, 2010 (edited) HiHave you try this?I use this for my OllyMod plugin.dataszPatch db 53h ; push ebxinvoke GetCurrentProcess mov Handle, eax mov szOffset,0xxxxxxh ;<<<< your offsetinvoke VirtualProtect, eax, 10,PAGE_EXECUTE_WRITECOPY, offset Oldinvoke WriteProcessMemory, Handle, szOffset, offset szPatch, 1, 0 I think before you patch this address add ReadProcessMemory and compare result for check if at this address push eaxGreets Edited August 13, 2010 by ragdog
ghandi Posted August 14, 2010 Posted August 14, 2010 (edited) Instead of posting "It didn't work" why not show us what you tried to use, maybe someone who has coded a plugin can help with your problem? What parameters are you passing to Assemble, etc... I am assuming you mean to change the code in the context of the debuggee, not OllyDbg itself? ragdog: mov szOffset,0xxxxxxh ;<<<< your offset invoke VirtualProtect, eax, 10,PAGE_EXECUTE_WRITECOPY, offset Old At this point, EAX == the handle to the process (FFFFFFFF) which is an invalid address to pass to VirtualProtect, i would have thought you would use 'szOffset' (thats a different prefix for a DWORD/UINT variable. ) Having said this, i was under the impression the OP was trying to make his plugin so that it modifies the target process, not OllyDbg. HR, Ghandi Edited August 14, 2010 by ghandi
ragdog Posted August 14, 2010 Posted August 14, 2010 (edited) Sorry i have what forgotinvoke GetCurrentProcess mov Handle, eax mov eax, 0xxxxxxxh ;your offset mov szOffset, eax invoke VirtualProtect, eax, 10,PAGE_EXECUTE_WRITECOPY, offset Old invoke WriteProcessMemory, Handle, szOffset, offset szPatch, 1, 0 Edited August 14, 2010 by ragdog
tianna0370 Posted August 16, 2010 Author Posted August 16, 2010 Thank you very much for both of your helps. What I did is to develop a plugin that analyze the assembly code in ollydbg window and then change some instructions automatically so that the executing sequence will be changed. If anyone have some ideas about how to change the instructions, please let me know.Thanks a lot again
ghandi Posted August 16, 2010 Posted August 16, 2010 Instead of posting "It didn't work" why not show us what you tried to use, maybe someone who has coded a plugin can help with your problem? What parameters are you passing to Assemble, etc... I am assuming you mean to change the code in the context of the debuggee, not OllyDbg itself?You have not provided any information, how can we help you if you wont do anything to help yourself.HR,Ghandi
tianna0370 Posted August 16, 2010 Author Posted August 16, 2010 Sorry about that. I wrote the code as below:void modifyInstruction(ulong address){ t_memory *pmem; unsigned int pocetBytup=0,pocetBytu=0,length=0; ulong cmdsize; char cmd[MAXCMDSIZE],*pdecode,*errors; ulong decodesize; t_disasm da; t_asmmodel am; cmdsize=MAXCMDSIZE; Readmemory(cmd,address+pocetBytu,cmdsize,MM_RESTORE|MM_SILENT);//read the original instruction and calculate the length of code pmem=Findmemory(address+pocetBytu); pdecode=Finddecode(address+pocetBytu,&decodesize); pocetBytup=pocetBytu; pocetBytu+=Disasm(cmd,cmdsize,address+pocetBytu,pdecode,&da,DISASM_CODE,0); strcpy(cmd,"PUSH 4");//get the new instruction which will write it to the memory Writememory(cmd,address,pocetBytu-pocetBytup,MM_RESTORE|MM_SILENT);//write the new instruction to the memory}After I test it on some case, the original instruction has been changed to two instructions: "PUSH EAX" and "PUSH EBP", not the expected instruction "PUSH 4". What's wrong with the code?Thank you
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now