File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99from unittest import TestSuite , TextTestRunner , TestLoader
1010
1111from scripts .basic_test import BasicTest
12+ from scripts .basic_struct_test import BasicStructTest
13+ from scripts .string_test import StringTest
1214
1315def test_suite ():
1416 suite = TestSuite ()
1517
1618 suite .addTest (TestLoader ().loadTestsFromTestCase (BasicTest ))
19+ suite .addTest (TestLoader ().loadTestsFromTestCase (BasicStructTest ))
20+ suite .addTest (TestLoader ().loadTestsFromTestCase (StringTest ))
1721
1822 return suite
1923
Original file line number Diff line number Diff line change 1+ #
2+ # This file is part of libdestruct (https://github.com/mrindeciso/libdestruct).
3+ # Copyright (c) 2024 Roberto Alessandro Bertolini. All rights reserved.
4+ # Licensed under the MIT license. See LICENSE file in the project root for details.
5+ #
6+
7+ import unittest
8+
9+ from libdebug import debugger
10+ from libdestruct import inflater , c_str
11+
12+ class StringTest (unittest .TestCase ):
13+ def test_basic (self ):
14+ d = debugger ("binaries/string_test" )
15+
16+ def callback (_ , __ ):
17+ pass
18+
19+ d .run ()
20+
21+ bp1 = d .bp ("signpost1" )
22+ bp2 = d .bp ("signpost2" )
23+ check = d .bp ("check" , callback = callback )
24+
25+ d .cont ()
26+
27+ assert bp1 .hit_on (d )
28+
29+ libdestruct = inflater (d .memory )
30+
31+ string = libdestruct .inflate (c_str , d .regs .rdi )
32+
33+ self .assertEqual (string .value , b"Hello, world!" )
34+
35+ string .value = b"Hello, WORLD!"
36+
37+ d .cont ()
38+
39+ assert bp2 .hit_on (d )
40+
41+ self .assertEqual (string .value , b"Hello," )
42+
43+ string .value = b", world!\x00 "
44+
45+ d .cont ()
46+
47+ d .kill ()
48+
49+ assert check .hit_count == 0
50+
51+ d .terminate ()
Original file line number Diff line number Diff line change 1+ //
2+ // This file is part of libdestruct (https://github.com/mrindeciso/libdestruct).
3+ // Copyright (c) 2024 Roberto Alessandro Bertolini. All rights reserved.
4+ // Licensed under the MIT license. See LICENSE file in the project root for details.
5+ //
6+
7+ // gcc -o binaries/string_test srcs/string_test.c
8+
9+ #include <stdio.h>
10+ #include <stdlib.h>
11+ #include <string.h>
12+ #include <sys/mman.h>
13+
14+ void signpost1 (char * address )
15+ {
16+
17+ }
18+
19+ void signpost2 ()
20+ {
21+
22+ }
23+
24+ void check ()
25+ {
26+
27+ }
28+
29+ int main ()
30+ {
31+ char test_string [] = "Hello, world!\0" ;
32+
33+ signpost1 (test_string );
34+
35+ if (strcmp (test_string , "Hello, WORLD!" ) != 0 ) {
36+ check ();
37+ }
38+
39+ test_string [6 ] = '\0' ;
40+
41+ signpost2 ();
42+
43+ if (strcmp (test_string , ", world!" ) != 0 ) {
44+ check ();
45+ }
46+
47+ return 0 ;
48+ }
You can’t perform that action at this time.
0 commit comments