1NAME=pd varsub-issue
2FILE=bins/mach0/mac-ls2
3CMDS=<<EOF
4s 0x100001232
5e asm.sub.var=0
6pd 1
7e asm.sub.var=1
8pd 1
9f fin.dus=0x1000054d0
10pd 1
11e asm.sub.rel=0
12pd 1
13EOF
14EXPECT=<<EOF
15            0x100001232      c70594420000.  mov dword [rip + 0x4294], 0x50 ; 'P' ; section.10.__DATA.__data
16                                                                       ; [0x1000054d0:4]=80 ; U"P."
17            0x100001232      c70594420000.  mov dword [section.10.__DATA.__data], 0x50 ; 'P'
18                                                                       ; [0x1000054d0:4]=80 ; U"P."
19            0x100001232      c70594420000.  mov dword [fin.dus], 0x50  ; 'P'
20                                                                       ; [0x1000054d0:4]=80 ; U"P."
21            0x100001232      c70594420000.  mov dword [rip + 0x4294], 0x50 ; 'P' ; fin.dus
22                                                                       ; [0x1000054d0:4]=80 ; U"P."
23EOF
24RUN
25
26NAME=pd multiplemain
27FILE=bins/elf/mipsloop
28CMDS=pd 1@main~main?
29EXPECT=<<EOF
301
31EOF
32RUN
33
34NAME=pd v8 and cortex
35FILE=malloc://128
36ARGS=-a arm -b 16
37CMDS=<<EOF
38?e
39pad fff7c0ea@e:asm.cpu=v8
40pad fff7c0ea@e:asm.cpu=cortex
41pad fff7c0ea@e:asm.cpu=v8
42pad fff7c0ea@e:asm.cpu=cortex
43pad fff7c0ea@e:asm.cpu=v8
44pad fff7c0ea@e:asm.cpu=
45pad fff7c0ea@e:asm.cpu=tetris
46EOF
47EXPECT=<<EOF
48
49blx 0xfffff584
50invalid
51blx 0xfffff584
52invalid
53blx 0xfffff584
54blx 0xfffff584
55blx 0xfffff584
56EOF
57RUN
58
59NAME=immstr
60FILE=malloc://128
61CMDS=<<EOF
62e asm.bits=64
63e asm.arch=x86
64e anal.arch=x86
65wx 6833320000
66e asm.imm.str=1
67pd 1
68EOF
69EXPECT=<<EOF
70            0x00000000      6833320000     push 0x3233                 ; '32'
71EOF
72RUN
73
74NAME=pd pseudo=1 cmtright=0
75FILE=malloc://128
76CMDS=<<EOF
77wx 4889e5
78e asm.arch=x86
79e asm.bits=64
80e asm.pseudo=1
81e asm.cmtright =0
82pd 1
83EOF
84EXPECT=<<EOF
85            0x00000000      4889e5         rbp = rsp
86EOF
87RUN
88
89NAME=pd 0
90FILE=malloc://128
91CMDS=pd 0
92EXPECT=<<EOF
93EOF
94RUN
95
96NAME=pd 1-1
97FILE=malloc://128
98CMDS=pd 1-1
99EXPECT=<<EOF
100EOF
101RUN
102
103NAME=pd foo-33
104FILE=malloc://128
105CMDS=f foo=33;pd foo-33
106EXPECT=<<EOF
107EOF
108RUN
109
110NAME=pd 1
111FILE=malloc://128
112CMDS=<<EOF
113e asm.arch=x86
114e asm.bits=64
115wx 90
116e asm.lines.bb=0
117b 1
118pd
119pd 1
120EOF
121EXPECT=<<EOF
122  0x00000000      90             nop
123  0x00000000      90             nop
124EOF
125RUN
126
127NAME=pd double comma
128FILE=malloc://128
129CMDS=<<EOF
130e asm.bits=64
131e asm.arch = x86
132e anal.arch = x86
133wx b8ffffffff
134e asm.lines.bb=0
135pd 1
136EOF
137EXPECT=<<EOF
138  0x00000000      b8ffffffff     mov eax, 0xffffffff                   ; -1
139EOF
140RUN
141
142NAME=pd@x:90
143FILE=malloc://128
144CMDS=<<EOF
145e asm.arch=x86
146e asm.bits=64
147e asm.lines.bb=0
148pd@x:90
149EOF
150EXPECT=<<EOF
151  0x00000000      90             nop
152EOF
153RUN
154
155NAME=asm.sub.names issue
156FILE=malloc://1024
157CMDS=<<EOF
158e asm.sub.names=1
159e asm.arch=arm
160e asm.bits=64
161
162wx fa67bba9
163pd 1
164EOF
165EXPECT=<<EOF
166            0x00000000      fa67bba9       stp x26, x25, [sp, -0x50]!
167EOF
168RUN
169
170NAME=asm.sub.names issue
171FILE=malloc://1024
172CMDS=<<EOF
173e asm.sub.names=0
174e asm.arch=arm
175e asm.bits=64
176wx fa67bba9
177pd 1
178EOF
179EXPECT=<<EOF
180            0x00000000      fa67bba9       stp x26, x25, [sp, -0x50]!
181EOF
182RUN
183
184NAME=asm.sub.names issue #6752
185FILE=malloc://1024
186CMDS=<<EOF
187s 0x100
188wx e801000000c350c3
189e asm.arch=x86
190e asm.bits=64
191aaaa
192e asm.pseudo=true
193e asm.offset=false
194e asm.lines.bb=false
195e asm.marks=false
196e asm.nbytes=0
197e asm.comments=false
198e asm.flags=false
199e asm.fcnlines=false
200e asm.calls=false
201e asm.functions=false
202e scr.color=false
203f-rip
204pd 1
205EOF
206EXPECT=<<EOF
207fcn.00000106 ()
208EOF
209RUN
210
211NAME=pd pseudo test for issue #7026
212FILE=malloc://8
213CMDS=<<EOF
214e asm.arch=x86
215e asm.bits=64
216wx 31ed
217e asm.pseudo=true
218e asm.comments=true
219e asm.cmtright=true
220pd 1
221e asm.cmtright=false
222pd 1
223EOF
224EXPECT=<<EOF
225            0x00000000      31ed           ebp = 0
226            0x00000000      31ed           ebp = 0
227EOF
228RUN
229
230NAME=pd pseudo test for issue #7268
231FILE=malloc://8
232CMDS=<<EOF
233e asm.arch=x86
234e asm.bits=64
235wx 4889e5
236e asm.pseudo=true
237e asm.comments=true
238e scr.color=1
239e asm.cmt.right=true
240pd 1
241e asm.cmt.right=false
242pd 1
243EOF
244EXPECT=<<EOF
245            0x00000000      4889e5         rbp = rsp
246            0x00000000      4889e5         rbp = rsp
247EOF
248RUN
249
250NAME=pd bits hint
251FILE=-
252ARGS=-a snes
253CMDS=<<EOF
254wx a97e00
255ahb 8
256e scr.color=1
257pd 1
258EOF
259EXPECT=<<EOF
260            0x00000000      a97e00         lda #0x007e
261EOF
262RUN
263
264NAME=ASCII Recognition
265FILE=malloc://1024
266CMDS=<<EOF
267e asm.arch=x86
268e asm.bits=32
269e scr.columns = 90
270wx ba3d000000
271pd 1
272EOF
273EXPECT=<<EOF
274            0x00000000      ba3d000000     mov edx, 0x3d               ; '='
275EOF
276RUN
277
278NAME=ASCII Recognition 2
279FILE=malloc://1024
280CMDS=<<EOF
281e asm.arch=x86
282e asm.bits=32
283e scr.columns = 90
284wx c6852fffffff61
285pd 1
286EOF
287EXPECT=<<EOF
288            0x00000000      c6852fffffff.  mov byte [ebp - 0xd1], 0x61 ; 'a'
289EOF
290RUN
291
292NAME=String capstone
293FILE=bins/elf/analysis/main
294CMDS=<<EOF
295e asm.arch = x86
296e asm.arch=x86
297e asm.bits=32
298e scr.columns = 90
299aa
300pd 1 @ 0x0040050a
301EOF
302EXPECT=<<EOF
303|           0x0040050a      bfc4054000     mov edi, str.Hello_World    ; 0x4005c4 ; "Hello World"
304EOF
305RUN
306
307NAME=pD -10
308FILE=malloc://1024
309CMDS=<<EOF
310e asm.arch=x86
311e asm.bits=64
312wx 90909090909090909090 ; s 10 ; pD -10
313EOF
314EXPECT=<<EOF
315            0x00000000      90             nop
316            0x00000001      90             nop
317            0x00000002      90             nop
318            0x00000003      90             nop
319            0x00000004      90             nop
320            0x00000005      90             nop
321            0x00000006      90             nop
322            0x00000007      90             nop
323            0x00000008      90             nop
324            0x00000009      90             nop
325EOF
326RUN
327
328NAME=pd -10
329FILE=malloc://1024
330CMDS=<<EOF
331e asm.arch=x86
332e asm.bits=64
333wx 90909090909090909090 ; s 10 ; pd -10
334EOF
335EXPECT=<<EOF
336            0x00000000      90             nop
337            0x00000001      90             nop
338            0x00000002      90             nop
339            0x00000003      90             nop
340            0x00000004      90             nop
341            0x00000005      90             nop
342            0x00000006      90             nop
343            0x00000007      90             nop
344            0x00000008      90             nop
345            0x00000009      90             nop
346EOF
347RUN
348
349NAME=pD -9 @ 0x0040050f
350FILE=bins/elf/analysis/main
351CMDS=<<EOF
352e asm.arch=x86
353e asm.bits=64
354pD -9 @ 0x0040050f
355EOF
356EXPECT=<<EOF
357            ;-- main:
358            0x00400506      55             push rbp
359            0x00400507      4889e5         mov rbp, rsp
360            0x0040050a      bfc4054000     mov edi, str.Hello_World    ; 0x4005c4 ; "Hello World"
361EOF
362RUN
363
364NAME=pd -3 @ 0x0040050f
365FILE=bins/elf/analysis/main
366CMDS=<<EOF
367e asm.arch=x86
368e asm.bits=64
369pd -3 @ 0x0040050f
370EOF
371EXPECT=<<EOF
372            ;-- main:
373            0x00400506      55             push rbp
374            0x00400507      4889e5         mov rbp, rsp
375            0x0040050a      bfc4054000     mov edi, str.Hello_World    ; 0x4005c4 ; "Hello World"
376EOF
377RUN
378
379NAME=pd 10 flags and cmts without offset
380FILE=bins/elf/echo-bin
381CMDS=<<EOF
382e asm.bytes=false
383e asm.offset=false
384e asm.cmt.right=0
385pd 10
386EOF
387EXPECT=<<EOF
388                 ; [14] -r-x section size 2466 named .text
389                 ;-- entry0:
390                 ;-- section..text:
391                 xor ebp, ebp
392                 mov r9, rdx
393                 pop rsi
394                 mov rdx, rsp
395                 and rsp, 0xfffffffffffffff0
396                 push rax
397                 push rsp
398                 lea r8, [0x000011e0]
399                 lea rcx, [0x00001170]
400                 ; 0xd7c
401                 lea rdi, main
402EOF
403RUN
404
405NAME=pda 10
406FILE=malloc://1024
407CMDS=<<EOF
408e asm.arch=x86
409e asm.bits=64
410wx 90909090909090909090 ; pda 10
411EOF
412EXPECT=<<EOF
4130x00000000                   90  nop
4140x00000001                   90  nop
4150x00000002                   90  nop
4160x00000003                   90  nop
4170x00000004                   90  nop
4180x00000005                   90  nop
4190x00000006                   90  nop
4200x00000007                   90  nop
4210x00000008                   90  nop
4220x00000009                   90  nop
423EOF
424RUN
425
426NAME=pdj -1
427FILE=malloc://1024
428CMDS=<<EOF
429e asm.arch=x86
430e asm.bits=32
431wx 56687cd3400090
432aaa
433s 6
434pdj -1
435EOF
436EXPECT=<<EOF
437[{"offset":1,"ptr":4248444,"val":4248444,"esil":"4248444,4,esp,-,=[4],4,esp,-=","refptr":false,"fcn_addr":0,"fcn_last":1020,"size":5,"opcode":"push 0x40d37c","disasm":"push 0x40d37c","bytes":"687cd34000","family":"cpu","type":"push","reloc":false,"type_num":13,"type2_num":0}]
438EOF
439RUN
440
441NAME=pdj 3 @ main
442FILE=bins/elf/analysis/main
443CMDS=<<EOF
444e asm.arch=x86
445e asm.bits=64
446pdj 3 @ main
447EOF
448EXPECT=<<EOF
449[{"offset":4195590,"esil":"rbp,8,rsp,-,=[8],8,rsp,-=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":1,"opcode":"push rbp","disasm":"push rbp","bytes":"55","family":"cpu","type":"rpush","reloc":false,"type_num":268435468,"type2_num":0,"flags":["main","sym.main"]},{"offset":4195591,"esil":"rsp,rbp,=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":3,"opcode":"mov rbp, rsp","disasm":"mov rbp, rsp","bytes":"4889e5","family":"cpu","type":"mov","reloc":false,"type_num":9,"type2_num":0},{"offset":4195594,"ptr":4195780,"val":4195780,"esil":"4195780,rdi,=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":5,"opcode":"mov edi, 0x4005c4","disasm":"mov edi, str.Hello_World","bytes":"bfc4054000","family":"cpu","type":"mov","reloc":false,"type_num":9,"type2_num":0}]
450EOF
451RUN
452
453NAME=pdj -3 @ 0x0040050f
454FILE=bins/elf/analysis/main
455CMDS=<<EOF
456e asm.arch=x86
457e asm.bits=64
458pdj -3 @ 0x0040050f
459EOF
460EXPECT=<<EOF
461[{"offset":4195590,"esil":"rbp,8,rsp,-,=[8],8,rsp,-=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":1,"opcode":"push rbp","disasm":"push rbp","bytes":"55","family":"cpu","type":"rpush","reloc":false,"type_num":268435468,"type2_num":0,"flags":["main","sym.main"]},{"offset":4195591,"esil":"rsp,rbp,=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":3,"opcode":"mov rbp, rsp","disasm":"mov rbp, rsp","bytes":"4889e5","family":"cpu","type":"mov","reloc":false,"type_num":9,"type2_num":0},{"offset":4195594,"ptr":4195780,"val":4195780,"esil":"4195780,rdi,=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":5,"opcode":"mov edi, 0x4005c4","disasm":"mov edi, str.Hello_World","bytes":"bfc4054000","family":"cpu","type":"mov","reloc":false,"type_num":9,"type2_num":0}]
462EOF
463RUN
464
465NAME=pdj str in opcode
466FILE=bins/java/Hello.class
467CMDS=pdj 1 @ 0x000002ae
468EXPECT=<<EOF
469[{"offset":686,"esil":"","refptr":false,"fcn_addr":0,"fcn_last":0,"size":2,"opcode":"ldc \"World\"","disasm":"ldc \"World\"","bytes":"120b","family":"cpu","type":"push","reloc":false,"type_num":13,"type2_num":2138640}]
470EOF
471RUN
472
473NAME=pdfline
474FILE=malloc://1024
475CMDS=<<EOF
476e asm.arch=x86
477e asm.bits=64
478e anal.eobjmp=true
479wx ff2572962100
480af
481pdf~jmp[0]
482afi~size[1]
483EOF
484EXPECT=<<EOF
485\
4866
487EOF
488RUN
489
490NAME=pdfline 2
491FILE=malloc://1024
492CMDS=<<EOF
493e asm.arch=x86
494e asm.bits=64
495e anal.eobjmp=false
496wx ff2572962100
497af
498afi~size[1]
499EOF
500EXPECT=<<EOF
5016
502EOF
503RUN
504
505NAME=pdfline defaults
506FILE=malloc://1024
507CMDS=<<EOF
508e asm.arch=x86
509e asm.bits=64
510wa jmp rax
511af
512afi~size[1]
513EOF
514EXPECT=<<EOF
5152
516EOF
517RUN
518
519NAME=pd asm.bytes and asm.lbytes
520FILE=malloc://1024
521CMDS=<<EOF
522e asm.arch=x86
523e asm.bits=64
524wx 488d85c0f9ffff488985b8f9ffff4585f6
525e asm.lines.bb = false
526e asm.lbytes = true
527e asm.nbytes = 6
528pd 3
529e asm.nbytes = 10
530pd 3
531e asm.lbytes = false
532pd 3
533e asm.nbytes = 6
534pd 3
535EOF
536EXPECT=<<EOF
537  0x00000000      488d85c0f9ff.  lea rax, [rbp - 0x640]
538  0x00000007      488985b8f9ff.  mov qword [rbp - 0x648], rax
539  0x0000000e      4585f6         test r14d, r14d
540  0x00000000      488d85c0f9ffff         lea rax, [rbp - 0x640]
541  0x00000007      488985b8f9ffff         mov qword [rbp - 0x648], rax
542  0x0000000e      4585f6                 test r14d, r14d
543  0x00000000              488d85c0f9ffff  lea rax, [rbp - 0x640]
544  0x00000007              488985b8f9ffff  mov qword [rbp - 0x648], rax
545  0x0000000e                      4585f6  test r14d, r14d
546  0x00000000       488d85c0f9ff.  lea rax, [rbp - 0x640]
547  0x00000007       488985b8f9ff.  mov qword [rbp - 0x648], rax
548  0x0000000e              4585f6  test r14d, r14d
549EOF
550RUN
551
552NAME=pd asm.sub.rel
553FILE=malloc://1024
554ARGS=-m 0x400000
555CMDS=<<EOF
556e io.va=true
557e asm.sub.rel=false
558e asm.arch=x86
559e asm.bits=64
560wx 488d0502000000
561e asm.lines.bb=false
562e asm.comments=false
563pd 1
564e asm.sub.rel=true
565pd 1
566EOF
567EXPECT=<<EOF
568  0x00400000      488d05020000.  lea rax, [rip + 2]
569  0x00400000      488d05020000.  lea rax, [0x00400009]
570EOF
571RUN
572
573NAME=pd asm.sub.varonly
574FILE=malloc://1024
575CMDS=<<EOF
576e anal.vars.stackname=true
577e asm.arch=x86
578e asm.bits=64
579e asm.sub.var=true
580e asm.lines.bb=false
581e asm.bytes=false
582e asm.comments=false
583e asm.lines.fcn=false
584e asm.offset=false
585e scr.color=false
586wx 554889e583ec60488b44244089ec5dc3
587af
588afva
589e asm.sub.varonly=true
590pd 1 @ 0~var
591pd 1 @ 7
592e asm.sub.varonly=false
593pd 1 @ 0~var
594pd 1 @ 7
595EOF
596EXPECT=<<EOF
597     ; var int64_t var_28h @ rsp+0x40
598     mov rax, qword [var_28h]
599     ; var int64_t var_28h @ rsp+0x40
600     mov rax, qword [rsp + var_28h]
601EOF
602RUN
603
604NAME=pd wide string
605FILE=bins/pe/c.exe
606CMDS=<<EOF
607e io.cache=true
608s 0x403000
609wx 4d00 5900 5200 4500 5300 0000
610s 0x00401334
611pd 1~MYRES?
612EOF
613EXPECT=<<EOF
6141
615EOF
616RUN
617
618NAME=pds change name
619FILE=bins/mach0/mac-ls
620CMDS=<<EOF
621e asm.flags=false
622s sym.func.100004401
623af
624afn newname
625s-
626pds
627EOF
628EXPECT=<<EOF
6290x100001085 call newname
6300x100001093 call sym.imp.setlocale
6310x1000010a3 call sym.imp.isatty
6320x1000054e0 [10] -rw- section size 40 named 10.__DATA.__data
6330x1000010b6 str.COLUMNS
6340x1000010bd call sym.imp.getenv
6350x1000010cf call sym.imp.atoi
6360x1000010e6 call sym.imp.ioctl
6370x10000110d str.COLUMNS
6380x100001114 call sym.imp.getenv
6390x100001121 call sym.imp.atoi
6400x10000112c call sym.imp.getuid
641EOF
642RUN
643
644NAME=pdf fcnline
645FILE=bins/pe/a.exe
646CMDS=<<EOF
647e asm.lines.fcn=true
648s 0x004017c0
649af+ 0x004017c0 fcn2.0x004017c0
650afb+ 0x4017c0 0x4017c0 13 0x4017dd 0x4017cd
651pdf
652?e
653e asm.lines.fcn=false
654pdf
655EOF
656EXPECT=<<EOF
657/ 13: fcn2.0x004017c0 ();
658|           0x004017c0      51             push ecx
659|           0x004017c1      89e1           mov ecx, esp
660|           0x004017c3      83c108         add ecx, 8
661|           0x004017c6      3d00100000     cmp eax, 0x1000
662\       ,=< 0x004017cb      7210           jb 0x4017dd
663
66413: fcn2.0x004017c0 ();
665          0x004017c0      51             push ecx
666          0x004017c1      89e1           mov ecx, esp
667          0x004017c3      83c108         add ecx, 8
668          0x004017c6      3d00100000     cmp eax, 0x1000
669      ,=< 0x004017cb      7210           jb 0x4017dd
670EOF
671RUN
672
673NAME=r_str_escape anal
674FILE=bins/pe/a.exe
675CMDS=pd 1 @ 0x00401322
676EXPECT=<<EOF
677            0x00401322      c70424043040.  mov dword [esp], 0x403004   ; [0x403004:4]=0xa7025 ; "%p\n"
678EOF
679RUN
680
681NAME=r_str_escape io + no 'u' prefix for single-char strings
682FILE=bins/pe/testapp-msvc64.exe
683CMDS=<<EOF
684pd 1 @ 0x140001034
685pd 1 @ 0x140001070
686EOF
687EXPECT=<<EOF
688            0x140001034      488d05495001.  lea rax, [0x140016084]     ; "\r"
689            0x140001070      488d053d5001.  lea rax, [0x1400160b4]     ; "a"
690EOF
691RUN
692
693NAME=r_str_escape anal addr
694FILE=bins/pe/cmd_adf_sample0.exe
695CMDS=pd 1 @ 0x0040116a
696EXPECT=<<EOF
697            0x0040116a      6828304000     push 0x403028               ; '(0@' ; "End\r\n"
698EOF
699RUN
700
701NAME=no rep flag in cmt with gen str flag (lea)
702FILE=bins/elf/analysis/ls-alxchk
703CMDS=<<EOF
704e asm.cmt.right=true
705pd 1 @ 0x0001145f
706e asm.cmt.right=false
707pd 1 @ 0x0001145f
708EOF
709EXPECT=<<EOF
710            0x0001145f      488d3d72a100.  lea rdi, str.A_NULL_argv_0__was_passed_through_an_exec_system_call._n ; 0x1b5d8 ; "A NULL argv[0] was passed through an exec system call.\n"
711            ; 0x1b5d8
712            ; "A NULL argv[0] was passed through an exec system call.\n"
713            0x0001145f      488d3d72a100.  lea rdi, str.A_NULL_argv_0__was_passed_through_an_exec_system_call._n
714EOF
715RUN
716
717NAME=flag in cmt with manual flag (lea)
718FILE=bins/elf/analysis/ls-alxchk
719CMDS=<<EOF
720f- @ 0x1b5d8
721f NULL_error 56 @ 0x1b5d8
722e asm.cmt.right=true
723pd 1 @ 0x0001145f
724e asm.cmt.right=false
725pd 1 @ 0x0001145f
726EOF
727EXPECT=<<EOF
728            0x0001145f      488d3d72a100.  lea rdi, [NULL_error]       ; 0x1b5d8 ; "A NULL argv[0] was passed through an exec system call.\n"
729            ; 0x1b5d8
730            ; "A NULL argv[0] was passed through an exec system call.\n"
731            0x0001145f      488d3d72a100.  lea rdi, [NULL_error]
732EOF
733RUN
734
735NAME=no rep flag in cmt with gen str flag (push)
736FILE=bins/pe/ConsoleApplication1.exe
737CMDS=<<EOF
738e asm.cmt.right=true
739pd 1 @ 0x004010f0
740e asm.cmt.right=false
741pd 1 @ 0x004010f0
742EOF
743EXPECT=<<EOF
744            0x004010f0      68b8214000     push str.Number_of_CPU__d_n ; 0x4021b8 ; u"Number of CPU %d\n"
745            ; 0x4021b8
746            ; u"Number of CPU %d\n"
747            0x004010f0      68b8214000     push str.Number_of_CPU__d_n
748EOF
749RUN
750
751NAME=flag in cmt with manual flag (push)
752FILE=bins/pe/ConsoleApplication1.exe
753CMDS=<<EOF
754f- @ 0x4021b8
755f num_cpu 36 @ 0x4021b8
756e asm.cmt.right=true
757pd 1 @ 0x004010f0
758e asm.cmt.right=false
759pd 1 @ 0x004010f0
760EOF
761EXPECT=<<EOF
762            0x004010f0      68b8214000     push 0x4021b8               ; num_cpu ; u"Number of CPU %d\n"
763            ; num_cpu
764            ; u"Number of CPU %d\n"
765            0x004010f0      68b8214000     push 0x4021b8
766EOF
767RUN
768
769NAME=no rep flag in cmt with gen sym flag (mov)
770FILE=bins/pe/ConsoleApplication1.exe
771CMDS=<<EOF
772e asm.cmt.right=true
773pd 1 @ 0x004010fa
774e asm.cmt.right=false
775pd 1 @ 0x004010fa
776EOF
777EXPECT=<<EOF
778            0x004010fa      8b3500204000   mov esi, dword [sym.imp.KERNEL32.dll_GetLastError] ; [0x402000:4]=0x29f4 reloc.KERNEL32.dll_GetLastError
779            ; [0x402000:4]=0x29f4 reloc.KERNEL32.dll_GetLastError
780            0x004010fa      8b3500204000   mov esi, dword [sym.imp.KERNEL32.dll_GetLastError]
781EOF
782RUN
783
784NAME=flag in cmt with manual flag (mov)
785FILE=bins/pe/ConsoleApplication1.exe
786CMDS=<<EOF
787f- @ 0x402000
788f ptr_GetLastError 0 @ 0x402000
789e asm.cmt.right=true
790pd 1 @ 0x004010fa
791e asm.cmt.right=false
792pd 1 @ 0x004010fa
793EOF
794EXPECT=<<EOF
795            0x004010fa      8b3500204000   mov esi, dword [ptr_GetLastError] ; [0x402000:4]=0x29f4 reloc.KERNEL32.dll_GetLastError
796            ; [0x402000:4]=0x29f4 reloc.KERNEL32.dll_GetLastError
797            0x004010fa      8b3500204000   mov esi, dword [ptr_GetLastError]
798EOF
799RUN
800
801NAME=pd asm.sub.names color
802FILE=bins/elf/analysis/ls-alxchk
803CMDS=<<EOF
804e asm.bytes=false
805e asm.comments=false
806e scr.color=1
807e asm.sub.names=true
808pd 1 @ 0x0001145f
809e asm.sub.names=false
810pd 1 @ 0x0001145f
811EOF
812EXPECT=<<EOF
813            0x0001145f      lea rdi, str.A_NULL_argv_0__was_passed_through_an_exec_system_call._n
814            0x0001145f      lea rdi, [0x0001b5d8]
815EOF
816RUN
817
818NAME=ANSI and wide string flag cmts
819FILE=bins/pe/testapp-msvc64.exe
820CMDS=<<EOF
821e str.escbslash=false
822e asm.cmt.right=true
823pd 1 @ 0x140001004
824pd 1 @ 0x140001010
825pd 1 @ 0x14000101c
826e asm.cmt.right=false
827pd 1 @ 0x140001004
828pd 1 @ 0x140001010
829pd 1 @ 0x14000101c
830EOF
831EXPECT=<<EOF
832            0x140001004      488d05f54f01.  lea rax, str._tANSIesc:_e_33m_r_n ; section..data
833                                                                       ; 0x140016000 ; "\tANSI\esc: \x1b[33m\r\n"
834            0x140001010      488d05015001.  lea rax, str._twideesc:_e_0m ; 0x140016018 ; u"\twide\esc: \x1b[0m\xa1\r\n"
835            0x14000101c      488d051d5001.  lea rax, str._wide__in_Arabic:_ ; 0x140016040 ; u"\"wide\" in Arabic: \u0648\u0627\u0633\u0639"
836            ; section..data
837            ; 0x140016000
838            ; "\tANSI\esc: \x1b[33m\r\n"
839            0x140001004      488d05f54f01.  lea rax, str._tANSIesc:_e_33m_r_n
840            ; 0x140016018
841            ; u"\twide\esc: \x1b[0m\xa1\r\n"
842            0x140001010      488d05015001.  lea rax, str._twideesc:_e_0m
843            ; 0x140016040
844            ; u"\"wide\" in Arabic: \u0648\u0627\u0633\u0639"
845            0x14000101c      488d051d5001.  lea rax, str._wide__in_Arabic:_
846EOF
847RUN
848
849NAME=no ffffff test for issue #7755
850FILE=bins/pe/testapp-msvc64.exe
851CMDS=pd 1 @ 0x140001040
852EXPECT=<<EOF
853            0x140001040      488d05415001.  lea rax, [0x140016088]     ; u"r2 \u1308\u23f4\u23f4"
854EOF
855RUN
856
857NAME=asm.asciidot
858FILE=bins/elf/strenc
859CMDS=<<EOF
860e asm.bytes=false
861e asm.cmt.off=false
862e str.escbslash=true
863e bin.str.enc=latin1
864e scr.strconv=asciiesc
865pd 1 @ 0x0040169d
866e scr.strconv=asciidot
867pd 1 @ 0x0040169d
868e asm.sub.names=false
869e asm.noisy=false
870pd 1 @ 0x00401693
871e bin.str.enc=utf8
872pd 1 @ 0x00401693
873e bin.str.enc=utf16le
874pd 1 @ 0x004016ac
875e bin.str.enc=utf32le
876pd 1 @ 0x004016ed
877pd 1 @ 0x004016f7
878EOF
879EXPECT=<<EOF
880            0x0040169d      mov esi, str.see_                          ; "see \xdab\xbee\xace\xcaf\n"
881            0x0040169d      mov esi, str.see_                          ; "see .b.e.e.f\n"
882            0x00401693      mov edi, 0x4021ff                          ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:.[33m ......... .[0m\n"
883            0x00401693      mov edi, 0x4021ff                          ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:.[33m ... .[0m."
884            0x004016ac      mov edi, 0x40224a                          ; 'J"@' ; u"utf16le> \\u00a2\\u20ac\\U00010348 in green:.[32m ... .[0m."
885            0x004016ed      mov edi, 0x40258c                          ; U"utf32le> \\u00a2\\u20ac\\U00010348 in cyan:.[36m ... .[0m."
886            0x004016f7      mov edi, 0x40266c                          ; U"Mountain range with embedded quad zeros: .A.A.A."
887EOF
888RUN
889
890NAME=bin.str.enc utf8
891FILE=bins/elf/strenc
892CMDS=<<EOF
893e asm.bytes=false
894e asm.sub.names=false
895e asm.noisy=false
896e str.escbslash=true
897e bin.str.enc=utf8
898pd 1 @ 0x00401693
899e bin.str.enc=latin1
900pd 1 @ 0x00401693
901e bin.str.enc=guess
902pd 1 @ 0x00401693
903EOF
904EXPECT=<<EOF
905            0x00401693      mov edi, 0x4021ff                          ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \u00a2\u20ac\U00010348 \x1b[0m\n"
906            0x00401693      mov edi, 0x4021ff                          ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \xc2\xa2\xe2\x82\xac\xf0\x90\x8d\x88 \x1b[0m\n"
907            0x00401693      mov edi, 0x4021ff                          ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \u00a2\u20ac\U00010348 \x1b[0m\n"
908EOF
909RUN
910
911NAME=bin.str.enc latin1
912FILE=bins/pe/testapp-msvc64.exe
913CMDS=<<EOF
914e asm.sub.names=false
915e asm.noisy=false
916e bin.str.enc=latin1
917pd 1 @ 0x140001058
918e bin.str.enc=utf8
919pd 1 @ 0x140001058
920EOF
921EXPECT=<<EOF
922            0x140001058      488d05415001.  lea rax, [0x1400160a0]     ; "latin1 gate: \xce\xbb\xab\xce"
923            0x140001058      488d05415001.  lea rax, [0x1400160a0]     ; "latin1 gate: \u03bb\xab\xce"
924EOF
925RUN
926
927NAME=bin.str.enc utf16le
928FILE=bins/elf/strenc
929CMDS=<<EOF
930e asm.bytes=false
931e asm.sub.names=false
932e asm.noisy=false
933e str.escbslash=true
934e bin.str.enc=guess
935pd 1 @ 0x004016ac
936e asm.sub.names=true
937e asm.cmt.off=false
938e bin.str.enc=guess
939pd 1 @ 0x004016b6
940e bin.str.enc=utf16le
941pd 1 @ 0x004016b6
942e bin.str.enc=guess
943pd 1 @ 0x004016c0
944e bin.str.enc=utf16le
945pd 1 @ 0x004016c0
946pd 1 @ 0x004016ca
947pd 1 @ 0x004016d4
948EOF
949EXPECT=<<EOF
950            0x004016ac      mov edi, 0x40224a                          ; 'J"@' ; u"utf16le> \\u00a2\\u20ac\\U00010348 in green:\x1b[32m \xa2\u20ac\U00010348 \x1b[0m\n"
951            0x004016b6      mov edi, str.__e_e_b__                     ; "_%e%e%b% "
952            0x004016b6      mov edi, str.__e_e_b__                     ; u"\u255f\u2565\u2565\u2562 is a wall with no embedded zeros\n"
953            0x004016c0      mov edi, str.__B_                          ; " %B%"
954            0x004016c0      mov edi, str.__B_                          ; u"\u2520\u2542\u2500\u2500\u2542\u2528 is a fence with embedded zeros\n"
955            0x004016ca      mov edi, str.__B__                         ; u"\u2520\u2542-\u2500-\u2500\u2542\u2528 is a fence with embedded double zeros\n"
956            0x004016d4      mov edi, str.e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k_e_e_e_e_e_e_e_e_e_k__n ; u"\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\n"
957EOF
958RUN
959
960NAME=bin.str.enc utf32le
961FILE=bins/elf/strenc
962CMDS=<<EOF
963e asm.bytes=false
964e asm.cmt.off=false
965e str.escbslash=true
966e bin.str.enc=utf16le
967pd 1 @ 0x004016de
968e bin.str.enc=utf32le
969pd 1 @ 0x004016de
970e asm.sub.names=false
971e asm.noisy=false
972e bin.str.enc=guess
973pd 1 @ 0x004016ed
974pd 1 @ 0x004016f7
975pd 1 @ 0x00401701
976e bin.str.enc=utf32le
977pd 1 @ 0x00401701
978EOF
979EXPECT=<<EOF
980            0x004016de      mov esi, str._tLinux_wideesc:_e_0m_r_n     ; u"\t"
981            0x004016de      mov esi, str._tLinux_wideesc:_e_0m_r_n     ; U"\tLinux_wide\\esc: \x1b[0m\xa1\r\n"
982            0x004016ed      mov edi, 0x40258c                          ; U"utf32le> \\u00a2\\u20ac\\U00010348 in cyan:\x1b[36m \xa2\u20ac\U00010348 \x1b[0m\n"
983            0x004016f7      mov edi, 0x40266c                          ; U"Mountain range with embedded quad zeros: \U00010300A\U00010300A\U00010300A\n"
984            0x00401701      mov edi, 0x402730                          ; '0'@' ; "e%"
985            0x00401701      mov edi, 0x402730                          ; '0'@' ; U"\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565"
986EOF
987RUN
988
989NAME=bin.str.enc guess utf16le
990FILE=bins/pe/testapp-msvc64.exe
991CMDS=<<EOF
992e asm.sub.names=false
993e asm.noisy=false
994e bin.str.enc=guess
995pd 1 @ 0x14000104c
996e bin.str.enc=utf16le
997pd 1 @ 0x14000104c
998EOF
999EXPECT=<<EOF
1000            0x14000104c      488d05455001.  lea rax, [0x140016098]     ; "@"
1001            0x14000104c      488d05455001.  lea rax, [0x140016098]     ; u"@\ufffd\ud801"
1002EOF
1003RUN
1004
1005NAME=bin.str.enc guess utf32le
1006FILE=bins/elf/strenc-guess-utf32le
1007CMDS=<<EOF
1008e asm.cmt.off=false
1009e asm.bytes=false
1010e bin.str.enc=guess
1011pd 1 @ 0x00400463
1012e bin.str.enc=utf32le
1013pd 1 @ 0x00400463
1014EOF
1015EXPECT=<<EOF
1016            0x00400463      mov edi, str.ABCDEF                        ; "A"
1017            0x00400463      mov edi, str.ABCDEF                        ; U"ABCDEF\U0010ffff  G\U00110000  H\U7ffdfeff\n"
1018EOF
1019RUN
1020
1021NAME=bin.str.enc alias
1022FILE=bins/elf/strenc
1023CMDS=<<EOF
1024e asm.sub.names=false
1025e asm.noisy=false
1026e asm.bytes=false
1027e asm.cmt.off=false
1028e str.escbslash=true
1029(test_str.enc enc; e bin.str.enc=$0; e bin.str.enc)
1030.(test_str.enc guess)
1031.(test_str.enc utf-8)
1032.(test_str.enc utf-16le)
1033pd 1 @ 0x004016c0
1034.(test_str.enc utf32-le)
1035pd 1 @ 0x004016ed
1036?e
1037.(test_str.enc UTF32BE)
1038.(test_str.enc UTF16-LE)
1039EOF
1040EXPECT=<<EOF
1041guess
1042utf8
1043utf16le
1044            0x004016c0      mov edi, 0x40230c                          ; u"\u2520\u2542\u2500\u2500\u2542\u2528 is a fence with embedded zeros\n"
1045utf32le
1046            0x004016ed      mov edi, 0x40258c                          ; U"utf32le> \\u00a2\\u20ac\\U00010348 in cyan:\x1b[36m \xa2\u20ac\U00010348 \x1b[0m\n"
1047
1048utf32be
1049utf16le
1050EOF
1051RUN
1052
1053NAME=bin.str.enc error handling
1054FILE=-
1055CMDS=<<EOF
1056(test_str.enc enc; e bin.str.enc=$0; e bin.str.enc)
1057.(test_str.enc UTF-32LE)
1058.(test_str.enc cat_sat_on_keyboard)
1059.(test_str.enc CAT_SAT_ON_KEYBOARD)
1060EOF
1061EXPECT=<<EOF
1062utf32le
1063utf32le
1064utf32le
1065EOF
1066EXPECT_ERR=<<EOF
1067Unknown encoding: cat_sat_on_keyboard
1068Unknown encoding: CAT_SAT_ON_KEYBOARD
1069EOF
1070RUN
1071
1072NAME=hide flag iff unchanged and string shown
1073FILE=bins/pe/testapp-msvc64.exe
1074CMDS=<<EOF
1075e asm.sub.names=false
1076e asm.noisy=false
1077e str.escbslash=false
1078e asm.cmt.right=true
1079pd 1 @ 0x140001010
1080pd 1 @ 0x140001028
1081e asm.cmt.right=false
1082pd 1 @ 0x140001010
1083pd 1 @ 0x140001028
1084fr str.wide__esc:__e_0m str.wide
1085e asm.cmt.right=true
1086pd 1 @ 0x140001010
1087e asm.cmt.right=false
1088pd 1 @ 0x140001010
1089EOF
1090EXPECT=<<EOF
1091            0x140001010      488d05015001.  lea rax, [0x140016018]     ; u"\twide\esc: \x1b[0m\xa1\r\n"
1092            0x140001028      488d05415001.  lea rax, [0x140016070]     ; str._fFormfeed_at_start
1093            ; u"\twide\esc: \x1b[0m\xa1\r\n"
1094            0x140001010      488d05015001.  lea rax, [0x140016018]
1095            ; str._fFormfeed_at_start
1096            0x140001028      488d05415001.  lea rax, [0x140016070]
1097            0x140001010      488d05015001.  lea rax, [0x140016018]     ; u"\twide\esc: \x1b[0m\xa1\r\n"
1098            ; u"\twide\esc: \x1b[0m\xa1\r\n"
1099            0x140001010      488d05015001.  lea rax, [0x140016018]
1100EOF
1101RUN
1102
1103NAME=asm.noisy
1104FILE=bins/pe/testapp-msvc64.exe
1105CMDS=<<EOF
1106e asm.sub.names=false
1107e asm.noisy=true
1108e str.escbslash=false
1109e asm.cmt.right=true
1110pd 1 @ 0x140001010
1111e asm.cmt.right=false
1112pd 1 @ 0x140001010
1113EOF
1114EXPECT=<<EOF
1115            0x140001010      488d05015001.  lea rax, [0x140016018]     ; str._twideesc:_e_0m ; u"\twide\esc: \x1b[0m\xa1\r\n"
1116            ; str._twideesc:_e_0m
1117            ; u"\twide\esc: \x1b[0m\xa1\r\n"
1118            0x140001010      488d05015001.  lea rax, [0x140016018]
1119EOF
1120RUN
1121
1122NAME=fcn name cmt alignment
1123FILE=bins/pe/ConsoleApplication1.exe
1124CMDS=<<EOF
1125e asm.sub.names=false
1126af @ main
1127pd 1 @ 0x00401157
1128EOF
1129EXPECT=<<EOF
1130|           0x00401157      e8b4feffff     call fcn.00401010
1131EOF
1132RUN
1133
1134NAME=call asm.sub.names=false flag cmt
1135FILE=bins/pe/ConsoleApplication1.exe
1136CMDS=<<EOF
1137e asm.sub.names=false
1138e asm.cmt.right=true
1139pd 1 @ 0x004010c6
1140e asm.cmt.right=false
1141pd 1 @ 0x004010c6
1142EOF
1143EXPECT=<<EOF
1144            0x004010c6      ff1508204000   call dword [0x402008]       ; sym.imp.KERNEL32.dll_GetProcAddress ; " *" ; FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
1145            ; sym.imp.KERNEL32.dll_GetProcAddress
1146            ; " *"
1147            ; FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
1148            0x004010c6      ff1508204000   call dword [0x402008]
1149EOF
1150RUN
1151
1152NAME=asm.cmt.off
1153FILE=bins/pe/testapp-msvc64.exe
1154CMDS=<<EOF
1155e asm.noisy=false
1156e str.escbslash=false
1157e asm.sub.names=true
1158e asm.cmt.off=false
1159pd 1 @ 0x140001010
1160e asm.sub.names=false
1161e asm.cmt.off=true
1162pd 1 @ 0x140001010
1163e asm.cmt.off=nodup
1164pd 1 @ 0x140001010
1165EOF
1166EXPECT=<<EOF
1167            0x140001010      488d05015001.  lea rax, str._twideesc:_e_0m ; u"\twide\esc: \x1b[0m\xa1\r\n"
1168            0x140001010      488d05015001.  lea rax, [0x140016018]     ; 0x140016018 ; u"\twide\esc: \x1b[0m\xa1\r\n"
1169            0x140001010      488d05015001.  lea rax, [0x140016018]     ; u"\twide\esc: \x1b[0m\xa1\r\n"
1170EOF
1171RUN
1172
1173NAME=no | highlight with asm.cmt.right=false & call statement
1174FILE=bins/pe/ConsoleApplication1.exe
1175CMDS=<<EOF
1176e asm.bytes=false
1177e scr.color=1
1178e asm.cmt.right=false
1179s main
1180af
1181pd 2 @ 0x004010e8
1182EOF
1183EXPECT=<<EOF
1184|           0x004010e8      push esi
1185|           ; 0x402004
1186|           ; DWORD GetCurrentProcessorNumber(void)
1187|           0x004010e9      call dword [sym.imp.KERNEL32.dll_GetCurrentProcessorNumber]
1188EOF
1189RUN
1190
1191NAME=varsub for rip variable
1192FILE=bins/elf/varsub_2
1193CMDS=<<EOF
1194aa; s main
1195e asm.syntax=att
1196e asm.var=0
1197e asm.lines.bb=0
1198e asm.bytes=0
1199e asm.comments=false
1200pdf
1201EOF
1202EXPECT=<<EOF
1203/ 21: int main (int argc, char **argv, char **envp);
1204| 0x0000061a      pushq %rbp
1205| 0x0000061b      movq %rsp, %rbp
1206| 0x0000061e      movl $1, obj.sa
1207| 0x00000628      movl $0, %eax
1208| 0x0000062d      popq %rbp
1209\ 0x0000062e      retq
1210EOF
1211RUN
1212
1213NAME=utf16le string with byte order mark
1214FILE=bins/elf/7786-utf16le
1215CMDS=<<EOF
1216e asm.bytes=false
1217pd 1 @ 0x004004ee
1218EOF
1219EXPECT=<<EOF
1220            0x004004ee      mov edi, str._____S                        ; 0x4005c0 ; u"\ufeff--> %S\ufeff\n"
1221EOF
1222RUN
1223
1224NAME=show string at src if dst is stack (x86_cs MOV)
1225FILE=bins/elf/7786-utf16le
1226CMDS=<<EOF
1227e asm.bytes=false
1228pd 1 @ 0x004004df
1229EOF
1230EXPECT=<<EOF
1231            0x004004df      mov qword [rbp - 8], str.Hello_World       ; 0x4005a0 ; u"\ufeffHello World\ufeff\n"
1232EOF
1233RUN
1234
1235NAME=pdJ 2
1236FILE=malloc://128
1237CMDS=<<EOF
1238e asm.arch=x86
1239e asm.bits=64
1240wx 9090
1241e asm.lines.bb=0
1242pdJ 2
1243EOF
1244EXPECT=<<EOF
1245[{"offset":0,"text":"  0x00000000      90             nop"},{"offset":1,"text":"  0x00000001      90             nop"}]
1246EOF
1247RUN
1248
1249NAME=pdJ comments
1250FILE=malloc://128
1251CMDS=<<EOF
1252e asm.arch=x86
1253e asm.bits=64
1254wx 90
1255e asm.lines.bb=0
1256CCu base64:dGVzdAo=
1257pdJ 1
1258CCu base64:dGVzdCAid2l0aCBxdW90ZXMiCg==
1259pdJ 1
1260e asm.cmt.right=false
1261pdJ 1
1262EOF
1263EXPECT=<<EOF
1264[{"offset":0,"text":"  0x00000000      90             nop                                   ; test"}]
1265[{"offset":0,"text":"  0x00000000      90             nop                                   ; test \"with quotes\""}]
1266[{"offset":0,"text":"  ; test \"with quotes\"\n"},{"offset":0,"text":"  0x00000000      90             nop"}]
1267EOF
1268RUN
1269
1270NAME=pdJ string comment
1271FILE=bins/elf/analysis/main
1272CMDS=<<EOF
1273aa
1274pdJ 1 @ 0x0040050a
1275EOF
1276EXPECT=<<EOF
1277[{"offset":4195594,"text":"|           0x0040050a      bfc4054000     mov edi, str.Hello_World    ; 0x4005c4 ; \"Hello World\""}]
1278EOF
1279RUN
1280
1281NAME=pdJ flags
1282FILE=bins/elf/analysis/main
1283CMDS=<<EOF
1284s main
1285pdJ 1 @ 0x00400506
1286aa
1287pdJ 1 @ 0x00400506
1288EOF
1289EXPECT=<<EOF
1290[{"offset":4195590,"text":"            ;-- main:"},{"offset":4195590,"text":"            0x00400506      55             push rbp"}]
1291[{"offset":4195590,"text":"            ; DATA XREF from entry0 @ 0x40042d"},{"offset":4195590,"text":"/ 16: int main (int argc, char **argv, char **envp);"},{"offset":4195590,"text":"|           0x00400506      55             push rbp"}]
1292EOF
1293RUN
1294
1295NAME=pdJ midflags reloc
1296FILE=malloc://8
1297CMDS=<<EOF
1298e asm.arch=x86
1299e asm.bits=64
1300f reloc.test @ 0x1
1301pdJ 1 @ 0x0
1302EOF
1303EXPECT=<<EOF
1304[{"offset":0,"text":"            0x00000000      0000           add byte [rax], al"}]
1305EOF
1306RUN
1307
1308NAME=pdJ string - oldshell
1309ARGS=-ecfg.newshell=false
1310FILE=malloc://128
1311CMDS=<<EOF
1312w Snoo"ping as" usual,
1313Cs 30
1314pdJ 1
1315EOF
1316EXPECT=<<EOF
1317[{"offset":0,"text":"            0x00000000     .string \"Snoo\\\"ping as\\\" usual,\" ; len=30"}]
1318EOF
1319RUN
1320
1321NAME=pdJ string - newshell
1322ARGS=-ecfg.newshell=true
1323FILE=malloc://128
1324CMDS=<<EOF
1325w "Snoo\"ping as\" usual,"
1326Cs 30
1327pdJ 1
1328EOF
1329EXPECT=<<EOF
1330[{"offset":0,"text":"            0x00000000     .string \"Snoo\\\"ping as\\\" usual,\" ; len=30"}]
1331EOF
1332RUN
1333
1334NAME=pdJ str in opcode
1335FILE=bins/java/Hello.class
1336CMDS=pdJ 1 @ 0x000002ae
1337EXPECT=<<EOF
1338[{"offset":686,"text":"            0x000002ae      120b           ldc \"World\""}]
1339EOF
1340RUN
1341
1342NAME=pdJ asm.cmt.right=0 + html
1343FILE=bins/elf/crackme0x05
1344CMDS=<<EOF
1345aaa
1346e asm.cmt.right=0
1347e scr.colors=1
1348e scr.html=1
1349e str.escbslash=1
1350pdJ 1 @ 0x08048532
1351EOF
1352EXPECT=<<EOF
1353[{"offset":134513970,"text":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;[0x8048679:4]=0x73736150"},{"offset":134513970,"text":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;\"Password&nbsp;Incorrect!\\n\""},{"offset":134513970,"text":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x08048532&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c70424798604.&nbsp;&nbsp;mov&nbsp;dword&nbsp;[esp],&nbsp;str.Password_Incorrect__n"}]
1354EOF
1355RUN
1356
1357NAME=pdJ asm.cmt.right=0 fcn name
1358FILE=bins/elf/crackme0x05
1359CMDS=<<EOF
1360af@sym.imp.__libc_start_main
1361af@0x080485a0
1362e asm.pseudo=1
1363e asm.cmt.right=0
1364pdJ 1 @ 0x080485f9
1365e asm.esil=1
1366pdJ 1 @ 0x080483ec
1367e asm.cmt.right=1
1368pdJ 1 @ 0x080483ec
1369EOF
1370EXPECT=<<EOF
1371[{"offset":134514169,"arrow":134514133,"text":"|       `=< 0x080485f9      72da           if (((unsigned) var) < 0) goto 0x80485d5"}]
1372[{"offset":134513644,"text":"            ; sym.imp.__libc_start_main"},{"offset":134513644,"text":"            ; int __libc_start_main(func main, int argc, char **ubp_av, func init, func fini, func rtld_fini, void *stack_end)"},{"offset":134513644,"text":"            0x080483ec      e873ffffff     134513508,eip,4,esp,-=,esp,=[],eip,="}]
1373[{"offset":134513644,"text":"            0x080483ec      e873ffffff     134513508,eip,4,esp,-=,esp,=[],eip,= ; sym.imp.__libc_start_main ; int __libc_start_main(func main, int argc, char **ubp_av, func init, func fini, func rtld_fini, void *stack_end)"}]
1374EOF
1375RUN
1376
1377NAME=pdJ asm.emu=1 comment
1378FILE=bins/elf/crackme0x05
1379CMDS=<<EOF
1380e asm.emu=1
1381pdJ 1 @ 0x08048566
1382EOF
1383EXPECT=<<EOF
1384[{"offset":134514022,"text":"            0x08048566      e829feffff     call sym.imp.printf         ; esp=0xfffffffffffffffc ; eip=0x8048394 -> 0xa00c25ff"},{"offset":134514022,"text":"                                                                       ; int printf(-1)"}]
1385EOF
1386RUN
1387
1388NAME=pdJ asm.emu=1 string
1389FILE=bins/elf/crackme0x00b
1390CMDS=<<EOF
1391s 0x080484aa
1392e asm.emu=1
1393e scr.color=0
1394pd 1
1395pdJ 1
1396e scr.color=1
1397pd 1
1398pdJ 1
1399EOF
1400EXPECT=<<EOF
1401            0x080484aa      b8e1850408     mov eax, 0x80485e1          ; eax=0x80485e1 "%ls"
1402[{"offset":134513834,"text":"            0x080484aa      b8e1850408     mov eax, 0x80485e1          ; eax=0x80485e1 \"%ls\""}]
1403            0x080484aa      b8e1850408     mov eax, 0x80485e1          ; eax=0x80485e1 "%ls"
1404[{"offset":134513834,"text":"            \u001b[32m0x080484aa\u001b[0m      \u001b[37mb8\u001b[37me1\u001b[37m85\u001b[37m04\u001b[37m08\u001b[0m     \u001b[37mmov\u001b[36m eax\u001b[0m,\u001b[36m\u001b[36m \u001b[33m0x80485e1\u001b[0m\u001b[0m\u001b[0m\u001b[31m          ; eax=0x80485e1 \u001b[7m\"%ls\"\u001b[27m\u001b[0m"}]
1405EOF
1406RUN
1407
1408NAME=pdJ asm.xrefs.fold asm.xrefs.max
1409FILE=-
1410CMDS=<<EOF
1411s 0
1412e asm.arch=x86
1413e asm.bits=64
1414axc 0 1
1415e asm.xrefs.fold=0
1416e asm.xrefs.max=5
1417pdJ 1
1418e asm.xrefs.fold=5
1419e asm.xrefs.max=0
1420pdJ 1
1421EOF
1422EXPECT=<<EOF
1423[{"offset":0,"text":"            ; XREFS: CODE 0x00000001  "},{"offset":0,"text":"            0x00000000      0000           add byte [rax], al"}]
1424[{"offset":0,"text":"            ; XREFS(1)"},{"offset":0,"text":"            0x00000000      0000           add byte [rax], al"}]
1425EOF
1426RUN
1427
1428NAME=pdJ escape flagname
1429FILE=bins/elf/crackme
1430CMDS=pdJ 1 @ 0x0040082f
1431EXPECT=<<EOF
1432[{"offset":4196399,"text":"            ;-- str.Password_Correct_:"},{"offset":4196399,"text":"            0x0040082f     .string \"Password Correct!\" ; len=18"}]
1433EOF
1434RUN
1435
1436NAME=pd0~{} - crash
1437FILE=-
1438CMDS=<<EOF
1439e scr.null =true
1440pd0~{}
1441EOF
1442EXPECT=<<EOF
1443EOF
1444RUN
1445
1446NAME=pI - crash
1447FILE=-
1448CMDS=<<EOF
1449e scr.null =true
1450pI 0x200
1451EOF
1452EXPECT=<<EOF
1453EOF
1454RUN
1455
1456NAME=pC - crash
1457FILE=-
1458CMDS=<<EOF
1459e scr.null =true
1460pC 0x200
1461EOF
1462EXPECT=<<EOF
1463EOF
1464RUN
1465
1466NAME=pd bin.str.purge
1467FILE=bins/elf/analysis/ls2
1468CMDS=<<EOF
1469e asm.bytes=false
1470s main
1471af
1472s 0x00404886
1473e bin.str.purge=false
1474pd 2
1475?e --1--
1476e bin.str.purge=true
1477pd 2
1478?e --2--
1479e bin.str.purge=0x4028a0
1480pd 2
1481?e --3--
1482e bin.str.purge=0x412420,0x4028a0
1483pd 2
1484?e --4--
1485e bin.str.purge=true
1486pd 1 @ 0x004028e0
1487pd 1 @ 0x00402abd
1488?e --5--
1489e bin.str.purge=true,0x414fbf
1490pd 1 @ 0x004028e0
1491pd 1 @ 0x00402abd
1492EOF
1493EXPECT=<<EOF
1494            0x00404886      mov rcx, 0x412420                          ; ' $A' ; "AWAVA\x89\xffAUATL\x8d%\xbe\x99 "
1495            0x0040488d      mov rdi, main                              ; section..text
1496                                                                       ; 0x4028a0 ; "AWAVAUATUS\x89\xfbH\x89\xf5H\x81\xec\x98\x03"
1497--1--
1498            0x00404886      mov rcx, 0x412420                          ; ' $A'
1499            0x0040488d      mov rdi, main                              ; section..text
1500                                                                       ; 0x4028a0
1501--2--
1502            0x00404886      mov rcx, 0x412420                          ; ' $A' ; "AWAVA\x89\xffAUATL\x8d%\xbe\x99 "
1503            0x0040488d      mov rdi, main                              ; section..text
1504                                                                       ; 0x4028a0
1505--3--
1506            0x00404886      mov rcx, 0x412420                          ; ' $A'
1507            0x0040488d      mov rdi, main                              ; section..text
1508                                                                       ; 0x4028a0
1509--4--
1510|           0x004028e0      mov esi, str._usr_share_locale             ; 0x414fbf ; "/usr/share/locale"
1511|           0x00402abd      mov edi, str.TABSIZE                       ; 0x414fe7
1512--5--
1513|           0x004028e0      mov esi, str._usr_share_locale             ; 0x414fbf
1514|           0x00402abd      mov edi, str.TABSIZE                       ; 0x414fe7
1515EOF
1516RUN
1517
1518NAME=pd, esil, emu.stroff and bin.str.purge
1519FILE=bins/elf/analysis/hello-android-mips
1520CMDS=<<EOF
1521e emu.str=true
1522s 0x0008049c
1523e bin.str.purge=
1524e emu.str.off=false
1525pd 2
1526?e ----
1527e emu.str.off=true
1528pd 2
1529?e ----
1530e bin.str.purge=0x80510
1531pd 2
1532EOF
1533EXPECT=<<EOF
1534            0x0008049c      0800023c       lui v0, 8                   ; segment.ehdr
1535            0x000804a0      10054424       addiu a0, v0, 0x510         ; "Hello World" sym..rodata
1536----
1537            0x0008049c      0800023c       lui v0, 8                   ; segment.ehdr
1538            0x000804a0      10054424       addiu a0, v0, 0x510         ; 0x80510 "Hello World" sym..rodata
1539----
1540            0x0008049c      0800023c       lui v0, 8                   ; segment.ehdr
1541            0x000804a0      10054424       addiu a0, v0, 0x510         ; sym..rodata
1542EOF
1543RUN
1544
1545NAME=emu.pre and double pd
1546FILE=bins/elf/analysis/hello-android-mips
1547CMDS=<<EOF
1548e emu.pre=true
1549e emu.str=true
1550f start @ 0x0008049c
1551s 0x000804a0
1552pd 1
1553pd 1  # should print the same as above
1554EOF
1555EXPECT=<<EOF
1556            0x000804a0      10054424       addiu a0, v0, 0x510         ; "Hello World" sym..rodata
1557            0x000804a0      10054424       addiu a0, v0, 0x510         ; "Hello World" sym..rodata
1558EOF
1559RUN
1560
1561NAME=pd @B
1562FILE=-
1563CMDS=<<EOF
1564e asm.functions=false
1565e asm.lines.bb=false
1566e asm.comments=false
1567e scr.color=0
1568e asm.arch=x86
1569e asm.bits=64
1570wx 83f803740e
1571af
1572pd 1 @B:0
1573pd 1 @B:1
1574pd 1 @B:-1
1575pd 1 @B:-2
1576EOF
1577EXPECT=<<EOF
15780x00000000      83f803         cmp eax, 3
15790x00000003      740e           je 0x13
15800x00000003      740e           je 0x13
15810x00000000      83f803         cmp eax, 3
1582EOF
1583RUN
1584
1585NAME=asm.bb.line
1586FILE=bins/elf/analysis/ls2
1587CMDS=<<EOF
1588e scr.utf8=false
1589e scr.color=0
1590e asm.bb.line=true
1591e asm.comments=false
1592s main
1593af
1594s 0x0040294b
1595pd 10
1596EOF
1597EXPECT=<<EOF
1598|           0x0040294b      c6059ea72100.  mov byte [0x0061d0f0], 0
1599|           0x00402952      83f802         cmp eax, 2
1600|       ,=< 0x00402955      0f8483080000   je 0x4031de
1601|       |   |
1602|       |   0x0040295b      83f803         cmp eax, 3
1603|      ,==< 0x0040295e      742f           je 0x40298f
1604|      ||   |
1605|      ||   0x00402960      83e801         sub eax, 1
1606|     ,===< 0x00402963      7405           je 0x40296a
1607|     |||   |
1608|     |||   0x00402965      e8b6f8ffff     call sym.imp.abort
1609|     |||   |
1610|     `---> 0x0040296a      bf01000000     mov edi, 1
1611|      ||   0x0040296f      e80cf9ffff     call sym.imp.isatty
1612EOF
1613RUN
1614
1615NAME=pd @a overwrites anal hints
1616FILE=bins/elf/analysis/ls-linux64
1617CMDS=<<EOF
1618e asm.comments=false
1619e asm.functions=false
1620e asm.lines.bb=false
1621e asm.flags=false
1622ahb 16
1623aha arm
1624pd 1
1625e anal.ignbithints=1
1626pd 1 @b:32
1627e anal.ignbithints=0
1628pd 1 @b:16
1629pd 1 @b:32
1630ah*
1631pd 1 @a:x86
1632ah*
1633pd 1 @a:x86:64
1634ah*
1635EOF
1636EXPECT=<<EOF
16370x00005c20      31ed4989       ldc p9, c8, [r1, -0x124]!
16380x00005c20      31ed4989       stmdbhi sb, {r0, r4, r5, r8, sl, fp, sp, lr, pc} ^
16390x00005c20      31ed4989       ldc p9, c8, [r1, -0x124]!
16400x00005c20      31ed4989       stmdbhi sb, {r0, r4, r5, r8, sl, fp, sp, lr, pc} ^
1641aha arm @ 0x5c20
1642ahb 16 @ 0x5c20
16430000:5c20     31ed           xor bp, bp
1644aha arm @ 0x5c20
1645ahb 16 @ 0x5c20
16460x00005c20      31ed           xor ebp, ebp
1647aha arm @ 0x5c20
1648ahb 16 @ 0x5c20
1649EOF
1650RUN
1651
1652NAME=pd bin.str.filter
1653FILE=bins/elf/analysis/ls2
1654CMDS=<<EOF
1655e asm.bytes=false
1656e asm.cmt.off=false
1657s 0x004028e0
1658e bin.str.filter=
1659pd 1
1660e bin.str.filter=U
1661pd 1
1662EOF
1663EXPECT=<<EOF
1664            0x004028e0      mov esi, str._usr_share_locale             ; "/usr/share/locale"
1665            0x004028e0      mov esi, str._usr_share_locale
1666EOF
1667RUN
1668
1669NAME=emu.str dup str/flag cmt fix
1670FILE=bins/elf/analysis/ls2
1671CMDS=<<EOF
1672e emu.str=true
1673e asm.sub.names=true
1674pd 1 @ 0x00402a5f
1675e asm.sub.names=false
1676pd 1 @ 0x00402a5f
1677EOF
1678EXPECT=<<EOF
1679            0x00402a5f      bfdf4f4100     mov edi, str.COLUMNS        ; 0x414fdf ; "COLUMNS"
1680            0x00402a5f      bfdf4f4100     mov edi, 0x414fdf           ; str.COLUMNS ; "COLUMNS"
1681EOF
1682RUN
1683
1684NAME=emu.strinv
1685FILE=bins/elf/redpill
1686CMDS=<<EOF
1687e scr.color=1
1688e asm.bytes=false
1689e emu.pre=true
1690e emu.str=true
1691e io.cache=true
1692wz abcdefghi @ 0x21f7
1693f abcdefghi @ 0x21f7
1694axd 0x21f7 @ 0x161d
1695e asm.cmt.right=true
1696e emu.str.inv=true
1697pd 1 @ 0x161d
1698e emu.str.inv=false
1699pd 1 @ 0x161d
1700?e
1701e asm.cmt.right=false
1702e emu.str.inv=true
1703pd 1 @ 0x161d
1704e emu.str.inv=false
1705pd 1 @ 0x161d
1706EOF
1707EXPECT=<<EOF
1708            0x0000161d      lea eax, [esi - abcdefghi]                 ; 0x21f7 ; "abcdefghi" ; "\n  Blue Pill" str._n__Blue_Pill
1709            0x0000161d      lea eax, [esi - abcdefghi]                 ; 0x21f7 ; "abcdefghi" ; "\n  Blue Pill" str._n__Blue_Pill
1710
1711            ; 0x21f7
1712            ; "abcdefghi"
1713               ; "\n  Blue Pill" str._n__Blue_Pill
1714            0x0000161d      lea eax, [esi - abcdefghi]
1715            ; 0x21f7
1716            ; "abcdefghi"
1717               ; "\n  Blue Pill" str._n__Blue_Pill
1718            0x0000161d      lea eax, [esi - abcdefghi]
1719EOF
1720RUN
1721
1722NAME=emu.strflag
1723FILE=bins/elf/redpill
1724CMDS=<<EOF
1725e asm.bytes=false
1726e emu.pre=true
1727e emu.str=true
1728e emu.str.flag=true
1729pd 1 @ 0x161d
1730e emu.str.flag=false
1731pd 1 @ 0x161d
1732pd 1 @ 0x1447
1733EOF
1734EXPECT=<<EOF
1735            0x0000161d      lea eax, [esi - 0x21f7]                    ; "\n  Blue Pill" str._n__Blue_Pill
1736            0x0000161d      lea eax, [esi - 0x21f7]                    ; "\n  Blue Pill"
1737            0x00001447      add esi, 0x2bb9                            ; section..got.plt
1738EOF
1739RUN
1740
1741NAME=ctrl chars
1742FILE=bins/elf/strenc-ctrlchars
1743CMDS=<<EOF
1744e asm.bytes=false
1745e asm.cmt.off=false
1746pd 1 @ 0x0040040b
1747EOF
1748EXPECT=<<EOF
1749            0x0040040b      mov edi, str.Control_chars:__b_v_f_n_r_t_a ; "Control chars: \b\v\f\n\r\t\a"
1750EOF
1751RUN
1752
1753NAME=data ref with no analop.ptr (#9610)
1754FILE=bins/firmware/main.bin
1755CMDS=<<EOF
1756f str.hello 12 @ 0x276
1757axd str.hello @ 0x260
1758pd 1 @ 0x260
1759EOF
1760EXPECT=<<EOF
1761            0x00000260      80e0           ldi r24, 0x00               ; 0x276 ; "hello world!"
1762EOF
1763RUN
1764
1765NAME=@b and @addr should coexist
1766FILE=bins/firmware/armthumb.bin
1767ARGS=-aarm -b32
1768CMDS=pd 1 @b:32 @0xc
1769EXPECT=<<EOF
1770            0x0000000c      01207047       ldrbmi r2, [r0, -r1]!
1771EOF
1772RUN
1773
1774NAME=ahb should not be deleted with @b (#9751)
1775FILE=bins/firmware/armthumb.bin
1776ARGS=-aarm -b32
1777CMDS=<<EOF
1778ahb 16 @0xc
1779ah*
1780pd 1 @b:32 @0xc
1781ah*
1782EOF
1783EXPECT=<<EOF
1784ahb 16 @ 0xc
1785            0x0000000c      01207047       ldrbmi r2, [r0, -r1]!
1786ahb 16 @ 0xc
1787EOF
1788RUN
1789
1790NAME=ahb should not override @b
1791FILE=bins/firmware/armthumb.bin
1792ARGS=-aarm -b32
1793CMDS=<<EOF
1794ahb 16 @0xc
1795pd 5 @b:32
1796EOF
1797EXPECT=<<EOF
1798            0x00000000      0000a0e1       mov r0, r0
1799            0x00000004      010000eb       bl 0x10
1800        @-> 0x00000008      feffffea       b 8
1801            0x0000000c      01207047       ldrbmi r2, [r0, -r1]!
1802            0x00000010      00c09fe5       ldr ip, [pc]                ; [0x18:4]=13 ; 24
1803EOF
1804RUN
1805
1806NAME=two-operand line highlight; asm.highlight ecHw fix; ec wordhl/linehl
1807FILE=bins/elf/redpill
1808CMDS=<<EOF
1809. scripts/palette.r2
1810e scr.color=3
1811e emu.str=true
1812e emu.pre=true
1813e emu.str.inv=false
1814e emu.str.flag=false
1815s 0x1457
1816e asm.highlight=$$
1817pd 3
1818e scr.color=1
1819pd 1
1820e scr.color=3
1821ec linehl none
1822pd 1
1823ec linehl rgb:002f00
1824pd 1
1825ec wordhl rgb:800
1826ecHw eax
1827e asm.highlight=0x1457
1828s 0
1829pd 1 @ 0x1457
1830EOF
1831EXPECT=<<EOF
1832            0x00001457      8d8689ddffff   lea eax, [esi - 0x2277]     ; " Take the Red Pill!! \n"
1833            0x0000145d      50             push eax
1834            0x0000145e      8b86f0ffffff   mov eax, dword [esi - 0x10]
1835            0x00001457      8d8689ddffff   lea eax, [esi - 0x2277]     ; " Take the Red Pill!! \n"
1836            0x00001457      8d8689ddffff   lea eax, [esi - 0x2277]     ; " Take the Red Pill!! \n"
1837            0x00001457      8d8689ddffff   lea eax, [esi - 0x2277]     ; " Take the Red Pill!! \n"
1838            0x00001457      8d8689ddffff   lea eax, [esi - 0x2277]     ; " Take the Red Pill!! \n"
1839EOF
1840RUN
1841
1842NAME=pdJ with backslashes, quotation marks, str.escbslash and bin.str.enc
1843FILE=-
1844CMDS=<<EOF
1845e io.cache=true
1846e asm.arch=x86
1847e asm.bits=32
1848e asm.bytes=false
1849s 0x1000
1850"wz path\"C:\\Program\n"
1851f ansi_str
1852s 0x2000
1853"wa mov eax, 0x1000"
1854e str.escbslash=true
1855pd 1
1856pdJ 1
1857e str.escbslash=false
1858pd 1
1859pdJ 1
1860s 0x3000
1861"ww path\"C:\\Program\r"
1862f wide_str
1863s 0x4000
1864"wa mov ebx, 0x3000"
1865e bin.str.enc=guess
1866pd 1
1867pdJ 1
1868e bin.str.enc=latin1
1869pd 1
1870pdJ 1
1871e bin.str.enc=utf16le
1872e str.escbslash=true
1873pd 1
1874pdJ 1
1875e str.escbslash=false
1876pd 1
1877pdJ 1
1878EOF
1879EXPECT=<<EOF
1880            0x00002000      mov eax, 0x1000                            ; ansi_str ; "path\"C:\\Program\n"
1881[{"offset":8192,"text":"            0x00002000      mov eax, 0x1000                            ; ansi_str ; \"path\\\"C:\\\\Program\\n\""}]
1882            0x00002000      mov eax, 0x1000                            ; ansi_str ; "path\"C:\Program\n"
1883[{"offset":8192,"text":"            0x00002000      mov eax, 0x1000                            ; ansi_str ; \"path\\\"C:\\Program\\n\""}]
1884            0x00004000      mov ebx, 0x3000                            ; wide_str ; u"path\"C:\Program\r"
1885[{"offset":16384,"text":"            0x00004000      mov ebx, 0x3000                            ; wide_str ; u\"path\\\"C:\\Program\\r\""}]
1886            0x00004000      mov ebx, 0x3000                            ; wide_str ; "p"
1887[{"offset":16384,"text":"            0x00004000      mov ebx, 0x3000                            ; wide_str ; \"p\""}]
1888            0x00004000      mov ebx, 0x3000                            ; wide_str ; u"path\"C:\\Program\r"
1889[{"offset":16384,"text":"            0x00004000      mov ebx, 0x3000                            ; wide_str ; u\"path\\\"C:\\\\Program\\r\""}]
1890            0x00004000      mov ebx, 0x3000                            ; wide_str ; u"path\"C:\Program\r"
1891[{"offset":16384,"text":"            0x00004000      mov ebx, 0x3000                            ; wide_str ; u\"path\\\"C:\\Program\\r\""}]
1892EOF
1893RUN
1894
1895NAME=arm asm.sub.var, asm.ucase and asm.pseudo (fp)
1896FILE=bins/elf/analysis/armcall
1897CMDS=<<EOF
1898e asm.bytes=false
1899e asm.comments=false
1900e io.cache=true
1901wv4 0xe59b0008 @ 0x00010464
1902wv4 0xe59b100c @ 0x00010468
1903af @ main
1904e asm.pseudo=false
1905e asm.sub.var=true
1906e asm.ucase=true
1907pd 4 @ 0x0001045c
1908?e
1909e asm.sub.var=false
1910e asm.ucase=false
1911pd 4 @ 0x0001045c
1912?e
1913e asm.pseudo=true
1914e asm.sub.var=true
1915e asm.sub.varonly=false
1916pd 4 @ 0x0001045c
1917?e
1918e asm.sub.varonly=true
1919s main
1920afvn local2 var_ch
1921afvn arg1 arg_8h
1922pd 4 @ 0x0001045c
1923EOF
1924EXPECT=<<EOF
1925|           0x0001045c      STR R0, [var_8h]
1926|           0x00010460      STR R1, [var_ch]
1927|           0x00010464      LDR R0, [arg_8h]
1928|           0x00010468      LDR R1, [arg_ch]
1929
1930|           0x0001045c      str r0, [fp, -8]
1931|           0x00010460      str r1, [fp, -0xc]
1932|           0x00010464      ldr r0, [fp, 8]
1933|           0x00010468      ldr r1, [fp, 0xc]
1934
1935|           0x0001045c      [fp - var_8h] = r0
1936|           0x00010460      [fp - var_ch] = r1
1937|           0x00010464      r0 = [fp + arg_8h]
1938|           0x00010468      r1 = [fp + arg_ch]
1939
1940|           0x0001045c      [var_8h] = r0
1941|           0x00010460      [local2] = r1
1942|           0x00010464      r0 = [arg1]
1943|           0x00010468      r1 = [arg_ch]
1944EOF
1945RUN
1946
1947NAME=pdfj with padding
1948FILE=bins/elf/padding_in_func
1949CMDS=<<EOF
1950s main
1951af
1952pdfj~{} | grep opcode
1953EOF
1954EXPECT=<<EOF
1955      "opcode": "push rbp",
1956      "opcode": "push rbx",
1957      "opcode": "push rax",
1958      "opcode": "mov ebx, edi",
1959      "opcode": "cmp ebx, 2",
1960      "opcode": "mov eax, 0x5758554a",
1961      "opcode": "mov ebp, 0x10c2377a",
1962      "opcode": "cmovl ebp, eax",
1963      "opcode": "mov eax, 0xbaad0c8f",
1964      "opcode": "cmp eax, 0xccdab13a",
1965      "opcode": "jg 0x40058a",
1966      "opcode": "jmp 0x4005ae",
1967      "opcode": "mov edi, 0x400664",
1968      "opcode": "xor eax, eax",
1969      "opcode": "mov esi, ebx",
1970      "opcode": "call 0x400440",
1971      "opcode": "mov eax, 0xccdab13b",
1972      "opcode": "cmp eax, 0xccdab13a",
1973      "opcode": "jle 0x4005ae",
1974      "opcode": "cmp eax, 0x10c2377a",
1975      "opcode": "je 0x400570",
1976      "opcode": "cmp eax, 0x5758554a",
1977      "opcode": "jne 0x4005b9",
1978      "opcode": "mov edi, 0x40066d",
1979      "opcode": "call 0x400430",
1980      "opcode": "mov eax, 0xccdab13b",
1981      "opcode": "cmp eax, 0xccdab13a",
1982      "opcode": "jg 0x40058a",
1983      "opcode": "cmp eax, 0xbaad0c8f",
1984      "opcode": "mov eax, ebp",
1985      "opcode": "je 0x400583",
1986      "opcode": "jmp 0x4005d0",
1987      "opcode": "cmp eax, 0xccdab13b",
1988      "opcode": "jne 0x4005d0",
1989      "opcode": "xor eax, eax",
1990      "opcode": "add rsp, 8",
1991      "opcode": "pop rbx",
1992      "opcode": "pop rbp",
1993      "opcode": "ret",
1994      "opcode": "jmp 0x4005d0",
1995EOF
1996RUN
1997
1998NAME=asm.imm.str, mov and movabs (#10473)
1999FILE=bins/elf/echo-bin
2000CMDS=<<EOF
2001e asm.bytes=false
2002e asm.imm.str=true
2003pd 1 @ 0x9a2
2004pd 1 @ 0x9a9
2005pd 1 @ 0x9b3
2006EOF
2007EXPECT=<<EOF
2008            0x000009a2      mov dword [rbp - 0x30], 0x3c3c2b3e         ; '>+<<'
2009            0x000009a9      mov word [rbp - 0x2c], 0x3e5d              ; ']>'
2010            0x000009b3      movabs rax, 0x3c2b3c3c5b3e3e3e             ; '>>>[<<+<'
2011EOF
2012RUN
2013
2014NAME=asm.imm.str, asm.cmd.right=false, pd and pdJ
2015FILE=bins/elf/echo-bin
2016CMDS=<<EOF
2017e asm.imm.str=true
2018e asm.cmt.right=false
2019pd 1 @ 0x9b3
2020?e
2021pdJ 1 @ 0x9b3
2022EOF
2023EXPECT=<<EOF
2024            ; '>>>[<<+<'
2025            0x000009b3      48b83e3e3e5b.  movabs rax, 0x3c2b3c3c5b3e3e3e
2026
2027[{"offset":2483,"text":"            ; '>>>[<<+<'"},{"offset":2483,"text":"            0x000009b3      48b83e3e3e5b.  movabs rax, 0x3c2b3c3c5b3e3e3e"}]
2028EOF
2029RUN
2030
2031NAME=asm.imm.str short false positive
2032FILE=bins/elf/analysis/fast
2033CMDS=<<EOF
2034e asm.bytes=false
2035e asm.imm.str=true
2036f- @ 0x08048574
2037pd 1 @ 0x08048444
2038EOF
2039EXPECT=<<EOF
2040            0x08048444      push 0x8048574
2041EOF
2042RUN
2043
2044NAME=asm.imm.str and flag
2045FILE=bins/elf/strenc
2046CMDS=<<EOF
2047e asm.bytes=false
2048e asm.imm.str=true
2049e bin.str.enc=utf16le
2050pd 1 @ 0x004016ca
2051f str.fence @ 0x40235a
2052e asm.cmt.off=false
2053pd 1 @ 0x004016ca
2054EOF
2055EXPECT=<<EOF
2056            0x004016ca      mov edi, str.__B__                         ; 0x40235a ; u"\u2520\u2542-\u2500-\u2500\u2542\u2528 is a fence with embedded double zeros\n"
2057            0x004016ca      mov edi, str.__B__                         ; str.fence ; u"\u2520\u2542-\u2500-\u2500\u2542\u2528 is a fence with embedded double zeros\n"
2058EOF
2059RUN
2060
2061NAME=#10989 double pre-disasm
2062FILE=bins/elf/echo-bin
2063CMDS=<<EOF
2064e asm.bytes=false
2065e asm.cmt.right=false
2066pd 1 @ 0xe78
2067EOF
2068EXPECT=<<EOF
2069            ; 'f'
2070            0x00000e78      mov byte [rbp - 0x274e], 0x66
2071EOF
2072RUN
2073
2074NAME=pdf show entry0 disasm instead of main
2075FILE=bins/elf/ls
2076CMDS=<<EOF
2077aa
2078pdf
2079EOF
2080EXPECT=<<EOF
2081/ 46: entry0 (int64_t arg3);
2082|           ; arg int64_t arg3 @ rdx
2083|           0x00005ae0      f30f1efa       endbr64
2084|           0x00005ae4      31ed           xor ebp, ebp
2085|           0x00005ae6      4989d1         mov r9, rdx                 ; arg3
2086|           0x00005ae9      5e             pop rsi
2087|           0x00005aea      4889e2         mov rdx, rsp
2088|           0x00005aed      4883e4f0       and rsp, 0xfffffffffffffff0
2089|           0x00005af1      50             push rax
2090|           0x00005af2      54             push rsp
2091|           0x00005af3      4c8d05660c01.  lea r8, [0x00016760]
2092|           0x00005afa      488d0def0b01.  lea rcx, [0x000166f0]
2093|           0x00005b01      488d3d68e5ff.  lea rdi, [main]             ; 0x4070 ; "AWAVAUATU\x89\xfdSH\x89\xf3H\x83\xecXH\x8b>dH\x8b\x04%("
2094\           0x00005b08      ff150ac30100   call qword [reloc.__libc_start_main] ; [0x21e18:8]=0
2095EOF
2096RUN
2097
2098NAME=asm.lines.ret, pd and pdJ
2099FILE=bins/elf/crackme0x05
2100CMDS=<<EOF
2101e asm.lines.ret=1
2102s 0x08048414
2103pd 2
2104?e
2105pdJ 2
2106EOF
2107EXPECT=<<EOF
2108            0x08048414      c3             ret
2109            ; --------------------------------------
2110            0x08048415      90             nop
2111
2112[{"offset":134513684,"text":"            0x08048414      c3             ret"},{"offset":134513684,"text":"            ; --------------------------------------"},{"offset":134513685,"text":"            0x08048415      90             nop"}]
2113EOF
2114RUN
2115
2116
2117NAME=disassemble PE with asm.flags.real enabled
2118FILE=bins/pe/ConsoleApplication1.exe
2119CMDS=<<EOF
2120e asm.flags.real=true
2121pi 10
2122EOF
2123EXPECT=<<EOF
2124call 0x401836
2125jmp 0x401322
2126push ebp
2127mov ebp, esp
2128push 0
2129call dword [SetUnhandledExceptionFilter]
2130push dword [ebp + 8]
2131call dword [UnhandledExceptionFilter]
2132push 0xc0000409
2133call dword [GetCurrentProcess]
2134EOF
2135RUN
2136
2137NAME=direct call without fcn + asm.flags.real
2138FILE=bins/elf/crackme0x05
2139CMDS=<<EOF
2140e asm.flags.real=false
2141pd 1 @ 0x8048566
2142e asm.flags.real=true
2143pd 1 @ 0x8048566
2144aaa
2145afl~printf
2146e asm.flags.real=false
2147pd 1 @ 0x8048566
2148e asm.flags.real=true
2149pd 1 @ 0x8048566
2150EOF
2151EXPECT=<<EOF
2152            0x08048566      e829feffff     call sym.imp.printf
2153            0x08048566      e829feffff     call printf                 ; sym.imp.printf
21540x08048394    1 6            sym.imp.printf
2155|           0x08048566      e829feffff     call sym.imp.printf         ; int printf(const char *format)
2156|           0x08048566      e829feffff     call printf                 ; sym.imp.printf ; int printf(const char *format)
2157EOF
2158RUN
2159
2160NAME=pd grep chain
2161FILE=malloc://8
2162CMDS=<<EOF
2163e asm.arch=x86
2164e asm.bits=64
2165wx 90905152539090 ; pd 7 ~&5,push
2166EOF
2167EXPECT=<<EOF
2168            0x00000002      51             push rcx
2169            0x00000003      52             push rdx
2170            0x00000004      53             push rbx
2171EOF
2172RUN
2173
2174NAME=pd grep chain fail
2175FILE=malloc://8
2176CMDS=<<EOF
2177e asm.arch=x86
2178e asm.bits=64
2179wx 90905152539090 ; pd 7 ~ 5 ~ push
2180EOF
2181EXPECT=<<EOF
2182EOF
2183RUN
2184
2185NAME=print fcn header without asm.flags.real
2186FILE=bins/elf/crackme0x05
2187CMDS=<<EOF
2188e asm.flags.real=false
2189e asm.lines.fcn=false
2190aaa
2191pdf @ 0x08048484~:1
2192EOF
2193EXPECT=<<EOF
219466: sym.parell (char *s);
2195EOF
2196RUN
2197
2198
2199NAME=print fcn header with asm.flags.real
2200FILE=bins/elf/crackme0x05
2201CMDS=<<EOF
2202e asm.flags.real=true
2203e asm.lines.fcn=false
2204aaa
2205pdf @ 0x08048484~:1
2206EOF
2207EXPECT=<<EOF
220866: parell (char *s);
2209EOF
2210RUN
2211
2212NAME=asm.imm.trim
2213FILE=bins/elf/crackme0x05
2214CMDS=<<EOF
2215s 0x080483d5
2216pi 1 @e:asm.imm.trim=false
2217pi 1 @e:asm.imm.trim=true
2218EOF
2219EXPECT=<<EOF
2220and esp, 0xfffffff0
2221and esp,
2222EOF
2223RUN
2224