interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / qualification / security673 / branch-check.om

212 lines · 3390 bytes Raw Blame History
1note Consume independently decoded GNU objdump output, not machine words from the compiler.
2note Exit61 target mismatch;62 invalid input;90 usage. Only the first branch mnemonic and unique mov marker
3note are selected: with no argument the first b.ne and mov x1, 12345 (forward corpus modes 0..3); with
4note argument 1 the first b.al and mov x4, 12345 (mode4, the backward continue to the loop head).
5global linebuf uchar 512
6global chunk uchar 4096
7global cursor ulong 1
8global branch ulong 1
9global marker ulong 1
10global bcount ulong 1
11global mcount ulong 1
12global form uchar 8
13global mn uchar 8
14global mnl ulong 1
15global label uchar 32
16global labl ulong 1
17text mnf "b.ne"
18text labf "mov\tx1, #0x3039"
19text mnb "b.al"
20text labb "mov\tx4, #0x3039"
21fn hexval b uchar to ulong
22if and ge b 48 le b 57
23ret sub ulong b 48
24end
25if and ge b 97 le b 102
26ret add sub ulong b 97 10
27end
28ret 16
29end
30fn number start ulong n ulong to ulong
31p = start
32value = ulong 0
33while lt p n
34v = hexval get linebuf p
35if eq v 16
36if eq p start
37exit 62
38end
39put cursor 0 p
40ret value
41end
42if ge sub p start 16
43exit 62
44end
45value = or shl value 4 v
46p = add p 1
47end
48if eq p start
49exit 62
50end
51put cursor 0 p
52ret value
53end
54fn hasmn i ulong n ulong to bool
55if or eq i 0 ge add i get mnl 0 n
56ret false
57end
58if and ne get linebuf sub i 1 9 ne get linebuf sub i 1 32
59ret false
60end
61for j ulong get mnl 0
62if ne get linebuf add i j get mn j
63ret false
64end
65end
66v = get linebuf add i get mnl 0
67ret or eq v 9 eq v 32
68end
69fn hasmark i ulong n ulong to bool
70if or eq i 0 gt add i get labl 0 n
71ret false
72end
73if and ne get linebuf sub i 1 9 ne get linebuf sub i 1 32
74ret false
75end
76for j ulong get labl 0
77if ne get linebuf add i j get label j
78ret false
79end
80end
81if lt add i get labl 0 n
82v = get linebuf add i get labl 0
83if and ne v 32 ne v 9
84ret false
85end
86end
87ret true
88end
89fn target i ulong n ulong to ulong
90p = add i get mnl 0
91while lt p n
92v = get linebuf p
93if and ne v 32 ne v 9
94if gt add p 2 n
95exit 62
96end
97if or ne v 48 ne get linebuf add p 1 120
98exit 62
99end
100value = number add p 2 n
101q = get cursor 0
102if lt q n
103v = get linebuf q
104if and ne v 32 ne v 9
105exit 62
106end
107end
108ret value
109end
110p = add p 1
111end
112exit 62
113end
114fn inspect n ulong to void
115p = ulong 0
116while lt p n
117if ne get linebuf p 32
118if eq hexval get linebuf p 16
119ret
120end
121addr = number p n
122q = get cursor 0
123if ge q n
124ret
125end
126if or ne get linebuf q 58 lt addr 176
127ret
128end
129for i ulong n
130if eq get bcount 0 0
131if hasmn i n
132put branch 0 target i n
133put bcount 0 1
134end
135end
136if hasmark i n
137put marker 0 addr
138put mcount 0 add get mcount 0 1
139end
140end
141ret
142end
143p = add p 1
144end
145end
146fn main to int
147back = false
148if eq argcnt 2
149r = argread 1 form 0 len form
150if or ne r 1 ne get form 0 49
151ret 90
152end
153back = true
154else
155if ne argcnt 1
156ret 90
157end
158end
159if back
160put mnl 0 len mnb
161for j ulong len mnb
162put mn j get mnb j
163end
164put labl 0 len labb
165for j ulong len labb
166put label j get labb j
167end
168else
169put mnl 0 len mnf
170for j ulong len mnf
171put mn j get mnf j
172end
173put labl 0 len labf
174for j ulong len labf
175put label j get labf j
176end
177end
178n = ulong 0
179go = true
180while go
181r = read 0 chunk 0 len chunk
182if lt r 0
183ret 62
184end
185if eq r 0
186go = false
187else
188for k ulong ulong r
189if eq get chunk k 10
190inspect n
191n = ulong 0
192else
193if ge n len linebuf
194ret 62
195end
196put linebuf n get chunk k
197n = add n 1
198end
199end
200end
201end
202if ne n 0
203inspect n
204end
205if or ne get bcount 0 1 ne get mcount 0 1
206ret 62
207end
208if ne get branch 0 get marker 0
209ret 61
210end
211ret 0
212end