NAME=Open LE cdogs.exe
FILE=bins/le/cdogs.exe
CMDS=iH~Signature[1]
EXPECT=<<EOF
LE
EOF
RUN

NAME=cdogs.exe entrypoint
FILE=bins/le/cdogs.exe
CMDS=ie~:1[1]
EXPECT=<<EOF
0x00026058
EOF
RUN

NAME=cdogs.exe sections
FILE=bins/le/cdogs.exe
CMDS=iS
EXPECT=<<EOF
[Sections]

nth paddr         size vaddr         vsize perm type name
---------------------------------------------------------
0   0x0000d200  0x1000 0x00010000   0x1000 -r-x ---- obj.1.page.0
1   0x0000e200  0x1000 0x00011000   0x1000 -r-x ---- obj.1.page.1
2   0x0000f200  0x1000 0x00012000   0x1000 -r-x ---- obj.1.page.2
3   0x00010200  0x1000 0x00013000   0x1000 -r-x ---- obj.1.page.3
4   0x00011200  0x1000 0x00014000   0x1000 -r-x ---- obj.1.page.4
5   0x00012200  0x1000 0x00015000   0x1000 -r-x ---- obj.1.page.5
6   0x00013200  0x1000 0x00016000   0x1000 -r-x ---- obj.1.page.6
7   0x00014200  0x1000 0x00017000   0x1000 -r-x ---- obj.1.page.7
8   0x00015200  0x1000 0x00018000   0x1000 -r-x ---- obj.1.page.8
9   0x00016200  0x1000 0x00019000   0x1000 -r-x ---- obj.1.page.9
10  0x00017200  0x1000 0x0001a000   0x1000 -r-x ---- obj.1.page.10
11  0x00018200  0x1000 0x0001b000   0x1000 -r-x ---- obj.1.page.11
12  0x00019200  0x1000 0x0001c000   0x1000 -r-x ---- obj.1.page.12
13  0x0001a200  0x1000 0x0001d000   0x1000 -r-x ---- obj.1.page.13
14  0x0001b200  0x1000 0x0001e000   0x1000 -r-x ---- obj.1.page.14
15  0x0001c200  0x1000 0x0001f000   0x1000 -r-x ---- obj.1.page.15
16  0x0001d200  0x1000 0x00020000   0x1000 -r-x ---- obj.1.page.16
17  0x0001e200  0x1000 0x00021000   0x1000 -r-x ---- obj.1.page.17
18  0x0001f200  0x1000 0x00022000   0x1000 -r-x ---- obj.1.page.18
19  0x00020200  0x1000 0x00023000   0x1000 -r-x ---- obj.1.page.19
20  0x00021200  0x1000 0x00024000   0x1000 -r-x ---- obj.1.page.20
21  0x00022200  0x1000 0x00025000   0x1000 -r-x ---- obj.1.page.21
22  0x00023200  0x1000 0x00026000   0x1000 -r-x ---- obj.1.page.22
23  0x00024200  0x1000 0x00027000   0x1000 -r-x ---- obj.1.page.23
24  0x00025200  0x1000 0x00028000   0x1000 -r-x ---- obj.1.page.24
25  0x00026200  0x1000 0x00029000   0x1000 -r-x ---- obj.1.page.25
26  0x00027200  0x1000 0x0002a000   0x1000 -r-x ---- obj.1.page.26
27  0x00028200  0x1000 0x0002b000   0x1000 -r-x ---- obj.1.page.27
28  0x00029200  0x1000 0x0002c000   0x1000 -r-x ---- obj.1.page.28
29  0x0002a200  0x1000 0x0002d000   0x1000 -r-x ---- obj.1.page.29
30  0x0002b200  0x1000 0x0002e000   0x1000 -r-x ---- obj.1.page.30
31  0x0002c200  0x1000 0x0002f000   0x1000 -r-x ---- obj.1.page.31
32  0x0002d200  0x1000 0x00030000   0x1000 -r-x ---- obj.1.page.32
33  0x0002e200  0x1000 0x00031000   0x1000 -r-x ---- obj.1.page.33
34  0x0002f200  0x1000 0x00032000   0x1000 -r-x ---- obj.1.page.34
35  0x00030200  0x1000 0x00033000   0x1000 -r-x ---- obj.1.page.35
36  0x00031200  0x1000 0x00034000   0x1000 -r-x ---- obj.1.page.36
37  0x00032200  0x1000 0x00035000   0x1000 -r-x ---- obj.1.page.37
38  0x00033200  0x1000 0x00036000   0x1000 -r-x ---- obj.1.page.38
39  0x00034200  0x1000 0x00037000   0x1000 -r-x ---- obj.1.page.39
40  0x00035200  0x1000 0x00038000   0x1000 -r-x ---- obj.1.page.40
41  0x00036200  0x1000 0x00039000   0x1000 -r-x ---- obj.1.page.41
42  0x00037200  0x1000 0x0003a000   0x1000 -r-x ---- obj.1.page.42
43  0x00038200  0x1000 0x0003b000   0x1000 -r-x ---- obj.1.page.43
44  0x00039200   0x2ef 0x0003c000    0x2ef -r-x ---- obj.1.page.44
45  0x0003a200  0x1000 0x00040000   0x1000 -rw- ---- obj.2.page.0
46  0x0003b200  0x1000 0x00041000   0x1000 -rw- ---- obj.2.page.1
47  0x0003c200  0x1000 0x00042000   0x1000 -rw- ---- obj.2.page.2
48  0x0003d200  0x1000 0x00043000   0x1000 -rw- ---- obj.2.page.3
49  0x0003e200  0x1000 0x00044000   0x1000 -rw- ---- obj.2.page.4
50  0x0003f200  0x1000 0x00045000   0x1000 -rw- ---- obj.2.page.5
51  0x00040200  0x1000 0x00046000   0x1000 -rw- ---- obj.2.page.6
52  0x00041200  0x1000 0x00047000   0x1000 -rw- ---- obj.2.page.7
53  0x00042200  0x1000 0x00048000   0x1000 -rw- ---- obj.2.page.8
54  0x00043200  0x1000 0x00049000   0x1000 -rw- ---- obj.2.page.9
55  0x00044200  0x1000 0x0004a000   0x1000 -rw- ---- obj.2.page.10
56  0x00045200  0x1000 0x0004b000   0x1000 -rw- ---- obj.2.page.11
57  0x00046200  0x1000 0x0004c000   0x1000 -rw- ---- obj.2.page.12
58  0x00047200  0x1000 0x0004d000   0x1000 -rw- ---- obj.2.page.13
59  0x00048200  0x1000 0x0004e000   0x1000 -rw- ---- obj.2.page.14
60  0x00049200   0xd8c 0x0004f000   0x1000 -rw- ---- obj.2.page.15
61  0x00000000     0x0 0x00050000  0x16030 -rw- ---- obj.2.page.zerofill

EOF
RUN

NAME=cdogs.exe relocations
FILE=bins/le/cdogs.exe
CMDS=<<EOF
ir > $relocs
cat $relocs~?
cat $relocs~0x00010~?
cat $relocs~0x00011~?
cat $relocs~0x00012~?
cat $relocs~0x00013~?
cat $relocs~0x00014~?
cat $relocs~0x00015~?
cat $relocs~0x00016~?
cat $relocs~0x00017~?
cat $relocs~0x00018~?
cat $relocs~0x00019~?
cat $relocs~0x0001a~?
cat $relocs~0x0001b~?
cat $relocs~0x0001c~?
cat $relocs~0x0001d~?
cat $relocs~0x0001e~?
cat $relocs~0x0001f~?
cat $relocs~0x00020~?
cat $relocs~0x00021~?
cat $relocs~0x00022~?
cat $relocs~0x00023~?
cat $relocs~0x00024~?
cat $relocs~0x00025~?
cat $relocs~0x00026~?
cat $relocs~0x00027~?
cat $relocs~0x00028~?
cat $relocs~0x00029~?
cat $relocs~0x0002a~?
cat $relocs~0x0002b~?
cat $relocs~0x0002c~?
cat $relocs~0x0002d~?
cat $relocs~0x0002e~?
cat $relocs~0x0002f~?
cat $relocs~0x00030~?
cat $relocs~0x00031~?
cat $relocs~0x00032~?
cat $relocs~0x00033~?
cat $relocs~0x00034~?
cat $relocs~0x00035~?
cat $relocs~0x00036~?
cat $relocs~0x00037~?
cat $relocs~0x00038~?
cat $relocs~0x00039~?
cat $relocs~0x0003a~?
cat $relocs~0x0003b~?
cat $relocs~0x0003c~?
cat $relocs~0x0003d~?
cat $relocs~0x0003e~?
cat $relocs~0x0003f~?
cat $relocs~0x00040~?
cat $relocs~0x00041~?
cat $relocs~0x00042~?
cat $relocs~0x00043~?
cat $relocs~0x00044~?
cat $relocs~0x00045~?
cat $relocs~0x00046~?
cat $relocs~0x00047~?
cat $relocs~0x00048~?
cat $relocs~0x00049~?
cat $relocs~0x0004a~?
cat $relocs~0x0004b~?
cat $relocs~0x0004c~?
cat $relocs~0x0004d~?
cat $relocs~0x0004e~?
cat $relocs~0x0004f~?
EOF
EXPECT=<<EOF
5239
151
160
102
133
208
172
337
212
143
325
262
174
219
305
296
330
260
322
409
186
415
502
181
307
380
113
85
240
124
198
179
186
222
159
110
318
274
24
366
356
179
103
128
157
128
8
0
0
282
533
670
17
2
0
0
95
81
45
6
0
0
381
561
588
EOF
RUN

NAME=Open LX GCC.EXE
FILE=bins/le/GCC.EXE
CMDS=iH~Signature[1]
EXPECT=<<EOF
LX
EOF
RUN

NAME=GCC.EXE entrypoint
FILE=bins/le/GCC.EXE
CMDS=ie~:1[1]
EXPECT=<<EOF
0x00010000
EOF
RUN

NAME=GCC.EXE sections
FILE=bins/le/GCC.EXE
CMDS=iS
EXPECT=<<EOF
[Sections]

nth paddr         size vaddr           vsize perm type name
-----------------------------------------------------------
0   0x00001000  0x1000 0x00010000     0x1000 -r-x ---- obj.1.page.0
1   0x00002000  0x1000 0x00011000     0x1000 -r-x ---- obj.1.page.1
2   0x00003000  0x1000 0x00012000     0x1000 -r-x ---- obj.1.page.2
3   0x00004000  0x1000 0x00013000     0x1000 -r-x ---- obj.1.page.3
4   0x00005000  0x1000 0x00014000     0x1000 -r-x ---- obj.1.page.4
5   0x00006000  0x1000 0x00015000     0x1000 -r-x ---- obj.1.page.5
6   0x00007000  0x1000 0x00016000     0x1000 -r-x ---- obj.1.page.6
7   0x00008000  0x1000 0x00017000     0x1000 -r-x ---- obj.1.page.7
8   0x00009000  0x1000 0x00018000     0x1000 -r-x ---- obj.1.page.8
9   0x0000a000  0x1000 0x00019000     0x1000 -r-x ---- obj.1.page.9
10  0x0000b000  0x1000 0x0001a000     0x1000 -r-x ---- obj.1.page.10
11  0x0000c000  0x1000 0x0001b000     0x1000 -r-x ---- obj.1.page.11
12  0x0000d000  0x1000 0x0001c000     0x1000 -r-x ---- obj.1.page.12
13  0x0000e000  0x1000 0x0001d000     0x1000 -r-x ---- obj.1.page.13
14  0x0000f000  0x1000 0x0001e000     0x1000 -r-x ---- obj.1.page.14
15  0x00010000  0x1000 0x00020000     0x1000 -rw- ---- obj.2.page.0
16  0x00000000     0x0 0x00021000     0x1804 -rw- ---- obj.2.page.zerofill
17  0x00000000     0x0 0x00030000  0x2000000 -rw- ---- obj.3
18  0x00000000     0x0 0x02030000   0x800000 -rw- ---- obj.4

EOF
RUN

NAME=GCC.EXE relocations
FILE=bins/le/GCC.EXE
CMDS=ir
EXPECT=<<EOF
[Relocations]

vaddr      paddr      type   ntype name
---------------------------------------
0x00010006 0x00001006 SET_32 8     emx.1
0x0001000d 0x0000100d SET_32 8     emx.2
0x0001d210 0x0000e210 SET_32 8     doscalls.273
0x0001d234 0x0000e234 SET_32 8     doscalls.253
0x0001d266 0x0000e266 SET_32 8     doscalls.283
0x0001d282 0x0000e282 SET_32 8     doscalls.229
0x0001d2f2 0x0000e2f2 SET_32 8     doscalls.257
0x0001d389 0x0000e389 SET_32 8     doscalls.282
0x0001d39f 0x0000e39f SET_32 8     doscalls.257
0x0001d3d9 0x0000e3d9 SET_32 8     doscalls.281
0x0001d3f4 0x0000e3f4 SET_32 8     doscalls.257


11 relocations
EOF
RUN

NAME=GCC.EXE linked libs
FILE=bins/le/GCC.EXE
CMDS=il
EXPECT=<<EOF
[Linked libraries]
emx
doscalls

2 libraries
EOF
RUN

NAME=Open LX GNUGREP.DLL
FILE=bins/le/GNUGREP.DLL
CMDS=iH~Signature[1]
EXPECT=<<EOF
LX
EOF
RUN

NAME=GNUGREP.DLL entrypoint
FILE=bins/le/GNUGREP.DLL
CMDS=ie~:1[1]
EXPECT=<<EOF
0x00010000
EOF
RUN

NAME=GNUGREP.DLL symbol
FILE=bins/le/GNUGREP.DLL
CMDS=is
EXPECT=<<EOF
[Symbols]
nth paddr      vaddr      bind   type size lib name     demangled
-----------------------------------------------------------------
1   0x00000000 0x00010ddc GLOBAL FUNC 0        grepmain
EOF
RUN

NAME=GNUGREP.DLL sections
FILE=bins/le/GNUGREP.DLL
CMDS=iS
EXPECT=<<EOF
[Sections]

nth paddr         size vaddr        vsize perm type name
--------------------------------------------------------
0   0x00001600  0x1000 0x00010000  0x1000 -r-x ---- obj.1.page.0
1   0x00002600  0x1000 0x00011000  0x1000 -r-x ---- obj.1.page.1
2   0x00003600  0x1000 0x00012000  0x1000 -r-x ---- obj.1.page.2
3   0x00004600  0x1000 0x00013000  0x1000 -r-x ---- obj.1.page.3
4   0x00005600  0x1000 0x00014000  0x1000 -r-x ---- obj.1.page.4
5   0x00006600  0x1000 0x00015000  0x1000 -r-x ---- obj.1.page.5
6   0x00007600  0x1000 0x00016000  0x1000 -r-x ---- obj.1.page.6
7   0x00008600   0xc10 0x00017000   0xc10 -r-x ---- obj.1.page.7
8   0x00009400     0x8 0x00020000     0x8 -r-x ---- obj.2.page.0
9   0x00009600     0x8 0x00030000     0x8 -r-x ---- obj.3.page.0
10  0x00001400   0x200 0x00040000   0x824 -rw- ---- obj.4.page.0

EOF
RUN

NAME=GNUGREP.DLL linked libs
FILE=bins/le/GNUGREP.DLL
CMDS=il
EXPECT=<<EOF
[Linked libraries]
GNUREGEX
EMXLIBC
emx

3 libraries
EOF
RUN

NAME=GNUGREP.DLL relocations
FILE=bins/le/GNUGREP.DLL
CMDS=<<EOF
ir > $relocs
cat $relocs~?
cat $relocs~GNUREGEX~?
cat $relocs~EMXLIBC~?
cat $relocs~emx~?
EOF
EXPECT=<<EOF
1170
8
183
1
EOF
RUN

NAME=DOOM.LE iS. by vaddr
FILE=bins/le/DOOM.LE
CMDS=<<EOF
?v $$
iS.~obj.1.page.45
EOF
EXPECT=<<EOF
0x3dde0
0   0x00041148  0x1000 0x0003d000  0x1000 -r-x ---- obj.1.page.45
EOF
RUN

NAME=DOOM.LE patched relocs
ARGS=-e bin.relocs.apply=true
FILE=bins/le/DOOM.LE
CMDS=<<EOF
s 0x0001ef2d
pd~debug~?
pd 6~w~?
pi 1 @ 0x0003b144
pi 1 @ 0x0003b175
pxwj 4@0xbc518
pxwj 4@0xbc534
iS.@0xbc518~obj.2.page.zerofill~?
iS.@0xbc534~obj.2.page.zerofill~?
EOF
EXPECT=<<EOF
1
1
mov ecx, dword [0xbc518]
mov ecx, dword [0xbc534]
[0]
[0]
1
1
EOF
RUN

NAME=DOOM.LE object bases
ENV=RABIN2_LE_BASES=0x1db000:0x27f000
ARGS=-e bin.relocs.apply=true
FILE=bins/le/DOOM.LE
CMDS=<<EOF
s 0x0001e9f2d
pd~debug~?
pd 6~w~?
pi 1 @ 0x206144
pi 1 @ 0x206175
pxwj 4@0x2eb518
pxwj 4@0x2eb534
iS.@0x2eb518~obj.2.page.zerofill~?
iS.@0x2eb534~obj.2.page.zerofill~?
EOF
EXPECT=<<EOF
1
1
mov ecx, dword [0x2eb518]
mov ecx, dword [0x2eb534]
[0]
[0]
1
1
EOF
RUN
