-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathswap_headers.c
1821 lines (1719 loc) · 57.1 KB
/
swap_headers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#define __darwin_i386_exception_state i386_exception_state
#define __darwin_i386_float_state i386_float_state
#define __darwin_i386_thread_state i386_thread_state
#include <mach-o/loader.h>
#include <mach/m68k/thread_status.h>
#undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
#undef MACHINE_THREAD_STATE_COUNT
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
#include <mach/ppc/thread_status.h>
#undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
#undef MACHINE_THREAD_STATE_COUNT
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
#include <mach/m88k/thread_status.h>
#include <mach/i860/thread_status.h>
#include <mach/i386/thread_status.h>
#include <mach/hppa/thread_status.h>
#include <mach/sparc/thread_status.h>
#include <mach/arm/thread_status.h>
#include "stuff/bool.h"
#include "stuff/bytesex.h"
#include "stuff/errors.h"
/*
* swap_object_headers() swaps the object file headers from the host byte sex
* into the non-host byte sex. It returns TRUE if it can and did swap the
* headers else returns FALSE and does not touch the headers and prints an error
* using the error() routine.
*/
__private_extern__
enum bool
swap_object_headers(
void *mach_header,
struct load_command *load_commands)
{
unsigned long i;
uint32_t magic, ncmds, sizeofcmds, cmd_multiple;
cpu_type_t cputype;
cpu_subtype_t cpusubtype;
struct mach_header *mh;
struct mach_header_64 *mh64;
enum byte_sex target_byte_sex;
struct load_command *lc, l;
struct segment_command *sg;
struct segment_command_64 *sg64;
struct section *s;
struct section_64 *s64;
struct symtab_command *st;
struct dysymtab_command *dyst;
struct symseg_command *ss;
struct fvmlib_command *fl;
struct thread_command *ut;
struct ident_command *id;
struct entry_point_command *ep;
struct source_version_command *sv;
struct dylib_command *dl;
struct sub_framework_command *sub;
struct sub_umbrella_command *usub;
struct sub_library_command *lsub;
struct sub_client_command *csub;
struct prebound_dylib_command *pbdylib;
struct dylinker_command *dyld;
struct routines_command *rc;
struct routines_command_64 *rc64;
struct twolevel_hints_command *hints;
struct prebind_cksum_command *cs;
struct uuid_command *uuid;
struct linkedit_data_command *ld;
struct rpath_command *rpath;
struct encryption_info_command *ec;
struct encryption_info_command_64 *ec64;
struct linker_option_command *lo;
struct dyld_info_command *dc;
struct version_min_command *vc;
struct build_version_command *bv;
struct build_tool_version *btv;
struct note_command *nc;
uint32_t flavor, count;
unsigned long nflavor;
char *p, *state, *cmd_name;
magic = *((uint32_t *)mach_header);
if(magic == MH_MAGIC){
mh = (struct mach_header *)mach_header;
ncmds = mh->ncmds;
sizeofcmds = mh->sizeofcmds;
cputype = mh->cputype;
cpusubtype = mh->cpusubtype;
cmd_multiple = 4;
mh64 = NULL;
}
else{
mh64 = (struct mach_header_64 *)mach_header;
ncmds = mh64->ncmds;
sizeofcmds = mh64->sizeofcmds;
cputype = mh64->cputype;
cpusubtype = mh64->cpusubtype;
cmd_multiple = 8;
mh = NULL;
}
/*
* Make a pass through the load commands checking them to the level
* that they can be parsed and then swapped.
*/
for(i = 0, lc = load_commands; i < ncmds; i++){
l = *lc;
/* check load command size for a correct multiple size */
if(lc->cmdsize % cmd_multiple != 0){
error("in swap_object_headers(): malformed load command %lu "
"(cmdsize not a multiple of %u)", i, cmd_multiple);
return(FALSE);
}
/* check that load command does not extends past end of commands */
if((char *)lc + lc->cmdsize >
(char *)load_commands + sizeofcmds){
error("in swap_object_headers(): truncated or malformed load "
"command %lu (extends past the end of the all load "
"commands)", i);
return(FALSE);
}
/* check that the load command size is not zero */
if(lc->cmdsize == 0){
error("in swap_object_headers(): malformed load command %lu "
"(cmdsize is zero)", i);
return(FALSE);
}
switch(lc->cmd){
case LC_SEGMENT:
sg = (struct segment_command *)lc;
if(sg->cmdsize != sizeof(struct segment_command) +
sg->nsects * sizeof(struct section)){
error("in swap_object_headers(): malformed load command "
"(inconsistent cmdsize in LC_SEGMENT command %lu for "
"the number of sections)", i);
return(FALSE);
}
break;
case LC_SEGMENT_64:
sg64 = (struct segment_command_64 *)lc;
if(sg64->cmdsize != sizeof(struct segment_command_64) +
sg64->nsects * sizeof(struct section_64)){
error("in swap_object_headers(): malformed load command "
"(inconsistent cmdsize in LC_SEGMENT_64 command %lu "
"for the number of sections)", i);
return(FALSE);
}
break;
case LC_SYMTAB:
st = (struct symtab_command *)lc;
if(st->cmdsize != sizeof(struct symtab_command)){
error("in swap_object_headers(): malformed load commands "
"(LC_SYMTAB command %lu has incorrect cmdsize", i);
return(FALSE);
}
break;
case LC_DYSYMTAB:
dyst = (struct dysymtab_command *)lc;
if(dyst->cmdsize != sizeof(struct dysymtab_command)){
error("in swap_object_headers(): malformed load commands "
"(LC_DYSYMTAB command %lu has incorrect cmdsize", i);
return(FALSE);
}
break;
case LC_SYMSEG:
ss = (struct symseg_command *)lc;
if(ss->cmdsize != sizeof(struct symseg_command)){
error("in swap_object_headers(): malformed load command "
"(LC_SYMSEG command %lu has incorrect cmdsize", i);
return(FALSE);
}
break;
case LC_IDFVMLIB:
case LC_LOADFVMLIB:
fl = (struct fvmlib_command *)lc;
if(fl->cmdsize < sizeof(struct fvmlib_command)){
error("in swap_object_headers(): malformed load commands "
"(%s command %lu has too small cmdsize field)",
fl->cmd == LC_IDFVMLIB ? "LC_IDFVMLIB" :
"LC_LOADFVMLIB", i);
return(FALSE);
}
if(fl->fvmlib.name.offset >= fl->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (name.offset field of %s command %lu "
"extends past the end of all load commands)",
fl->cmd == LC_IDFVMLIB ? "LC_IDFVMLIB" :
"LC_LOADFVMLIB", i);
return(FALSE);
}
break;
case LC_ID_DYLIB:
cmd_name = "LC_ID_DYLIB";
goto check_dylib_command;
case LC_LOAD_DYLIB:
cmd_name = "LC_LOAD_DYLIB";
goto check_dylib_command;
case LC_LOAD_WEAK_DYLIB:
cmd_name = "LC_LOAD_WEAK_DYLIB";
goto check_dylib_command;
case LC_REEXPORT_DYLIB:
cmd_name = "LC_REEXPORT_DYLIB";
goto check_dylib_command;
case LC_LOAD_UPWARD_DYLIB:
cmd_name = "LC_LOAD_UPWARD_DYLIB";
goto check_dylib_command;
case LC_LAZY_LOAD_DYLIB:
cmd_name = "LC_LAZY_LOAD_DYLIB";
goto check_dylib_command;
check_dylib_command:
dl = (struct dylib_command *)lc;
if(dl->cmdsize < sizeof(struct dylib_command)){
error("in swap_object_headers(): malformed load commands "
"(%s command %lu has too small cmdsize field)",
cmd_name, i);
return(FALSE);
}
if(dl->dylib.name.offset >= dl->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (name.offset field of %s command %lu "
"extends past the end of all load commands)",
cmd_name, i);
return(FALSE);
}
break;
case LC_SUB_FRAMEWORK:
sub = (struct sub_framework_command *)lc;
if(sub->cmdsize < sizeof(struct sub_framework_command)){
error("in swap_object_headers(): malformed load commands "
"(LC_SUB_FRAMEWORK command %lu has too small cmdsize "
"field)", i);
return(FALSE);
}
if(sub->umbrella.offset >= sub->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (umbrella.offset field of "
"LC_SUB_FRAMEWORK command %lu extends past the end "
"of all load commands)", i);
return(FALSE);
}
break;
case LC_SUB_UMBRELLA:
usub = (struct sub_umbrella_command *)lc;
if(usub->cmdsize < sizeof(struct sub_umbrella_command)){
error("in swap_object_headers(): malformed load commands "
"(LC_SUB_UMBRELLA command %lu has too small cmdsize "
"field)", i);
return(FALSE);
}
if(usub->sub_umbrella.offset >= usub->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (sub_umbrella.offset field of "
"LC_SUB_UMBRELLA command %lu extends past the end "
"of all load commands)", i);
return(FALSE);
}
break;
case LC_SUB_LIBRARY:
lsub = (struct sub_library_command *)lc;
if(lsub->cmdsize < sizeof(struct sub_library_command)){
error("in swap_object_headers(): malformed load commands "
"(LC_SUB_LIBRARY command %lu has too small cmdsize "
"field)", i);
return(FALSE);
}
if(lsub->sub_library.offset >= lsub->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (sub_library.offset field of "
"LC_SUB_LIBRARY command %lu extends past the end "
"of all load commands)", i);
return(FALSE);
}
break;
case LC_SUB_CLIENT:
csub = (struct sub_client_command *)lc;
if(csub->cmdsize < sizeof(struct sub_client_command)){
error("in swap_object_headers(): malformed load commands "
"(LC_SUB_CLIENT command %lu has too small cmdsize "
"field)", i);
return(FALSE);
}
if(csub->client.offset >= csub->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (client.offset field of "
"LC_SUB_CLIENT command %lu extends past the end "
"of all load commands)", i);
return(FALSE);
}
break;
case LC_PREBOUND_DYLIB:
pbdylib = (struct prebound_dylib_command *)lc;
if(pbdylib->cmdsize < sizeof(struct prebound_dylib_command)){
error("in swap_object_headers(): malformed load commands "
"(LC_PREBOUND_DYLIB command %lu has too small "
"cmdsize field)", i);
return(FALSE);
}
if(pbdylib->name.offset >= pbdylib->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (name.offset field of "
"LC_PREBOUND_DYLIB command %lu extends past the end "
"of all load commands)", i);
return(FALSE);
}
if(pbdylib->linked_modules.offset >= pbdylib->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (linked_modules.offset field of "
"LC_PREBOUND_DYLIB command %lu extends past the end "
"of all load commands)", i);
return(FALSE);
}
break;
case LC_ID_DYLINKER:
cmd_name = "LC_ID_DYLINKER";
goto check_dylinker_command;
case LC_LOAD_DYLINKER:
cmd_name = "LC_LOAD_DYLINKER";
goto check_dylinker_command;
case LC_DYLD_ENVIRONMENT:
cmd_name = "LC_DYLD_ENVIRONMENT";
goto check_dylinker_command;
check_dylinker_command:
dyld = (struct dylinker_command *)lc;
if(dyld->cmdsize < sizeof(struct dylinker_command)){
error("in swap_object_headers(): malformed load commands "
"(%s command %lu has too small cmdsize field)",
cmd_name, i);
return(FALSE);
}
if(dyld->name.offset >= dyld->cmdsize){
error("in swap_object_headers(): truncated or malformed "
"load commands (name.offset field of %s command %lu "
"extends past the end of all load commands)",
cmd_name, i);
return(FALSE);
}
break;
case LC_UNIXTHREAD:
case LC_THREAD:
ut = (struct thread_command *)lc;
state = (char *)ut + sizeof(struct thread_command);
if(cputype == CPU_TYPE_MC680x0){
struct m68k_thread_state_regs *cpu;
struct m68k_thread_state_68882 *fpu;
struct m68k_thread_state_user_reg *user_reg;
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while(state < p){
flavor = *((uint32_t *)state);
state += sizeof(uint32_t);
count = *((uint32_t *)state);
state += sizeof(uint32_t);
switch(flavor){
case M68K_THREAD_STATE_REGS:
if(count != M68K_THREAD_STATE_REGS_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not M68K_THREAD_STATE_REGS_COUNT for "
"flavor number %lu which is a M68K_THREAD_"
"STATE_REGS flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu = (struct m68k_thread_state_regs *)state;
state += sizeof(struct m68k_thread_state_regs);
break;
case M68K_THREAD_STATE_68882:
if(count != M68K_THREAD_STATE_68882_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not M68K_THREAD_STATE_68882_COUNT for "
"flavor number %lu which is a M68K_THREAD_"
"STATE_68882 flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
fpu = (struct m68k_thread_state_68882 *)state;
state += sizeof(struct m68k_thread_state_68882);
break;
case M68K_THREAD_STATE_USER_REG:
if(count != M68K_THREAD_STATE_USER_REG_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not M68K_THREAD_STATE_USER_REG_COUNT for "
"flavor number %lu which is a M68K_THREAD_"
"STATE_USER_REG flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
user_reg =
(struct m68k_thread_state_user_reg *)state;
state += sizeof(struct m68k_thread_state_user_reg);
break;
default:
error("in swap_object_headers(): malformed "
"load commands (unknown "
"flavor %u for flavor number %lu in %s command"
" %lu can't byte swap it)", flavor, nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
nflavor++;
}
break;
}
if(cputype == CPU_TYPE_POWERPC ||
cputype == CPU_TYPE_VEO ||
cputype == CPU_TYPE_POWERPC64){
ppc_thread_state_t *cpu;
ppc_float_state_t *fpu;
ppc_exception_state_t *except;
ppc_thread_state64_t *cpu64;
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while(state < p){
flavor = *((uint32_t *)state);
state += sizeof(uint32_t);
count = *((uint32_t *)state);
state += sizeof(uint32_t);
switch(flavor){
case PPC_THREAD_STATE:
if(count != PPC_THREAD_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not PPC_THREAD_STATE_COUNT for "
"flavor number %lu which is a PPC_THREAD_"
"STATE flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu = (ppc_thread_state_t *)state;
state += sizeof(ppc_thread_state_t);
break;
case PPC_FLOAT_STATE:
if(count != PPC_FLOAT_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not PPC_FLOAT_STATE_COUNT for "
"flavor number %lu which is a PPC_FLOAT_"
"STATE flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
fpu = (ppc_float_state_t *)state;
state += sizeof(ppc_float_state_t);
break;
case PPC_EXCEPTION_STATE:
if(count != PPC_EXCEPTION_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not PPC_EXCEPTION_STATE_COUNT for "
"flavor number %lu which is a PPC_EXCEPT"
"ION_STATE flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
except = (ppc_exception_state_t *)state;
state += sizeof(ppc_exception_state_t);
break;
case PPC_THREAD_STATE64:
if(count != PPC_THREAD_STATE64_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not PPC_THREAD_STATE64_COUNT for "
"flavor number %lu which is a PPC_THREAD_"
"STATE64 flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu64 = (ppc_thread_state64_t *)state;
state += sizeof(ppc_thread_state64_t);
break;
default:
error("in swap_object_headers(): malformed "
"load commands (unknown "
"flavor %u for flavor number %lu in %s command"
" %lu can't byte swap it)", flavor, nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
nflavor++;
}
break;
}
if(cputype == CPU_TYPE_MC88000){
m88k_thread_state_grf_t *cpu;
m88k_thread_state_xrf_t *fpu;
m88k_thread_state_user_t *user;
m88110_thread_state_impl_t *spu;
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while(state < p){
flavor = *((uint32_t *)state);
state += sizeof(uint32_t);
count = *((uint32_t *)state);
state += sizeof(uint32_t);
switch(flavor){
case M88K_THREAD_STATE_GRF:
if(count != M88K_THREAD_STATE_GRF_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not M88K_THREAD_STATE_GRF_COUNT for "
"flavor number %lu which is a M88K_THREAD_"
"STATE_GRF flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu = (m88k_thread_state_grf_t *)state;
state += sizeof(m88k_thread_state_grf_t);
break;
case M88K_THREAD_STATE_XRF:
if(count != M88K_THREAD_STATE_XRF_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not M88K_THREAD_STATE_XRF_COUNT for "
"flavor number %lu which is a M88K_THREAD_"
"STATE_XRF flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
fpu = (m88k_thread_state_xrf_t *)state;
state += sizeof(m88k_thread_state_xrf_t);
break;
case M88K_THREAD_STATE_USER:
if(count != M88K_THREAD_STATE_USER_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not M88K_THREAD_STATE_USER_COUNT for "
"flavor number %lu which is a M88K_THREAD_"
"STATE_USER flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
user = (m88k_thread_state_user_t *)state;
state += sizeof(m88k_thread_state_user_t);
break;
case M88110_THREAD_STATE_IMPL:
if(count != M88110_THREAD_STATE_IMPL_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not M88110_THREAD_STATE_IMPL_COUNT for "
"flavor number %lu which is a M88110_THREAD"
"_STATE_IMPL flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
spu = (m88110_thread_state_impl_t *)state;
state += sizeof(m88110_thread_state_impl_t);
break;
default:
error("in swap_object_headers(): malformed "
"load commands (unknown "
"flavor %u for flavor number %lu in %s command"
" %lu can't byte swap it)", flavor, nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
nflavor++;
}
break;
}
if(cputype == CPU_TYPE_I860){
struct i860_thread_state_regs *cpu;
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while(state < p){
flavor = *((uint32_t *)state);
state += sizeof(uint32_t);
count = *((uint32_t *)state);
state += sizeof(uint32_t);
switch(flavor){
case I860_THREAD_STATE_REGS:
if(count != I860_THREAD_STATE_REGS_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not I860_THREAD_STATE_REGS_COUNT for "
"flavor number %lu which is a I860_THREAD_"
"STATE_REGS flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu = (struct i860_thread_state_regs *)state;
state += sizeof(struct i860_thread_state_regs);
break;
default:
error("in swap_object_headers(): malformed "
"load commands (unknown "
"flavor %u for flavor number %lu in %s command"
" %lu can't byte swap it)", flavor, nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
nflavor++;
}
break;
}
if(cputype == CPU_TYPE_I386
#ifdef x86_THREAD_STATE64
|| cputype == CPU_TYPE_X86_64
#endif /* x86_THREAD_STATE64 */
){
i386_thread_state_t *cpu;
#ifdef x86_THREAD_STATE64
x86_thread_state64_t *cpu64;
#endif /* x86_THREAD_STATE64 */
/* current i386 thread states */
#if i386_THREAD_STATE == 1
struct i386_float_state *fpu;
i386_exception_state_t *exc;
#endif /* i386_THREAD_STATE == 1 */
/* i386 thread states on older releases */
#if i386_THREAD_STATE == -1
i386_thread_fpstate_t *fpu;
i386_thread_exceptstate_t *exc;
i386_thread_cthreadstate_t *user;
#endif /* i386_THREAD_STATE == -1 */
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while(state < p){
flavor = *((uint32_t *)state);
state += sizeof(uint32_t);
count = *((uint32_t *)state);
state += sizeof(uint32_t);
switch((int)flavor){
case i386_THREAD_STATE:
/* current i386 thread states */
#if i386_THREAD_STATE == 1
case -1:
#endif /* i386_THREAD_STATE == 1 */
/* i386 thread states on older releases */
#if i386_THREAD_STATE == -1
case 1:
#endif /* i386_THREAD_STATE == -1 */
if(count != i386_THREAD_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not i386_THREAD_STATE_COUNT for flavor "
"number %lu which is a i386_THREAD_STATE "
"flavor in %s command %lu)", nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
cpu = (i386_thread_state_t *)state;
state += sizeof(i386_thread_state_t);
break;
/* current i386 thread states */
#if i386_THREAD_STATE == 1
case i386_FLOAT_STATE:
if(count != i386_FLOAT_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not i386_FLOAT_STATE_COUNT for flavor "
"number %lu which is a i386_FLOAT_STATE "
"flavor in %s command %lu)", nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
fpu = (struct i386_float_state *)state;
state += sizeof(struct i386_float_state);
break;
case i386_EXCEPTION_STATE:
if(count != I386_EXCEPTION_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not I386_EXCEPTION_STATE_COUNT for "
"flavor number %lu which is a i386_"
"EXCEPTION_STATE flavor in %s command %lu)",
nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
exc = (i386_exception_state_t *)state;
state += sizeof(i386_exception_state_t);
break;
#endif /* i386_THREAD_STATE == 1 */
/* i386 thread states on older releases */
#if i386_THREAD_STATE == -1
case i386_THREAD_FPSTATE:
if(count != i386_THREAD_FPSTATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not i386_THREAD_FPSTATE_COUNT for flavor "
"number %lu which is a i386_THREAD_FPSTATE "
"flavor in %s command %lu)", nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
fpu = (i386_thread_fpstate_t *)state;
state += sizeof(i386_thread_fpstate_t);
break;
case i386_THREAD_EXCEPTSTATE:
if(count != i386_THREAD_EXCEPTSTATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not i386_THREAD_EXCEPTSTATE_COUNT for "
"flavor number %lu which is a i386_THREAD_"
"EXCEPTSTATE flavor in %s command %lu)",
nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
exc = (i386_thread_exceptstate_t *)state;
state += sizeof(i386_thread_fpstate_t);
break;
case i386_THREAD_CTHREADSTATE:
if(count != i386_THREAD_CTHREADSTATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not i386_THREAD_CTHREADSTATE_COUNT for "
"flavor number %lu which is a i386_THREAD_"
"CTHREADSTATE flavor in %s command %lu)",
nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
user = (i386_thread_cthreadstate_t *)state;
state += sizeof(i386_thread_fpstate_t);
break;
#endif /* i386_THREAD_STATE == -1 */
#ifdef x86_THREAD_STATE64
case x86_THREAD_STATE64:
if(count != x86_THREAD_STATE64_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not x86_THREAD_STATE64_COUNT for "
"flavor number %lu which is an x86_THREAD_"
"STATE64 flavor in %s command %lu)",
nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
cpu64 = (x86_thread_state64_t *)state;
state += sizeof(x86_thread_state64_t);
break;
#endif /* x86_THREAD_STATE64 */
default:
error("in swap_object_headers(): malformed "
"load commands (unknown "
"flavor %u for flavor number %lu in %s command"
" %lu can't byte swap it)", flavor, nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
nflavor++;
}
break;
}
if(cputype == CPU_TYPE_HPPA){
struct hp_pa_integer_thread_state *cpu;
struct hp_pa_frame_thread_state *frame;
struct hp_pa_fp_thread_state *fpu;
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while(state < p){
flavor = *((uint32_t *)state);
state += sizeof(uint32_t);
count = *((uint32_t *)state);
state += sizeof(uint32_t);
switch(flavor){
case HPPA_INTEGER_THREAD_STATE:
if(count != HPPA_INTEGER_THREAD_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not HPPA_INTEGER_THREAD_STATE_COUNT for "
"flavor number %lu which is a HPPA_INTEGER"
"_THREAD_STATE flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu = (struct hp_pa_integer_thread_state *)state;
state += sizeof(struct hp_pa_integer_thread_state);
break;
case HPPA_FRAME_THREAD_STATE:
if(count != HPPA_FRAME_THREAD_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not HPPA_FRAME_THREAD_STATE_COUNT for "
"flavor number %lu which is a HPPA_FRAME"
"_THREAD_STATE flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
frame = (struct hp_pa_frame_thread_state *)state;
state += sizeof(struct hp_pa_frame_thread_state);
break;
case HPPA_FP_THREAD_STATE:
if(count != HPPA_FP_THREAD_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not HPPA_FP_THREAD_STATE_COUNT for "
"flavor number %lu which is a HPPA_FP"
"_THREAD_STATE flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
fpu = (struct hp_pa_fp_thread_state *)state;
state += sizeof(struct hp_pa_fp_thread_state);
break;
default:
error("in swap_object_headers(): malformed "
"load commands (unknown "
"flavor %u for flavor number %lu in %s command"
" %lu can't byte swap it)", flavor, nflavor,
ut->cmd == LC_UNIXTHREAD ? "LC_UNIXTHREAD" :
"LC_THREAD", i);
return(FALSE);
}
nflavor++;
}
break;
}
if(cputype == CPU_TYPE_SPARC) {
struct sparc_thread_state_regs *cpu;
struct sparc_thread_state_fpu *fpu;
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while (state < p) {
flavor = *((uint32_t *) state);
state += sizeof(uint32_t);
count = *((uint32_t *) state);
state += sizeof(uint32_t);
switch (flavor) {
case SPARC_THREAD_STATE_REGS:
if (count != SPARC_THREAD_STATE_REGS_COUNT) {
error("in swap_object_headers(): malformed "
"load commands (count "
"not SPARC_THREAD_STATE_REGS_COUNT for "
"flavor number %lu which is a SPARC_THREAD_"
"STATE_REGS flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu = (struct sparc_thread_state_regs *) state;
state += sizeof(struct sparc_thread_state_regs);
break;
case SPARC_THREAD_STATE_FPU:
if (count != SPARC_THREAD_STATE_FPU_COUNT) {
error("in swap_object_headers(): malformed "
"load commands (count "
"not SPARC_THREAD_STATE_FPU_COUNT for "
"flavor number %lu which is a SPARC_THREAD_"
"STATE_FPU flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
fpu = (struct sparc_thread_state_fpu *) state;
state += sizeof(struct sparc_thread_state_fpu);
break;
}
}
break;
}
if(cputype == CPU_TYPE_ARM){
arm_thread_state_t *cpu;
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while(state < p){
flavor = *((uint32_t *)state);
state += sizeof(uint32_t);
count = *((uint32_t *)state);
state += sizeof(uint32_t);
switch(flavor){
case ARM_THREAD_STATE:
if(count != ARM_THREAD_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not ARM_THREAD_STATE_COUNT for "
"flavor number %lu which is a ARM_THREAD_"
"STATE flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu = (arm_thread_state_t *)state;
state += sizeof(arm_thread_state_t);
break;
default:
error("in swap_object_headers(): malformed load "
"commands (unknown flavor for flavor number "
"%lu in %s command %lu can't byte swap it)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
nflavor++;
}
break;
}
if(cputype == CPU_TYPE_ARM64){
arm_thread_state64_t *cpu;
nflavor = 0;
p = (char *)ut + ut->cmdsize;
while(state < p){
flavor = *((uint32_t *)state);
state += sizeof(uint32_t);
count = *((uint32_t *)state);
state += sizeof(uint32_t);
switch(flavor){
case ARM_THREAD_STATE:
if(count != ARM_THREAD_STATE_COUNT){
error("in swap_object_headers(): malformed "
"load commands (count "
"not ARM_THREAD_STATE_COUNT for "
"flavor number %lu which is a ARM_THREAD_"
"STATE flavor in %s command %lu)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
cpu = (arm_thread_state64_t *)state;
state += sizeof(arm_thread_state64_t);
break;
default:
error("in swap_object_headers(): malformed load "
"commands (unknown flavor for flavor number "
"%lu in %s command %lu can't byte swap it)",
nflavor, ut->cmd == LC_UNIXTHREAD ?
"LC_UNIXTHREAD" : "LC_THREAD", i);
return(FALSE);
}
nflavor++;
}
break;