BVB Source Codes

x64dbg Show AnalysisPass.cpp Source code

Return Download x64dbg: download AnalysisPass.cpp Source code - Download x64dbg Source code - Type:.cpp
  1. #include <assert.h>
  2. #include <thread>
  3. #include "AnalysisPass.h"
  4. #include "memory.h"
  5.  
  6. AnalysisPass::AnalysisPass(duint VirtualStart, duint VirtualEnd, BBlockArray & MainBlocks) : m_MainBlocks(MainBlocks)
  7. {
  8.     assert(VirtualEnd > VirtualStart);
  9.  
  10.     // Internal class data
  11.     m_VirtualStart = VirtualStart;
  12.     m_VirtualEnd = VirtualEnd;
  13.     m_InternalMaxThreads = 0;
  14.  
  15.     // Read remote instruction data to local memory
  16.     m_DataSize = VirtualEnd - VirtualStart;
  17.     m_Data = (unsigned char*)VirtualAlloc(nullptr, m_DataSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  18.  
  19.     if(!MemRead(VirtualStart, m_Data, m_DataSize))
  20.     {
  21.         VirtualFree(m_Data, 0, MEM_RELEASE);
  22.         assert(false);
  23.     }
  24. }
  25.  
  26. AnalysisPass::~AnalysisPass()
  27. {
  28.     if(m_Data)
  29.         VirtualFree(m_Data, 0, MEM_RELEASE);
  30. }
  31.  
  32. BasicBlock* AnalysisPass::FindBBlockInRange(duint Address)
  33. {
  34.     // NOTE: __MUST__ BE A SORTED VECTOR
  35.     //
  36.     // Use a binary search
  37.     duint indexLo = 0;
  38.     duint indexHi = m_MainBlocks.size();
  39.  
  40.     // Get a pointer to pure data
  41.     const auto blocks = m_MainBlocks.data();
  42.  
  43.     while(indexHi > indexLo)
  44.     {
  45.         duint indexMid = (indexLo + indexHi) / 2;
  46.         auto entry = &blocks[indexMid];
  47.  
  48.         if(Address < entry->VirtualStart)
  49.         {
  50.             // Continue search in lower half
  51.             indexHi = indexMid;
  52.         }
  53.         else if(Address >= entry->VirtualEnd)
  54.         {
  55.             // Continue search in upper half
  56.             indexLo = indexMid + 1;
  57.         }
  58.         else
  59.         {
  60.             // Address is within limits, return entry
  61.             return entry;
  62.         }
  63.     }
  64.  
  65.     // Not found
  66.     return nullptr;
  67. }
  68.  
  69. duint AnalysisPass::FindBBlockIndex(BasicBlock* Block)
  70. {
  71.     // Fast pointer arithmetic to find index
  72.     return ((duint)Block - (duint)m_MainBlocks.data()) / sizeof(BasicBlock);
  73. }
  74.  
  75. duint AnalysisPass::IdealThreadCount()
  76. {
  77.     if(m_InternalMaxThreads == 0)
  78.     {
  79.         // Determine the maximum hardware thread count at once
  80.         duint maximumThreads = max(std::thread::hardware_concurrency(), 1);
  81.  
  82.         // Don't consume 100% of the CPU, adjust accordingly
  83.         if(maximumThreads > 1)
  84.             maximumThreads -= 1;
  85.  
  86.         SetIdealThreadCount(maximumThreads);
  87.     }
  88.  
  89.     return m_InternalMaxThreads;
  90. }
  91.  
  92. void AnalysisPass::SetIdealThreadCount(duint Count)
  93. {
  94.     m_InternalMaxThreads = (BYTE)min(Count, 255);
  95. }
downloadAnalysisPass.cpp Source code - Download x64dbg Source code
Related Source Codes/Software:
pencil - Multiplatform GUI Prototyping/Wireframing 2017-04-16
rainloop-webmail - Simple, modern & fast web-based email client ... 2017-04-16
qt - Qt binding for Go (Golang) which supports Windows ... 2017-04-16
MLeaksFinder - Find memory leaks in your iOS app at develop time. 2017-04-16
jsfeat - JavaScript Computer Vision library. 2017-04-16
later - A javascript library for defining recurring schedu... 2017-04-16
Android-ItemTouchHelper-Demo - Basic example of using ItemTouchHelper to add drag... 2017-04-16
onionshare - Securely and anonymously share a file of any size ... 2017-04-16
android-viewflow - A horizontal view scroller library for Android 2017-04-16
css-in-js - React: CSS in JS techniques comparison. 2017-04-16
mama2 - Mother plan - all firewood high flame 2017-04-23
BlurEffectForAndroidDesign - Sample to show how to implement blur graphical tri... 2017-04-23
sphinx_rtd_theme - Sphinx theme for readthedocs.org 2017-04-23
rouge - A pure-ruby code highlighter that is compatible wi... 2017-04-23
spring-security-oauth - Support for adding OAuth1(a) and OAuth2 features (... 2017-04-23
Toucan - Fabulous Image Processing in Swift 2017-04-23
CoffeeScriptRedux - 2017-04-23
breakpoint - Really simple media queries in Sa 2017-04-23
libsvm - 2017-04-22
grr - GRR Rapid Response: remote live forensics for inci... 2017-04-22

 Back to top