Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

887 lines
27 KiB

4 years ago
  1. #include <precomp.h>
  2. #pragma hdrstop
  3. #define MYOF_FLAGS (OF_READ | OF_SHARE_DENY_NONE)
  4. int read_name(
  5. int ifile,
  6. LPSTR pch
  7. ) {
  8. char length;
  9. int rc;
  10. rc = _lread( ifile, &length, sizeof(length) );
  11. if ( rc != sizeof(length) ) {
  12. PRINTF("Could not read name length\n");
  13. *pch = '\0';
  14. return( -1 );
  15. }
  16. rc = _lread( ifile, pch, length );
  17. if ( rc != length ) {
  18. PRINTF("Could not read name\n");
  19. *pch = '\0';
  20. return( -1 );
  21. }
  22. *(pch + length) = '\0';
  23. return( (int)length );
  24. }
  25. BOOL FindExport(
  26. LPSTR filename,
  27. WORD segment,
  28. WORD offset,
  29. LPSTR sym_text,
  30. int direction,
  31. LONG *dist
  32. ) {
  33. int iFile;
  34. OFSTRUCT ofs;
  35. int rc;
  36. IMAGE_DOS_HEADER doshdr;
  37. IMAGE_OS2_HEADER winhdr;
  38. BYTE Table[65536];
  39. BYTE bBundles;
  40. BYTE bFlags;
  41. BYTE *ptr;
  42. WORD wIndex = 1;
  43. int i;
  44. int this_dist;
  45. int wIndexBest = -1;
  46. char myfilename[256];
  47. #pragma pack(1)
  48. typedef struct
  49. {
  50. BYTE bFlags;
  51. UNALIGNED WORD wSegOffset;
  52. } FENTRY, *PFENTRY;
  53. typedef struct
  54. {
  55. BYTE bFlags;
  56. UNALIGNED WORD wINT3F;
  57. BYTE bSegNumber;
  58. UNALIGNED WORD wSegOffset;
  59. } MENTRY, *PMENTRY;
  60. #pragma pack()
  61. strcpy(myfilename, filename);
  62. if (-1 == (iFile=OpenFile(myfilename, &ofs, MYOF_FLAGS))) {
  63. PRINTF("Error reading file %s\n", filename);
  64. strcpy(myfilename, filename);
  65. strcat(myfilename, ".exe");
  66. if (-1 == (iFile=OpenFile(myfilename, &ofs, MYOF_FLAGS))) {
  67. PRINTF("Error reading file %s\n", myfilename);
  68. strcpy(myfilename, filename);
  69. strcat(myfilename, ".dll");
  70. if (-1 == (iFile=OpenFile(myfilename, &ofs, MYOF_FLAGS))) {
  71. PRINTF("Error reading file %s\n", myfilename);
  72. return FALSE;
  73. }
  74. }
  75. }
  76. rc = _lread(iFile, &doshdr, sizeof(doshdr));
  77. if (rc != sizeof(doshdr)) {
  78. //PRINTF("Error reading DOS header\n");
  79. goto Error;
  80. }
  81. if (doshdr.e_magic != IMAGE_DOS_SIGNATURE) {
  82. //PRINTF("Error - no DOS EXE signature");
  83. goto Error;
  84. }
  85. rc = _llseek(iFile, doshdr.e_lfanew, FILE_BEGIN);
  86. if (rc == -1) {
  87. //PRINTF("Error - could not seek - probably not Win3.1 exe\n");
  88. goto Error;
  89. }
  90. rc = _lread(iFile, &winhdr, sizeof(winhdr));
  91. if (rc != sizeof(winhdr)) {
  92. //PRINTF("Error - could not read WIN header - probably not Win3.1 exe\n");
  93. goto Error;
  94. }
  95. if (winhdr.ne_magic != IMAGE_OS2_SIGNATURE) {
  96. //PRINTF("Error - not WIN EXE signature\n");
  97. goto Error;
  98. }
  99. rc = _llseek(iFile, doshdr.e_lfanew+winhdr.ne_enttab, FILE_BEGIN);
  100. if (rc == -1) {
  101. //PRINTF("Error - could not seek to entry table\n");
  102. goto Error;
  103. }
  104. rc = _lread(iFile, Table, winhdr.ne_cbenttab);
  105. if (rc != winhdr.ne_cbenttab) {
  106. //PRINTF("Error - could not read entry table\n");
  107. goto Error;
  108. }
  109. ptr = Table;
  110. while (TRUE) {
  111. bBundles = *ptr++;
  112. if (bBundles == 0)
  113. break;
  114. bFlags = *ptr++;
  115. switch (bFlags) {
  116. case 0: // Placeholders
  117. wIndex += bBundles;
  118. break;
  119. case 0xff: // movable segments
  120. for (i=0; i<(int)bBundles; ++i) {
  121. PMENTRY pe = (PMENTRY )ptr;
  122. if (pe->bSegNumber == segment) {
  123. this_dist = (direction == BEFORE) ? offset - pe->wSegOffset
  124. : pe->wSegOffset - offset;
  125. if ( this_dist >= 0 && (this_dist < *dist || *dist == -1) ) {
  126. // mark this as the best match so far
  127. *dist = this_dist;
  128. wIndexBest = wIndex;
  129. }
  130. }
  131. ptr += sizeof(MENTRY);
  132. wIndex++;
  133. }
  134. break;
  135. default: // fixed segments
  136. if ((int)bFlags != segment) {
  137. ptr += (int)bBundles * sizeof(FENTRY);
  138. wIndex += (int)bBundles;
  139. } else {
  140. for (i=0; i<(int)bBundles; ++i) {
  141. PFENTRY pe = (PFENTRY)ptr;
  142. this_dist = (direction == BEFORE) ? offset - pe->wSegOffset
  143. : pe->wSegOffset - offset;
  144. if ( this_dist >= 0 && (this_dist < *dist || *dist == -1) ) {
  145. // mark this as the best match so far
  146. *dist = this_dist;
  147. wIndexBest = wIndex;
  148. }
  149. ptr += sizeof(FENTRY);
  150. wIndex++;
  151. }
  152. }
  153. break;
  154. }
  155. }
  156. if (wIndexBest == -1) {
  157. // no match found - error out
  158. Error:
  159. _lclose(iFile);
  160. return FALSE;
  161. }
  162. // Success: match found
  163. // wIndexBest = ordinal of the function
  164. // segment:offset = address to look up
  165. // *dist = distance from segment:offset to the symbol
  166. // filename = name of .exe/.dll
  167. // Look for the ordinal in the resident name table
  168. rc = _llseek(iFile, doshdr.e_lfanew+winhdr.ne_restab, FILE_BEGIN);
  169. if (rc == -1) {
  170. //PRINTF("Error - unable to seek to residentname table\n");
  171. goto Error;
  172. }
  173. rc = _lread(iFile, Table, winhdr.ne_modtab-winhdr.ne_restab);
  174. if (rc != winhdr.ne_modtab-winhdr.ne_restab) {
  175. //PRINTF("Error - unable to read entire resident name table\n");
  176. goto Error;
  177. }
  178. ptr = Table;
  179. while (*ptr) {
  180. if ( *(UNALIGNED USHORT *)(ptr+1+*ptr) == (USHORT)wIndexBest) {
  181. // found the matching name
  182. *(ptr+1+*ptr) = '\0'; // null-terminate the function name
  183. wsprintf(sym_text, "%s", ptr+1);
  184. goto Finished;
  185. }
  186. ptr += *ptr + 3;
  187. }
  188. // Look for the ordinal in the non-resident name table
  189. rc = _llseek(iFile, doshdr.e_lfanew+winhdr.ne_nrestab, FILE_BEGIN);
  190. if (rc == -1) {
  191. //PRINTF("Error - unable to seek to non-residentname table\n");
  192. goto Error;
  193. }
  194. rc = _lread(iFile, Table, winhdr.ne_cbnrestab);
  195. if (rc != winhdr.ne_cbnrestab) {
  196. //PRINTF("Error - unable to read entire non-resident name table\n");
  197. goto Error;
  198. }
  199. ptr = Table;
  200. while (*ptr) {
  201. if ( *(UNALIGNED USHORT *)(ptr+1+*ptr) == (USHORT)wIndexBest) {
  202. // found the matching name
  203. *(ptr+1+*ptr) = '\0'; // null-terminate the function name
  204. wsprintf(sym_text, "%s", ptr+1);
  205. goto Finished;
  206. }
  207. ptr += *ptr + 3;
  208. }
  209. // fall into error path - no match found
  210. goto Error;
  211. Finished:
  212. _lclose(iFile);
  213. return TRUE;
  214. }
  215. int read_symbol(
  216. int ifile,
  217. LPSTR pch,
  218. LONG *offset
  219. ) {
  220. int rc;
  221. WORD word;
  222. rc = _lread( ifile, (LPSTR)&word, sizeof(WORD) );
  223. if ( rc != sizeof(WORD) ) {
  224. PRINTF("Could not read symbol offset\n");
  225. *pch = '\0';
  226. *offset = 0L;
  227. return(-1);
  228. }
  229. *offset = (LONG)word;
  230. rc = read_name( ifile, pch );
  231. return( rc );
  232. }
  233. BOOL FindSymbol(
  234. WORD selector,
  235. LONG offset,
  236. LPSTR sym_text,
  237. LONG *dist,
  238. int direction,
  239. int mode
  240. ) {
  241. BOOL result;
  242. int length;
  243. int iFile;
  244. char filename[256];
  245. OFSTRUCT ofs;
  246. LONG filesize;
  247. LONG start_position;
  248. LONG position;
  249. WORD w1;
  250. WORD num_syms;
  251. WORD w3;
  252. WORD w4;
  253. WORD next_off;
  254. #ifdef NEED_INDICES
  255. WORD index;
  256. char c2;
  257. int nSubEtry;
  258. #endif
  259. char c1;
  260. int rc;
  261. int cnt;
  262. LONG this_offset;
  263. WORD r2;
  264. WORD seg_num;
  265. char b[12];
  266. char name_buff[128];
  267. LONG this_dist;
  268. HEAPENTRY he = {0};
  269. *dist = -1;
  270. strcpy( sym_text, "[Unknown]" );
  271. result = FALSE;
  272. if ( mode == V86_MODE ) {
  273. return FALSE;
  274. // v86_addr = ((ULONG)selector << 4) + (ULONG)offset;
  275. }
  276. /*
  277. ** Search for selector in kernel heap
  278. */
  279. he.Selector = selector;
  280. while (FindHeapEntry(&he, FALSE)) {
  281. {
  282. strcpy(filename, he.FileName);
  283. strcat(filename,".sym");
  284. iFile = OpenFile( filename, &ofs, MYOF_FLAGS );
  285. if ( iFile == -1 ) {
  286. PRINTF("Could not open symbol file \"%s\"\n", filename );
  287. // Open the .EXE/.DLL file and see if the address corresponds
  288. // to an exported function.
  289. result = FindExport(he.FileName,(WORD)(he.SegmentNumber+1),(WORD)offset,sym_text,direction,dist);
  290. if (!result) {
  291. // not found in any .dll/.exe's export table, so just print file name,
  292. // segment number, and offset
  293. wsprintf(sym_text,"%s(%X):%04X",he.OwnerName, he.SegmentNumber,offset);
  294. *dist = 0;
  295. result = TRUE;
  296. }
  297. continue;
  298. }
  299. rc = _lread( iFile, (LPSTR)&filesize, sizeof(filesize) );
  300. if ( rc != sizeof(filesize) ) {
  301. PRINTF("Could not read file size\n");
  302. _lclose( iFile );
  303. return( FALSE );
  304. }
  305. filesize <<= 4;
  306. rc = _lread( iFile, (LPSTR)&w1, sizeof(w1) );
  307. if ( rc != sizeof(w1) ) {
  308. PRINTF("Could not read w1\n");
  309. _lclose( iFile );
  310. return( FALSE );
  311. }
  312. rc = _lread( iFile, (LPSTR)&num_syms, sizeof(num_syms) );
  313. if ( rc != sizeof(num_syms) ) {
  314. PRINTF("Could not read num_syms\n");
  315. _lclose( iFile );
  316. return( FALSE );
  317. }
  318. rc = _lread( iFile, (LPSTR)&w3, sizeof(w3) );
  319. if ( rc != sizeof(w3) ) {
  320. PRINTF("Could not read w3\n");
  321. _lclose( iFile );
  322. return( FALSE );
  323. }
  324. rc = _lread( iFile, (LPSTR)&w4, sizeof(w4) );
  325. if ( rc != sizeof(w4) ) {
  326. PRINTF("Could not read w4\n");
  327. _lclose( iFile );
  328. return( FALSE );
  329. }
  330. rc = _lread( iFile, (LPSTR)&next_off, sizeof(next_off) );
  331. if ( rc != sizeof(next_off) ) {
  332. PRINTF("Could not read next_off\n");
  333. _lclose( iFile );
  334. return( FALSE );
  335. }
  336. start_position = ((LONG)next_off) << 4;
  337. rc = _lread( iFile, (LPSTR)&c1, sizeof(c1) );
  338. if ( rc != sizeof(c1) ) {
  339. PRINTF("Could not read c1\n");
  340. _lclose( iFile );
  341. return( FALSE );
  342. }
  343. read_name( iFile, name_buff );
  344. #ifdef NEED_ABSOLUTES
  345. #ifdef NEED_SYM4
  346. rc = _lread( iFile, (LPSTR)&c2, sizeof(c2) );
  347. if ( rc != sizeof(c2) ) {
  348. PRINTF("Could not read c2\n");
  349. _lclose( iFile );
  350. return( FALSE );
  351. }
  352. #endif
  353. cnt = num_syms;
  354. while ( cnt ) {
  355. length = read_symbol( lpOutputRoutine, iFile, name_buff, &
  356. this_offset );
  357. if ( length == 0 ) {
  358. PRINTF("Error access symbols in file %s\n", filename );
  359. break;
  360. }
  361. --cnt;
  362. }
  363. #ifdef NEED_INDICES
  364. cnt = num_syms;
  365. while ( cnt ) {
  366. rc = _lread( iFile, (LPSTR)&index, sizeof(index) );
  367. if ( rc != sizeof(index) ) {
  368. PRINTF("Could not read index table entry\n");
  369. _lclose( iFile );
  370. return( FALSE );
  371. }
  372. PRINTF("Index: %04X\n", index );
  373. --cnt;
  374. }
  375. #endif
  376. #endif
  377. position = start_position;
  378. do {
  379. rc = _llseek( iFile, position, FILE_BEGIN );
  380. if ( rc == -1 ) {
  381. PRINTF("Failed to seek to next record\n");
  382. _lclose( iFile );
  383. return( FALSE );
  384. }
  385. rc = _lread( iFile, (LPSTR)&next_off, sizeof(next_off) );
  386. if ( rc != sizeof(next_off) ) {
  387. PRINTF("Could not read next_off\n");
  388. _lclose( iFile );
  389. return( FALSE );
  390. }
  391. position = ((LONG)next_off) << 4;
  392. rc = _lread( iFile, (LPSTR)&num_syms, sizeof(num_syms) );
  393. if ( rc != sizeof(num_syms) ) {
  394. PRINTF("Could not read num_syms\n");
  395. _lclose( iFile );
  396. return( FALSE );
  397. }
  398. rc = _lread( iFile, (LPSTR)&r2, sizeof(r2) );
  399. if ( rc != sizeof(r2) ) {
  400. PRINTF("Could not read r2\n");
  401. _lclose( iFile );
  402. return( FALSE );
  403. }
  404. rc = _lread( iFile, (LPSTR)&seg_num, sizeof(seg_num) );
  405. if ( rc != sizeof(seg_num) ) {
  406. PRINTF("Could not read seg_num\n");
  407. _lclose( iFile );
  408. return( FALSE );
  409. }
  410. if ( mode == PROT_MODE && seg_num != (WORD)(he.SegmentNumber+1) ) {
  411. /*
  412. ** Skip reading of symbols for segments with the wrong seg_num
  413. */
  414. continue;
  415. }
  416. cnt = 0;
  417. while ( cnt < 12 ) {
  418. rc = _lread( iFile, (LPSTR)&b[cnt], sizeof(b[0]) );
  419. if ( rc != sizeof(b[0]) ) {
  420. PRINTF("Could not read 12 byte b array\n");
  421. _lclose( iFile );
  422. return( FALSE );
  423. }
  424. cnt++;
  425. }
  426. read_name( iFile, name_buff );
  427. cnt = num_syms;
  428. while ( cnt ) {
  429. length = read_symbol( iFile, name_buff,
  430. &this_offset );
  431. if ( length == 0 ) {
  432. PRINTF("Error access symbols in file %s\n", filename );
  433. break;
  434. }
  435. switch( mode ) {
  436. case PROT_MODE:
  437. switch( direction ) {
  438. case BEFORE:
  439. this_dist = offset - this_offset;
  440. break;
  441. case AFTER:
  442. this_dist = this_offset - offset;
  443. break;
  444. }
  445. break;
  446. case V86_MODE:
  447. #if 0
  448. mod_addr = mod_offset + (ULONG)(seg_num << 4) + this_offset;
  449. switch( direction ) {
  450. case BEFORE:
  451. this_dist = v86_addr - mod_addr;
  452. break;
  453. case AFTER:
  454. this_dist = mod_addr - v86_addr;
  455. break;
  456. }
  457. #endif
  458. break;
  459. }
  460. if ( this_dist >= 0 && (this_dist < *dist || *dist == -1) ) {
  461. *dist = this_dist;
  462. strcpy( sym_text, name_buff );
  463. result = TRUE;
  464. }
  465. --cnt;
  466. }
  467. #ifdef NEED_INDICES
  468. cnt = num_syms;
  469. while ( cnt ) {
  470. rc = _lread( iFile, (LPSTR)&index, sizeof(index) );
  471. if ( rc != sizeof(index) ) {
  472. PRINTF("Could not read index table entry\n");
  473. _lclose( iFile );
  474. return( FALSE );
  475. }
  476. --cnt;
  477. }
  478. #endif
  479. } while ( position != start_position && position != 0 );
  480. _lclose( iFile );
  481. }
  482. }
  483. return( result );
  484. }
  485. BOOL FindAddress(
  486. WORD *selector,
  487. LONG *offset,
  488. LPSTR sym_text,
  489. int mode
  490. ) {
  491. int length;
  492. int iFile;
  493. char filename[256];
  494. OFSTRUCT ofs;
  495. LONG filesize;
  496. LONG start_position;
  497. LONG position;
  498. WORD w1;
  499. WORD num_syms;
  500. WORD w3;
  501. WORD w4;
  502. WORD next_off;
  503. #ifdef NEED_INDICES
  504. WORD index;
  505. #endif
  506. char c1;
  507. char c2;
  508. int rc;
  509. int cnt;
  510. LONG this_offset;
  511. WORD r2;
  512. WORD seg_num;
  513. char b[12];
  514. char name_buff[128];
  515. char name1[200];
  516. HEAPENTRY he = {0};
  517. strcpy(name1,sym_text);
  518. _strupr(name1);
  519. if (mode == V86_MODE) { //BUGBUG
  520. return FALSE;
  521. }
  522. /*
  523. ** Search for selector in kernel heap
  524. */
  525. while (FindHeapEntry(&he, FALSE)) {
  526. {
  527. strcpy(filename, he.FileName);
  528. strcat(filename,".sym");
  529. iFile = OpenFile( filename, &ofs, MYOF_FLAGS );
  530. if ( iFile == -1 ) {
  531. // PRINTF("Could not open symbol file \"%s\"\n", filename );
  532. continue;
  533. }
  534. rc = _lread( iFile, (LPSTR)&filesize, sizeof(filesize) );
  535. if ( rc != sizeof(filesize) ) {
  536. PRINTF("Could not read file size\n");
  537. _lclose( iFile );
  538. return( FALSE );
  539. }
  540. filesize <<= 4;
  541. rc = _lread( iFile, (LPSTR)&w1, sizeof(w1) );
  542. if ( rc != sizeof(w1) ) {
  543. PRINTF("Could not read w1\n");
  544. _lclose( iFile );
  545. return( FALSE );
  546. }
  547. rc = _lread( iFile, (LPSTR)&num_syms, sizeof(num_syms) );
  548. if ( rc != sizeof(num_syms) ) {
  549. PRINTF("Could not read num_syms\n");
  550. _lclose( iFile );
  551. return( FALSE );
  552. }
  553. rc = _lread( iFile, (LPSTR)&w3, sizeof(w3) );
  554. if ( rc != sizeof(w3) ) {
  555. PRINTF("Could not read w3\n");
  556. _lclose( iFile );
  557. return( FALSE );
  558. }
  559. rc = _lread( iFile, (LPSTR)&w4, sizeof(w4) );
  560. if ( rc != sizeof(w4) ) {
  561. PRINTF("Could not read w4\n");
  562. _lclose( iFile );
  563. return( FALSE );
  564. }
  565. rc = _lread( iFile, (LPSTR)&next_off, sizeof(next_off) );
  566. if ( rc != sizeof(next_off) ) {
  567. PRINTF("Could not read next_off\n");
  568. _lclose( iFile );
  569. return( FALSE );
  570. }
  571. start_position = ((LONG)next_off) << 4;
  572. rc = _lread( iFile, (LPSTR)&c1, sizeof(c1) );
  573. if ( rc != sizeof(c1) ) {
  574. PRINTF("Could not read c1\n");
  575. _lclose( iFile );
  576. return( FALSE );
  577. }
  578. read_name( iFile, name_buff );
  579. rc = _lread( iFile, (LPSTR)&c2, sizeof(c2) );
  580. if ( rc != sizeof(c2) ) {
  581. PRINTF("Could not read c2\n");
  582. _lclose( iFile );
  583. return( FALSE );
  584. }
  585. cnt = num_syms;
  586. while ( cnt ) {
  587. length = read_symbol( iFile, name_buff,
  588. &this_offset );
  589. if ( length == 0 ) {
  590. PRINTF("Error access symbols in file %s\n", filename );
  591. break;
  592. }
  593. --cnt;
  594. }
  595. #ifdef NEED_INDICES
  596. cnt = num_syms;
  597. while ( cnt ) {
  598. rc = _lread( iFile, (LPSTR)&index, sizeof(index) );
  599. if ( rc != sizeof(index) ) {
  600. PRINTF("Could not read index table entry\n");
  601. _lclose( iFile );
  602. return( FALSE );
  603. }
  604. PRINTF("Index: %04X\n", index );
  605. --cnt;
  606. }
  607. #endif
  608. position = start_position;
  609. do {
  610. rc = _llseek( iFile, position, FILE_BEGIN );
  611. if ( rc == -1 ) {
  612. PRINTF("Failed to seek to next record\n");
  613. _lclose( iFile );
  614. return( FALSE );
  615. }
  616. rc = _lread( iFile, (LPSTR)&next_off, sizeof(next_off) );
  617. if ( rc != sizeof(next_off) ) {
  618. PRINTF("Could not read next_off\n");
  619. _lclose( iFile );
  620. return( FALSE );
  621. }
  622. position = ((LONG)next_off) << 4;
  623. rc = _lread( iFile, (LPSTR)&num_syms, sizeof(num_syms) );
  624. if ( rc != sizeof(num_syms) ) {
  625. PRINTF("Could not read num_syms\n");
  626. _lclose( iFile );
  627. return( FALSE );
  628. }
  629. rc = _lread( iFile, (LPSTR)&r2, sizeof(r2) );
  630. if ( rc != sizeof(r2) ) {
  631. PRINTF("Could not read r2\n");
  632. _lclose( iFile );
  633. return( FALSE );
  634. }
  635. rc = _lread( iFile, (LPSTR)&seg_num, sizeof(seg_num) );
  636. if ( rc != sizeof(seg_num) ) {
  637. PRINTF("Could not read seg_num\n");
  638. _lclose( iFile );
  639. return( FALSE );
  640. }
  641. if ( mode == PROT_MODE &&
  642. seg_num != (WORD)(he.SegmentNumber+1) ) {
  643. /*
  644. ** Skip reading of symbols for segments with the wrong seg_num
  645. */
  646. continue;
  647. }
  648. cnt = 0;
  649. while ( cnt < 12 ) {
  650. rc = _lread( iFile, (LPSTR)&b[cnt], sizeof(b[0]) );
  651. if ( rc != sizeof(b[0]) ) {
  652. PRINTF("Could not read 12 byte b array\n");
  653. _lclose( iFile );
  654. return( FALSE );
  655. }
  656. cnt++;
  657. }
  658. read_name( iFile, name_buff );
  659. cnt = num_syms;
  660. while ( cnt ) {
  661. length = read_symbol( iFile, name_buff, &this_offset );
  662. if ( length == 0 ) {
  663. PRINTF("Error access symbols in file %s\n", filename );
  664. break;
  665. }
  666. if ( _stricmp(name_buff,sym_text) == 0 ) {
  667. switch( mode ) {
  668. case PROT_MODE:
  669. *selector = (WORD)(he.gnode.pga_handle | 1);
  670. *offset = this_offset;
  671. _lclose( iFile );
  672. return( TRUE );
  673. #if 0
  674. case V86_MODE:
  675. *selector = se[nEntry].selector + seg_num;
  676. *offset = this_offset;
  677. _lclose( iFile );
  678. return( TRUE );
  679. #endif
  680. }
  681. }
  682. {
  683. char name2[200];
  684. strcpy(name2,name_buff);
  685. _strupr(name2);
  686. if ( strstr(name2,name1) != 0 ) {
  687. switch( mode ) {
  688. case PROT_MODE:
  689. *selector = (WORD)(he.gnode.pga_handle | 1);
  690. *offset = this_offset;
  691. PRINTF("%04X:%04X = %s\n", *selector, *offset, name_buff );
  692. break;
  693. #if 0
  694. case V86_MODE:
  695. *selector = se[nEntry].selector + seg_num;
  696. *offset = this_offset;
  697. PRINTF("%04X:%04X = %s\n", *selector, *offset, name_buff );
  698. break;
  699. #endif
  700. }
  701. }
  702. }
  703. --cnt;
  704. }
  705. } while ( position != start_position && position != 0 );
  706. _lclose( iFile );
  707. }
  708. }
  709. return( FALSE );
  710. }
  711. VOID
  712. ListNear(
  713. ) {
  714. VDMCONTEXT ThreadContext;
  715. WORD selector;
  716. LONG offset;
  717. CHAR sym_text[1000];
  718. DWORD dist;
  719. BOOL b;
  720. int mode;
  721. mode = GetContext( &ThreadContext );
  722. if (!GetNextToken()) {
  723. selector = (WORD) ThreadContext.SegCs;
  724. offset = ThreadContext.Eip;
  725. } else if (!ParseIntelAddress(&mode, &selector, &offset)) {
  726. return;
  727. }
  728. if ( mode == PROT_MODE ) {
  729. PRINTF( "#%04X:%04lX", selector, offset );
  730. }
  731. if ( mode == V86_MODE ) {
  732. PRINTF( "&%04X:%04lX", selector, offset );
  733. }
  734. b = FindSymbol( selector, offset, sym_text, &dist, BEFORE, mode );
  735. if ( !b ) {
  736. PRINTF(" = Could not find symbol before");
  737. } else {
  738. if ( dist == 0 ) {
  739. PRINTF(" = %s", sym_text );
  740. } else {
  741. PRINTF(" = %s + 0x%lx", sym_text, dist );
  742. }
  743. }
  744. b = FindSymbol( selector, offset, sym_text, &dist, AFTER, mode );
  745. if ( !b ) {
  746. PRINTF(" = Could not find symbol after");
  747. } else {
  748. if ( dist == 0 ) {
  749. PRINTF(" = %s", sym_text );
  750. } else {
  751. PRINTF(" = %s - 0x%lx", sym_text, dist );
  752. }
  753. }
  754. PRINTF("\n");
  755. }
  756. VOID
  757. EvaluateSymbol(
  758. ) {
  759. VDMCONTEXT ThreadContext;
  760. BOOL result;
  761. WORD selector;
  762. LONG offset;
  763. int mode;
  764. try {
  765. mode = GetContext( &ThreadContext );
  766. result = FindAddress( &selector, &offset, lpArgumentString, mode );
  767. if ( result ) {
  768. if ( mode == PROT_MODE ) {
  769. PRINTF("Symbol %s = #%04X:%04X PROT_MODE\n", lpArgumentString, selector, offset );
  770. }
  771. if ( mode == V86_MODE ) {
  772. PRINTF("Symbol %s = &%04X:%04X V86_MODE\n", lpArgumentString, selector, offset );
  773. }
  774. return;
  775. }
  776. if ( mode == PROT_MODE ) {
  777. mode = V86_MODE;
  778. } else {
  779. if ( mode == V86_MODE ) {
  780. mode = PROT_MODE;
  781. }
  782. }
  783. result = FindAddress( &selector, &offset, lpArgumentString, mode );
  784. if ( result ) {
  785. if ( mode == PROT_MODE ) {
  786. PRINTF("Symbol %s = #%04X:%04X PROT_MODE\n", lpArgumentString, selector, offset );
  787. }
  788. if ( mode == V86_MODE ) {
  789. PRINTF("Symbol %s = &%04X:%04X V86_MODE\n", lpArgumentString, selector, offset );
  790. }
  791. return;
  792. }
  793. PRINTF("Could not find symbol %s\n", lpArgumentString );
  794. } except (1) {
  795. PRINTF("Exception 0x%08x in !bde.es, don't forget to thank Dave Hart for saving\n"
  796. "your debugging bacon by adding a try/except block!\n"
  797. "And while you're at it remind him to take out this caffeine-induced spew.\n",
  798. GetExceptionCode());
  799. }
  800. }