PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Src/Dependencies/BeaEngine/beaengineSources/Includes/Routines_Disasm.c

http://hadesmem.googlecode.com/
C | 1077 lines | 900 code | 53 blank | 124 comment | 387 complexity | e3ee5cd728548c94f0d4c88c40254a8c MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, Apache-2.0, LGPL-3.0
  1. /* Copyright 2006-2009, BeatriX
  2. * File coded by BeatriX
  3. *
  4. * This file is part of BeaEngine.
  5. *
  6. * BeaEngine is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * BeaEngine is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with BeaEngine. If not, see <http://www.gnu.org/licenses/>. */
  18. /* ====================================================================
  19. *
  20. * ==================================================================== */
  21. int __bea_callspec__ Disasm (PDISASM pMyDisasm) {
  22. if (InitVariables(pMyDisasm)) {
  23. (void) AnalyzeOpcode(pMyDisasm);
  24. if (!GV.OutOfBlock) {
  25. FixArgSizeForMemoryOperand(pMyDisasm);
  26. FixREXPrefixes(pMyDisasm);
  27. FillSegmentsRegisters(pMyDisasm);
  28. CompleteInstructionFields(pMyDisasm);
  29. #ifndef BEA_LIGHT_DISASSEMBLY
  30. if (GV.SYNTAX_ == ATSyntax) {
  31. BuildCompleteInstructionATSyntax(pMyDisasm);
  32. }
  33. else {
  34. BuildCompleteInstruction(pMyDisasm);
  35. }
  36. #endif
  37. if (GV.ERROR_OPCODE) {
  38. return -1;
  39. }
  40. else {
  41. return (int) (GV.EIP_-(*pMyDisasm).EIP);
  42. }
  43. }
  44. else {
  45. return 0;
  46. }
  47. }
  48. else {
  49. return -1;
  50. }
  51. }
  52. /* ====================================================================
  53. *
  54. * ==================================================================== */
  55. void __bea_callspec__ CompleteInstructionFields (PDISASM pMyDisasm) {
  56. if (((*pMyDisasm).Instruction.BranchType == JmpType) || ((*pMyDisasm).Instruction.BranchType == CallType)) {
  57. (*pMyDisasm).Argument1.AccessMode = READ;
  58. }
  59. }
  60. /* ====================================================================
  61. *
  62. * ==================================================================== */
  63. int __bea_callspec__ InitVariables (PDISASM pMyDisasm) {
  64. (void) memset (&GV, 0, sizeof (InternalDatas));
  65. GV.EIP_ = (*pMyDisasm).EIP;
  66. GV.EIP_REAL = GV.EIP_;
  67. GV.EIP_VA = (*pMyDisasm).VirtualAddr;
  68. if ((*pMyDisasm).SecurityBlock != 0) GV.EndOfBlock = GV.EIP_+(*pMyDisasm).SecurityBlock;
  69. GV.OperandSize = 32;
  70. GV.OriginalOperandSize = 32;
  71. GV.AddressSize = 32;
  72. GV.Architecture = (*pMyDisasm).Archi;
  73. (*pMyDisasm).Prefix.Number = 0;
  74. if (GV.Architecture == 64) {
  75. GV.AddressSize = 64;
  76. }
  77. if (GV.Architecture == 16) {
  78. GV.OperandSize = 16;
  79. GV.OriginalOperandSize = 16;
  80. GV.AddressSize = 16;
  81. }
  82. (void) memset (&(*pMyDisasm).Argument1, 0, sizeof (ARGTYPE));
  83. (void) memset (&(*pMyDisasm).Argument2, 0, sizeof (ARGTYPE));
  84. (void) memset (&(*pMyDisasm).Argument3, 0, sizeof (ARGTYPE));
  85. (void) memset (&(*pMyDisasm).Prefix, 0, sizeof (PREFIXINFO));
  86. (*pMyDisasm).Argument1.AccessMode = WRITE;
  87. (*pMyDisasm).Argument1.ArgPosition = LowPosition;
  88. (*pMyDisasm).Argument2.ArgPosition = LowPosition;
  89. (*pMyDisasm).Argument3.ArgPosition = LowPosition;
  90. (*pMyDisasm).Argument1.ArgType = NO_ARGUMENT;
  91. (*pMyDisasm).Argument2.ArgType = NO_ARGUMENT;
  92. (*pMyDisasm).Argument3.ArgType = NO_ARGUMENT;
  93. (*pMyDisasm).Argument2.AccessMode = READ;
  94. (*pMyDisasm).Argument3.AccessMode = READ;
  95. (void) memset (&(*pMyDisasm).Instruction, 0, sizeof (INSTRTYPE));
  96. GV.TAB_ = (UInt32)(*pMyDisasm).Options & 0xff;
  97. GV.SYNTAX_ = (UInt32)(*pMyDisasm).Options & 0xff00;
  98. GV.FORMATNUMBER = (UInt32)(*pMyDisasm).Options & 0xff0000;
  99. GV.SEGMENTREGS = (UInt32)(*pMyDisasm).Options & 0xff000000;
  100. GV.OutOfBlock = 0;
  101. return 1;
  102. }
  103. /* ====================================================================
  104. *
  105. * ==================================================================== */
  106. void __bea_callspec__ FixArgSizeForMemoryOperand (PDISASM pMyDisasm) {
  107. if (GV.MemDecoration == Arg2byte) {
  108. (*pMyDisasm).Argument2.ArgSize = 8;
  109. }
  110. else if (GV.MemDecoration == Arg2word) {
  111. (*pMyDisasm).Argument2.ArgSize = 16;
  112. }
  113. else if (GV.MemDecoration == Arg2dword) {
  114. (*pMyDisasm).Argument2.ArgSize = 32;
  115. }
  116. else if (GV.MemDecoration == Arg2qword) {
  117. (*pMyDisasm).Argument2.ArgSize = 64;
  118. }
  119. else if (GV.MemDecoration == Arg2multibytes) {
  120. (*pMyDisasm).Argument2.ArgSize = 0;
  121. }
  122. else if (GV.MemDecoration == Arg2tbyte) {
  123. (*pMyDisasm).Argument2.ArgSize = 80;
  124. }
  125. else if (GV.MemDecoration == Arg2fword) {
  126. (*pMyDisasm).Argument2.ArgSize = 48;
  127. }
  128. else if (GV.MemDecoration == Arg2dqword) {
  129. (*pMyDisasm).Argument2.ArgSize = 128;
  130. }
  131. if (GV.MemDecoration == Arg1byte) {
  132. (*pMyDisasm).Argument1.ArgSize = 8;
  133. }
  134. else if (GV.MemDecoration == Arg1word) {
  135. (*pMyDisasm).Argument1.ArgSize = 16;
  136. }
  137. else if (GV.MemDecoration == Arg1dword) {
  138. (*pMyDisasm).Argument1.ArgSize = 32;
  139. }
  140. else if (GV.MemDecoration == Arg1qword) {
  141. (*pMyDisasm).Argument1.ArgSize = 64;
  142. }
  143. else if (GV.MemDecoration == Arg1multibytes) {
  144. (*pMyDisasm).Argument1.ArgSize = 0;
  145. }
  146. else if (GV.MemDecoration == Arg1tbyte) {
  147. (*pMyDisasm).Argument1.ArgSize = 80;
  148. }
  149. else if (GV.MemDecoration == Arg1fword) {
  150. (*pMyDisasm).Argument1.ArgSize = 48;
  151. }
  152. else if (GV.MemDecoration == Arg1dqword) {
  153. (*pMyDisasm).Argument1.ArgSize = 128;
  154. }
  155. }
  156. /* ====================================================================
  157. *
  158. * ==================================================================== */
  159. void __bea_callspec__ FixREXPrefixes (PDISASM pMyDisasm) {
  160. (*pMyDisasm).Prefix.REX.W_ = GV.REX.W_;
  161. (*pMyDisasm).Prefix.REX.R_ = GV.REX.R_;
  162. (*pMyDisasm).Prefix.REX.X_ = GV.REX.X_;
  163. (*pMyDisasm).Prefix.REX.B_ = GV.REX.B_;
  164. (*pMyDisasm).Prefix.REX.state = GV.REX.state;
  165. }
  166. /* ====================================================================
  167. *
  168. * ==================================================================== */
  169. int __bea_callspec__ AnalyzeOpcode (PDISASM pMyDisasm) {
  170. (*pMyDisasm).Instruction.Opcode = *((UInt8*) (UIntPtr)(GV.EIP_));
  171. (void) opcode_map1[*((UInt8*) (UIntPtr)GV.EIP_)](pMyDisasm);
  172. return 1;
  173. }
  174. /* ====================================================================
  175. *
  176. * ==================================================================== */
  177. void __bea_callspec__ EbGb(PDISASM pMyDisasm)
  178. {
  179. GV.MemDecoration = Arg1byte;
  180. GV.OperandSize = 8;
  181. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  182. Reg_Opcode(&(*pMyDisasm).Argument2, pMyDisasm);
  183. GV.OperandSize = 32;
  184. GV.EIP_ += GV.DECALAGE_EIP+2;
  185. }
  186. /* ====================================================================
  187. *
  188. * ==================================================================== */
  189. void __bea_callspec__ GbEb(PDISASM pMyDisasm)
  190. {
  191. GV.MemDecoration = Arg2byte;
  192. GV.OperandSize = 8;
  193. MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm);
  194. Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm);
  195. GV.OperandSize = 32;
  196. GV.EIP_ += GV.DECALAGE_EIP+2;
  197. }
  198. /* ====================================================================
  199. *
  200. * ==================================================================== */
  201. void __bea_callspec__ EvGv(PDISASM pMyDisasm)
  202. {
  203. if (GV.OperandSize == 64) {
  204. GV.MemDecoration = Arg1qword;
  205. }
  206. else if (GV.OperandSize == 32) {
  207. GV.MemDecoration = Arg1dword;
  208. }
  209. else {
  210. GV.MemDecoration = Arg1word;
  211. }
  212. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  213. Reg_Opcode(&(*pMyDisasm).Argument2, pMyDisasm);
  214. GV.EIP_ += GV.DECALAGE_EIP+2;
  215. }
  216. /* ====================================================================
  217. *
  218. * ==================================================================== */
  219. void __bea_callspec__ ExGx(PDISASM pMyDisasm)
  220. {
  221. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  222. Reg_Opcode(&(*pMyDisasm).Argument2, pMyDisasm);
  223. GV.EIP_ += GV.DECALAGE_EIP+2;
  224. }
  225. /* ====================================================================
  226. *
  227. * ==================================================================== */
  228. void __bea_callspec__ EvIv(PDISASM pMyDisasm)
  229. {
  230. if (GV.OperandSize >= 32) {
  231. if (GV.OperandSize == 64) {
  232. GV.MemDecoration = Arg1qword;
  233. }
  234. else {
  235. GV.MemDecoration = Arg1dword;
  236. }
  237. GV.ImmediatSize = 32; /* place this instruction before MOD_RM routine to inform it there is an immediat value */
  238. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  239. GV.EIP_ += GV.DECALAGE_EIP+6;
  240. if (!Security(0, pMyDisasm)) return;
  241. #ifndef BEA_LIGHT_DISASSEMBLY
  242. if (GV.OperandSize == 64) {
  243. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.16llX",(Int64) *((Int32*)(UIntPtr) (GV.EIP_-4)));
  244. }
  245. else {
  246. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.8X",(Int64) *((UInt32*)(UIntPtr) (GV.EIP_-4)));
  247. }
  248. #endif
  249. (*pMyDisasm).Argument2.ArgType = CONSTANT_TYPE+ABSOLUTE_;
  250. (*pMyDisasm).Argument2.ArgSize = 32;
  251. (*pMyDisasm).Instruction.Immediat = *((UInt32*)(UIntPtr) (GV.EIP_-4));
  252. }
  253. else {
  254. GV.MemDecoration = Arg1word;
  255. GV.ImmediatSize = 16;
  256. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  257. GV.EIP_ += GV.DECALAGE_EIP+4;
  258. if (!Security(0, pMyDisasm)) return;
  259. #ifndef BEA_LIGHT_DISASSEMBLY
  260. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.4X",(Int64)*((UInt16*)(UIntPtr) (GV.EIP_-2)));
  261. #endif
  262. (*pMyDisasm).Argument2.ArgType = CONSTANT_TYPE+ABSOLUTE_;
  263. (*pMyDisasm).Argument2.ArgSize = 16;
  264. (*pMyDisasm).Instruction.Immediat = *((UInt16*)(UIntPtr) (GV.EIP_-2));
  265. }
  266. }
  267. /* ====================================================================
  268. *
  269. * ==================================================================== */
  270. void __bea_callspec__ EvIb(PDISASM pMyDisasm)
  271. {
  272. Int8 MyNumber;
  273. (*pMyDisasm).Argument2.ArgType = CONSTANT_TYPE+ABSOLUTE_;
  274. (*pMyDisasm).Argument2.ArgSize = 8;
  275. GV.ImmediatSize = 8;
  276. if (GV.OperandSize >= 32) {
  277. if (GV.OperandSize == 64) {
  278. GV.MemDecoration = Arg1qword;
  279. }
  280. else {
  281. GV.MemDecoration = Arg1dword;
  282. }
  283. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  284. GV.EIP_ += GV.DECALAGE_EIP+3;
  285. if (!Security(0, pMyDisasm)) return;
  286. if (GV.OperandSize == 32) {
  287. #ifndef BEA_LIGHT_DISASSEMBLY
  288. MyNumber = *((Int8*)(UIntPtr) (GV.EIP_-1));
  289. if (MyNumber > 0) {
  290. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.2X",(Int64)*((Int8*)(UIntPtr) (GV.EIP_-1)));
  291. }
  292. else {
  293. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.8X",(Int64)*((Int8*)(IntPtr) (GV.EIP_-1)));
  294. }
  295. #endif
  296. }
  297. else {
  298. #ifndef BEA_LIGHT_DISASSEMBLY
  299. MyNumber = *((Int8*)(UIntPtr) (GV.EIP_-1));
  300. if (MyNumber > 0) {
  301. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.2X",(Int64)*((Int8*)(UIntPtr) (GV.EIP_-1)));
  302. }
  303. else {
  304. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.16llX",(Int64)*((Int8*)(IntPtr) (GV.EIP_-1)));
  305. }
  306. #endif
  307. }
  308. (*pMyDisasm).Instruction.Immediat = *((UInt8*)(UIntPtr) (GV.EIP_-1));
  309. }
  310. else {
  311. GV.MemDecoration = Arg1word;
  312. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  313. GV.EIP_ += GV.DECALAGE_EIP+3;
  314. if (!Security(0, pMyDisasm)) return;
  315. #ifndef BEA_LIGHT_DISASSEMBLY
  316. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.4X",(Int64)*((Int8*)(UIntPtr) (GV.EIP_-1)));
  317. #endif
  318. (*pMyDisasm).Instruction.Immediat = *((UInt8*)(UIntPtr) (GV.EIP_-1));
  319. }
  320. }
  321. /* ====================================================================
  322. *
  323. * ==================================================================== */
  324. void __bea_callspec__ EbIb(PDISASM pMyDisasm)
  325. {
  326. (*pMyDisasm).Argument2.ArgType = CONSTANT_TYPE+ABSOLUTE_;
  327. (*pMyDisasm).Argument2.ArgSize = 8;
  328. GV.ImmediatSize = 8;
  329. GV.MemDecoration = Arg1byte;
  330. GV.OperandSize = 8;
  331. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  332. GV.OperandSize = 32;
  333. GV.EIP_ += GV.DECALAGE_EIP+3;
  334. if (!Security(0, pMyDisasm)) return;
  335. #ifndef BEA_LIGHT_DISASSEMBLY
  336. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.8X",(Int64)*((Int8*)(UIntPtr) (GV.EIP_-1)));
  337. #endif
  338. (*pMyDisasm).Instruction.Immediat = *((UInt8*)(UIntPtr) (GV.EIP_-1));
  339. }
  340. /* ====================================================================
  341. *
  342. * ==================================================================== */
  343. void __bea_callspec__ Eb(PDISASM pMyDisasm)
  344. {
  345. GV.MemDecoration = Arg1byte;
  346. GV.OperandSize = 8;
  347. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  348. GV.OperandSize = 32;
  349. GV.EIP_ += GV.DECALAGE_EIP+2;
  350. }
  351. /* ====================================================================
  352. *
  353. * ==================================================================== */
  354. void __bea_callspec__ Ev(PDISASM pMyDisasm)
  355. {
  356. if (GV.OperandSize == 64) {
  357. GV.MemDecoration = Arg1qword;
  358. }
  359. else if (GV.OperandSize == 32) {
  360. GV.MemDecoration = Arg1dword;
  361. }
  362. else {
  363. GV.MemDecoration = Arg1word;
  364. }
  365. MOD_RM(&(*pMyDisasm).Argument1, pMyDisasm);
  366. GV.EIP_ += GV.DECALAGE_EIP+2;
  367. }
  368. /* ====================================================================
  369. *
  370. * ==================================================================== */
  371. void __bea_callspec__ GvEv(PDISASM pMyDisasm)
  372. {
  373. if (GV.OperandSize == 64) {
  374. GV.MemDecoration = Arg2qword;
  375. }
  376. else if (GV.OperandSize == 32) {
  377. GV.MemDecoration = Arg2dword;
  378. }
  379. else {
  380. GV.MemDecoration = Arg2word;
  381. }
  382. MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm);
  383. Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm);
  384. GV.EIP_ += GV.DECALAGE_EIP+2;
  385. }
  386. /* ====================================================================
  387. *
  388. * ==================================================================== */
  389. void __bea_callspec__ GvEb(PDISASM pMyDisasm)
  390. {
  391. if (GV.OperandSize == 64) {
  392. GV.MemDecoration = Arg2byte;
  393. GV.OperandSize = 8;
  394. MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm);
  395. GV.OperandSize = 64;
  396. }
  397. else if (GV.OperandSize == 32) {
  398. GV.MemDecoration = Arg2byte;
  399. GV.OperandSize = 8;
  400. MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm);
  401. GV.OperandSize = 32;
  402. }
  403. else {
  404. GV.MemDecoration = Arg2byte;
  405. GV.OperandSize = 8;
  406. MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm);
  407. GV.OperandSize = 16;
  408. }
  409. Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm);
  410. GV.EIP_ += GV.DECALAGE_EIP+2;
  411. }
  412. /* ====================================================================
  413. *
  414. * ==================================================================== */
  415. void __bea_callspec__ GxEx(PDISASM pMyDisasm)
  416. {
  417. MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm);
  418. Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm);
  419. GV.EIP_ += GV.DECALAGE_EIP+2;
  420. }
  421. /* ====================================================================
  422. *
  423. * ==================================================================== */
  424. void __bea_callspec__ GvEw(PDISASM pMyDisasm)
  425. {
  426. GV.MemDecoration = Arg2word;
  427. GV.OriginalOperandSize = GV.OperandSize;
  428. GV.OperandSize = 16;
  429. MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm);
  430. GV.OperandSize = GV.OriginalOperandSize;
  431. Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm);
  432. GV.EIP_ += GV.DECALAGE_EIP+2;
  433. }
  434. /* ====================================================================
  435. *
  436. * ==================================================================== */
  437. void __bea_callspec__ ALIb(PDISASM pMyDisasm)
  438. {
  439. long MyNumber;
  440. if (!Security(2, pMyDisasm)) return;
  441. GV.ImmediatSize = 8;
  442. MyNumber = *((Int8*)(IntPtr) (GV.EIP_+1));
  443. #ifndef BEA_LIGHT_DISASSEMBLY
  444. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.2X",(Int64) MyNumber);
  445. #endif
  446. (*pMyDisasm).Instruction.Immediat = MyNumber;
  447. #ifndef BEA_LIGHT_DISASSEMBLY
  448. (void) strcpy((char*) &(*pMyDisasm).Argument1.ArgMnemonic, Registers8Bits[0]);
  449. #endif
  450. (*pMyDisasm).Argument1.ArgType = REGISTER_TYPE+GENERAL_REG+REG0;
  451. (*pMyDisasm).Argument1.ArgSize = 8;
  452. (*pMyDisasm).Argument2.ArgType = CONSTANT_TYPE+ABSOLUTE_;
  453. (*pMyDisasm).Argument2.ArgSize = 8;
  454. GV.EIP_ += 2;
  455. }
  456. /* ====================================================================
  457. *
  458. * ==================================================================== */
  459. void __bea_callspec__ eAX_Iv(PDISASM pMyDisasm)
  460. {
  461. UInt32 MyNumber;
  462. (*pMyDisasm).Argument1.ArgType = REGISTER_TYPE+GENERAL_REG+REG0;
  463. (*pMyDisasm).Argument2.ArgType = CONSTANT_TYPE+ABSOLUTE_;
  464. if (GV.OperandSize == 64) {
  465. if (!Security(5, pMyDisasm)) return;
  466. GV.ImmediatSize = 32;
  467. (*pMyDisasm).Argument1.ArgSize = 64;
  468. (*pMyDisasm).Argument2.ArgSize = 32;
  469. MyNumber = *((UInt32*)(UIntPtr) (GV.EIP_+1));
  470. #ifndef BEA_LIGHT_DISASSEMBLY
  471. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.16llX",(Int64) MyNumber);
  472. #endif
  473. (*pMyDisasm).Instruction.Immediat = MyNumber;
  474. if (GV.REX.B_ == 1) {
  475. #ifndef BEA_LIGHT_DISASSEMBLY
  476. (void) strcpy ((char*) (*pMyDisasm).Argument1.ArgMnemonic, Registers64Bits[0+8]);
  477. #endif
  478. }
  479. else {
  480. #ifndef BEA_LIGHT_DISASSEMBLY
  481. (void) strcpy ((char*) (*pMyDisasm).Argument1.ArgMnemonic, Registers64Bits[0]);
  482. #endif
  483. }
  484. GV.EIP_+= 5;
  485. }
  486. else if (GV.OperandSize == 32) {
  487. if (!Security(5, pMyDisasm)) return;
  488. GV.ImmediatSize = 32;
  489. (*pMyDisasm).Argument1.ArgSize = 32;
  490. (*pMyDisasm).Argument2.ArgSize = 32;
  491. MyNumber = *((UInt32*)(UIntPtr) (GV.EIP_+1));
  492. #ifndef BEA_LIGHT_DISASSEMBLY
  493. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.8X",(Int64) MyNumber);
  494. #endif
  495. (*pMyDisasm).Instruction.Immediat = MyNumber;
  496. if (GV.REX.B_ == 1) {
  497. #ifndef BEA_LIGHT_DISASSEMBLY
  498. (void) strcpy ((char*) (*pMyDisasm).Argument1.ArgMnemonic, Registers32Bits[0+8]);
  499. #endif
  500. }
  501. else {
  502. #ifndef BEA_LIGHT_DISASSEMBLY
  503. (void) strcpy ((char*) (*pMyDisasm).Argument1.ArgMnemonic, Registers32Bits[0]);
  504. #endif
  505. }
  506. GV.EIP_+= 5;
  507. }
  508. else {
  509. if (!Security(3, pMyDisasm)) return;
  510. GV.ImmediatSize = 16;
  511. (*pMyDisasm).Argument1.ArgSize = 16;
  512. (*pMyDisasm).Argument2.ArgSize = 16;
  513. MyNumber = *((UInt16*)(UIntPtr) (GV.EIP_+1));
  514. #ifndef BEA_LIGHT_DISASSEMBLY
  515. (void) CopyFormattedNumber(pMyDisasm, (char*) &(*pMyDisasm).Argument2.ArgMnemonic,"%.8X", (Int64) MyNumber);
  516. #endif
  517. (*pMyDisasm).Instruction.Immediat = MyNumber;
  518. if (GV.REX.B_ == 1) {
  519. #ifndef BEA_LIGHT_DISASSEMBLY
  520. (void) strcpy ((char*) (*pMyDisasm).Argument1.ArgMnemonic, Registers16Bits[0+8]);
  521. #endif
  522. }
  523. else {
  524. #ifndef BEA_LIGHT_DISASSEMBLY
  525. (void) strcpy ((char*) (*pMyDisasm).Argument1.ArgMnemonic, Registers16Bits[0]);
  526. #endif
  527. }
  528. GV.EIP_+= 3;
  529. }
  530. }
  531. /* ====================================================================
  532. *
  533. * ==================================================================== */
  534. int __bea_callspec__ Security(int len, PDISASM pMyDisasm)
  535. {
  536. if ((GV.EndOfBlock != 0) && (GV.EIP_+(UInt64)len > GV.EndOfBlock)) {
  537. GV.OutOfBlock = 1;
  538. return 0;
  539. }
  540. return 1;
  541. }
  542. /* ====================================================================
  543. *
  544. * ==================================================================== */
  545. void __bea_callspec__ FillFlags(PDISASM pMyDisasm, int index)
  546. {
  547. (*pMyDisasm).Instruction.Flags = EFLAGS_TABLE[index];
  548. }
  549. /* ====================================================================
  550. *
  551. * ==================================================================== */
  552. void __bea_callspec__ CalculateRelativeAddress(UInt64 * pMyAddress, Int64 MyNumber, PDISASM pMyDisasm)
  553. {
  554. GV.RelativeAddress = 1;
  555. if (GV.EIP_VA != 0) {
  556. *pMyAddress = (UInt64) (GV.EIP_VA+(UInt64) MyNumber);
  557. }
  558. else {
  559. *pMyAddress = (UInt64) (GV.EIP_REAL+(UInt64) MyNumber);
  560. }
  561. }
  562. /* ====================================================================
  563. *
  564. * ==================================================================== */
  565. #ifndef BEA_LIGHT_DISASSEMBLY
  566. size_t __bea_callspec__ CopyFormattedNumber(PDISASM pMyDisasm, char* pBuffer, const char* pFormat, Int64 MyNumber)
  567. {
  568. size_t i = 0;
  569. if (!strcmp(pFormat,"%.2X")) MyNumber = MyNumber & 0xFF;
  570. if (!strcmp(pFormat,"%.4X")) MyNumber = MyNumber & 0xFFFF;
  571. if (!strcmp(pFormat,"%.8X")) MyNumber = MyNumber & 0xFFFFFFFF;
  572. if (GV.FORMATNUMBER == PrefixedNumeral) {
  573. (void) strcpy(pBuffer, "0x");
  574. (void) sprintf (pBuffer+2, pFormat, MyNumber);
  575. i += strlen(pBuffer);
  576. }
  577. else {
  578. (void) sprintf (pBuffer+i, pFormat, MyNumber);
  579. i += strlen(pBuffer);
  580. (void) strcpy(pBuffer+i, "h");
  581. i++;
  582. }
  583. return i;
  584. }
  585. #endif
  586. /* ====================================================================
  587. *
  588. * ==================================================================== */
  589. void __bea_callspec__ FillSegmentsRegisters(PDISASM pMyDisasm)
  590. {
  591. if (((*pMyDisasm).Prefix.LockPrefix == InUsePrefix) && !((*pMyDisasm).Argument1.ArgType & MEMORY_TYPE)) {
  592. (*pMyDisasm).Prefix.LockPrefix = InvalidPrefix;
  593. }
  594. if ((*pMyDisasm).Instruction.Category == GENERAL_PURPOSE_INSTRUCTION+STRING_INSTRUCTION) {
  595. (*pMyDisasm).Argument1.SegmentReg = ESReg;
  596. (*pMyDisasm).Argument2.SegmentReg = DSReg;
  597. /* =============== override affects Arg2 */
  598. if ((*pMyDisasm).Argument2.ArgType & MEMORY_TYPE) {
  599. if ((*pMyDisasm).Prefix.FSPrefix == InUsePrefix) {
  600. (*pMyDisasm).Argument2.SegmentReg = FSReg;
  601. }
  602. else if ((*pMyDisasm).Prefix.GSPrefix == InUsePrefix) {
  603. (*pMyDisasm).Argument2.SegmentReg = GSReg;
  604. }
  605. else if ((*pMyDisasm).Prefix.CSPrefix == InUsePrefix) {
  606. (*pMyDisasm).Argument2.SegmentReg = CSReg;
  607. }
  608. else if ((*pMyDisasm).Prefix.ESPrefix == InUsePrefix) {
  609. (*pMyDisasm).Argument2.SegmentReg = ESReg;
  610. }
  611. else if ((*pMyDisasm).Prefix.SSPrefix == InUsePrefix) {
  612. (*pMyDisasm).Argument2.SegmentReg = SSReg;
  613. }
  614. else {
  615. (*pMyDisasm).Argument2.SegmentReg = DSReg;
  616. }
  617. }
  618. }
  619. else {
  620. if ((*pMyDisasm).Argument1.ArgType & MEMORY_TYPE) {
  621. if (((*pMyDisasm).Argument1.Memory.BaseRegister == REG4) || ((*pMyDisasm).Argument1.Memory.BaseRegister == REG5)) {
  622. (*pMyDisasm).Argument1.SegmentReg = SSReg;
  623. /* ========== override is invalid here */
  624. if ((*pMyDisasm).Argument2.ArgType != MEMORY_TYPE) {
  625. if ((*pMyDisasm).Prefix.FSPrefix == InUsePrefix) {
  626. (*pMyDisasm).Argument1.SegmentReg = FSReg;
  627. (*pMyDisasm).Prefix.FSPrefix = InvalidPrefix;
  628. }
  629. else if ((*pMyDisasm).Prefix.GSPrefix == InUsePrefix) {
  630. (*pMyDisasm).Argument1.SegmentReg = GSReg;
  631. (*pMyDisasm).Prefix.GSPrefix = InvalidPrefix;
  632. }
  633. else if ((*pMyDisasm).Prefix.CSPrefix == InUsePrefix) {
  634. (*pMyDisasm).Argument1.SegmentReg = CSReg;
  635. (*pMyDisasm).Prefix.CSPrefix = InvalidPrefix;
  636. }
  637. else if ((*pMyDisasm).Prefix.DSPrefix == InUsePrefix) {
  638. (*pMyDisasm).Argument1.SegmentReg = DSReg;
  639. (*pMyDisasm).Prefix.DSPrefix = InvalidPrefix;
  640. }
  641. else if ((*pMyDisasm).Prefix.ESPrefix == InUsePrefix) {
  642. (*pMyDisasm).Argument1.SegmentReg = ESReg;
  643. (*pMyDisasm).Prefix.ESPrefix = InvalidPrefix;
  644. }
  645. else if ((*pMyDisasm).Prefix.SSPrefix == InUsePrefix) {
  646. (*pMyDisasm).Argument1.SegmentReg = SSReg;
  647. (*pMyDisasm).Prefix.SSPrefix = InvalidPrefix;
  648. }
  649. }
  650. }
  651. else {
  652. (*pMyDisasm).Argument1.SegmentReg = DSReg;
  653. /* ============= test if there is override */
  654. if ((*pMyDisasm).Prefix.FSPrefix == InUsePrefix) {
  655. (*pMyDisasm).Argument1.SegmentReg = FSReg;
  656. }
  657. else if ((*pMyDisasm).Prefix.GSPrefix == InUsePrefix) {
  658. (*pMyDisasm).Argument1.SegmentReg = GSReg;
  659. }
  660. else if ((*pMyDisasm).Prefix.CSPrefix == InUsePrefix) {
  661. (*pMyDisasm).Argument1.SegmentReg = CSReg;
  662. }
  663. else if ((*pMyDisasm).Prefix.ESPrefix == InUsePrefix) {
  664. (*pMyDisasm).Argument1.SegmentReg = ESReg;
  665. }
  666. else if ((*pMyDisasm).Prefix.SSPrefix == InUsePrefix) {
  667. (*pMyDisasm).Argument1.SegmentReg = SSReg;
  668. }
  669. }
  670. }
  671. if ((*pMyDisasm).Argument2.ArgType & MEMORY_TYPE) {
  672. if (((*pMyDisasm).Argument2.Memory.BaseRegister == REG4) || ((*pMyDisasm).Argument2.Memory.BaseRegister == REG5)) {
  673. (*pMyDisasm).Argument2.SegmentReg = SSReg;
  674. /* ========== override is invalid here */
  675. if ((*pMyDisasm).Prefix.FSPrefix == InUsePrefix) {
  676. (*pMyDisasm).Argument2.SegmentReg = FSReg;
  677. (*pMyDisasm).Prefix.FSPrefix = InvalidPrefix;
  678. }
  679. else if ((*pMyDisasm).Prefix.GSPrefix == InUsePrefix) {
  680. (*pMyDisasm).Argument2.SegmentReg = GSReg;
  681. (*pMyDisasm).Prefix.GSPrefix = InvalidPrefix;
  682. }
  683. else if ((*pMyDisasm).Prefix.CSPrefix == InUsePrefix) {
  684. (*pMyDisasm).Argument2.SegmentReg = CSReg;
  685. (*pMyDisasm).Prefix.CSPrefix = InvalidPrefix;
  686. }
  687. else if ((*pMyDisasm).Prefix.DSPrefix == InUsePrefix) {
  688. (*pMyDisasm).Argument2.SegmentReg = DSReg;
  689. (*pMyDisasm).Prefix.DSPrefix = InvalidPrefix;
  690. }
  691. else if ((*pMyDisasm).Prefix.ESPrefix == InUsePrefix) {
  692. (*pMyDisasm).Argument2.SegmentReg = ESReg;
  693. (*pMyDisasm).Prefix.ESPrefix = InvalidPrefix;
  694. }
  695. else if ((*pMyDisasm).Prefix.SSPrefix == InUsePrefix) {
  696. (*pMyDisasm).Argument2.SegmentReg = SSReg;
  697. (*pMyDisasm).Prefix.SSPrefix = InvalidPrefix;
  698. }
  699. }
  700. else {
  701. (*pMyDisasm).Argument2.SegmentReg = DSReg;
  702. /* ============= test if there is override */
  703. if ((*pMyDisasm).Prefix.FSPrefix == InUsePrefix) {
  704. (*pMyDisasm).Argument2.SegmentReg = FSReg;
  705. }
  706. else if ((*pMyDisasm).Prefix.GSPrefix == InUsePrefix) {
  707. (*pMyDisasm).Argument2.SegmentReg = GSReg;
  708. }
  709. else if ((*pMyDisasm).Prefix.CSPrefix == InUsePrefix) {
  710. (*pMyDisasm).Argument2.SegmentReg = CSReg;
  711. }
  712. else if ((*pMyDisasm).Prefix.ESPrefix == InUsePrefix) {
  713. (*pMyDisasm).Argument2.SegmentReg = ESReg;
  714. }
  715. else if ((*pMyDisasm).Prefix.SSPrefix == InUsePrefix) {
  716. (*pMyDisasm).Argument2.SegmentReg = SSReg;
  717. }
  718. }
  719. }
  720. }
  721. }
  722. #ifndef BEA_LIGHT_DISASSEMBLY
  723. /* ====================================================================
  724. *
  725. * ==================================================================== */
  726. void __bea_callspec__ BuildCompleteInstruction(PDISASM pMyDisasm)
  727. {
  728. size_t i = 0;
  729. /* =============== Copy Instruction Mnemonic */
  730. if ((*pMyDisasm).Prefix.RepnePrefix == InUsePrefix) {
  731. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "repne ");
  732. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  733. }
  734. if ((*pMyDisasm).Prefix.RepPrefix == InUsePrefix) {
  735. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "rep ");
  736. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  737. }
  738. if ((*pMyDisasm).Prefix.LockPrefix == InUsePrefix) {
  739. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "lock ");
  740. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  741. }
  742. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Instruction.Mnemonic);
  743. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  744. /* =============== if TAB = 1, add tabulation */
  745. if (GV.TAB_ == 1) {
  746. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, space_tab[i>10 ? 0 : 10-i]);
  747. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  748. }
  749. /* =============== if Arg1.IsMemoryType, add decoration-example == "dword ptr ds:[" */
  750. if ((GV.MemDecoration >0) && (GV.MemDecoration < 99)) {
  751. if (GV.SYNTAX_ == NasmSyntax) {
  752. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, NasmPrefixes[GV.MemDecoration-1]);
  753. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  754. if ((GV.SEGMENTREGS != 0) || (GV.SEGMENTFS != 0)){
  755. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "[");
  756. i++;
  757. if (GV.SEGMENTREGS != 0) {
  758. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[(*pMyDisasm).Argument1.SegmentReg]);
  759. }
  760. else {
  761. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[3]);
  762. }
  763. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  764. }
  765. else {
  766. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "[");
  767. i++;
  768. }
  769. }
  770. else {
  771. if (GV.SYNTAX_ == MasmSyntax) {
  772. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, MasmPrefixes[GV.MemDecoration-1]);
  773. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  774. }
  775. else {
  776. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, GoAsmPrefixes[GV.MemDecoration-1]);
  777. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  778. }
  779. if ((GV.SEGMENTREGS != 0) || (GV.SEGMENTFS != 0)){
  780. if (GV.SEGMENTREGS != 0) {
  781. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[(*pMyDisasm).Argument1.SegmentReg]);
  782. }
  783. else {
  784. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[3]);
  785. }
  786. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  787. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "[");
  788. i++;
  789. }
  790. else {
  791. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "[");
  792. i++;
  793. }
  794. }
  795. /* =============== add Arg1.Mnemonic */
  796. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Argument1.ArgMnemonic);
  797. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  798. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "]");
  799. i++;
  800. }
  801. /* =============== add Arg1.Mnemonic */
  802. else {
  803. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Argument1.ArgMnemonic);
  804. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  805. }
  806. /* =============== if Arg2.Exists and Arg1.Exists , add"," */
  807. if (((UInt8)*((UInt8*) &(*pMyDisasm).Argument1.ArgMnemonic) != 0) && ((UInt8)*((UInt8*) &(*pMyDisasm).Argument2.ArgMnemonic) != 0)) {
  808. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, ", ");
  809. i += 2;
  810. }
  811. /* =============== if Arg2.IsMemoryType, add decoration-example == "dword ptr ds:[" */
  812. if ((GV.MemDecoration >100) && (GV.MemDecoration < 199)) {
  813. GV.MemDecoration -= 100;
  814. if (GV.SYNTAX_ == NasmSyntax) {
  815. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, NasmPrefixes[GV.MemDecoration-1]);
  816. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  817. if ((GV.SEGMENTREGS != 0) || (GV.SEGMENTFS != 0)){
  818. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "[");
  819. i++;
  820. if (GV.SEGMENTREGS != 0) {
  821. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[(*pMyDisasm).Argument2.SegmentReg]);
  822. }
  823. else {
  824. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[3]);
  825. }
  826. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  827. }
  828. else {
  829. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "[");
  830. i++;
  831. }
  832. }
  833. else {
  834. if (GV.SYNTAX_ == MasmSyntax) {
  835. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, MasmPrefixes[GV.MemDecoration-1]);
  836. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  837. }
  838. else {
  839. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, GoAsmPrefixes[GV.MemDecoration-1]);
  840. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  841. }
  842. if ((GV.SEGMENTREGS != 0) || (GV.SEGMENTFS != 0)){
  843. if (GV.SEGMENTREGS != 0) {
  844. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[(*pMyDisasm).Argument2.SegmentReg]);
  845. }
  846. else {
  847. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[3]);
  848. }
  849. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  850. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "[");
  851. i++;
  852. }
  853. else {
  854. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "[");
  855. i++;
  856. }
  857. }
  858. /* =============== add Arg2.ArgMnemonic */
  859. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Argument2.ArgMnemonic);
  860. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  861. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "]");
  862. i++;
  863. }
  864. /* =============== add Arg2.ArgMnemonic */
  865. else {
  866. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Argument2.ArgMnemonic);
  867. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  868. }
  869. /* =============== if Arg3.Exists */
  870. if (GV.third_arg != 0) {
  871. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, ", ");
  872. i += 2;
  873. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Argument3.ArgMnemonic);
  874. }
  875. }
  876. /* ====================================================================
  877. *
  878. * ==================================================================== */
  879. void __bea_callspec__ BuildCompleteInstructionATSyntax(PDISASM pMyDisasm)
  880. {
  881. size_t i = 0;
  882. /* =============== Copy Instruction Mnemonic */
  883. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr, (char*) &(*pMyDisasm).Instruction.Mnemonic);
  884. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  885. /* =============== suffix the mnemonic */
  886. if (GV.MemDecoration != 0) {
  887. if (GV.MemDecoration > 99) GV.MemDecoration -= 100;
  888. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[GV.MemDecoration-1]);
  889. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  890. }
  891. else {
  892. if ((*pMyDisasm).Argument1.ArgType != NO_ARGUMENT) {
  893. if ((*pMyDisasm).Argument1.ArgSize == 8) {
  894. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[0]);
  895. }
  896. else if ((*pMyDisasm).Argument1.ArgSize == 16) {
  897. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[1]);
  898. }
  899. else if ((*pMyDisasm).Argument1.ArgSize == 32) {
  900. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[2]);
  901. }
  902. else if ((*pMyDisasm).Argument1.ArgSize == 64) {
  903. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[3]);
  904. }
  905. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  906. }
  907. else if ((*pMyDisasm).Argument1.ArgType != NO_ARGUMENT) {
  908. if ((*pMyDisasm).Argument1.ArgSize == 8) {
  909. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[0]);
  910. }
  911. else if ((*pMyDisasm).Argument1.ArgSize == 16) {
  912. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[1]);
  913. }
  914. else if ((*pMyDisasm).Argument1.ArgSize == 32) {
  915. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[2]);
  916. }
  917. else if ((*pMyDisasm).Argument1.ArgSize == 64) {
  918. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i-1, ATSuffixes[3]);
  919. }
  920. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  921. }
  922. }
  923. /* =============== if TAB = 1, add tabulation */
  924. if (GV.TAB_ == 1) {
  925. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, space_tab[i>10 ? 0 : 10-i]);
  926. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  927. }
  928. /* =============== if Arg3.Exists, display it */
  929. if (GV.third_arg != 0) {
  930. if ((*pMyDisasm).Argument3.ArgType & REGISTER_TYPE) {
  931. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "%");
  932. i++;
  933. }
  934. else if ((*pMyDisasm).Argument3.ArgType & CONSTANT_TYPE) {
  935. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "\x24");
  936. i++;
  937. }
  938. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Argument3.ArgMnemonic);
  939. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  940. }
  941. /* =============== if Arg3.Exists and Arg2.Exists , display " , " */
  942. if ((GV.third_arg != 0) && (*((UInt8*) &(*pMyDisasm).Argument2.ArgMnemonic) != 0)) {
  943. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, ", ");
  944. i += 2;
  945. }
  946. /* =============== if Arg2 exists, display it */
  947. if (*((UInt8*) &(*pMyDisasm).Argument2.ArgMnemonic) != 0) {
  948. if ((*pMyDisasm).Argument2.ArgType & CONSTANT_TYPE) {
  949. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "\x24");
  950. i++;
  951. }
  952. else {
  953. if ((*pMyDisasm).Instruction.BranchType != 0) {
  954. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "*");
  955. i++;
  956. }
  957. if ((*pMyDisasm).Argument2.ArgType & REGISTER_TYPE) {
  958. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "%");
  959. i++;
  960. }
  961. else if ((*pMyDisasm).Argument2.ArgType & CONSTANT_TYPE) {
  962. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "\x24");
  963. i++;
  964. }
  965. else {
  966. if ((GV.SEGMENTREGS != 0) || (GV.SEGMENTFS != 0)){
  967. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "%");
  968. i++;
  969. if (GV.SEGMENTREGS != 0) {
  970. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[(*pMyDisasm).Argument2.SegmentReg]);
  971. }
  972. else {
  973. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[3]);
  974. }
  975. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  976. }
  977. }
  978. }
  979. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Argument2.ArgMnemonic);
  980. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  981. }
  982. /* =============== if Arg2.Exists and Arg1.Exists , display " , " */
  983. if (((UInt8)*((UInt8*) &(*pMyDisasm).Argument1.ArgMnemonic) != 0) && ((UInt8)*((UInt8*) &(*pMyDisasm).Argument2.ArgMnemonic) != 0)) {
  984. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, ", ");
  985. i += 2;
  986. }
  987. /* =============== if Arg1 exists, display it */
  988. if (*((UInt8*) &(*pMyDisasm).Argument1.ArgMnemonic) != 0) {
  989. if ((*pMyDisasm).Argument1.ArgType & CONSTANT_TYPE) {
  990. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "\x24");
  991. i++;
  992. }
  993. else {
  994. if ((*pMyDisasm).Instruction.BranchType != 0) {
  995. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "*");
  996. i++;
  997. }
  998. if ((*pMyDisasm).Argument1.ArgType & REGISTER_TYPE) {
  999. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "%");
  1000. i++;
  1001. }
  1002. else if ((*pMyDisasm).Argument1.ArgType & CONSTANT_TYPE) {
  1003. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "\x24");
  1004. i++;
  1005. }
  1006. else {
  1007. if ((GV.SEGMENTREGS != 0) || (GV.SEGMENTFS != 0)){
  1008. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, "%");
  1009. i++;
  1010. if (GV.SEGMENTREGS != 0) {
  1011. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[(*pMyDisasm).Argument1.SegmentReg]);
  1012. }
  1013. else {
  1014. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, SegmentRegs[3]);
  1015. }
  1016. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  1017. }
  1018. }
  1019. }
  1020. (void) strcpy ((char*) &(*pMyDisasm).CompleteInstr+i, (char*) &(*pMyDisasm).Argument1.ArgMnemonic);
  1021. i = strlen((char*) &(*pMyDisasm).CompleteInstr);
  1022. }
  1023. }
  1024. #endif