You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: HOW-TO-USE.rst
+15-22Lines changed: 15 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
Introduction
2
-
*************
2
+
============
3
3
4
4
Welcome back to the wonderful times world of SEGV's (from the Python interpreter)!
5
5
@@ -30,7 +30,7 @@ instructions. Another reason why using ``pydisasm --xasm`` is
30
30
preferable right now.
31
31
32
32
Format of assembly file
33
-
-----------------------
33
+
=======================
34
34
35
35
Again, easiest to consult the ``pydisasm --xasm`` output ``.pyasm``-file that is
36
36
produced. Even easier, just to look in the test directory_ for files that end
@@ -45,7 +45,8 @@ determines which Python bytecode opcodes to use and which Python
45
45
interpreter can be used to run the resulting program.
46
46
47
47
Module-level info
48
-
-----------------
48
+
------------------
49
+
49
50
50
51
Here is an example of the module-level information:
51
52
@@ -62,7 +63,7 @@ there is also a size modulo 2**32 that is recorded.
62
63
# Source code size mod 2**32: 577 bytes
63
64
64
65
Method-level info
65
-
.................
66
+
------------------
66
67
67
68
Here is an example:
68
69
@@ -111,7 +112,7 @@ So you could instead write:
111
112
112
113
LOAD_CONST (1)
113
114
114
-
which in this case does the same thing since `1 = constant[3]`. If the value 1 does not appear anywhere in the constants list, the assember would append the value 1 to the end of the list of the constants list. When writing the final bytecode file an appropriate constant index will be inserted into that instruction.
115
+
which in this case does the same thing since `1 = constant[3]`. If the value 1 does not appear anywhere in the constants list, the assembler would append the value 1 to the end of the list of the constants list. When writing the final bytecode file an appropriate constant index will be inserted into that instruction.
115
116
116
117
Line Numbers and Labels
117
118
-----------------------
@@ -151,7 +152,7 @@ Instructions
151
152
-------------
152
153
153
154
The module level bytecode line determines what Python opcodes are
154
-
exceptable and how operands are interpreted.
155
+
acceptable and how operands are interpreted.
155
156
156
157
Instructions come after the other module or function information that starts with `#` and
157
158
is shown above.
@@ -161,15 +162,16 @@ module field which would start with a #. And it is not a line number
161
162
or label listed in the last section. We've seen examples of
162
163
instructions above.
163
164
164
-
Opcodes
165
-
+++++++
165
+
Operation name
166
+
...............
166
167
167
168
Instructions start with an opcode name like ``LOAD_CONST``. The specific opcode names used depends on the Python version you are using.
168
169
So make sure to consult the "opcodes" section of the "dis" module documentation for the version of Python listed at the top of the metadata section.
169
170
170
171
171
-
Operands
172
-
++++++++
172
+
Operand
173
+
........
174
+
173
175
174
176
An instruction may also have an operand depending
175
177
on whether the opcode requires one or not. However as we've seen above,
@@ -192,6 +194,8 @@ parenthesis. For example:
192
194
193
195
Instructions can also have additional stuff after the operand and that is ignored.
194
196
197
+
Internally operand values are integers or indexes in some table. When an index value is more than 255 (the largest value that fits in a single byte), an ``EXTENDED_OPERAND`` instruction is added automatically.
198
+
195
199
Cool Stuff
196
200
----------
197
201
@@ -206,20 +210,9 @@ doesn't have to be the same as the Python interpreter that runs
206
210
TODO
207
211
-----
208
212
209
-
Possibly we should figure out when to put in ``EXTENDED_ARGS``
210
-
instructions. And for now, even though you put in ``EXTENDED_ARGS``,
211
-
the operand that follows may have the value folded into it. For
212
-
example in Python 3.6 where an operand can be at most 255, of you
213
-
wanted to jump relative 259 bytes you'd write:
214
-
215
-
::
216
-
217
-
EXTENDED_ARG 1 # Needed because below offset is greater than 255 away
218
-
JUMP_FORWARD 259 # Should really be 3 (= 259 - 256)
219
-
220
213
We should have a better API to generate instructions from inside
221
214
Python. This is pretty straightforward to do.
222
215
223
-
I've not put much in the way of error checking and error reporting.
216
+
There is some error checking of consistency of the input file, but more error checking is desirable.
0 commit comments