summaryrefslogtreecommitdiff
path: root/other/prefix
diff options
context:
space:
mode:
authorRoot THC2026-02-24 12:42:47 +0000
committerRoot THC2026-02-24 12:42:47 +0000
commitc9cbeced5b3f2bdd7407e29c0811e65954132540 (patch)
treeaefc355416b561111819de159ccbd86c3004cf88 /other/prefix
parent073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff)
initial
Diffstat (limited to 'other/prefix')
-rw-r--r--other/prefix/prefixbin0 -> 5871 bytes
-rw-r--r--other/prefix/prefix.asm103
-rw-r--r--other/prefix/prefix.c77
3 files changed, 180 insertions, 0 deletions
diff --git a/other/prefix/prefix b/other/prefix/prefix
new file mode 100644
index 0000000..bebdddb
--- /dev/null
+++ b/other/prefix/prefix
Binary files differ
diff --git a/other/prefix/prefix.asm b/other/prefix/prefix.asm
new file mode 100644
index 0000000..b77aade
--- /dev/null
+++ b/other/prefix/prefix.asm
@@ -0,0 +1,103 @@
1
2 BITS 32
3
4 org 0x08048000
5
6ehdr: ; Elf32_Ehdr
7 db 0x7F, "ELF", 1, 1, 1 ; e_ident
8 times 9 db 0
9 dw 2 ; e_type
10 dw 3 ; e_machine
11 dd 1 ; e_version
12 dd _start ; e_entry
13 dd phdr - $$ ; e_phoff
14 dd 0 ; e_shoff
15 dd 0 ; e_flags
16 dw ehdrsize ; e_ehsize
17 dw phdrsize ; e_phentsize
18 dw 1 ; e_phnum
19 dw 0 ; e_shentsize
20 dw 0 ; e_shnum
21 dw 0 ; e_shstrndx
22
23ehdrsize equ ($ - ehdr)
24
25phdr: ; Elf32_Phdr
26 dd 1 ; p_type
27 dd 0 ; p_offset
28 dd $$ ; p_vaddr
29 dd $$ ; p_paddr
30 dd filesize ; p_filesz
31 dd filesize ; p_memsz
32 dd 7 ; p_flags
33 dd 0x1000 ; p_align
34
35phdrsize equ ($ - phdr)
36
37prefixarr db 0x2e, 0x36, 0x3e, 0x26, 0x64, 0x65, 0x67, 0xf2, 0xf3
38prefixlen dd 9
39
40; fd 0 = random file
41; fd 1 = output file
42_start:
43
44 db 0x3e
45 db 0x26
46 db 0x64
47 db 0x65
48 db 0x67
49 db 0x36
50 db 0x2e
51 db 0xf3
52 db 0xf2
53 pushf
54
55; WORKS
56; db 0x3e
57; pushf
58
59; WORKS
60; db 0x26
61; pushf
62
63; WORKS
64; db 0x64
65; pushf
66
67; WORKS
68; db 0x65
69; pushf
70
71; WORKS, pulls lower 16 bits only
72; db 0x66
73; pushf
74
75; WORKS
76; db 0x67
77; pushf
78
79; WORKS
80; db 0x36
81; pushf
82
83; WORKS
84; db 0x2e
85; pushf
86
87; WORKS
88; db 0xf3
89; pushf
90
91; WORKS
92; db 0xf2
93; pushf
94
95; SIGILL
96; db 0xf0
97; popf
98
99 int3
100
101filesize equ ($ - $$)
102
103
diff --git a/other/prefix/prefix.c b/other/prefix/prefix.c
new file mode 100644
index 0000000..707aa45
--- /dev/null
+++ b/other/prefix/prefix.c
@@ -0,0 +1,77 @@
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <sys/time.h>
6#include <time.h>
7
8
9int
10main (int argc, char *argv[])
11{
12 unsigned char prefix_arr[] = {
13 0x2e, /* cs segment override */
14 0x36, /* ss segment override */
15 0x3e, /* ds segment override */
16 0x26, /* es segment override */
17 0x64, /* fs segment override */
18 0x65, /* gs segment override */
19 0x67, /* adress size override */
20 0xf2, /* repne/repnz prefix */
21 0xf3, /* repe/repz prefix */
22 /* 0xf0,*/ /* lock prefix */
23 /* 0x66,*/ /* operand size override */
24 };
25
26 unsigned char code[64];
27 int n, i,
28 clen,
29 cwlk;
30 unsigned long ef_should,
31 ef_is;
32
33
34 srandom (time (NULL));
35
36 for (n = 0 ; n < 32 ; ++n) {
37 clen = random () % 14;
38 clen += 1;
39
40 memset (code, '\x00', sizeof (code));
41
42 for (cwlk = 0 ; clen > 0 ; --clen, ++cwlk) {
43 code[cwlk] = prefix_arr[random () %
44 (sizeof (prefix_arr) / sizeof (prefix_arr[0]))];
45 }
46 code[cwlk++] = 0x9c; /* pushf */
47 code[cwlk++] = 0x5a; /* popl %edx */
48 code[cwlk] = 0xc3; /* ret */
49
50 printf ("%4d (%2d):", n, cwlk);
51 for (i = 0 ; i < cwlk ; ++i)
52 printf (" %02x", code[i]);
53 printf ("\n");
54
55 printf ("\tef 0x%08lx got 0x%08lx\n", ef_should, ef_is);
56
57 __asm__ __volatile__ ("
58 pushf
59 popl %%eax
60 pushl $0x41414141
61 call *%%edx
62 addl $4, %%esp"
63 : "=a" (ef_should), "=d" (ef_is)
64 : "d" ((unsigned long) code)
65 );
66
67 if (ef_should != ef_is) {
68 printf ("\tATTENTION: difference detected.\n");
69
70 exit (EXIT_FAILURE);
71 }
72 }
73
74 exit (EXIT_SUCCESS);
75}
76
77