Advertisement
BullyATWiiplaza

Pointer Search Logic

Mar 19th, 2015
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. import java.io.IOException;
  2.  
  3. public class PointerSearch
  4. {
  5.     MemoryDumps memoryDumps;
  6.     MemoryPointerData memoryPointer;
  7.  
  8.     public PointerSearch(String directoryPath) throws IOException
  9.     {
  10.         memoryDumps = new MemoryDumps(directoryPath);
  11.     }
  12.  
  13.     public void performPointerSearch() throws IOException
  14.     {
  15.         long startingAddress;
  16.  
  17.         // The absolute memory address which marks the beginning of the game's RAM
  18.         startingAddress = 0x14000000;
  19.         memoryPointer = new MemoryPointerData(startingAddress, memoryDumps);
  20.         memoryPointer.setMaximumOffset(0x400);
  21.  
  22.         findPossiblePointers(memoryPointer);
  23.     }
  24.  
  25.     private void findPossiblePointers(MemoryPointerData pointer)
  26.     {
  27.         Debugging.printLine("Finding possible pointers:");
  28.  
  29.         for (int memoryDumpContentOffset = 0; memoryDumpContentOffset < memoryDumps
  30.                 .getMemoryDumpContents()[0].length; memoryDumpContentOffset++)
  31.         {
  32.             // Find values which look like possible pointer candidates
  33.             if (pointer.isPossiblePointer(memoryDumps.getMemoryDumpContents()[0][memoryDumpContentOffset]))
  34.             {
  35.                 // Calculate the offset between the address' value and the target address
  36.                 long pointerOffset = memoryDumps.getTargetAddresses()[0]
  37.                         + pointer.getLowestAddress()
  38.                         - memoryDumps.getMemoryDumpContents()[0][memoryDumpContentOffset];
  39.  
  40.                 // We do not want pointers with negative or huge offsets
  41.                 if (!pointer.isWithinOffsetBounds(pointerOffset))
  42.                 {
  43.                     continue;
  44.                 }
  45.  
  46.                 boolean allMatch = true;
  47.  
  48.                 for (int memoryDumpsIndex = 1; memoryDumpsIndex < memoryDumps
  49.                         .getMemoryDumpsAmount(); memoryDumpsIndex++)
  50.                 {
  51.                     // Does the pointer we've found work on all of the RAM dumps supplied?
  52.                     if (memoryDumps.getMemoryDumpContents()[memoryDumpsIndex][memoryDumpContentOffset]
  53.                             + pointerOffset == memoryDumps.getTargetAddresses()[memoryDumpsIndex]
  54.                             + pointer.getLowestAddress())
  55.                     {
  56.                         // Debugging.printLine("Yes!");
  57.  
  58.                     } else
  59.                     {
  60.                         // Debugging.printLine("No!");
  61.  
  62.                         allMatch = false;
  63.                     }
  64.                 }
  65.  
  66.                 // Print out pointers which seem reliable
  67.                 if (allMatch)
  68.                 {
  69.                     Debugging
  70.                             .printLine("["
  71.                                     + HexadecimalUtilities
  72.                                             .toHexadecimal(
  73.                                                     memoryDumpContentOffset
  74.                                                             + pointer
  75.                                                                     .getLowestAddress())
  76.                                             .substring(8)
  77.                                     + "] + "
  78.                                     + HexadecimalUtilities
  79.                                             .toHexadecimal(pointerOffset));
  80.                 }
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement