-
Notifications
You must be signed in to change notification settings - Fork 2
/
database.cpp
797 lines (771 loc) · 26.9 KB
/
database.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/************************************************************************
* database.cpp *
* - functions for loading and saving database files *
************************************************************************/
#include <windows.h>
#include "dasm.h"
#include "debug.h"
#include "disasm.h"
#include "gname.h"
#include "relocs.h"
#include "xref.h"
#include "data.h"
#include "exeload.h"
#include "schedule.h"
#include "resource.h"
#include "decrypt.h"
/************************************************************************
* forward declarations *
************************************************************************/
BOOL CALLBACK loadmessbox(HWND hdwnd,UINT message,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK savemessbox(HWND hdwnd,UINT message,WPARAM wParam,LPARAM lParam);
/************************************************************************
* savedecryptitems *
* - this saves the list of decryptors to the database *
************************************************************************/
bool savedecryptitems(savefile *sf)
{ dword ndecs;
ndecs=decrypter.numlistitems();
decrypter.resetiterator();
if(!sf->swrite(&ndecs,sizeof(dword)))
return false;
while(ndecs)
{ if(!decrypter.write_item(sf))
return false;
ndecs--;
}
return true;
}
/************************************************************************
* loaddecryptitems *
* - here we reload the list of decryptors *
************************************************************************/
bool loaddecryptitems(savefile *sf)
{ dword ndecs,num;
if(!sf->sread(&ndecs,sizeof(dword),&num))
return false;
while(ndecs)
{ if(!decrypter.read_item(sf))
return false;
ndecs--;
}
return true;
}
/************************************************************************
* retstacksavedb *
* - Borg keeps track of the stack even through saves. It simply saves *
* the full stack *
************************************************************************/
bool retstacksavedb(savefile *sf)
{ if(!sf->swrite(&dio.retstack.stacktop,sizeof(int)))
return false;
if(!sf->swrite(dio.retstack.callstack,sizeof(lptr)*CALLSTACKSIZE))
return false;
return true;
}
/************************************************************************
* retstackloaddb *
* - reloads the stack from the saved database file *
************************************************************************/
bool retstackloaddb(savefile *sf)
{ dword num;
if(!sf->sread(&dio.retstack.stacktop,sizeof(int),&num))
return false;
if(!sf->sread(dio.retstack.callstack,sizeof(lptr)*CALLSTACKSIZE,&num))
return false;
return true;
}
/************************************************************************
* dissavedb *
* - this routine saves the entire disassembly database to the database *
* save file. It converts instruction pointers into instruction uids *
* and converts data pointers into offsets for saving *
************************************************************************/
bool dissavedb(savefile *sf,byte *filebuff)
{ dword ndsms;
dsmitemsave structsave;
dsmitem *currdsm;
ndsms=dsm.numlistitems();
dsm.resetiterator();
if(!sf->swrite(&ndsms,sizeof(dword)))
return false;
while(ndsms)
{ currdsm=dsm.nextiterator();
structsave.addr=currdsm->addr;
structsave.type=currdsm->type;
structsave.length=currdsm->length;
structsave.modrm=currdsm->modrm;
structsave.mode32=currdsm->mode32;
structsave.override=currdsm->override;
structsave.flags=currdsm->flags;
structsave.displayflags=currdsm->displayflags;
if(structsave.type==dsmxref)
{ structsave.fileoffset=0; // NULL ptrs
structsave.tptroffset=0;
}
else if(structsave.type==dsmcode)
{ structsave.fileoffset=currdsm->data-filebuff;
structsave.tptroffset=((asminstdata *)currdsm->tptr)->uniqueid;
}
else
{ structsave.fileoffset=strlen((char *)currdsm->data)+1; // strlen
structsave.tptroffset=0; // points to str as well
}
if(!sf->swrite(&structsave,sizeof(dsmitemsave)))
return false;
if((structsave.type!=dsmxref)&&(structsave.type!=dsmcode))
{ if(!sf->swrite(currdsm->tptr,structsave.fileoffset))
return false;
}
ndsms--;
}
// need to save callstack and some other stuff too.
if(!sf->swrite(&dio.curraddr,sizeof(lptr)))
return false;
if(!sf->swrite(&dio.subitem,sizeof(dsmitemtype)))
return false;
if(!sf->swrite(&dsm.itables,sizeof(int)))
return false;
if(!sf->swrite(&dsm.jtables,sizeof(int)))
return false;
if(!sf->swrite(&dsm.irefs,sizeof(int)))
return false;
return retstacksavedb(sf);
}
/************************************************************************
* disloaddb *
* - this routine loads the entire disassembly database from the save *
* file It converts instruction uids into the instruction pointers and *
* converts offsets back into pointers. We have to search the assembly *
* instructions for the uids in order to find the correct instruction. *
************************************************************************/
bool disloaddb(savefile *sf,byte *filebuff)
{ dword ndsms,num;
dsmitemsave structsave;
dsmitem *currdsm;
int asminstctr;
asminstdata *findasm;
if(!sf->sread(&ndsms,sizeof(dword),&num))
return false;
while(ndsms)
{ currdsm=new dsmitem;
if(!sf->sread(&structsave,sizeof(dsmitemsave),&num))
return false;
currdsm->addr=structsave.addr;
currdsm->type=structsave.type;
currdsm->length=structsave.length;
currdsm->modrm=structsave.modrm;
currdsm->mode32=structsave.mode32;
currdsm->override=structsave.override;
currdsm->flags=structsave.flags;
currdsm->displayflags=structsave.displayflags;
if(structsave.type==dsmxref)
{ currdsm->data=NULL;
currdsm->tptr=NULL;
}
else if(structsave.type==dsmcode)
{ currdsm->data=structsave.fileoffset+filebuff;
// now reset the tptr = asminstdata ptr (need to find it from the uniqueid)
asminstctr=0;
findasm=reconstruct[asminstctr];
while((dword)(findasm[0].uniqueid/1000)!=(dword)(structsave.tptroffset/1000))
{ asminstctr++;
findasm=reconstruct[asminstctr];
if(findasm==NULL)
{
#ifdef DEBUG
DebugMessage("File Loader:Failed to find instruction table for %lu",structsave.tptroffset);
#endif
return false;
}
}
asminstctr=0;
while(findasm[asminstctr].uniqueid!=structsave.tptroffset)
{ asminstctr++;
if((!findasm[asminstctr].instbyte)&&(!findasm[asminstctr].processor))
{
#ifdef DEBUG
DebugMessage("File Loader:Failed to find instruction %lu",structsave.tptroffset);
#endif
return false;
}
}
currdsm->tptr=(void *)&findasm[asminstctr];
}
else
{ currdsm->data=new byte[structsave.fileoffset];
currdsm->tptr=currdsm->data;
}
if((structsave.type!=dsmxref)&&(structsave.type!=dsmcode))
{ if(!sf->sread(currdsm->tptr,structsave.fileoffset,&num))
return false;
}
dsm.addto(currdsm);
ndsms--;
}
// need to save callstack and some other stuff too.
if(!sf->sread(&dio.curraddr,sizeof(lptr),&num))
return false;
if(!sf->sread(&dio.subitem,sizeof(dsmitemtype),&num))
return false;
if(!sf->sread(&dsm.itables,sizeof(int),&num))
return false;
if(!sf->sread(&dsm.jtables,sizeof(int),&num))
return false;
if(!sf->sread(&dsm.irefs,sizeof(int),&num))
return false;
dsm.dissettable();
dio.setcuraddr(dio.curraddr);
return retstackloaddb(sf);
}
/************************************************************************
* saverelocitems *
* - this saves the relocs list to the database file. *
* - we can simply save the number of items followed by each item *
************************************************************************/
bool saverelocitems(savefile *sf)
{ dword nrels;
nrels=reloc.numlistitems();
reloc.resetiterator();
// save number of reloc items
if(!sf->swrite(&nrels,sizeof(dword)))
return false;
while(nrels)
{ if(!reloc.write_item(sf))
return false;
nrels--;
}
return true;
}
/************************************************************************
* loadrelocitems *
* - this reloads the list of relocs from the database file and *
* constructs the list again *
************************************************************************/
bool loadrelocitems(savefile *sf)
{ dword nrels,num;
// get number of items
if(!sf->sread(&nrels,sizeof(dword),&num))
return false;
while(nrels)
{ if(!reloc.read_item(sf))
return false;
nrels--;
}
return true;
}
/************************************************************************
* gnamesavedb *
* - saves all the names in the list to the database file being saved. *
* this is in a one-pass compatible loading format. ie number of items *
* followed by each item, and for strings the length of the string *
* followed by the string. *
************************************************************************/
bool gnamesavedb(gname *gn,savefile *sf)
{ dword nexps,nlen;
gnameitem *currexp;
nexps=gn->numlistitems();
gn->resetiterator();
if(!sf->swrite(&nexps,sizeof(dword)))
return false;
while(nexps)
{ currexp=gn->nextiterator();
if(!sf->swrite(&(currexp->addr),sizeof(lptr)))
return false;
nlen=strlen(currexp->name)+1;
if(!sf->swrite(&nlen,sizeof(dword)))
return false;
if(!sf->swrite(currexp->name,nlen))
return false;
nexps--;
}
return true;
}
/************************************************************************
* gnameloaddb *
* - loads the names from the database file and reconstructs the names *
* list *
************************************************************************/
bool gnameloaddb(gname *gn,savefile *sf)
{ dword nexps,num,nlen;
gnameitem *currexp;
if(!sf->sread(&nexps,sizeof(dword),&num))
return false;
while(nexps)
{ currexp=new gnameitem;
if(!sf->sread(&(currexp->addr),sizeof(lptr),&num))
return false;
if(!sf->sread(&nlen,sizeof(dword),&num))
return false;
currexp->name=new char[nlen];
if(!sf->sread(currexp->name,nlen,&num))
return false;
gn->addto(currexp);
nexps--;
}
return true;
}
/************************************************************************
* savedatasegitems *
* - we save the data segment data structures to the database file. *
************************************************************************/
bool savedatasegitems(savefile *sf,byte *filebuff)
{ dword nsegs;
nsegs=dta.numlistitems();
dta.resetiterator();
if(!sf->swrite(&nsegs,sizeof(dword)))
return false;
while(nsegs)
{ if(!dta.write_item(sf,filebuff))
return false;
nsegs--;
}
return true;
}
/************************************************************************
* loaddatasegitems *
* - loads the data segment data structures in *
************************************************************************/
bool loaddatasegitems(savefile *sf,byte *filebuff)
{ dword nsegs,num;
if(!sf->sread(&nsegs,sizeof(dword),&num))
return false;
#ifdef DEBUG
DebugMessage("Loading %lu datasegs",nsegs);
#endif
while(nsegs)
{ if(!dta.read_item(sf,filebuff))
return false;
nsegs--;
}
return true;
}
/************************************************************************
* xrefsavedb *
* save xref list to database file, simply writes the list item out *
* consisting of loc and ref_by, ie two addresses *
************************************************************************/
bool xrefsavedb(savefile *sf)
{ dword nxrefs;
xrefitem *currxref;
nxrefs=xrefs.numlistitems();
xrefs.resetiterator();
if(!sf->swrite(&nxrefs,sizeof(dword)))
return false;
while(nxrefs)
{ currxref=xrefs.nextiterator();
if(!sf->swrite(currxref,sizeof(xrefitem)))
return false;
nxrefs--;
}
return true;
}
/************************************************************************
* xrefloaddb *
* load xref list to database file, simply reads the list item in *
* consisting of loc and ref_by, ie two addresses *
* and adds it to the new list *
************************************************************************/
bool xrefloaddb(savefile *sf)
{ dword nxrefs,num;
xrefitem *currxref;
if(!sf->sread(&nxrefs,sizeof(dword),&num))
return false;
while(nxrefs)
{ currxref=new xrefitem;
if(!sf->sread(currxref,sizeof(xrefitem),&num))
return false;
xrefs.addto(currxref);
nxrefs--;
}
return true;
}
/************************************************************************
* savedbcoord *
* - coordinates saving of the databases when save as database file is *
* chosen in Borg *
************************************************************************/
void savedbcoord(char *fname,char *exename)
{ savefile sf;
dword flen;
dword bver;
HWND sbox;
// open file
sbox=CreateDialog(hInst,MAKEINTRESOURCE(save_box),mainwindow,(DLGPROC)savemessbox);
if(!sf.sopen(fname,GENERIC_WRITE,1,CREATE_ALWAYS,0))
{ DestroyWindow(sbox);
return;
}
// save header to identify as a database file
if(!sf.swrite("BORG",4))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Header Info[1]:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save BORG_VERSION
bver=BORG_VER;
if(!sf.swrite(&bver,sizeof(bver)))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Header Info[2]:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save filename of exe file.
flen=strlen(exename)+1;
if(!sf.swrite(&flen,sizeof(dword)))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Header Info[3]:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
if(!sf.swrite(exename,flen))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Header Info[4]:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save options.
if(!sf.swrite(&options,sizeof(globaloptions)))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Options:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
if(!sf.swrite(&floader.exetype,sizeof(int)))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Exetype:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save segment info
if(!savedatasegitems(&sf,floader.fbuff))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Segments:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save import info
if(!gnamesavedb(&import,&sf))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Imports:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save export info
if(!gnamesavedb(&expt,&sf))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Exports:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save names
if(!gnamesavedb(&name,&sf))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Names:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save relocs
if(!saverelocitems(&sf))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Relocs:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save xrefs
if(!xrefsavedb(&sf))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Xrefs:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save asm database
if(!dissavedb(&sf,floader.fbuff))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Database:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
// save decrypter list
if(!savedecryptitems(&sf))
{ DestroyWindow(sbox);
MessageBox(mainwindow,"Decryptors:File write failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return;
}
sf.flushfilewrite();
// close file
DestroyWindow(sbox);
}
/************************************************************************
* loaddbcoord *
* - coordinates loading of the databases when load database file is *
* chosen in Borg *
************************************************************************/
bool loaddbcoord(char *fname,char *exename)
{ savefile sf;
char tbuff[20];
dword num;
dword flen,fsize,gsize;
dword bver;
HWND lbox;
// open file
lbox=CreateDialog(hInst,MAKEINTRESOURCE(load_box),mainwindow,(DLGPROC)loadmessbox);
if(!sf.sopen(fname,GENERIC_READ,1,OPEN_EXISTING,0))
{ DestroyWindow(lbox);
return false;
}
// load header check its a database file
tbuff[4]=0;
if(!sf.sread(tbuff,4,&num))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return false;
}
if(strcmp(tbuff,"BORG"))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Not A Borg Database File",fname,MB_OK|MB_ICONEXCLAMATION);
return false;
}
// read BORG_VERSION
if(!sf.sread(&bver,sizeof(bver),&num))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return false;
}
if(bver>BORG_VER)
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Savefile from a later version [or very early version]!",fname,MB_OK|MB_ICONEXCLAMATION);
return false;
}
if(bver<BORG_VER)
{ MessageBox(mainwindow,"Warning:earlier version savefile [will attempt load]",fname,MB_OK|MB_ICONEXCLAMATION);
#ifdef DEBUG
DebugMessage("Detected version:%d.%d Savefile",bver/100,bver%100);
#endif
}
// load filename of exe file.
flen=0;
if(!sf.sread(&flen,sizeof(dword),&num))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return false;
}
if(!sf.sread(exename,flen,&num))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return false;
}
#ifdef DEBUG
DebugMessage("Filename:%s",exename);
#endif
// added 226 to allow load of older databases
gsize=sizeof(globaloptions);
if(bver<222)
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Older databases are incompatible, please reuse the older version of Borg","Prior to 2.22",MB_OK|MB_ICONEXCLAMATION);
return false;
}
// load options.
if(!sf.sread(&options,gsize,&num))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return false;
}
#ifdef DEBUG
DebugMessage("Global Options Size:%d",gsize);
#endif
if(!sf.sread(&floader.exetype,sizeof(int),&num))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
return false;
}
// load exe file.
// - any errors from here on will now be fatal, and Borg will need to exit
floader.efile=CreateFile(exename,GENERIC_READ|GENERIC_WRITE,1,NULL,OPEN_EXISTING,0,NULL);
if(floader.efile==INVALID_HANDLE_VALUE)
{ floader.efile=CreateFile(exename,GENERIC_READ,1,NULL,OPEN_EXISTING,0,NULL);
if(floader.efile==INVALID_HANDLE_VALUE)
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File open failed ?",exename,MB_OK|MB_ICONEXCLAMATION);
return false;
}
options.readonly=true;
MessageBox(mainwindow,"Couldn't obtain write permission to file\nFile opened readonly - will not be able to apply any patches",
"Borg Message",MB_OK);
}
if(GetFileType(floader.efile)!=FILE_TYPE_DISK)
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File open failed ?",exename,MB_OK|MB_ICONEXCLAMATION);
CloseHandle(floader.efile);
return false;
}
fsize=GetFileSize(floader.efile,NULL);
floader.fbuff=new byte[fsize];
SetFilePointer(floader.efile,0x00,NULL,FILE_BEGIN);
if(!ReadFile(floader.efile,floader.fbuff,fsize,&num,NULL))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"File read failed ?",exename,MB_OK|MB_ICONEXCLAMATION);
CloseHandle(floader.efile);
delete floader.fbuff;
return false;
}
// load segment info
if(!loaddatasegitems(&sf,floader.fbuff))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nSegments:File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
#ifdef DEBUG
DebugMessage("Loading Imports");
#endif
// load import info
if(!gnameloaddb(&import,&sf))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nImports:File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
#ifdef DEBUG
DebugMessage("Loading Exports");
#endif
// load export info
if(!gnameloaddb(&expt,&sf))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nExports:File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
#ifdef DEBUG
DebugMessage("Loading Names");
#endif
// load names
if(!gnameloaddb(&name,&sf))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nNames:File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
#ifdef DEBUG
DebugMessage("Loading Relocs");
#endif
// load relocs
if(!loadrelocitems(&sf))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nRelocs:File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
#ifdef DEBUG
DebugMessage("Loading Xrefs");
#endif
// load xrefs
if(!xrefloaddb(&sf))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nXrefs:File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
#ifdef DEBUG
DebugMessage("Loading Asm database");
#endif
// load asm database
if(!disloaddb(&sf,floader.fbuff))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nDatabase:File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
#ifdef DEBUG
DebugMessage("Relocating File");
#endif
if(!reloc.relocfile())
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nRelocating File",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
#ifdef DEBUG
DebugMessage("Loading Decryptors");
#endif
if(!loaddecryptitems(&sf))
{ DestroyWindow(lbox);
MessageBox(mainwindow,"Fatal Error\nDecryptors:File read failed ?",fname,MB_OK|MB_ICONEXCLAMATION);
DestroyWindow(mainwindow);
return false;
}
DestroyWindow(lbox);
return true;
}
/************************************************************************
* savedb *
* - the first place of call when save as database is selected. *
* - asks the user to select a file before calling the fileloader savedb *
* which is where the save to database is controlled from *
************************************************************************/
void savedb(void)
{ char szFile[MAX_PATH*2];
if(scheduler.sizelist())
{ MessageBox(mainwindow,"There are still items to process yet","Borg Warning",MB_OK|MB_ICONEXCLAMATION);
return;
}
getfiletosave(szFile);
if(szFile[0])
{ savedbcoord(szFile,current_exe_name);
}
}
/************************************************************************
* loaddb *
* - the first place of call when load from database is selected. *
* - asks the user to select a file before calling the fileloader loaddb *
* which is where the load from database is controlled from *
* - starts up the secondary thread when the file is loaded *
************************************************************************/
void loaddb(void)
{ char szFile[MAX_PATH*2];
getfiletoload(szFile);
if(szFile[0])
{ if(loaddbcoord(szFile,current_exe_name))
{ StatusMessage("File Opened");
strcat(winname," : ");
strcat(winname,current_exe_name);
SetWindowText(mainwindow,winname);
InThread=true;
ThreadHandle=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread,0,0,&ThreadId);
changemenus();
scheduler.addtask(scrolling,priority_userrequest,nlptr,NULL);
}
else
MessageBox(mainwindow,"File open failed ?",program_name,MB_OK|MB_ICONEXCLAMATION);
}
}
/************************************************************************
* savemessbox *
* - A small dialog box which contains the message 'saving' to be shown *
* as a database file is saved *
************************************************************************/
#ifdef __BORLANDC__
#pragma warn -par
#endif
BOOL CALLBACK savemessbox(HWND hdwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ switch(message)
{ case WM_INITDIALOG:
CenterWindow(hdwnd);
return false;
default:
break;
}
return false;
}
#ifdef __BORLANDC__
#pragma warn +par
#endif
/************************************************************************
* loadmessbox *
* - A small dialog box which contains the message 'loading' to be shown *
* as a database file is loaded *
************************************************************************/
#ifdef __BORLANDC__
#pragma warn -par
#endif
BOOL CALLBACK loadmessbox(HWND hdwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ switch(message)
{ case WM_INITDIALOG:
CenterWindow(hdwnd);
return false;
default:
break;
}
return false;
}
#ifdef __BORLANDC__
#pragma warn +par
#endif