Skip to content

Commit ef2ab33

Browse files
committed
test: add tests about writes with ctypes
1 parent 77629f3 commit ef2ab33

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

test/binaries/ctypes_test

32 Bytes
Binary file not shown.

test/scripts/ctypes_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def test_all_types(self):
1717
d.run()
1818

1919
bp = d.breakpoint("leak")
20+
check = d.breakpoint("correct")
2021

2122
class provola(struct):
2223
a: c_bool
@@ -78,5 +79,34 @@ class provola(struct):
7879
self.assertEqual(obj.y.value, 0xbeefbeefbeef)
7980
self.assertEqual(obj.z.value, 0xd00dd00dd00dd00d)
8081

82+
obj.a.value = False
83+
obj.b.value = 1234
84+
obj.c.value = b'\x23'
85+
obj.e.value = 1234.5678
86+
obj.f.value = 234.567
87+
obj.g.value = 23456
88+
obj.h.value = 32767
89+
obj.i.value = 0xadbeef
90+
obj.j.value = 0xadbeefdeadbeef
91+
obj.k.value = 98
92+
obj.l.value = 0xadbeefd00dbeef
93+
obj.m.value = 345.678
94+
obj.n.value = 0xedbeefdeadbeef
95+
obj.o.value = 8765
96+
obj.p.value = 0xeadbeefdeadbeef
97+
obj.r.value = 0x234567
98+
obj.s.value = 0x2345
99+
obj.t.value = 0xeadbeef
100+
obj.u.value = 0x2345
101+
obj.v.value = 0xbadbeef
102+
obj.w.value = 0xbadbeefbadbeef
103+
obj.x.value = 0x28
104+
obj.y.value = 0xbadbadbadbad
105+
obj.z.value = 0xbadd00dbadd00d
106+
107+
d.cont()
108+
109+
self.assertTrue(check.hit_on(d))
110+
81111
d.kill()
82112
d.terminate()

test/srcs/ctypes_test.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdint.h>
1111
#include <string.h>
1212
#include <time.h>
13+
#include <math.h>
1314

1415
#pragma pack(push, 1)
1516
struct provola {
@@ -48,6 +49,11 @@ void leak(struct provola *ptr)
4849

4950
}
5051

52+
void correct()
53+
{
54+
55+
}
56+
5157
int main()
5258
{
5359
struct provola object;
@@ -79,5 +85,79 @@ int main()
7985

8086
leak(&object);
8187

88+
if (object.a != 0)
89+
return 0;
90+
91+
if (object.b != 1234)
92+
return 0;
93+
94+
if (object.c != 0x23)
95+
return 0;
96+
97+
if (object.e != 1234.5678)
98+
return 0;
99+
100+
if (object.f < 234.5 || object.f > 234.6)
101+
return 0;
102+
103+
if (object.g != 23456)
104+
return 0;
105+
106+
if (object.h != 32767)
107+
return 0;
108+
109+
if (object.i != 0xadbeef)
110+
return 0;
111+
112+
if (object.j != 0xadbeefdeadbeef)
113+
return 0;
114+
115+
if (object.k != 98)
116+
return 0;
117+
118+
if (object.l != 0xadbeefd00dbeef)
119+
return 0;
120+
121+
if (object.m != 345.678)
122+
return 0;
123+
124+
if (object.n != 0xedbeefdeadbeef)
125+
return 0;
126+
127+
if (object.o != 8765)
128+
return 0;
129+
130+
if (object.p != 0xeadbeefdeadbeef)
131+
return 0;
132+
133+
if (object.r != 0x234567)
134+
return 0;
135+
136+
if (object.s != (void *) 0x2345)
137+
return 0;
138+
139+
if (object.t != 0xeadbeef)
140+
return 0;
141+
142+
if (object.u != 0x2345)
143+
return 0;
144+
145+
if (object.v != 0xbadbeef)
146+
return 0;
147+
148+
if (object.w != 0xbadbeefbadbeef)
149+
return 0;
150+
151+
if (object.x != 0x28)
152+
return 0;
153+
154+
if (object.y != 0xbadbadbadbad)
155+
return 0;
156+
157+
if (object.z != 0xbadd00dbadd00d)
158+
return 0;
159+
160+
correct();
161+
82162
return 0;
83163
}

0 commit comments

Comments
 (0)