Advertisement
Madmouse

Mips breakpoint detection using memory scanning

Jan 31st, 2015
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. /*
  2. #############################
  3. # MIPS breakpoint detection #
  4. #############################
  5.  
  6. .text
  7. .abicalls
  8. .global scan    
  9.  
  10. # bool scan(void* code, unsigned int size);
  11. scan:
  12.         li $t0, 0x5000D                 # breakpoint constant
  13. loop:
  14.         lw $t3, ($a0)                   # load bytecode
  15.         beq $t3, $t0, fuck              # if this is a breakpoint fucked
  16.         beq $t3, 0, safe                # if the counter is 0 we are safe
  17.         subu $a1, 1                     # decrement counter
  18.         addu $a0, 1                     # increment our pointer
  19.         j loop                          # if we are looping loop
  20.  
  21. safe:
  22.         li $v0, 0x0     # return false
  23.         li $v1, 0x0
  24.         jr $ra
  25.  
  26. fuck:
  27.         li $v0, 0x1     # return true
  28.         li $v1, 0x0
  29.         jr $ra
  30.  
  31. */
  32.  
  33.  
  34. bool scan(void (*fun), unsigned int depth)  /// scans a function for break points
  35. {
  36.     int i;
  37.     long unsigned int inst;
  38.     for(i=0;i<=depth;i+=sizeof(inst))   /// count from offset start to depth
  39.     {
  40.         inst = (*(volatile unsigned int *)((unsigned int)fun + i));
  41.         if (inst == 0x5000D)    /// if this is a break point
  42.             return true;    /// return true
  43.     }
  44.     return false;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement