DBG: restore patch range function
This commit is contained in:
		
							parent
							
								
									4529e210c9
								
							
						
					
					
						commit
						574bc468e9
					
				|  | @ -66,6 +66,18 @@ static bool _mempatch(duint va, const unsigned char* src, duint size) | |||
|     return mempatch(fdProcessInfo->hProcess, (void*)va, src, size, 0); | ||||
| } | ||||
| 
 | ||||
| static void _patchrestorerange(duint start, duint end) | ||||
| { | ||||
|     if(start > end) | ||||
|     { | ||||
|         duint a=start; | ||||
|         start=end; | ||||
|         end=a; | ||||
|     } | ||||
|     for(duint i=start; i<end+1; i++) | ||||
|         patchdel(i, true); | ||||
| } | ||||
| 
 | ||||
| void dbgfunctionsinit() | ||||
| { | ||||
|     _dbgfunctions.AssembleAtEx=assembleat; | ||||
|  | @ -78,4 +90,5 @@ void dbgfunctionsinit() | |||
|     _dbgfunctions.PatchGet=_patchget; | ||||
|     _dbgfunctions.PatchInRange=_patchinrange; | ||||
|     _dbgfunctions.MemPatch=_mempatch; | ||||
|     _dbgfunctions.PatchRestoreRange=_patchrestorerange; | ||||
| } | ||||
|  | @ -11,6 +11,7 @@ typedef bool (*ASSEMBLE)(duint addr, unsigned char* dest, int* size, const char* | |||
| typedef bool (*PATCHGET)(duint addr); | ||||
| typedef bool (*PATCHINRANGE)(duint start, duint end); | ||||
| typedef bool (*MEMPATCH)(duint va, const unsigned char* src, duint size); | ||||
| typedef void (*PATCHRESTORERANGE)(duint start, duint end); | ||||
| 
 | ||||
| struct DBGFUNCTIONS | ||||
| { | ||||
|  | @ -24,6 +25,7 @@ struct DBGFUNCTIONS | |||
|     PATCHGET PatchGet; | ||||
|     PATCHINRANGE PatchInRange; | ||||
|     MEMPATCH MemPatch; | ||||
|     PATCHRESTORERANGE PatchRestoreRange; | ||||
| }; | ||||
| 
 | ||||
| #ifdef BUILD_DBG | ||||
|  |  | |||
|  | @ -52,14 +52,20 @@ bool patchget(uint addr, PATCHINFO* patch) | |||
|     return (found->second.oldbyte != found->second.newbyte); | ||||
| } | ||||
| 
 | ||||
| bool patchdel(uint addr) | ||||
| bool patchdel(uint addr, bool restore) | ||||
| { | ||||
|     if(!DbgIsDebugging()) | ||||
|         return false; | ||||
|     return (patches.erase(modhashfromva(addr))==1); | ||||
|     PatchesInfo::iterator found=patches.find(modhashfromva(addr)); | ||||
|     if(found==patches.end()) //not found
 | ||||
|         return false; | ||||
|     if(restore) | ||||
|         memwrite(fdProcessInfo->hProcess, (void*)(found->second.addr+modbasefromaddr(addr)), &found->second.oldbyte, sizeof(char), 0); | ||||
|     patches.erase(found); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void patchdelrange(uint start, uint end) | ||||
| void patchdelrange(uint start, uint end, bool restore) | ||||
| { | ||||
|     if(!DbgIsDebugging()) | ||||
|         return; | ||||
|  | @ -73,7 +79,11 @@ void patchdelrange(uint start, uint end) | |||
|     while(i!=patches.end()) | ||||
|     { | ||||
|         if(bDelAll || (i->second.addr>=start && i->second.addr<end)) | ||||
|         { | ||||
|             if(restore) | ||||
|                 memwrite(fdProcessInfo->hProcess, (void*)(i->second.addr+modbase), &i->second.oldbyte, sizeof(char), 0); | ||||
|             patches.erase(i++); | ||||
|         } | ||||
|         else | ||||
|             i++; | ||||
|     } | ||||
|  |  | |||
|  | @ -14,8 +14,8 @@ typedef std::map<uint, PATCHINFO> PatchesInfo; | |||
| 
 | ||||
| bool patchset(uint addr, unsigned char oldbyte, unsigned char newbyte); | ||||
| bool patchget(uint addr, PATCHINFO* patch); | ||||
| bool patchdel(uint addr); | ||||
| void patchdelrange(uint start, uint end); | ||||
| bool patchdel(uint addr, bool restore); | ||||
| void patchdelrange(uint start, uint end, bool restore); | ||||
| void patchclear(const char* mod); | ||||
| bool patchenum(PATCHINFO* patchlist, size_t* cbsize); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue