├── LICENSE ├── subasm.py ├── subasm.spec └── subleq.rop /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Ryan Hileman 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /subasm.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | ## var 4 | # x 5 | # x[0] 6 | # x[x] 7 | 8 | ## immediates 9 | # 0 10 | # 0x1 11 | # -1 12 | # 'a' 13 | # [0, 1, 2, 3] # global array of 32-bit imms 14 | # [aaaaaaa] # global array of 32-bit chars 15 | 16 | ## operators 17 | # + - * / % 18 | 19 | ## labels 20 | # label: 21 | 22 | ## jumps 23 | # jmp label 24 | # jmp label if var var_or_imm 25 | 26 | ## conditionals 27 | # == != < > <= >= 28 | 29 | # var parsing 30 | var_embed = r'\w+(\[[^\]]+\])?' 31 | imm_embed = r"(-?(0x[0-9a-fA-F]+|[0-9]+|'[a-z]')|len\(\w+\))" 32 | var_imm_embed = r'({}|{})'.format(var_embed, imm_embed) 33 | 34 | array_embed = r"\[([a-z]+|{}(,\s*{})*)\]".format(imm_embed, imm_embed) 35 | 36 | var_re = re.compile(r'^((?P\w+?)(?P\[[^\]]+\])?)$') 37 | imm_re = re.compile(r"^((?P-?(0x[0-9a-fA-F]+|[0-9]+))|'(?P[a-z])')$") 38 | array_re = re.compile(r"\[((?P[a-z]+)|(?P[^]]+))\]") 39 | 40 | ops = '-=+*/%' 41 | op_embed = '(' + ('|'.join([re.escape(o) for o in ops])) + ')' 42 | conds = ['==', '!=', '<', '<=', '>='] 43 | cond_embed = '(' + ('|'.join([re.escape(o) for o in conds])) + ')' 44 | 45 | label_re = re.compile(r'^(?P\w+):$') 46 | assign_line_re = re.compile(r'^(?P{})\s*=\s*(?P{}|{})$'.format(var_embed, var_imm_embed, array_embed)) 47 | expr_line_re = re.compile(r'^(?P{})\s*=\s*(?P{})\s*(?P{})\s*(?P{})$'.format(var_embed, var_imm_embed, op_embed, var_imm_embed)) 48 | jump_line_re = re.compile(r'^jmp\s*(?P