Skip to content

Commit

Permalink
Deploying to gh-pages from @ 0fab510 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
patacca committed May 3, 2024
1 parent 4bdfe4d commit d8316e1
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 22 deletions.
36 changes: 22 additions & 14 deletions _modules/bindiff/bindiff.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ <h1>Source code for bindiff.bindiff</h1><div class="highlight"><pre>
<span class="c1"># The block has been match but in another function thus unmatched here</span>
<span class="k">if</span> <span class="n">function</span><span class="o">.</span><span class="n">addr</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">maps</span><span class="p">:</span>
<span class="n">bbs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">bb</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">bbs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">bb</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">bbs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">bb</span><span class="p">)</span>
<span class="k">return</span> <span class="n">bbs</span>

<div class="viewcode-block" id="BinDiff.primary_unmatched_basic_block">
Expand Down Expand Up @@ -463,24 +463,23 @@ <h1>Source code for bindiff.bindiff</h1><div class="highlight"><pre>
<div class="viewcode-block" id="BinDiff.from_binary_files">
<a class="viewcode-back" href="../../differs/bindiff.html#bindiff.BinDiff.from_binary_files">[docs]</a>
<span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">from_binary_files</span><span class="p">(</span><span class="n">p1_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">p2_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Optional</span><span class="p">[</span><span class="s2">&quot;BinDiff&quot;</span><span class="p">]:</span>
<span class="k">def</span> <span class="nf">from_binary_files</span><span class="p">(</span><span class="n">p1_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">p2_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">override</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Optional</span><span class="p">[</span><span class="s2">&quot;BinDiff&quot;</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Diff two executable files. Thus it export .BinExport files from IDA</span>
<span class="sd"> and then diff the two resulting files in BinDiff.</span>

<span class="sd"> :param p1_path: primary binary file to diff</span>
<span class="sd"> :param p2_path: secondary binary file to diff</span>
<span class="sd"> :param diff_out: output file for the diff</span>
<span class="sd"> :param override: override Binexports files and diffing</span>
<span class="sd"> :return: BinDiff object representing the diff</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="n">p1</span> <span class="o">=</span> <span class="n">ProgramBinExport</span><span class="o">.</span><span class="n">from_binary_file</span><span class="p">(</span><span class="n">p1_path</span><span class="p">)</span>
<span class="n">p2</span> <span class="o">=</span> <span class="n">ProgramBinExport</span><span class="o">.</span><span class="n">from_binary_file</span><span class="p">(</span><span class="n">p2_path</span><span class="p">)</span>
<span class="n">p1_binexport</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">p1_path</span><span class="si">}</span><span class="s2">.BinExport&quot;</span><span class="p">)</span>
<span class="n">p2_binexport</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">p2_path</span><span class="si">}</span><span class="s2">.BinExport&quot;</span><span class="p">)</span>
<span class="n">p1</span> <span class="o">=</span> <span class="n">ProgramBinExport</span><span class="o">.</span><span class="n">from_binary_file</span><span class="p">(</span><span class="n">p1_path</span><span class="p">,</span> <span class="n">override</span><span class="o">=</span><span class="n">override</span><span class="p">)</span>
<span class="n">p2</span> <span class="o">=</span> <span class="n">ProgramBinExport</span><span class="o">.</span><span class="n">from_binary_file</span><span class="p">(</span><span class="n">p2_path</span><span class="p">,</span> <span class="n">override</span><span class="o">=</span><span class="n">override</span><span class="p">)</span>
<span class="k">if</span> <span class="n">p1</span> <span class="ow">and</span> <span class="n">p2</span><span class="p">:</span>
<span class="n">retcode</span> <span class="o">=</span> <span class="n">BinDiff</span><span class="o">.</span><span class="n">raw_diffing</span><span class="p">(</span><span class="n">p1_binexport</span><span class="p">,</span> <span class="n">p2_binexport</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">)</span>
<span class="k">return</span> <span class="n">BinDiff</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">)</span> <span class="k">if</span> <span class="n">retcode</span> <span class="k">else</span> <span class="kc">None</span>
<span class="k">return</span> <span class="n">BinDiff</span><span class="o">.</span><span class="n">from_binexport_files</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">,</span> <span class="n">override</span><span class="o">=</span><span class="n">override</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logging</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;p1 or p2 could not have been &#39;binexported&#39;&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">None</span></div>
Expand All @@ -490,20 +489,29 @@ <h1>Source code for bindiff.bindiff</h1><div class="highlight"><pre>
<a class="viewcode-back" href="../../differs/bindiff.html#bindiff.BinDiff.from_binexport_files">[docs]</a>
<span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">from_binexport_files</span><span class="p">(</span>
<span class="n">p1_binexport</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">p2_binexport</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">:</span> <span class="nb">str</span>
<span class="n">p1_binexport</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">ProgramBinExport</span><span class="p">,</span> <span class="nb">str</span><span class="p">],</span>
<span class="n">p2_binexport</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">ProgramBinExport</span><span class="p">,</span> <span class="nb">str</span><span class="p">],</span>
<span class="n">diff_out</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">override</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Optional</span><span class="p">[</span><span class="s2">&quot;BinDiff&quot;</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Diff two binexport files. Diff the two binexport files with bindiff</span>
<span class="sd"> and then load a BinDiff instance.</span>

<span class="sd"> :param p1_binexport: primary binexport file to diff</span>
<span class="sd"> :param p2_binexport: secondary binexport file to diff</span>
<span class="sd"> :param p1_binexport: primary binexport file to diff (path or object)</span>
<span class="sd"> :param p2_binexport: secondary binexport file to diff (path or object)</span>
<span class="sd"> :param diff_out: output file for the diff</span>
<span class="sd"> :param override: override Binexports files and diffing</span>
<span class="sd"> :return: BinDiff object representing the diff</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">p1_path</span> <span class="o">=</span> <span class="n">p1_binexport</span><span class="o">.</span><span class="n">path</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p1_binexport</span><span class="p">,</span> <span class="n">ProgramBinExport</span><span class="p">)</span> <span class="k">else</span> <span class="n">p1_binexport</span>
<span class="n">p2_path</span> <span class="o">=</span> <span class="n">p2_binexport</span><span class="o">.</span><span class="n">path</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p2_binexport</span><span class="p">,</span> <span class="n">ProgramBinExport</span><span class="p">)</span> <span class="k">else</span> <span class="n">p2_binexport</span>

<span class="n">retcode</span> <span class="o">=</span> <span class="n">BinDiff</span><span class="o">.</span><span class="n">raw_diffing</span><span class="p">(</span><span class="n">p1_binexport</span><span class="p">,</span> <span class="n">p2_binexport</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">)</span>
<span class="k">return</span> <span class="n">BinDiff</span><span class="p">(</span><span class="n">p1_binexport</span><span class="p">,</span> <span class="n">p2_binexport</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">)</span> <span class="k">if</span> <span class="n">retcode</span> <span class="k">else</span> <span class="kc">None</span></div>
<span class="k">if</span> <span class="ow">not</span> <span class="n">Path</span><span class="p">(</span><span class="n">diff_out</span><span class="p">)</span><span class="o">.</span><span class="n">exists</span><span class="p">()</span> <span class="ow">or</span> <span class="n">override</span><span class="p">:</span>
<span class="n">retcode</span> <span class="o">=</span> <span class="n">BinDiff</span><span class="o">.</span><span class="n">raw_diffing</span><span class="p">(</span><span class="n">p1_path</span><span class="p">,</span> <span class="n">p2_path</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">)</span>
<span class="k">return</span> <span class="n">BinDiff</span><span class="p">(</span><span class="n">p1_binexport</span><span class="p">,</span> <span class="n">p2_binexport</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">)</span> <span class="k">if</span> <span class="n">retcode</span> <span class="k">else</span> <span class="kc">None</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">BinDiff</span><span class="p">(</span><span class="n">p1_binexport</span><span class="p">,</span> <span class="n">p2_binexport</span><span class="p">,</span> <span class="n">diff_out</span><span class="p">)</span></div>


<span class="nd">@staticmethod</span>
Expand Down
7 changes: 6 additions & 1 deletion _modules/binexport/basic_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ <h1>Source code for binexport.basic_block</h1><div class="highlight"><pre>

<span class="bp">self</span><span class="o">.</span><span class="n">addr</span><span class="p">:</span> <span class="n">Addr</span> <span class="o">=</span> <span class="kc">None</span> <span class="c1">#: basic bloc address</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bytes</span> <span class="o">=</span> <span class="sa">b</span><span class="s2">&quot;&quot;</span> <span class="c1">#: bytes of the basic block</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_len</span> <span class="o">=</span> <span class="mi">0</span> <span class="c1">#: Length of the basic block (number of instructions)</span>

<span class="c1"># Ranges are in fact the true basic blocks but BinExport</span>
<span class="c1"># doesn&#39;t have the same basic block semantic and merge multiple basic blocks into one.</span>
Expand All @@ -145,6 +146,7 @@ <h1>Source code for binexport.basic_block</h1><div class="highlight"><pre>
<span class="k">for</span> <span class="n">rng</span> <span class="ow">in</span> <span class="n">pb_bb</span><span class="o">.</span><span class="n">instruction_index</span><span class="p">:</span>
<span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="n">instruction_index_range</span><span class="p">(</span><span class="n">rng</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bytes</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">program</span><span class="o">.</span><span class="n">proto</span><span class="o">.</span><span class="n">instruction</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span><span class="o">.</span><span class="n">raw_bytes</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_len</span> <span class="o">+=</span> <span class="mi">1</span>

<span class="c1"># The first instruction determines the basic block address</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">addr</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Expand All @@ -159,11 +161,14 @@ <h1>Source code for binexport.basic_block</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">addr</span><span class="p">)</span>

<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">instructions</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>

<span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2">:0x</span><span class="si">%x</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">addr</span><span class="p">)</span>

<span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_len</span>

<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">program</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">ProgramBinExport</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
Expand Down
3 changes: 3 additions & 0 deletions _modules/binexport/program.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ <h1>Source code for binexport.program</h1><div class="highlight"><pre>
<span class="nb">super</span><span class="p">(</span><span class="n">ProgramBinExport</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_pb</span> <span class="o">=</span> <span class="n">BinExport2</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="p">:</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">file</span><span class="p">)</span> <span class="c1">#: Binexport file path</span>

<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="s2">&quot;rb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_pb</span><span class="o">.</span><span class="n">ParseFromString</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="mh">0xFFFFFFFF</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">architecture</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;32&quot;</span><span class="p">)</span> <span class="k">else</span> <span class="mh">0xFFFFFFFFFFFFFFFF</span>
Expand Down
Loading

0 comments on commit d8316e1

Please sign in to comment.