ZealOS/docs/System/Utils/BinRep.html
2021-07-03 02:51:43 -04:00

135 lines
14 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.05">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</style>
</head>
<body>
<pre style="font-family:courier;font-size:10pt">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Compiler&quot;</span><span class=cF0>
<a name="l2"></a>
<a name="l3"></a></span><span class=cF5>DefineListLoad</span><span class=cF0>(</span><span class=cF6>&quot;ST_BIN_FILE_TYPES&quot;</span><span class=cF0>, </span><span class=cF6>&quot;END\0&quot;</span><span class=cF0>
<a name="l4"></a> </span><span class=cF6>&quot; \0&quot;</span><span class=cF0>
<a name="l5"></a> </span><span class=cF6>&quot;REL_I0\0&quot;</span><span class=cF0>
<a name="l6"></a> </span><span class=cF6>&quot;IMM_U0\0&quot;</span><span class=cF0>
<a name="l7"></a> </span><span class=cF6>&quot;REL_I8\0&quot;</span><span class=cF0>
<a name="l8"></a> </span><span class=cF6>&quot;IMM_U8\0&quot;</span><span class=cF0>
<a name="l9"></a> </span><span class=cF6>&quot;REL_I16\0&quot;</span><span class=cF0>
<a name="l10"></a> </span><span class=cF6>&quot;IMM_U16\0&quot;</span><span class=cF0>
<a name="l11"></a> </span><span class=cF6>&quot;REL_I32\0&quot;</span><span class=cF0>
<a name="l12"></a> </span><span class=cF6>&quot;IMM_U32\0&quot;</span><span class=cF0>
<a name="l13"></a> </span><span class=cF6>&quot;REL_I64\0&quot;</span><span class=cF0>
<a name="l14"></a> </span><span class=cF6>&quot;IMM_U64\0&quot;</span><span class=cF0>
<a name="l15"></a> </span><span class=cF6>&quot; \0 \0 \0 \0&quot;</span><span class=cF0>
<a name="l16"></a> </span><span class=cF6>&quot;REL32_EXPORT\0&quot;</span><span class=cF0>
<a name="l17"></a> </span><span class=cF6>&quot;IMM32_EXPORT\0&quot;</span><span class=cF0>
<a name="l18"></a> </span><span class=cF6>&quot;REL64_EXPORT\0&quot;</span><span class=cF0>
<a name="l19"></a> </span><span class=cF6>&quot;IMM64_EXPORT\0&quot;</span><span class=cF0>
<a name="l20"></a> </span><span class=cF6>&quot;ABS_ADDR\0&quot;</span><span class=cF0>
<a name="l21"></a> </span><span class=cF6>&quot;CODE_HEAP\0&quot;</span><span class=cF0>
<a name="l22"></a> </span><span class=cF6>&quot;ZEROED_CODE_HEAP\0&quot;</span><span class=cF0>
<a name="l23"></a> </span><span class=cF6>&quot;DATA_HEAP\0&quot;</span><span class=cF0>
<a name="l24"></a> </span><span class=cF6>&quot;ZEROED_DATA_HEAP\0&quot;</span><span class=cF0>
<a name="l25"></a> </span><span class=cF6>&quot;MAIN&quot;</span><span class=cF0>);
<a name="l26"></a>
<a name="l27"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>BinRep</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *filename)
<a name="l28"></a>{</span><span class=cF2>//Reports imports, exports, etc for a .BIN file</span><span class=cF0>
<a name="l29"></a></span><span class=cF2>//See </span><a href="https://tomawezome.github.io/ZealOS/Compiler/CMain.html#l525"><span class=cF4>Patch Table Generation</span></a><span class=cF2> and </span><a href="https://tomawezome.github.io/ZealOS/Kernel/KLoad.html#l208"><span class=cF4>Load</span></a><span class=cF2>().</span><span class=cF0>
<a name="l30"></a> </span><span class=cF1>U8</span><span class=cF0> *fbuf, *ptr, *sptr, *absname;
<a name="l31"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, size, etype;
<a name="l32"></a> </span><span class=cF1>Bool</span><span class=cF0> res = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l33"></a> </span><span class=cF9>CBinFile</span><span class=cF0> *bf;
<a name="l34"></a> </span><span class=cF9>CHashExport</span><span class=cF0> *saved_hash_ptr = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l35"></a>
<a name="l36"></a> fbuf = </span><span class=cF5>ExtDefault</span><span class=cF0>(filename, </span><span class=cF6>&quot;BIN&quot;</span><span class=cF0>);
<a name="l37"></a>
<a name="l38"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>bf = </span><span class=cF5>FileRead</span><span class=cF0>(fbuf, &amp;size)</span><span class=cF7>)</span><span class=cF0>)
<a name="l39"></a> </span><span class=cF1>goto</span><span class=cF0> br_done1;
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (bf-&gt;bin_signature != </span><span class=cF3>BIN_SIGNATURE_VAL</span><span class=cF0>)
<a name="l41"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l42"></a> </span><span class=cF6>&quot;Not a CosmiC Binary File.\n&quot;</span><span class=cF0>;
<a name="l43"></a> </span><span class=cF1>goto</span><span class=cF0> br_done2;
<a name="l44"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l45"></a>
<a name="l46"></a> absname = </span><span class=cF5>FileNameAbs</span><span class=cF0>(fbuf);
<a name="l47"></a> </span><span class=cF5>Free</span><span class=cF0>(fbuf);
<a name="l48"></a> fbuf = </span><span class=cF5>StrNew</span><span class=cF0>(absname);
<a name="l49"></a> </span><span class=cF5>FileExtRemove</span><span class=cF0>(fbuf);
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (fbuf[</span><span class=cFE>1</span><span class=cF0>] == </span><span class=cF6>':'</span><span class=cF0> &amp;&amp; </span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>fbuf</span><span class=cF7>)</span><span class=cF0> &gt; </span><span class=cFE>2</span><span class=cF0>)
<a name="l51"></a> </span><span class=cF6>&quot; MODULE_NAME:%s\n&quot;</span><span class=cF0>, fbuf + </span><span class=cFE>2</span><span class=cF0>;
<a name="l52"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l53"></a> </span><span class=cF6>&quot;NO MODULE NAME\n&quot;</span><span class=cF0>;
<a name="l54"></a>
<a name="l55"></a> </span><span class=cF1>if</span><span class=cF0> (bf-&gt;org != </span><span class=cF3>INVALID_PTR</span><span class=cF0>)
<a name="l56"></a> </span><span class=cF6>&quot; ORG:%X\n&quot;</span><span class=cF0>, bf-&gt;org;
<a name="l57"></a>
<a name="l58"></a> </span><span class=cF6>&quot; MODULE_ALIGN:%X\n&quot;</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0> &lt;&lt; bf-&gt;module_align_bits;
<a name="l59"></a>
<a name="l60"></a> ptr = bf(</span><span class=cF1>U8</span><span class=cF0> *) + bf-&gt;patch_table_offset;
<a name="l61"></a> </span><span class=cF1>while</span><span class=cF0> (etype = *ptr++)
<a name="l62"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l63"></a> i = *ptr(</span><span class=cF9>U32</span><span class=cF0> *)++;
<a name="l64"></a> sptr = ptr;
<a name="l65"></a> ptr += </span><span class=cF5>StrLen</span><span class=cF0>(sptr) + </span><span class=cFE>1</span><span class=cF0>;
<a name="l66"></a> </span><span class=cF6>&quot;$LTCYAN$%16Z:$GREEN$%s$FG$:%X &quot;</span><span class=cF0>, etype, </span><span class=cF6>&quot;ST_BIN_FILE_TYPES&quot;</span><span class=cF0>, sptr, i;
<a name="l67"></a> </span><span class=cF1>switch</span><span class=cF0> (etype)
<a name="l68"></a> {
<a name="l69"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>IET_REL_I0</span><span class=cF0> ... </span><span class=cF3>IET_IMM_I64</span><span class=cF0>:
<a name="l70"></a> </span><span class=cF1>if</span><span class=cF0> (*sptr)
<a name="l71"></a> saved_hash_ptr = </span><span class=cF5>HashFind</span><span class=cF0>(sptr, </span><span class=cF5>Fs</span><span class=cF0>-&gt;hash_table, </span><span class=cF3>HTG_ALL</span><span class=cF0>);
<a name="l72"></a> </span><span class=cF1>if</span><span class=cF0> (!saved_hash_ptr)
<a name="l73"></a> </span><span class=cF6>&quot;Unresolved Reference:%s\n&quot;</span><span class=cF0>, sptr;
<a name="l74"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l75"></a>
<a name="l76"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>IET_ABS_ADDR</span><span class=cF0>:
<a name="l77"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l78"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; i; j++)
<a name="l79"></a> </span><span class=cF6>&quot;%X &quot;</span><span class=cF0>, *ptr(</span><span class=cF9>U32</span><span class=cF0> *)++;
<a name="l80"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l81"></a>
<a name="l82"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>IET_CODE_HEAP</span><span class=cF0>:
<a name="l83"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>IET_ZEROED_CODE_HEAP</span><span class=cF0>:
<a name="l84"></a> </span><span class=cF6>&quot;Size:%X\n&quot;</span><span class=cF0>, *ptr(</span><span class=cF9>U32</span><span class=cF0> *)++;
<a name="l85"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; i; j++)
<a name="l86"></a> </span><span class=cF6>&quot;%X &quot;</span><span class=cF0>, *ptr(</span><span class=cF9>U32</span><span class=cF0> *)++;
<a name="l87"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l88"></a>
<a name="l89"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>IET_DATA_HEAP</span><span class=cF0>:
<a name="l90"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>IET_ZEROED_DATA_HEAP</span><span class=cF0>:
<a name="l91"></a> </span><span class=cF6>&quot;Size:%X\n&quot;</span><span class=cF0>, *ptr(</span><span class=cF9>I64</span><span class=cF0> *)++;
<a name="l92"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; i; j++)
<a name="l93"></a> </span><span class=cF6>&quot;%X &quot;</span><span class=cF0>, *ptr(</span><span class=cF9>U32</span><span class=cF0> *)++;
<a name="l94"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l95"></a> }
<a name="l96"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l97"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l98"></a> res = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l99"></a> </span><span class=cF5>Free</span><span class=cF0>(absname);
<a name="l100"></a>br_done2:
<a name="l101"></a> </span><span class=cF5>Free</span><span class=cF0>(bf);
<a name="l102"></a>br_done1:
<a name="l103"></a> </span><span class=cF5>Free</span><span class=cF0>(fbuf);
<a name="l104"></a>
<a name="l105"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l106"></a>}
</span></pre></body>
</html>