Skip to content

Commit d98f13f

Browse files
authored
Merge pull request #1546 from elicn/fix-enum
Fix open files flags
2 parents 4a34aef + 74dc496 commit d98f13f

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

qiling/os/posix/const.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ def __str__(self) -> str:
459459
# open flags #
460460
################################
461461

462+
FLAG_UNSUPPORTED = -1
463+
462464
class macos_x86_open_flags(QlPrettyFlag):
463465
O_RDONLY = 0x000000
464466
O_WRONLY = 0x000001
@@ -473,8 +475,8 @@ class macos_x86_open_flags(QlPrettyFlag):
473475
O_EXCL = 0x000800
474476
O_NOCTTY = 0x020000
475477
O_DIRECTORY = 0x100000
476-
O_BINARY = 0x000000
477-
O_LARGEFILE = 0x000000
478+
O_BINARY = FLAG_UNSUPPORTED
479+
O_LARGEFILE = FLAG_UNSUPPORTED
478480

479481

480482
class linux_x86_open_flags(QlPrettyFlag):
@@ -491,8 +493,8 @@ class linux_x86_open_flags(QlPrettyFlag):
491493
O_EXCL = 0x000080
492494
O_NOCTTY = 0x000100
493495
O_DIRECTORY = 0x010000
494-
O_BINARY = 0x000000
495-
O_LARGEFILE = 0x000000
496+
O_BINARY = FLAG_UNSUPPORTED
497+
O_LARGEFILE = FLAG_UNSUPPORTED
496498

497499

498500
class linux_arm_open_flags(QlPrettyFlag):
@@ -509,7 +511,7 @@ class linux_arm_open_flags(QlPrettyFlag):
509511
O_EXCL = 0x000080
510512
O_NOCTTY = 0x000100
511513
O_DIRECTORY = 0x004000
512-
O_BINARY = 0x000000
514+
O_BINARY = FLAG_UNSUPPORTED
513515
O_LARGEFILE = 0x020000
514516

515517

@@ -527,7 +529,7 @@ class linux_mips_open_flags(QlPrettyFlag):
527529
O_EXCL = 0x000400
528530
O_NOCTTY = 0x000800
529531
O_DIRECTORY = 0x010000
530-
O_BINARY = 0x000000
532+
O_BINARY = FLAG_UNSUPPORTED
531533
O_LARGEFILE = 0x002000
532534

533535

@@ -545,8 +547,8 @@ class linux_riscv_open_flags(QlPrettyFlag):
545547
O_EXCL = 0x000080
546548
O_NOCTTY = 0x000100
547549
O_DIRECTORY = 0x010000
548-
O_BINARY = 0x000000
549-
O_LARGEFILE = 0x000000
550+
O_BINARY = FLAG_UNSUPPORTED
551+
O_LARGEFILE = FLAG_UNSUPPORTED
550552

551553

552554
class linux_ppc_open_flags(QlPrettyFlag):
@@ -563,7 +565,7 @@ class linux_ppc_open_flags(QlPrettyFlag):
563565
O_EXCL = 0x000080
564566
O_NOCTTY = 0x000100
565567
O_DIRECTORY = 0x004000
566-
O_BINARY = 0x000000
568+
O_BINARY = FLAG_UNSUPPORTED
567569
O_LARGEFILE = 0x010000
568570

569571

@@ -581,26 +583,26 @@ class freebsd_x86_open_flags(QlPrettyFlag):
581583
O_EXCL = 0x000800
582584
O_NOCTTY = 0x008000
583585
O_DIRECTORY = 0x20000
584-
O_BINARY = 0x000000
585-
O_LARGEFILE = 0x000000
586+
O_BINARY = FLAG_UNSUPPORTED
587+
O_LARGEFILE = FLAG_UNSUPPORTED
586588

587589

588590
class windows_x86_open_flags(QlPrettyFlag):
589591
O_RDONLY = 0x000000
590592
O_WRONLY = 0x000001
591593
O_RDWR = 0x000002
592-
O_NONBLOCK = 0x000000
594+
O_NONBLOCK = FLAG_UNSUPPORTED
593595
O_APPEND = 0x000008
594-
O_ASYNC = 0x000000
595-
O_SYNC = 0x000000
596-
O_NOFOLLOW = 0x000000
596+
O_ASYNC = FLAG_UNSUPPORTED
597+
O_SYNC = FLAG_UNSUPPORTED
598+
O_NOFOLLOW = FLAG_UNSUPPORTED
597599
O_CREAT = 0x000100
598600
O_TRUNC = 0x000200
599601
O_EXCL = 0x000400
600-
O_NOCTTY = 0x000000
601-
O_DIRECTORY = 0x000000
602+
O_NOCTTY = FLAG_UNSUPPORTED
603+
O_DIRECTORY = FLAG_UNSUPPORTED
602604
O_BINARY = 0x008000
603-
O_LARGEFILE = 0x000000
605+
O_LARGEFILE = FLAG_UNSUPPORTED
604606

605607

606608
class qnx_arm_open_flags(QlPrettyFlag):
@@ -611,13 +613,13 @@ class qnx_arm_open_flags(QlPrettyFlag):
611613
O_APPEND = 0x00008
612614
O_ASYNC = 0x10000
613615
O_SYNC = 0x00020
614-
O_NOFOLLOW = 0x000000
616+
O_NOFOLLOW = FLAG_UNSUPPORTED
615617
O_CREAT = 0x00100
616618
O_TRUNC = 0x00200
617619
O_EXCL = 0x00400
618620
O_NOCTTY = 0x00800
619-
O_DIRECTORY = 0x000000
620-
O_BINARY = 0x000000
621+
O_DIRECTORY = FLAG_UNSUPPORTED
622+
O_BINARY = FLAG_UNSUPPORTED
621623
O_LARGEFILE = 0x08000
622624

623625

qiling/os/posix/const_mapping.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ def ql_open_flag_mapping(ql: Qiling, flags: int) -> int:
114114
# convert emulated os flags to hosting os flags.
115115
# flags names are consistent across all classes, even if they are not supported, to maintain compatibility
116116
for ef in emul_flags:
117-
# test whether flag i set, excluding unsupported flags and 0 values
118-
if ef and flags & ef.value:
117+
# test whether flag is set, excluding unsupported flags
118+
if (ef != FLAG_UNSUPPORTED) and (flags & ef.value):
119119
hf = host_flags[ef.name or '']
120120

121121
# if flag is also supported on the host, set it
122-
if hf:
122+
if hf != FLAG_UNSUPPORTED:
123123
ret |= hf.value
124124

125125
# NOTE: not sure why this one is needed

0 commit comments

Comments
 (0)