-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinfo_win.c
659 lines (617 loc) · 13.8 KB
/
info_win.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
/**
* @namespace biew
* @file info_win.c
* @brief This file contains information interface of BIEW project.
* @version -
* @remark this source file is part of Binary vIEW project (BIEW).
* The Binary vIEW (BIEW) is copyright (C) 1995 Nickols_K.
* All rights reserved. This software is redistributable under the
* licence given in the file "Licence.en" ("Licence.ru" in russian
* translation) distributed in the BIEW archive.
* @note Requires POSIX compatible development system
*
* @author Nickols_K
* @since 1995
* @note Development, fixes and improvements
* @author Mauro Giachero
* @date 02.11.2007
* @note Added ASSEMBle option to casmtext
**/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "colorset.h"
#include "bmfile.h"
#include "tstrings.h"
#include "reg_form.h"
#include "bconsole.h"
#include "beyeutil.h"
#include "beyehelp.h"
#include "libbeye/kbd_code.h"
#include "libbeye/beyelib.h"
static void __NEAR__ __FASTCALL__ ShowFunKey(const char * key,const char * text)
{
twSetColorAttr(prompt_cset.digit);
twPutS(key);
twSetColorAttr(prompt_cset.button);
twPutS(text);
}
static const char * ftext[] = { "1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10" };
static void __NEAR__ __FASTCALL__ drawControlKeys(int flg)
{
char ckey;
if(flg & KS_SHIFT) ckey = 'S';
else
if(flg & KS_ALT) ckey = 'A';
else
if(flg & KS_CTRL) ckey = 'C';
else ckey = ' ';
twGotoXY(1,1);
twSetColorAttr(prompt_cset.control);
twPutChar(ckey);
}
void __FASTCALL__ __drawMultiPrompt(const char *norm[], const char *shift[], const char *alt[], const char *ctrl[])
{
TWindow *using;
int flg = __kbdGetShiftsKey();
int i;
const char * cptr;
using = twUsedWin();
twUseWin(HelpWnd);
twFreezeWin(HelpWnd);
twGotoXY(2,1);
for(i = 0;i < 10;i++)
{
/* todo: it might be better to ensure that if
text!=NULL then text[i]!=NULL, rather than
checking it all the time
*/
if (flg & KS_SHIFT)
cptr = shift && shift[i] ? shift[i] : " ";
else if (flg & KS_ALT)
cptr = alt && alt[i] ? alt[i] : " ";
else if (flg & KS_CTRL)
cptr = ctrl && ctrl[i] ? ctrl[i] : " ";
else cptr = norm && norm[i] ? norm[i] : " ";
ShowFunKey(ftext[i],cptr);
}
drawControlKeys(flg);
twRefreshWin(HelpWnd);
twUseWin(using);
}
void __FASTCALL__ __drawSinglePrompt(const char *prmt[])
{
__drawMultiPrompt(prmt, NULL, NULL, NULL);
}
static const char * ShiftFxText[] =
{
"ModHlp",
" ",
" ",
" ",
"Where ",
"SysInf",
"NextSr",
"Tools ",
" ",
"FilUtl"
};
static const char * FxText[] =
{
"Intro ",
"ViMode",
"More ",
" ",
"Goto ",
"ReRead",
"Search",
" ",
"Setup ",
"Quit "
};
static void __NEAR__ fillFxText( void )
{
FxText[3] = activeMode->misckey_name ? activeMode->misckey_name() : NULL;
FxText[7] = detectedFormat->showHdr || IsNewExe() ? "Header" : NULL;
}
void drawPrompt( void )
{
fillFxText();
__drawMultiPrompt(FxText, ShiftFxText, detectedFormat->prompt, activeMode->prompt);
}
static const char * amenu_names[] =
{
"~Base",
"~Alternative",
"~Format-depended",
"~Mode-depended"
};
int MainActionFromMenu( void )
{
unsigned nModes;
int i;
nModes = sizeof(amenu_names)/sizeof(char *);
i = SelBoxA(amenu_names,nModes," Select action: ",0);
if(i != -1)
{
switch(i)
{
default:
case 0:
fillFxText();
i = SelBoxA(FxText,10," Select base action: ",0);
if(i!=-1) return KE_F(i+1);
break;
case 1:
i = SelBoxA(ShiftFxText,10," Select alternative action: ",0);
if(i!=-1) return KE_SHIFT_F(i+1);
break;
case 2:
i = SelBoxA(detectedFormat->prompt,10," Select format-depended action: ",0);
if(i!=-1) return KE_ALT_F(i+1);
break;
case 3:
i = SelBoxA(activeMode->prompt,10," Select mode-depended action: ",0);
if(i!=-1) return KE_CTL_F(i+1);
break;
}
}
return 0;
}
static const char * fetext[] =
{
"Help ",
"Update",
"InitXX",
"Not ",
"Or XX",
"And XX",
"Xor XX",
"Put XX",
"Undo ",
"Escape"
};
static const char * casmtext[] =
{
"AsmRef",
"SysInf",
"Tools ",
"Assemb",
" ",
" ",
" ",
" ",
" ",
" "
};
static const char * empttext[] =
{
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"Escape"
};
static const char * emptlsttext[] =
{
" ",
" ",
" ",
"SaveAs",
" ",
" ",
" ",
" ",
" ",
" "
};
void drawEditPrompt( void )
{
__drawSinglePrompt(fetext);
}
/*
int EditActionFromMenu( void )
{
int i;
i = SelBoxA(fetext,10," Select editor's action: ",0);
if(i != -1) return KE_F(i+1);
return 0;
}
*/
void drawEmptyPrompt( void )
{
__drawSinglePrompt(empttext);
}
void drawEmptyListPrompt( void )
{
__drawSinglePrompt(emptlsttext);
}
void drawAsmEdPrompt( void )
{
__drawMultiPrompt(fetext, NULL, NULL, casmtext);
}
int EditAsmActionFromMenu( void )
{
int i;
i = SelBoxA(amenu_names,2," Select asm editor's action: ",0);
if(i != -1)
{
switch(i)
{
default:
case 0:
fillFxText();
i = SelBoxA(fetext,10," Select base action: ",0);
if(i!=-1) return KE_F(i+1);
break;
case 1:
i = SelBoxA(casmtext,10," Select alternative action: ",0);
if(i!=-1) return KE_CTL_F(i+1);
break;
}
}
return 0;
}
static const char * ordlisttxt[] =
{
" ",
"SrtNam",
"SrtOrd",
"SaveAs",
" ",
" ",
"Search",
" ",
" ",
"Escape"
};
static const char * listtxt[] =
{
" ",
"Sort ",
" ",
"SaveAs",
" ",
" ",
"Search",
" ",
" ",
"Escape"
};
static const char * searchlisttxt[] =
{
" ",
" ",
" ",
"SaveAs",
" ",
" ",
"Search",
" ",
" ",
"Escape"
};
static const char * shlisttxt[] =
{
" ",
" ",
" ",
" ",
" ",
" ",
"NextSr",
" ",
" ",
" "
};
static const char * helptxt[] =
{
"Licenc",
"KeyHlp",
"Credit",
" ",
" ",
" ",
" ",
" ",
" ",
"Escape"
};
static const char * helplisttxt[] =
{
" ",
" ",
" ",
" ",
" ",
" ",
"Search",
" ",
" ",
"Escape"
};
void drawListPrompt( void )
{
__drawMultiPrompt(listtxt, shlisttxt, NULL, NULL);
}
void drawOrdListPrompt( void )
{
__drawMultiPrompt(ordlisttxt, shlisttxt, NULL, NULL);
}
void drawSearchListPrompt( void )
{
__drawMultiPrompt(searchlisttxt, shlisttxt, NULL, NULL);
}
void drawHelpPrompt( void )
{
__drawSinglePrompt(helptxt);
}
int HelpActionFromMenu( void )
{
int i;
i = SelBoxA(helptxt,10," Select help action: ",0);
if(i != -1) return KE_F(i+1);
return 0;
}
void drawHelpListPrompt( void )
{
__drawMultiPrompt(helplisttxt, shlisttxt, NULL, NULL);
}
typedef struct tagvbyte
{
char x;
char y;
char image;
}vbyte;
typedef struct tagcvbyte
{
char x;
char y;
char image;
Color color;
}cvbyte;
const vbyte stars[] = {
{ 51,8,'.' },
{ 48,6,'*' },
{ 50,11,'*' },
{ 49,9,'.' },
{ 69,6,'*' },
{ 72,11,'*' },
{ 68,10,'.' },
{ 71,8,'.' },
{ 70,12,'*' },
{ 48,12,'.' }
};
const cvbyte buttons[] = {
{ 65,12,0x07, LightRed },
{ 66,12,0x07, LightGreen },
{ 67,12,0x07, LightCyan },
{ 55,12,TWC_SH, Black },
{ 56,12,TWC_SH, Black }
};
void About( void )
{
TWindow * hwnd;
int i;
char str[2];
const char core[8] = { TWC_LT_SHADE, TWC_LT_SHADE, TWC_LT_SHADE, TWC_LT_SHADE, TWC_LT_SHADE, TWC_LT_SHADE, TWC_LT_SHADE, 0x00 };
hwnd = WindowOpen(0,0,73,13,TWS_FRAMEABLE | TWS_NLSOEM);
twCentredWin(hwnd,NULL);
twSetColor(LightCyan,Black);
twClearWin();
twSetFrame(hwnd,TW_DOUBLE_FRAME,White,Black);
twSetTitle(hwnd,BIEW_VER_MSG,TW_TMODE_CENTER,White,Black);
twShowWin(hwnd);
twUseWin(hwnd);
twFreezeWin(hwnd);
twGotoXY(1,1); twPutS(msgAboutText);
twTextColor(White);
for(i = 0;i < 13;i++) { twGotoXY(47,i + 1); twPutChar(TWC_SV); }
for(i = 0;i < 47;i++) { twGotoXY(i + 1,6); twPutChar(TWC_SH); }
twGotoXY(47,6); twPutChar(TWC_SV_Sl);
twTextColor(LightRed);
for(i = 0;i < 5;i++)
{
Color bcol[5] = { White, LightCyan, Cyan, LightBlue, Blue };
twTextColor(bcol[i]);
twGotoXY(49,i + 1);
twPutS(BiewPicture[i]);
}
twTextColor(LightGreen); twTextBkGnd(Green);
for(i = 0;i < 7;i++)
{
twGotoXY(1,i+7); twPutS(MBoardPicture[i]);
}
twinDrawFrame(3,8,13,12,TW_UP3D_FRAME,White,LightGray);
twinDrawFrame(4,9,12,11,TW_DN3D_FRAME,Black,LightGray);
twGotoXY(5,10);
twPutS(core);
twTextColor(Brown); twTextBkGnd(Black);
for(i = 0;i < 7;i++)
{
twGotoXY(17,i+7); twPutS(ConnectorPicture[i]);
}
twTextColor(Gray); twTextBkGnd(Black);
for(i = 0;i < 7;i++)
{
twGotoXY(22,i+7); twPutS(BitStreamPicture[i]);
}
twTextColor(LightGray); twTextBkGnd(Black);
for(i = 0;i < 7;i++)
{
twGotoXY(31,i+7); twPutS(BiewerPicture[i]);
}
twTextColor(LightCyan); twTextBkGnd(Blue);
for(i = 0;i < 5;i++)
{
twGotoXY(32,i+8); twPutS(BiewerScreenPicture[i]);
}
twTextBkGnd(Black); twTextColor(LightCyan);
for(i = 0;i < 10;i++) twDirectWrite(stars[i].x,stars[i].y,&stars[i].image,1);
twTextColor(LightGray);
for(i = 0;i < 7;i++)
{
twGotoXY(52,i + 6);
twPutS(CompPicture[i]);
}
twTextBkGnd(LightGray);
for(i = 0;i < 5;i++)
{
twTextColor(buttons[i].color);
str[0] = buttons[i].image;
str[1] = 0;
twDirectWrite(buttons[i].x,buttons[i].y,str,1);
}
twSetColor(Yellow,Blue);
for(i = 0;i < 4;i++)
{
twGotoXY(54,i + 7);
twPutS(CompScreenPicture[i]);
}
twRefreshWin(hwnd);
while(1)
{
int ch;
ch = GetEvent(drawHelpPrompt,HelpActionFromMenu,hwnd);
switch(ch)
{
case KE_ESCAPE:
case KE_F(10): goto bye_help;
case KE_F(1): hlpDisplay(1); break;
case KE_F(2): hlpDisplay(3); break;
case KE_F(3): hlpDisplay(4); break;
default: break;
}
}
bye_help:
CloseWnd(hwnd);
}
__filesize_t __FASTCALL__ WhereAMI(__filesize_t ctrl_pos)
{
TWindow *hwnd,*wait_wnd;
char vaddr[64],prev_func[61],next_func[61],oname[25];
const char *btn;
int obj_class,obj_bitness;
unsigned obj_num,func_class;
__filesize_t obj_start,obj_end;
__filesize_t cfpos,ret_addr,va,prev_func_pa,next_func_pa;
hwnd = CrtDlgWndnls(" Current position information ",78,5);
twSetFooterAttr(hwnd,"[Enter] - Prev. entry [Ctrl-Enter | F5] - Next entry]",TW_TMODE_RIGHT,dialog_cset.selfooter);
twGotoXY(1,1);
wait_wnd = PleaseWaitWnd();
cfpos = BMGetCurrFilePos();
if(detectedFormat->set_state) detectedFormat->set_state(PS_ACTIVE);
if(detectedFormat->prepare_structs)
detectedFormat->prepare_structs(ctrl_pos,ctrl_pos);
va = detectedFormat->pa2va ? detectedFormat->pa2va(ctrl_pos) : ctrl_pos;
vaddr[0] = '\0';
#if (__WORDSIZE >= 32) && !defined(__QNX4__)
sprintf(&vaddr[strlen(vaddr)],"%016llXH",va);
#else
sprintf(&vaddr[strlen(vaddr)],"%08lXH",va);
#endif
prev_func_pa = next_func_pa = 0;
prev_func[0] = next_func[0] = '\0';
if(detectedFormat->GetPubSym)
{
prev_func_pa = detectedFormat->GetPubSym(prev_func,sizeof(prev_func),
&func_class,ctrl_pos,True);
next_func_pa = detectedFormat->GetPubSym(next_func,sizeof(next_func),
&func_class,ctrl_pos,False);
}
prev_func[sizeof(prev_func)-1] = next_func[sizeof(next_func)-1] = '\0';
if(detectedFormat->GetObjAttr)
{
obj_num = detectedFormat->GetObjAttr(ctrl_pos,oname,sizeof(oname),
&obj_start,&obj_end,&obj_class,
&obj_bitness);
oname[sizeof(oname)-1] = 0;
}
else
{
obj_num = 0;
oname[0] = 0;
obj_start = 0;
obj_end = BMGetFLength();
obj_class = OC_CODE;
obj_bitness = DAB_USE16;
}
CloseWnd(wait_wnd);
switch(obj_bitness)
{
case DAB_USE16: btn = "USE16"; break;
case DAB_USE32: btn = "USE32"; break;
case DAB_USE64: btn = "USE64"; break;
case DAB_USE128:btn = "USE128"; break;
case DAB_USE256:btn = "USE256"; break;
default: btn = "";
}
twPrintF(
#if (__WORDSIZE >= 32) && !defined(__QNX4__)
"File offset : %016llXH\n"
#else
"File offset : %08lXH\n"
#endif
"Virt. address: %s\n"
"%s entry : %s\n"
"Next entry : %s\n"
#if (__WORDSIZE >= 32) && !defined(__QNX4__)
"Curr. object : #%u %s %s %016llXH=%016llXH %s"
#else
"Curr. object : #%u %s %s %08lXH=%08lXH %s"
#endif
,ctrl_pos
,vaddr
,prev_func_pa == ctrl_pos ? "Curr." : "Prev."
,prev_func
,next_func
,obj_num
,obj_class == OC_CODE ? "CODE" : obj_class == OC_DATA ? "DATA" : "no obj."
,btn
,obj_start
,obj_end
,oname
);
ret_addr = ctrl_pos;
while(1)
{
int ch;
ch = GetEvent(drawEmptyPrompt,NULL,hwnd);
switch(ch)
{
case KE_F(10):
case KE_ESCAPE: goto exit;
case KE_ENTER:
{
if(prev_func_pa)
{
ret_addr = prev_func_pa;
}
else ErrMessageBox(NOT_ENTRY,NULL);
}
goto exit;
case KE_F(5):
case KE_CTL_ENTER:
{
if(next_func_pa)
{
ret_addr = next_func_pa;
}
else ErrMessageBox(NOT_ENTRY,NULL);
}
goto exit;
default: break;
}
}
exit:
if(detectedFormat->drop_structs) detectedFormat->drop_structs();
if(detectedFormat->set_state) detectedFormat->set_state(PS_INACTIVE);
BMSeek(cfpos,BM_SEEK_SET);
CloseWnd(hwnd);
return ret_addr;
}