MgDisasmBase.cpp 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781
  1. // MgDisasmBase.cpp: implementation of the CMgDisasmBase class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "MgAsmCom.h"
  6. #include "MgAsmComDef.h"
  7. //-------------------------------------------------------------------------------------------------------------------------
  8. //全局变量声明:
  9. // Bit combinations that can be potentially dangerous when executed:
  10. t_cmddata g_Dangerous[] =
  11. {
  12. { 0x00FFFF, 0x00DCF7, 0, 0, 0, 0, 0, C_DANGER95, "Win95/98 may crash when NEG ESP is executed" },
  13. { 0x00FFFF, 0x00D4F7, 0, 0, 0, 0, 0, C_DANGER95, "Win95/98 may crash when NOT ESP is executed" },
  14. { 0x00FFFF, 0x0020CD, 0, 0, 0, 0, 0, C_DANGER95, "Win95/98 may crash when VxD call is executed in user mode" },
  15. { 0xF8FFFF, 0xC8C70F, 0, 0, 0, 0, 1, C_DANGERLOCK, "LOCK CMPXCHG8B may crash some processors when executed" },
  16. { 0x000000, 0x000000, 0, 0, 0, 0, 0, 0, "" }
  17. };
  18. //-------------------------------------------------------------------------------------------------------------------------
  19. //
  20. //////////////////////////////////////////////////////////////////////
  21. // Construction/Destruction
  22. //////////////////////////////////////////////////////////////////////
  23. CMgDisasmBase::CMgDisasmBase()
  24. {
  25. //
  26. m_pDisasm = NULL;
  27. //
  28. m_pCmd = NULL; // Pointer to binary data
  29. m_pPFixup = NULL; // Pointer to possible fixups or NULL
  30. m_ulSize = 0; // Remaining size of the command buffer
  31. m_nMode = 0; // Disassembly mode (DISASM_xxx)
  32. //
  33. m_ulDataSize = 0; // Size of data (1,2,4 bytes)
  34. m_ulAddrSize = 0; // Size of address (2 or 4 bytes)
  35. //
  36. m_nSegPrefix = 0; // Segment override prefix or SEG_UNDEF
  37. m_nHasRM = 0; // Command has ModR/M byte
  38. m_nHasSIB = 0; // Command has SIB byte
  39. m_nDispSize = 0; // Size of displacement (if any)
  40. m_nImmSize = 0; // Size of immediate data (if any)
  41. m_nSoftError = 0; // Noncritical disassembler error
  42. m_nDump = 0; // Current length of command dump
  43. m_nResult = 0; // Current length of disassembly
  44. m_nAddComment = 0; // Comment value of operand
  45. //
  46. m_nIDEAL = 0; // Force IDEAL decoding mode
  47. m_nLowercase = 0; // Force lowercase display
  48. m_nTabArguments = 1; // Tab between mnemonic and arguments
  49. m_nExtraSpace = 0; // Extra space between arguments
  50. m_nPutDefSeg = 0; // Display default segments in listing
  51. m_nShowMemSize = 0; // Always show memory size
  52. m_nShowNEAR = 0; // Show NEAR modifiers
  53. m_nShortStringCmds = 0; // Use short form of string commands
  54. m_nSizeSens = 0; // How to decode size-sensitive mnemonics
  55. m_nSymbolic = 0; // Show symbolic addresses in disasm
  56. m_nFarCalls = 0; // Accept far calls, returns & addresses
  57. m_nDecodeVxd = 0; // Decode VxD calls (Win95/98)
  58. m_nPrivileged = 0; // Accept privileged commands
  59. m_nIOCommand = 0; // Accept I/O commands
  60. m_nBadShift = 0; // Accept shift out of range 1..31
  61. m_nExtraPrefix = 0; // Accept superfluous prefixes
  62. m_nLockedbus = 0; // Accept LOCK prefixes
  63. m_nStackAlign = 0; // Accept unaligned stack operations
  64. m_nIsWindowsNT = 0; // When checking for dangers, assume NT
  65. }
  66. CMgDisasmBase::~CMgDisasmBase()
  67. {
  68. }
  69. //----------------------------------------------------------------------------
  70. // Disassemble name of 1, 2 or 4-byte general-purpose integer register and, if
  71. // requested and available, dump its contents. Parameter type changes decoding
  72. // of contents for some operand types.
  73. //----------------------------------------------------------------------------
  74. void CMgDisasmBase::DecodeRG(int index, int datasize, int type)
  75. {
  76. int sizeindex;
  77. char name[9];
  78. if (m_nMode < DISASM_DATA)
  79. {
  80. return; // No need to decode
  81. }
  82. index &= 0x07;
  83. if (m_ulDataSize == 1)
  84. {
  85. sizeindex = 0;
  86. }
  87. else if (m_ulDataSize == 2)
  88. {
  89. sizeindex = 1;
  90. }
  91. else if (m_ulDataSize == 4)
  92. {
  93. sizeindex = 2;
  94. }
  95. else
  96. {
  97. m_pDisasm->error = DAE_INTERN;
  98. return;
  99. }
  100. if (m_nMode >= DISASM_FILE)
  101. {
  102. strcpy(name, g_szRegName[sizeindex][index]);
  103. if (m_nLowercase)
  104. {
  105. strlwr(name);
  106. }
  107. if (type < PSEUDOOP) // Not a pseudooperand
  108. {
  109. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%s"), name);
  110. }
  111. }
  112. }
  113. //----------------------------------------------------------------------------
  114. // Disassemble name of 80-bit floating-point register and, if available, dump
  115. // its contents.
  116. //----------------------------------------------------------------------------
  117. void CMgDisasmBase::DecodeST(int index, int pseudoop)
  118. {
  119. int i;
  120. char s[32];
  121. if (m_nMode < DISASM_FILE)
  122. {
  123. return; // No need to decode
  124. }
  125. index &= 0x07;
  126. i = sprintf(s, ("%s(%i)"), (m_nLowercase ? ("st") : ("ST")), index);
  127. if (pseudoop == 0)
  128. {
  129. strcpy(m_pDisasm->result + m_nResult, s);
  130. m_nResult += i;
  131. };
  132. }
  133. //----------------------------------------------------------------------------
  134. // Disassemble name of 64-bit MMX register.
  135. //----------------------------------------------------------------------------
  136. void CMgDisasmBase::DecodeMX(int index)
  137. {
  138. char* pr;
  139. if (m_nMode < DISASM_FILE)
  140. {
  141. return; // No need to decode
  142. }
  143. index &= 0x07;
  144. pr = m_pDisasm->result + m_nResult;
  145. m_nResult += sprintf(pr, ("%s%i"), (m_nLowercase ? ("mm") : ("MM")), index);
  146. }
  147. //----------------------------------------------------------------------------
  148. // Disassemble name of 64-bit 3DNow! register and, if available, dump its
  149. // contents.
  150. //----------------------------------------------------------------------------
  151. void CMgDisasmBase::DecodeNR(int index)
  152. {
  153. char* pr;
  154. if (m_nMode < DISASM_FILE)
  155. {
  156. return; // No need to decode
  157. }
  158. index &= 0x07;
  159. pr = m_pDisasm->result + m_nResult;
  160. m_nResult += sprintf(pr, ("%s%i"), (m_nLowercase ? ("mm") : ("MM")), index);
  161. }
  162. //----------------------------------------------------------------------------
  163. // Disassemble memory/register from the ModRM/SIB bytes and, if available, dump
  164. // address and contents of memory.
  165. //----------------------------------------------------------------------------
  166. void CMgDisasmBase::DecodeMR(int type)
  167. {
  168. int j, memonly, inmemory, seg;
  169. int c, sib;
  170. ulong dsize, regsize, addr;
  171. char s[TEXTLEN];
  172. //
  173. if (m_ulSize < 2)
  174. {
  175. m_pDisasm->error = DAE_CROSS; // ModR/M byte outside the memory block
  176. return;
  177. }
  178. m_nHasRM = 1;
  179. dsize = regsize = m_ulDataSize; // Default size of addressed reg/memory
  180. memonly = 0; // Register in ModM field is allowed
  181. // Size and kind of addressed memory or register in ModM has no influence on
  182. // the command size, and exact calculations are omitted if only command size
  183. // is requested. If register is used, optype will be incorrect and we need
  184. // to correct it later.
  185. c = m_pCmd[1] & 0xC7; // Leave only Mod and M fields
  186. if (m_nMode >= DISASM_DATA)
  187. {
  188. // Register operand
  189. if ((c & 0xC0) == 0xC0)
  190. {
  191. inmemory = 0;
  192. }
  193. else
  194. {
  195. inmemory = 1; // Memory operand
  196. }
  197. switch (type)
  198. {
  199. case MRG: // Memory/register in ModRM byte
  200. {
  201. if (inmemory)
  202. {
  203. if (m_ulDataSize == 1)
  204. {
  205. m_pDisasm->memtype = DEC_BYTE;
  206. }
  207. else if (m_ulDataSize == 2)
  208. {
  209. m_pDisasm->memtype = DEC_WORD;
  210. }
  211. else
  212. {
  213. m_pDisasm->memtype = DEC_DWORD;
  214. }
  215. }
  216. break;
  217. }
  218. case MRJ: // Memory/reg in ModRM as JUMP target
  219. {
  220. if (m_ulDataSize != 2 && inmemory)
  221. {
  222. m_pDisasm->memtype = DEC_DWORD;
  223. }
  224. if (m_nMode >= DISASM_FILE && m_nShowNEAR != 0)
  225. {
  226. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%s "), (m_nLowercase ? ("near") : ("NEAR")));
  227. }
  228. break;
  229. }
  230. case MR1: // 1-byte memory/register in ModRM byte
  231. {
  232. dsize = regsize = 1;
  233. if (inmemory)
  234. {
  235. m_pDisasm->memtype = DEC_BYTE;
  236. }
  237. break;
  238. }
  239. case MR2: // 2-byte memory/register in ModRM byte
  240. {
  241. dsize = regsize = 2;
  242. if (inmemory)
  243. {
  244. m_pDisasm->memtype = DEC_WORD;
  245. }
  246. break;
  247. }
  248. case MR4: // 4-byte memory/register in ModRM byte
  249. case RR4: // 4-byte memory/register (register only)
  250. {
  251. dsize = regsize = 4;
  252. if (inmemory)
  253. {
  254. m_pDisasm->memtype = DEC_DWORD;
  255. }
  256. break;
  257. }
  258. case MR8: // 8-byte memory/MMX register in ModRM
  259. case RR8: // 8-byte MMX register only in ModRM
  260. {
  261. dsize = 8;
  262. if (inmemory)
  263. {
  264. m_pDisasm->memtype = DEC_QWORD;
  265. }
  266. break;
  267. }
  268. case MRD: // 8-byte memory/3DNow! register in ModRM
  269. case RRD: // 8-byte memory/3DNow! (register only)
  270. {
  271. dsize = 8;
  272. if (inmemory)
  273. {
  274. m_pDisasm->memtype = DEC_3DNOW;
  275. }
  276. break;
  277. }
  278. case MMA: // Memory address in ModRM byte for LEA
  279. {
  280. memonly = 1;
  281. break;
  282. }
  283. case MML: // Memory in ModRM byte (for LES)
  284. {
  285. dsize = m_ulDataSize + 2;
  286. memonly = 1;
  287. if (m_ulDataSize == 4 && inmemory)
  288. {
  289. m_pDisasm->memtype = DEC_FWORD;
  290. }
  291. m_pDisasm->warnings |= DAW_SEGMENT;
  292. break;
  293. }
  294. case MMS: // Memory in ModRM byte (as SEG:OFFS)
  295. {
  296. dsize = m_ulDataSize + 2;
  297. memonly = 1;
  298. if (m_ulDataSize == 4 && inmemory)
  299. {
  300. m_pDisasm->memtype = DEC_FWORD;
  301. }
  302. if (m_nMode >= DISASM_FILE)
  303. {
  304. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%s "), (m_nLowercase ? ("far") : ("FAR")));
  305. }
  306. break;
  307. }
  308. case MM6: // Memory in ModRM (6-byte descriptor)
  309. {
  310. dsize = 6;
  311. memonly = 1;
  312. if (inmemory)
  313. {
  314. m_pDisasm->memtype = DEC_FWORD;
  315. }
  316. break;
  317. }
  318. case MMB: // Two adjacent memory locations (BOUND)
  319. {
  320. dsize = (m_nIDEAL ? m_ulDataSize : m_ulDataSize * 2);
  321. memonly = 1;
  322. break;
  323. }
  324. case MD2: // Memory in ModRM byte (16-bit integer)
  325. case MB2: // Memory in ModRM byte (16-bit binary)
  326. {
  327. dsize = 2;
  328. memonly = 1;
  329. if (inmemory)
  330. {
  331. m_pDisasm->memtype = DEC_WORD;
  332. }
  333. break;
  334. }
  335. case MD4: // Memory in ModRM byte (32-bit integer)
  336. {
  337. dsize = 4;
  338. memonly = 1;
  339. if (inmemory)
  340. {
  341. m_pDisasm->memtype = DEC_DWORD;
  342. }
  343. break;
  344. }
  345. case MD8: // Memory in ModRM byte (64-bit integer)
  346. {
  347. dsize = 8;
  348. memonly = 1;
  349. if (inmemory)
  350. {
  351. m_pDisasm->memtype = DEC_QWORD;
  352. }
  353. break;
  354. }
  355. case MDA: // Memory in ModRM byte (80-bit BCD)
  356. {
  357. dsize = 10;
  358. memonly = 1;
  359. if (inmemory)
  360. {
  361. m_pDisasm->memtype = DEC_TBYTE;
  362. }
  363. break;
  364. }
  365. case MF4: // Memory in ModRM byte (32-bit float)
  366. {
  367. dsize = 4;
  368. memonly = 1;
  369. if (inmemory)
  370. {
  371. m_pDisasm->memtype = DEC_FLOAT4;
  372. }
  373. break;
  374. }
  375. case MF8: // Memory in ModRM byte (64-bit float)
  376. {
  377. dsize = 8;
  378. memonly = 1;
  379. if (inmemory)
  380. {
  381. m_pDisasm->memtype = DEC_FLOAT8;
  382. }
  383. break;
  384. }
  385. case MFA: // Memory in ModRM byte (80-bit float)
  386. {
  387. dsize = 10;
  388. memonly = 1;
  389. if (inmemory)
  390. {
  391. m_pDisasm->memtype = DEC_FLOAT10;
  392. }
  393. break;
  394. }
  395. case MFE: // Memory in ModRM byte (FPU environment)
  396. {
  397. dsize = 28;
  398. memonly = 1;
  399. break;
  400. }
  401. case MFS: // Memory in ModRM byte (FPU state)
  402. {
  403. dsize = 108;
  404. memonly = 1;
  405. break;
  406. }
  407. case MFX: // Memory in ModRM byte (ext. FPU state)
  408. {
  409. dsize = 512;
  410. memonly = 1;
  411. break;
  412. }
  413. default: // Operand is not in ModM!
  414. {
  415. m_pDisasm->error = DAE_INTERN;
  416. break;
  417. }
  418. }
  419. }
  420. addr = 0;
  421. // There are many possibilities to decode ModM/SIB address. The first
  422. // possibility is register in ModM - general-purpose, MMX or 3DNow!
  423. if ((c & 0xC0) == 0xC0) // Decode register operand
  424. {
  425. if (type == MR8 || type == RR8)
  426. {
  427. DecodeMX(c); // MMX register
  428. }
  429. else if (type == MRD || type == RRD)
  430. {
  431. DecodeNR(c); // 3DNow! register
  432. }
  433. else
  434. {
  435. DecodeRG(c, regsize, type); // General-purpose register
  436. }
  437. //
  438. if (memonly != 0)
  439. {
  440. m_nSoftError = DAE_MEMORY; // Register where only memory allowed
  441. }
  442. return;
  443. }
  444. // Next possibility: 16-bit addressing mode, very seldom in 32-bit flat model
  445. // but still supported by processor. SIB byte is never used here.
  446. if (m_ulAddrSize == 2)
  447. {
  448. if (c == 0x06) // Special case of immediate address
  449. {
  450. m_nDispSize = 2;
  451. if (m_ulSize < 4)
  452. {
  453. m_pDisasm->error = DAE_CROSS; // Disp16 outside the memory block
  454. }
  455. else if (m_nMode >= DISASM_DATA)
  456. {
  457. m_pDisasm->adrconst = addr = *(ushort*)(m_pCmd + 2);
  458. if (addr == 0)
  459. {
  460. m_pDisasm->zeroconst = 1;
  461. }
  462. seg = SEG_DS;
  463. Memadr(seg, (""), addr, dsize);
  464. }
  465. }
  466. else
  467. {
  468. m_pDisasm->indexed = 1;
  469. if ((c & 0xC0) == 0x40) // 8-bit signed displacement
  470. {
  471. if (m_ulSize < 3)
  472. {
  473. m_pDisasm->error = DAE_CROSS;
  474. }
  475. else
  476. {
  477. addr = (signed char)m_pCmd[2] & 0xFFFF;
  478. }
  479. m_nDispSize = 1;
  480. }
  481. else if ((c & 0xC0) == 0x80) // 16-bit unsigned displacement
  482. {
  483. if (m_ulSize < 4)
  484. {
  485. m_pDisasm->error = DAE_CROSS;
  486. }
  487. else
  488. {
  489. addr = *(ushort*)(m_pCmd + 2);
  490. }
  491. m_nDispSize = 2;
  492. }
  493. if (m_nMode >= DISASM_DATA && m_pDisasm->error == DAE_NOERR)
  494. {
  495. m_pDisasm->adrconst = addr;
  496. if (addr == 0)
  497. {
  498. m_pDisasm->zeroconst = 1;
  499. }
  500. seg = g_addr16[c & 0x07].defseg;
  501. Memadr(seg, g_addr16[c & 0x07].descr, addr, dsize);
  502. }
  503. }
  504. }
  505. // Next possibility: immediate 32-bit address.
  506. else if (c == 0x05) // Special case of immediate address
  507. {
  508. m_nDispSize = 4;
  509. if (m_ulSize < 6)
  510. {
  511. m_pDisasm->error = DAE_CROSS; // Disp32 outside the memory block
  512. }
  513. else if (m_nMode >= DISASM_DATA)
  514. {
  515. m_pDisasm->adrconst = addr = *(ulong*)(m_pCmd + 2);
  516. if (m_pPFixup == NULL)
  517. {
  518. m_pPFixup = m_pCmd + 2;
  519. }
  520. m_pDisasm->fixupsize += 4;
  521. if (addr == 0)
  522. {
  523. m_pDisasm->zeroconst = 1;
  524. }
  525. seg = SEG_DS;
  526. Memadr(seg, (""), addr, dsize);
  527. }
  528. }
  529. // Next possibility: 32-bit address with SIB byte.
  530. else if ((c & 0x07) == 0x04) // SIB addresation
  531. {
  532. sib = m_pCmd[2];
  533. m_nHasSIB = 1;
  534. *s = '\0';
  535. if (c == 0x04 && (sib & 0x07) == 0x05)
  536. {
  537. m_nDispSize = 4; // Immediate address without base
  538. if (m_ulSize < 7)
  539. {
  540. m_pDisasm->error = DAE_CROSS; // Disp32 outside the memory block
  541. }
  542. else
  543. {
  544. m_pDisasm->adrconst = addr = *(ulong*)(m_pCmd + 3);
  545. if (m_pPFixup == NULL)
  546. {
  547. m_pPFixup = m_pCmd + 3;
  548. }
  549. m_pDisasm->fixupsize += 4;
  550. if (addr == 0)
  551. {
  552. m_pDisasm->zeroconst = 1;
  553. }
  554. if ((sib & 0x38) != 0x20) // Index register present
  555. {
  556. m_pDisasm->indexed = 1;
  557. if (type == MRJ)
  558. {
  559. m_pDisasm->jmptable = addr;
  560. }
  561. }
  562. seg = SEG_DS;
  563. }
  564. }
  565. else // Base and, eventually, displacement
  566. {
  567. if ((c & 0xC0) == 0x40) // 8-bit displacement
  568. {
  569. m_nDispSize = 1;
  570. if (m_ulSize < 4)
  571. {
  572. m_pDisasm->error = DAE_CROSS;
  573. }
  574. else
  575. {
  576. m_pDisasm->adrconst = addr = (signed char)m_pCmd[3];
  577. if (addr == 0)
  578. {
  579. m_pDisasm->zeroconst = 1;
  580. }
  581. }
  582. }
  583. else if ((c & 0xC0) == 0x80) // 32-bit displacement
  584. {
  585. m_nDispSize = 4;
  586. if (m_ulSize < 7)
  587. {
  588. m_pDisasm->error = DAE_CROSS; // Disp32 outside the memory block
  589. }
  590. else
  591. {
  592. m_pDisasm->adrconst = addr = *(ulong*)(m_pCmd + 3);
  593. if (m_pPFixup == NULL)
  594. {
  595. m_pPFixup = m_pCmd + 3;
  596. }
  597. m_pDisasm->fixupsize += 4;
  598. if (addr == 0)
  599. {
  600. m_pDisasm->zeroconst = 1;
  601. }
  602. // Most compilers use address of type [index*4+displacement] to
  603. // address jump table (switch). But, for completeness, I allow all
  604. // cases which include index with scale 1 or 4, base or both.
  605. if (type == MRJ)
  606. {
  607. m_pDisasm->jmptable = addr;
  608. }
  609. }
  610. }
  611. m_pDisasm->indexed = 1;
  612. j = sib & 0x07;
  613. if (m_nMode >= DISASM_FILE)
  614. {
  615. strcpy(s, g_szRegName[2][j]);
  616. seg = g_addr32[j].defseg;
  617. }
  618. }
  619. if ((sib & 0x38) != 0x20) // Scaled index present
  620. {
  621. if ((sib & 0xC0) == 0x40)
  622. {
  623. m_pDisasm->indexed = 2;
  624. }
  625. else if ((sib & 0xC0) == 0x80)
  626. {
  627. m_pDisasm->indexed = 4;
  628. }
  629. else if ((sib & 0xC0) == 0xC0)
  630. {
  631. m_pDisasm->indexed = 8;
  632. }
  633. else
  634. {
  635. m_pDisasm->indexed = 1;
  636. }
  637. }
  638. if (m_nMode >= DISASM_FILE && m_pDisasm->error == DAE_NOERR)
  639. {
  640. if ((sib & 0x38) != 0x20) // Scaled index present
  641. {
  642. if (*s != '\0')
  643. {
  644. strcat(s, ("+"));
  645. }
  646. strcat(s, g_addr32[(sib >> 3) & 0x07].descr);
  647. if ((sib & 0xC0) == 0x40)
  648. {
  649. m_pDisasm->jmptable = 0; // Hardly a switch!
  650. strcat(s, ("*2"));
  651. }
  652. else if ((sib & 0xC0) == 0x80)
  653. {
  654. strcat(s, ("*4"));
  655. }
  656. else if ((sib & 0xC0) == 0xC0)
  657. {
  658. m_pDisasm->jmptable = 0; // Hardly a switch!
  659. strcat(s, ("*8"));
  660. }
  661. }
  662. Memadr(seg, s, addr, dsize);
  663. }
  664. }
  665. // Last possibility: 32-bit address without SIB byte.
  666. else // No SIB
  667. {
  668. if ((c & 0xC0) == 0x40)
  669. {
  670. m_nDispSize = 1;
  671. if (m_ulSize < 3)
  672. {
  673. m_pDisasm->error = DAE_CROSS; // Disp8 outside the memory block
  674. }
  675. else
  676. {
  677. m_pDisasm->adrconst = addr = (signed char)m_pCmd[2];
  678. if (addr == 0)
  679. {
  680. m_pDisasm->zeroconst = 1;
  681. }
  682. }
  683. }
  684. else if ((c & 0xC0) == 0x80)
  685. {
  686. m_nDispSize = 4;
  687. if (m_ulSize < 6)
  688. {
  689. m_pDisasm->error = DAE_CROSS; // Disp32 outside the memory block
  690. }
  691. else
  692. {
  693. m_pDisasm->adrconst = addr = *(ulong*)(m_pCmd + 2);
  694. if (m_pPFixup == NULL)
  695. {
  696. m_pPFixup = m_pCmd + 2;
  697. }
  698. m_pDisasm->fixupsize += 4;
  699. if (addr == 0)
  700. {
  701. m_pDisasm->zeroconst = 1;
  702. }
  703. if (type == MRJ)
  704. {
  705. m_pDisasm->jmptable = addr;
  706. }
  707. }
  708. }
  709. m_pDisasm->indexed = 1;
  710. if (m_nMode >= DISASM_FILE && m_pDisasm->error == DAE_NOERR)
  711. {
  712. seg = g_addr32[c & 0x07].defseg;
  713. Memadr(seg, g_addr32[c & 0x07].descr, addr, dsize);
  714. }
  715. }
  716. }
  717. //----------------------------------------------------------------------------
  718. // Disassemble implicit source of string operations and, if available, dump
  719. // address and contents.
  720. //----------------------------------------------------------------------------
  721. void CMgDisasmBase::DecodeSO(void)
  722. {
  723. if (m_nMode < DISASM_FILE)
  724. {
  725. return; // No need to decode
  726. }
  727. if (m_ulDataSize == 1)
  728. {
  729. m_pDisasm->memtype = DEC_BYTE;
  730. }
  731. else if (m_ulDataSize == 2)
  732. {
  733. m_pDisasm->memtype = DEC_WORD;
  734. }
  735. else if (m_ulDataSize == 4)
  736. {
  737. m_pDisasm->memtype = DEC_DWORD;
  738. }
  739. m_pDisasm->indexed = 1;
  740. Memadr(SEG_DS, g_szRegName[m_ulAddrSize == 2 ? 1 : 2][REG_ESI], 0L, m_ulDataSize);
  741. }
  742. //----------------------------------------------------------------------------
  743. // Disassemble implicit destination of string operations and, if available,
  744. // dump address and contents. Destination always uses segment ES, and this
  745. // setting cannot be overridden.
  746. //----------------------------------------------------------------------------
  747. void CMgDisasmBase::DecodeDE(void)
  748. {
  749. int seg;
  750. if (m_nMode < DISASM_FILE)
  751. {
  752. return; // No need to decode
  753. }
  754. if (m_ulDataSize == 1)
  755. {
  756. m_pDisasm->memtype = DEC_BYTE;
  757. }
  758. else if (m_ulDataSize == 2)
  759. {
  760. m_pDisasm->memtype = DEC_WORD;
  761. }
  762. else if (m_ulDataSize == 4)
  763. {
  764. m_pDisasm->memtype = DEC_DWORD;
  765. }
  766. m_pDisasm->indexed = 1;
  767. seg = m_nSegPrefix;
  768. m_nSegPrefix = SEG_ES; // Fake Memadr by changing segment prefix
  769. Memadr(SEG_DS, g_szRegName[m_ulAddrSize == 2 ? 1 : 2][REG_EDI], 0L, m_ulDataSize);
  770. m_nSegPrefix = seg; // Restore segment prefix
  771. }
  772. //----------------------------------------------------------------------------
  773. // Decode XLAT operand and, if available, dump address and contents.
  774. //----------------------------------------------------------------------------
  775. void CMgDisasmBase::DecodeXL(void)
  776. {
  777. if (m_nMode < DISASM_FILE)
  778. {
  779. return; // No need to decode
  780. }
  781. m_pDisasm->memtype = DEC_BYTE;
  782. m_pDisasm->indexed = 1;
  783. Memadr(SEG_DS, (m_ulAddrSize == 2 ? ("BX+AL") : ("EBX+AL")), 0L, 1);
  784. }
  785. //----------------------------------------------------------------------------
  786. // Decode immediate operand of size constsize. If sxt is non-zero, byte operand
  787. // should be sign-extended to sxt bytes. If type of immediate constant assumes
  788. // this, small negative operands may be displayed as signed negative numbers.
  789. // Note that in most cases immediate operands are not shown in comment window.
  790. //----------------------------------------------------------------------------
  791. void CMgDisasmBase::DecodeIM(int constsize, int sxt, int type)
  792. {
  793. int i;
  794. signed long data;
  795. ulong l;
  796. char name[TEXTLEN] = { 0 }, comment[TEXTLEN] = { 0 };
  797. //
  798. m_nImmSize += constsize; // Allows several immediate operands
  799. if (m_nMode < DISASM_DATA)
  800. {
  801. return;
  802. }
  803. l = 1 + m_nHasRM + m_nHasSIB + m_nDispSize + (m_nImmSize - constsize);
  804. data = 0;
  805. //
  806. if (m_ulSize < l + constsize)
  807. {
  808. m_pDisasm->error = DAE_CROSS;
  809. }
  810. else if (constsize == 1)
  811. {
  812. if (sxt == 0)
  813. {
  814. data = (uchar)m_pCmd[l];
  815. }
  816. else
  817. {
  818. data = (signed char)m_pCmd[l];
  819. }
  820. if (type == IMS && ((data & 0xE0) != 0 || data == 0))
  821. {
  822. m_pDisasm->warnings |= DAW_SHIFT;
  823. m_pDisasm->cmdtype |= C_RARE;
  824. }
  825. }
  826. else if (constsize == 2)
  827. {
  828. if (sxt == 0)
  829. {
  830. data = *(ushort*)(m_pCmd + l);
  831. }
  832. else
  833. {
  834. data = *(short*)(m_pCmd + l);
  835. }
  836. }
  837. else
  838. {
  839. data = *(long*)(m_pCmd + l);
  840. if (m_pPFixup == NULL)
  841. {
  842. m_pPFixup = m_pCmd + l;
  843. }
  844. m_pDisasm->fixupsize += 4;
  845. }
  846. if (sxt == 2)
  847. {
  848. data &= 0x0000FFFF;
  849. }
  850. if (data == 0 && m_pDisasm->error == 0)
  851. {
  852. m_pDisasm->zeroconst = 1;
  853. }
  854. // Command ENTER, as an exception from Intel's rules, has two immediate
  855. // constants. As the second constant is rarely used, I exclude it from
  856. // search if the first constant is non-zero (which is usually the case).
  857. if (m_pDisasm->immconst == 0)
  858. {
  859. m_pDisasm->immconst = data;
  860. }
  861. if (m_nMode >= DISASM_FILE && m_pDisasm->error == DAE_NOERR)
  862. {
  863. if (m_nMode >= DISASM_CODE && type != IMU)
  864. {
  865. i = Decodeaddress(data, name, TEXTLEN - m_nResult - 24, comment);
  866. }
  867. else
  868. {
  869. i = 0;
  870. comment[0] = '\0';
  871. }
  872. if (i != 0 && m_nSymbolic != 0)
  873. {
  874. strcpy(m_pDisasm->result + m_nResult, name);
  875. m_nResult += i;
  876. }
  877. else if (type == IMU || type == IMS || type == IM2 || data >= 0 || data < NEGLIMIT)
  878. {
  879. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%lX"), data);
  880. }
  881. else
  882. {
  883. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("-%lX"), -data);
  884. }
  885. //
  886. if (m_nAddComment && comment[0] != '\0')
  887. {
  888. strcpy(m_pDisasm->comment, comment);
  889. }
  890. }
  891. }
  892. //----------------------------------------------------------------------------
  893. // Decode VxD service name (always 4-byte).
  894. //----------------------------------------------------------------------------
  895. void CMgDisasmBase::DecodeVX(void)
  896. {
  897. ulong l, data;
  898. //
  899. m_nImmSize += 4; // Allows several immediate operands
  900. if (m_nMode < DISASM_DATA)
  901. {
  902. return;
  903. }
  904. l = 1 + m_nHasRM + m_nHasSIB + m_nDispSize + (m_nImmSize - 4);
  905. if (m_ulSize < l + 4)
  906. {
  907. m_pDisasm->error = DAE_CROSS;
  908. return;
  909. }
  910. data = *(long*)(m_pCmd + l);
  911. if (data == 0 && m_pDisasm->error == 0)
  912. {
  913. m_pDisasm->zeroconst = 1;
  914. }
  915. if (m_pDisasm->immconst == 0)
  916. {
  917. m_pDisasm->immconst = data;
  918. }
  919. if (m_nMode >= DISASM_FILE && m_pDisasm->error == DAE_NOERR)
  920. {
  921. if ((data & 0x00008000) != 0 && memicmp(("VxDCall"), m_pDisasm->result, 7) == 0)
  922. {
  923. memcpy(m_pDisasm->result, m_nLowercase ? ("vxdjump") : ("VxDJump"), 7);
  924. }
  925. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%lX"), data);
  926. }
  927. }
  928. //----------------------------------------------------------------------------
  929. // Decode implicit constant 1 (used in shift commands). This operand is so
  930. // insignificant that it is never shown in comment window.
  931. //----------------------------------------------------------------------------
  932. void CMgDisasmBase::DecodeC1(void)
  933. {
  934. if (m_nMode < DISASM_DATA)
  935. {
  936. return;
  937. }
  938. m_pDisasm->immconst = 1;
  939. if (m_nMode >= DISASM_FILE)
  940. {
  941. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("1"));
  942. }
  943. }
  944. //----------------------------------------------------------------------------
  945. // Decode immediate absolute data address. This operand is used in 8080-
  946. // compatible commands which allow to move data from memory to accumulator and
  947. // back. Note that bytes ModRM and SIB never appear in commands with IA operand.
  948. //----------------------------------------------------------------------------
  949. void CMgDisasmBase::DecodeIA(void)
  950. {
  951. ulong addr;
  952. if (m_ulSize < 1 + m_ulAddrSize)
  953. {
  954. m_pDisasm->error = DAE_CROSS;
  955. return;
  956. }
  957. m_nDispSize = m_ulAddrSize;
  958. if (m_nMode < DISASM_DATA)
  959. {
  960. return;
  961. }
  962. if (m_ulDataSize == 1)
  963. {
  964. m_pDisasm->memtype = DEC_BYTE;
  965. }
  966. else if (m_ulDataSize == 2)
  967. {
  968. m_pDisasm->memtype = DEC_WORD;
  969. }
  970. else if (m_ulDataSize == 4)
  971. {
  972. m_pDisasm->memtype = DEC_DWORD;
  973. }
  974. if (m_ulAddrSize == 2)
  975. {
  976. addr = *(ushort*)(m_pCmd + 1);
  977. }
  978. else
  979. {
  980. addr = *(ulong*)(m_pCmd + 1);
  981. if (m_pPFixup == NULL)
  982. {
  983. m_pPFixup = m_pCmd + 1;
  984. }
  985. m_pDisasm->fixupsize += 4;
  986. }
  987. m_pDisasm->adrconst = addr;
  988. if (addr == 0)
  989. {
  990. m_pDisasm->zeroconst = 1;
  991. }
  992. if (m_nMode >= DISASM_FILE)
  993. {
  994. Memadr(SEG_DS, (""), addr, m_ulDataSize);
  995. }
  996. }
  997. //----------------------------------------------------------------------------
  998. // Decodes jump relative to nextip of size offsize.
  999. //----------------------------------------------------------------------------
  1000. void CMgDisasmBase::DecodeRJ(ulong offsize, ulong nextip)
  1001. {
  1002. int i;
  1003. ulong addr;
  1004. char s[TEXTLEN];
  1005. //
  1006. if (m_ulSize < offsize + 1)
  1007. {
  1008. m_pDisasm->error = DAE_CROSS;
  1009. return;
  1010. }
  1011. m_nDispSize = offsize; // Interpret offset as displacement
  1012. if (m_nMode < DISASM_DATA)
  1013. {
  1014. return;
  1015. }
  1016. if (offsize == 1)
  1017. {
  1018. addr = (signed char)m_pCmd[1] + nextip;
  1019. }
  1020. else if (offsize == 2)
  1021. {
  1022. addr = *(signed short*)(m_pCmd + 1) + nextip;
  1023. }
  1024. else
  1025. {
  1026. addr = *(ulong*)(m_pCmd + 1) + nextip;
  1027. }
  1028. if (m_ulDataSize == 2)
  1029. {
  1030. addr &= 0xFFFF;
  1031. }
  1032. m_pDisasm->jmpconst = addr;
  1033. if (addr == 0)
  1034. {
  1035. m_pDisasm->zeroconst = 1;
  1036. }
  1037. if (m_nMode >= DISASM_FILE)
  1038. {
  1039. if (offsize == 1)
  1040. {
  1041. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%s "), (m_nLowercase == 0 ? ("SHORT") : ("short")));
  1042. }
  1043. if (m_nMode >= DISASM_CODE)
  1044. {
  1045. i = Decodeaddress(addr, s, TEXTLEN, m_pDisasm->comment);
  1046. }
  1047. else
  1048. {
  1049. i = 0;
  1050. }
  1051. if (m_nSymbolic == 0 || i == 0)
  1052. {
  1053. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%08lX"), addr);
  1054. }
  1055. else
  1056. {
  1057. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%.*s"), TEXTLEN - m_nResult - 25, s);
  1058. }
  1059. if (m_nSymbolic == 0 && i != 0 && m_pDisasm->comment[0] == '\0')
  1060. {
  1061. strcpy(m_pDisasm->comment, s);
  1062. }
  1063. }
  1064. }
  1065. //----------------------------------------------------------------------------
  1066. // Decode immediate absolute far jump address. In flat model, such addresses
  1067. // are not used (mostly because selector is specified directly in the command),
  1068. // so I neither decode as symbol nor comment it. To allow search for selector
  1069. // by value, I interprete it as an immediate constant.
  1070. //----------------------------------------------------------------------------
  1071. void CMgDisasmBase::DecodeJF(void)
  1072. {
  1073. ulong addr, seg;
  1074. //
  1075. if (m_ulSize < 1 + m_ulAddrSize + 2)
  1076. {
  1077. m_pDisasm->error = DAE_CROSS;
  1078. return;
  1079. }
  1080. m_nDispSize = m_ulAddrSize;
  1081. m_nImmSize = 2; // Non-trivial but allowed interpretation
  1082. if (m_nMode < DISASM_DATA)
  1083. {
  1084. return;
  1085. }
  1086. if (m_ulAddrSize == 2)
  1087. {
  1088. addr = *(ushort*)(m_pCmd + 1);
  1089. seg = *(ushort*)(m_pCmd + 3);
  1090. }
  1091. else
  1092. {
  1093. addr = *(ulong*)(m_pCmd + 1);
  1094. seg = *(ushort*)(m_pCmd + 5);
  1095. }
  1096. m_pDisasm->jmpconst = addr;
  1097. m_pDisasm->immconst = seg;
  1098. if (addr == 0 || seg == 0)
  1099. {
  1100. m_pDisasm->zeroconst = 1;
  1101. }
  1102. if (m_nMode >= DISASM_FILE)
  1103. {
  1104. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%s %04X:%08X"), (m_nLowercase == 0 ? ("FAR") : ("far")), seg, addr);
  1105. }
  1106. }
  1107. //----------------------------------------------------------------------------
  1108. // Decode segment register. In flat model, operands of this type are seldom.
  1109. //----------------------------------------------------------------------------
  1110. void CMgDisasmBase::DecodeSG(int index)
  1111. {
  1112. int i;
  1113. if (m_nMode < DISASM_DATA)
  1114. {
  1115. return;
  1116. }
  1117. index &= 0x07;
  1118. if (index >= 6)
  1119. {
  1120. m_nSoftError = DAE_BADSEG; // Undefined segment register
  1121. }
  1122. if (m_nMode >= DISASM_FILE)
  1123. {
  1124. i = sprintf(m_pDisasm->result + m_nResult, ("%s"), g_szSegName[index]);
  1125. if (m_nLowercase)
  1126. {
  1127. strlwr(m_pDisasm->result + m_nResult);
  1128. }
  1129. m_nResult += i;
  1130. }
  1131. }
  1132. //----------------------------------------------------------------------------
  1133. // Decode control register addressed in R part of ModRM byte. Operands of
  1134. // this type are extremely rare. Contents of control registers are accessible
  1135. // only from privilege level 0, so I cannot dump them here.
  1136. //----------------------------------------------------------------------------
  1137. void CMgDisasmBase::DecodeCR(int index)
  1138. {
  1139. m_nHasRM = 1;
  1140. if (m_nMode >= DISASM_FILE)
  1141. {
  1142. index = (index >> 3) & 0x07;
  1143. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%s"), g_szCRName[index]);
  1144. if (m_nLowercase)
  1145. {
  1146. strlwr(m_pDisasm->result + m_nResult);
  1147. }
  1148. }
  1149. }
  1150. //----------------------------------------------------------------------------
  1151. // Decode debug register addressed in R part of ModRM byte. Operands of
  1152. // this type are extremely rare. I can dump only those debug registers
  1153. // available in CONTEXT structure.
  1154. //----------------------------------------------------------------------------
  1155. void CMgDisasmBase::DecodeDR(int index)
  1156. {
  1157. int i;
  1158. m_nHasRM = 1;
  1159. if (m_nMode >= DISASM_FILE)
  1160. {
  1161. index = (index >> 3) & 0x07;
  1162. i = sprintf(m_pDisasm->result + m_nResult, ("%s"), g_szDRName[index]);
  1163. if (m_nLowercase)
  1164. {
  1165. strlwr(m_pDisasm->result + m_nResult);
  1166. }
  1167. m_nResult += i;
  1168. }
  1169. }
  1170. //----------------------------------------------------------------------------
  1171. // Service function, adds valid memory adress in MASM or Ideal format to
  1172. // disassembled string. Parameters: defseg - default segment for given
  1173. // register combination, descr - fully decoded register part of address,
  1174. // offset - constant part of address, dsize - data size in bytes. If global
  1175. // flag 'symbolic' is set, function also tries to decode offset as name of
  1176. // some label.
  1177. //----------------------------------------------------------------------------
  1178. void CMgDisasmBase::Memadr(int defseg, const char* descr, long offset, int dsize)
  1179. {
  1180. int i, n, seg;
  1181. char* pr;
  1182. char s[TEXTLEN];
  1183. if (m_nMode < DISASM_FILE || descr == NULL)
  1184. {
  1185. return; // No need or possibility to decode
  1186. }
  1187. //
  1188. pr = m_pDisasm->result + m_nResult;
  1189. n = 0;
  1190. //
  1191. if (m_nSegPrefix != SEG_UNDEF)
  1192. {
  1193. seg = m_nSegPrefix;
  1194. }
  1195. else
  1196. {
  1197. seg = defseg;
  1198. }
  1199. //
  1200. if (m_nIDEAL != 0)
  1201. {
  1202. pr[n++] = '[';
  1203. }
  1204. // In some cases Disassembler may omit size of memory operand. Namely, flag
  1205. // showmemsize must be 0, type bit C_EXPL must be 0 (this bit namely means
  1206. // that explicit operand size is necessary) and type of command must not be
  1207. // C_MMX or C_NOW (because bit C_EXPL has in these cases different meaning).
  1208. // Otherwise, exact size must be supplied.
  1209. if (m_nShowMemSize != 0 || (m_pDisasm->cmdtype & C_TYPEMASK) == C_MMX ||
  1210. (m_pDisasm->cmdtype & C_TYPEMASK) == C_NOW || (m_pDisasm->cmdtype & C_EXPL) != 0
  1211. )
  1212. {
  1213. if (dsize < sizeof(g_szSizeName) / sizeof(g_szSizeName[0]))
  1214. {
  1215. n += sprintf(pr + n, ("%s %s"), g_szSizeName[dsize], (m_nIDEAL == 0 ? ("PTR ") : ("")));
  1216. }
  1217. else
  1218. {
  1219. n += sprintf(pr + n, ("(%i-BYTE) %s"), dsize, (m_nIDEAL == 0 ? ("PTR ") : ("")));
  1220. }
  1221. }
  1222. //
  1223. if ((m_nPutDefSeg != 0 || seg != defseg) && seg != SEG_UNDEF)
  1224. {
  1225. n += sprintf(pr + n, ("%s:"), g_szSegName[seg]);
  1226. }
  1227. //
  1228. if (m_nIDEAL == 0)
  1229. {
  1230. pr[n++] = '[';
  1231. }
  1232. //
  1233. n += sprintf(pr + n, ("%s"), descr);
  1234. if (m_nLowercase)
  1235. {
  1236. strlwr(pr);
  1237. }
  1238. //
  1239. if (offset == 0L)
  1240. {
  1241. if (*descr == '\0')
  1242. {
  1243. pr[n++] = '0';
  1244. }
  1245. }
  1246. else
  1247. {
  1248. if (m_nSymbolic && m_nMode >= DISASM_CODE)
  1249. {
  1250. i = Decodeaddress(offset, s, TEXTLEN - n - 24, NULL);
  1251. }
  1252. else
  1253. {
  1254. i = 0;
  1255. }
  1256. //
  1257. if (i > 0)
  1258. {
  1259. // Offset decoded in symbolic form
  1260. if (*descr != '\0')
  1261. {
  1262. pr[n++] = '+';
  1263. }
  1264. strcpy(pr + n, s);
  1265. n += i;
  1266. }
  1267. else if (offset < 0 && offset > -16384 && *descr != '\0')
  1268. {
  1269. n += sprintf(pr + n, ("-%lX"), -offset);
  1270. }
  1271. else
  1272. {
  1273. if (*descr != '\0') pr[n++] = '+';
  1274. n += sprintf(pr + n, ("%lX"), offset);
  1275. }
  1276. }
  1277. pr[n++] = ']';
  1278. pr[n] = '\0';
  1279. m_nResult += n;
  1280. }
  1281. //----------------------------------------------------------------------------
  1282. // Decodes address into symb (nsymb bytes long, including the terminating zero
  1283. // character) and comments its possible meaning. Returns number of bytes in
  1284. // symb not including terminating zero.
  1285. //----------------------------------------------------------------------------
  1286. int CMgDisasmBase::Decodeaddress(ulong addr, char* symb, int nsymb, char* comment)
  1287. {
  1288. // Environment-specific routine! Do it yourself!
  1289. return 0;
  1290. }
  1291. //----------------------------------------------------------------------------
  1292. // Skips 3DNow! operands and extracts command suffix. Returns suffix or -1 if
  1293. // suffix lies outside the memory block. This subroutine assumes that cmd still
  1294. // points to the beginning of 3DNow! command (i.e. to the sequence of two bytes
  1295. // 0F, 0F).
  1296. //----------------------------------------------------------------------------
  1297. int CMgDisasmBase::Get3dnowsuffix(void)
  1298. {
  1299. int c, sib;
  1300. ulong offset = 3;
  1301. if (m_ulSize < 3)
  1302. {
  1303. return -1; // Suffix outside the memory block
  1304. }
  1305. c = m_pCmd[2] & 0xC7; // Leave only Mod and M fields
  1306. // Register in ModM - general-purpose, MMX or 3DNow!
  1307. if ((c & 0xC0) == 0xC0) {}
  1308. // 16-bit addressing mode, SIB byte is never used here.
  1309. else if (m_ulAddrSize == 2)
  1310. {
  1311. if (c == 0x06) // Special case of immediate address
  1312. {
  1313. offset += 2;
  1314. }
  1315. else if ((c & 0xC0) == 0x40) // 8-bit signed displacement
  1316. {
  1317. offset++;
  1318. }
  1319. else if ((c & 0xC0) == 0x80) // 16-bit unsigned displacement
  1320. {
  1321. offset += 2;
  1322. }
  1323. }
  1324. // Immediate 32-bit address.
  1325. else if (c == 0x05) // Special case of immediate address
  1326. {
  1327. offset += 4;
  1328. }
  1329. // 32-bit address with SIB byte.
  1330. else if ((c & 0x07) == 0x04) // SIB addresation
  1331. {
  1332. if (m_ulSize < 4)
  1333. {
  1334. return -1; // Suffix outside the memory block
  1335. }
  1336. //
  1337. sib = m_pCmd[3];
  1338. offset++;
  1339. //
  1340. if (c == 0x04 && (sib & 0x07) == 0x05)
  1341. {
  1342. offset += 4; // Immediate address without base
  1343. }
  1344. else if ((c & 0xC0) == 0x40) // 8-bit displacement
  1345. {
  1346. offset += 1;
  1347. }
  1348. else if ((c & 0xC0) == 0x80) // 32-bit dislacement
  1349. {
  1350. offset += 4;
  1351. }
  1352. }
  1353. // 32-bit address without SIB byte
  1354. else if ((c & 0xC0) == 0x40)
  1355. {
  1356. offset += 1;
  1357. }
  1358. else if ((c & 0xC0) == 0x80)
  1359. {
  1360. offset += 4;
  1361. }
  1362. //
  1363. if (offset >= m_ulSize)
  1364. {
  1365. return -1; // Suffix outside the memory block
  1366. }
  1367. return m_pCmd[offset];
  1368. }
  1369. //--------------------------------------------------------------------------------
  1370. // Function attempts to calculate address of assembler instruction which is n
  1371. // lines back in the listing. Maximal stepback is limited to 127. In general,
  1372. // this is rather non-trivial task. Proposed solution may cause problems which
  1373. // however are not critical here.
  1374. //--------------------------------------------------------------------------------
  1375. ulong CMgDisasmBase::Disassembleback(char* block, ulong base, ulong size, ulong ip, int n)
  1376. {
  1377. int i;
  1378. ulong abuf[131], addr, back, cmdsize;
  1379. char* pdata;
  1380. t_disasm da;
  1381. //
  1382. if (block == NULL)
  1383. {
  1384. return 0; // Error, no code!
  1385. }
  1386. if (n < 0)
  1387. {
  1388. n = 0; // Try to correct obvious errors
  1389. }
  1390. else if (n > 127)
  1391. {
  1392. n = 127;
  1393. }
  1394. if (ip > base + size)
  1395. {
  1396. ip = base + size;
  1397. }
  1398. if (n == 0)
  1399. {
  1400. return ip; // Obvious answers
  1401. }
  1402. if (ip <= base + n)
  1403. {
  1404. return base;
  1405. }
  1406. back = MAXCMDSIZE * (n + 3); // Command length limited to MAXCMDSIZE
  1407. if (ip < base + back)
  1408. {
  1409. back = ip - base;
  1410. }
  1411. addr = ip - back;
  1412. pdata = block + (addr - base);
  1413. for (i = 0; addr < ip; i++)
  1414. {
  1415. abuf[i % 128] = addr;
  1416. cmdsize = Disasm(pdata, back, addr, &da, DISASM_SIZE);
  1417. pdata += cmdsize;
  1418. addr += cmdsize;
  1419. back -= cmdsize;
  1420. }
  1421. if (i < n)
  1422. {
  1423. return abuf[0];
  1424. }
  1425. else
  1426. {
  1427. return abuf[(i - n + 128) % 128];
  1428. }
  1429. }
  1430. //--------------------------------------------------------------------------------
  1431. // Function attempts to calculate address of assembler instruction which is n
  1432. // lines forward in the listing.
  1433. //--------------------------------------------------------------------------------
  1434. ulong CMgDisasmBase::Disassembleforward(char* block, ulong base, ulong size, ulong ip, int n)
  1435. {
  1436. int i;
  1437. ulong cmdsize;
  1438. char* pdata;
  1439. t_disasm da;
  1440. if (block == NULL)
  1441. {
  1442. return 0; // Error, no code!
  1443. }
  1444. if (ip < base)
  1445. {
  1446. ip = base; // Try to correct obvious errors
  1447. }
  1448. if (ip > base + size)
  1449. {
  1450. ip = base + size;
  1451. }
  1452. if (n <= 0)
  1453. {
  1454. return ip;
  1455. }
  1456. //
  1457. pdata = block + (ip - base);
  1458. size -= (ip - base);
  1459. //
  1460. for (i = 0; i < n && size > 0; i++)
  1461. {
  1462. cmdsize = Disasm(pdata, size, ip, &da, DISASM_SIZE);
  1463. pdata += cmdsize;
  1464. ip += cmdsize;
  1465. size -= cmdsize;
  1466. }
  1467. return ip;
  1468. }
  1469. //----------------------------------------------------------------------------
  1470. //
  1471. //
  1472. //----------------------------------------------------------------------------
  1473. ulong CMgDisasmBase::Disasm(char* src, ulong srcsize, ulong srcip, t_disasm* disasm, int disasmmode)
  1474. {
  1475. //
  1476. int nIsPrefix = 0;
  1477. int nRepeated = 0;
  1478. int nLockPrefix = 0; // Non-zero if lock prefix present
  1479. int nRepPrefix = 0; // REPxxx prefix or 0
  1480. //
  1481. ulong u = 0, code = 0;
  1482. int i = 0, j = 0, is3dnow = 0;
  1483. int cxsize = 0;
  1484. int mnemosize = 0;
  1485. int operand = 0;
  1486. int arg = 0;
  1487. //
  1488. t_cmddata* pd, * pdan;
  1489. //
  1490. char name[TEXTLEN], * pname;
  1491. // 32-bit code and data segments only!
  1492. m_ulDataSize = 4;
  1493. m_ulAddrSize = 4;
  1494. // Prepare disassembler variables and initialize structure disasm.
  1495. m_nSegPrefix = SEG_UNDEF;
  1496. m_nHasRM = 0;
  1497. m_nHasSIB = 0;
  1498. m_nDispSize = 0;
  1499. m_nImmSize = 0;
  1500. m_nDump = 0;
  1501. m_nResult = 0;
  1502. m_nSoftError = 0;
  1503. //
  1504. m_pCmd = src;
  1505. m_ulSize = srcsize;
  1506. m_pPFixup = NULL;
  1507. //结构初始化:
  1508. m_pDisasm = disasm;
  1509. m_pDisasm->ip = srcip;
  1510. m_pDisasm->comment[0] = '\0';
  1511. m_pDisasm->cmdtype = C_BAD;
  1512. m_pDisasm->nprefix = 0;
  1513. m_pDisasm->memtype = DEC_UNKNOWN;
  1514. m_pDisasm->indexed = 0;
  1515. m_pDisasm->jmpconst = 0;
  1516. m_pDisasm->jmptable = 0;
  1517. m_pDisasm->adrconst = 0;
  1518. m_pDisasm->immconst = 0;
  1519. m_pDisasm->zeroconst = 0;
  1520. m_pDisasm->fixupoffset = 0;
  1521. m_pDisasm->fixupsize = 0;
  1522. m_pDisasm->warnings = 0;
  1523. m_pDisasm->error = DAE_NOERR;
  1524. // No need to use register contents
  1525. m_nMode = disasmmode;
  1526. // Correct 80x86 command may theoretically contain up to 4 prefixes belonging
  1527. // to different prefix groups. This limits maximal possible size of the
  1528. // command to MAXCMDSIZE=16 bytes. In order to maintain this limit, if
  1529. // Disasm() detects second prefix from the same group, it flushes first
  1530. // prefix in the sequence as a pseudocommand.
  1531. //
  1532. while (m_ulSize > 0)
  1533. {
  1534. nIsPrefix = 1;
  1535. switch (*m_pCmd)
  1536. {
  1537. case 0x26:
  1538. {
  1539. if (m_nSegPrefix == SEG_UNDEF)
  1540. {
  1541. m_nSegPrefix = SEG_ES;
  1542. }
  1543. else
  1544. {
  1545. nRepeated = 1;
  1546. }
  1547. break;
  1548. }
  1549. case 0x2E:
  1550. {
  1551. if (m_nSegPrefix == SEG_UNDEF)
  1552. {
  1553. m_nSegPrefix = SEG_CS;
  1554. }
  1555. else
  1556. {
  1557. nRepeated = 1;
  1558. }
  1559. break;
  1560. }
  1561. case 0x36:
  1562. {
  1563. if (m_nSegPrefix == SEG_UNDEF)
  1564. {
  1565. m_nSegPrefix = SEG_SS;
  1566. }
  1567. else
  1568. {
  1569. nRepeated = 1;
  1570. }
  1571. break;
  1572. }
  1573. case 0x3E:
  1574. {
  1575. if (m_nSegPrefix == SEG_UNDEF)
  1576. {
  1577. m_nSegPrefix = SEG_DS;
  1578. }
  1579. else
  1580. {
  1581. nRepeated = 1;
  1582. }
  1583. break;
  1584. }
  1585. case 0x64:
  1586. {
  1587. if (m_nSegPrefix == SEG_UNDEF)
  1588. {
  1589. m_nSegPrefix = SEG_FS;
  1590. }
  1591. else
  1592. {
  1593. nRepeated = 1;
  1594. }
  1595. break;
  1596. }
  1597. case 0x65:
  1598. {
  1599. if (m_nSegPrefix == SEG_UNDEF)
  1600. {
  1601. m_nSegPrefix = SEG_GS;
  1602. }
  1603. else
  1604. {
  1605. nRepeated = 1;
  1606. }
  1607. break;
  1608. }
  1609. case 0x66:
  1610. {
  1611. if (m_ulDataSize == 4)
  1612. {
  1613. m_ulDataSize = 2;
  1614. }
  1615. else
  1616. {
  1617. nRepeated = 1;
  1618. }
  1619. break;
  1620. }
  1621. case 0x67:
  1622. {
  1623. if (m_ulAddrSize == 4)
  1624. {
  1625. m_ulAddrSize = 2;
  1626. }
  1627. else
  1628. {
  1629. nRepeated = 1;
  1630. }
  1631. break;
  1632. }
  1633. case 0xF0:
  1634. {
  1635. if (nLockPrefix == 0)
  1636. {
  1637. nLockPrefix = 0xF0;
  1638. }
  1639. else
  1640. {
  1641. nRepeated = 1;
  1642. }
  1643. break;
  1644. }
  1645. case 0xF2:
  1646. {
  1647. if (nRepPrefix == 0)
  1648. {
  1649. nRepPrefix = 0xF2;
  1650. }
  1651. else
  1652. {
  1653. nRepeated = 1;
  1654. }
  1655. break;
  1656. }
  1657. case 0xF3:
  1658. {
  1659. if (nRepPrefix == 0)
  1660. {
  1661. nRepPrefix = 0xF3;
  1662. }
  1663. else
  1664. {
  1665. nRepeated = 1;
  1666. }
  1667. break;
  1668. }
  1669. default:
  1670. {
  1671. nIsPrefix = 0;
  1672. break;
  1673. }
  1674. }
  1675. //
  1676. if (nRepPrefix == 0 || nRepeated != 0)
  1677. {
  1678. break;
  1679. }
  1680. //
  1681. if (m_nMode >= DISASM_FILE)
  1682. {
  1683. m_nDump += sprintf(m_pDisasm->dump + m_nDump, ("%02X:"), *m_pCmd);
  1684. }
  1685. //
  1686. m_pDisasm->nprefix++;
  1687. m_pCmd++;
  1688. srcip++;
  1689. m_ulSize--;
  1690. u++;
  1691. }
  1692. //
  1693. if (nRepeated) //nRepeated == 1
  1694. {
  1695. //
  1696. if (m_nMode >= DISASM_FILE)
  1697. {
  1698. m_pDisasm->dump[3] = '\0'; //end 00 // Leave only first dumped prefix
  1699. m_pDisasm->nprefix = 1;
  1700. switch (m_pCmd[-(long)u])
  1701. {
  1702. case 0x26:
  1703. {
  1704. pname = (char*)(g_szSegName[SEG_ES]);
  1705. break;
  1706. }
  1707. case 0x2E:
  1708. {
  1709. pname = (char*)(g_szSegName[SEG_CS]);
  1710. break;
  1711. }
  1712. case 0x36:
  1713. {
  1714. pname = (char*)(g_szSegName[SEG_SS]);
  1715. break;
  1716. }
  1717. case 0x3E:
  1718. {
  1719. pname = (char*)(g_szSegName[SEG_DS]);
  1720. break;
  1721. }
  1722. case 0x64:
  1723. {
  1724. pname = (char*)(g_szSegName[SEG_FS]);
  1725. break;
  1726. }
  1727. case 0x65:
  1728. {
  1729. pname = (char*)(g_szSegName[SEG_GS]);
  1730. break;
  1731. }
  1732. case 0x66:
  1733. {
  1734. pname = ("DATASIZE");
  1735. break;
  1736. }
  1737. case 0x67:
  1738. {
  1739. pname = ("ADDRSIZE");
  1740. break;
  1741. }
  1742. case 0xF0:
  1743. {
  1744. pname = ("LOCK");
  1745. break;
  1746. }
  1747. case 0xF2:
  1748. {
  1749. pname = ("REPNE");
  1750. break;
  1751. }
  1752. case 0xF3:
  1753. {
  1754. pname = ("REPE");
  1755. break;
  1756. }
  1757. default:
  1758. {
  1759. pname = "?";
  1760. break;
  1761. }
  1762. }
  1763. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("PREFIX %s:"), pname);
  1764. if (m_nLowercase)
  1765. {
  1766. strlwr(m_pDisasm->result);
  1767. }
  1768. if (m_nExtraPrefix == 0) strcpy(m_pDisasm->comment, ("Superfluous prefix"));
  1769. }
  1770. m_pDisasm->warnings |= DAW_PREFIX;
  1771. if (nLockPrefix)
  1772. {
  1773. m_pDisasm->warnings |= DAW_LOCK;
  1774. }
  1775. m_pDisasm->cmdtype = C_RARE;
  1776. return 1;
  1777. }
  1778. // If lock prefix available, display it and forget, because it has no
  1779. // influence on decoding of rest of the command.
  1780. if (nLockPrefix != 0)
  1781. {
  1782. if (m_nMode >= DISASM_FILE)
  1783. {
  1784. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("LOCK "));
  1785. }
  1786. m_pDisasm->warnings |= DAW_LOCK;
  1787. }
  1788. // Fetch (if available) first 3 bytes of the command, add repeat prefix and
  1789. // find command in the command table.
  1790. code = 0;
  1791. if (m_ulSize > 0)
  1792. {
  1793. *(((char*)&code) + 0) = m_pCmd[0];
  1794. }
  1795. if (m_ulSize > 1)
  1796. {
  1797. *(((char*)&code) + 1) = m_pCmd[1];
  1798. }
  1799. if (m_ulSize > 2)
  1800. {
  1801. *(((char*)&code) + 2) = m_pCmd[2];
  1802. }
  1803. if (nRepPrefix != 0) // RER/REPE/REPNE is considered to be
  1804. {
  1805. code = (code << 8) | nRepPrefix; // part of command.
  1806. }
  1807. if (m_nDecodeVxd && (code & 0xFFFF) == 0x20CD)
  1808. {
  1809. pd = &g_VxdCmd; // Decode VxD call (Win95/98)
  1810. }
  1811. else
  1812. {
  1813. for (pd = g_CmdData; pd->mask != 0; pd++)
  1814. {
  1815. if (((code ^ pd->code) & pd->mask) != 0)
  1816. {
  1817. continue;
  1818. }
  1819. if (m_nMode >= DISASM_FILE && m_nShortStringCmds &&
  1820. (pd->arg1 == MSO || pd->arg1 == MDE || pd->arg2 == MSO || pd->arg2 == MDE))
  1821. {
  1822. continue; // Search short form of string command
  1823. }
  1824. break;
  1825. }
  1826. }
  1827. //
  1828. if ((pd->type & C_TYPEMASK) == C_NOW)
  1829. {
  1830. // 3DNow! commands require additional search.
  1831. is3dnow = 1;
  1832. j = Get3dnowsuffix();
  1833. if (j < 0)
  1834. {
  1835. m_pDisasm->error = DAE_CROSS;
  1836. }
  1837. else
  1838. {
  1839. for (; pd->mask != 0; pd++)
  1840. {
  1841. if (((code ^ pd->code) & pd->mask) != 0)
  1842. {
  1843. continue;
  1844. }
  1845. if (((uchar*)&(pd->code))[2] == j)
  1846. {
  1847. break;
  1848. }
  1849. }
  1850. }
  1851. }
  1852. // Command not found
  1853. if (pd->mask == 0)
  1854. {
  1855. m_pDisasm->cmdtype = C_BAD;
  1856. if (m_ulSize < 2)
  1857. {
  1858. m_pDisasm->error = DAE_CROSS;
  1859. }
  1860. else
  1861. {
  1862. m_pDisasm->error = DAE_BADCMD;
  1863. }
  1864. }
  1865. else
  1866. {
  1867. m_pDisasm->cmdtype = pd->type;
  1868. cxsize = m_ulDataSize;
  1869. //
  1870. if (m_nSegPrefix == SEG_FS || m_nSegPrefix == SEG_GS || nLockPrefix != 0)
  1871. {
  1872. m_pDisasm->cmdtype |= C_RARE; // These prefixes are rare
  1873. }
  1874. //
  1875. if (pd->bits == PR)
  1876. {
  1877. m_pDisasm->warnings |= DAW_PRIV; // Privileged command (ring 0)
  1878. }
  1879. else if (pd->bits == WP)
  1880. {
  1881. m_pDisasm->warnings |= DAW_IO; // I/O command
  1882. }
  1883. // Win32 programs usually try to keep stack dword-aligned, so INC ESP
  1884. // (44) and DEC ESP (4C) usually don't appear in real code. Also check for
  1885. // ADD ESP,imm and SUB ESP,imm (81,C4,imm32; 83,C4,imm8; 81,EC,imm32;
  1886. // 83,EC,imm8).
  1887. if (m_pCmd[0] == 0x44 || m_pCmd[0] == 0x4C ||
  1888. (m_ulSize >= 3 && (m_pCmd[0] == 0x81 || m_pCmd[0] == 0x83) &&
  1889. (m_pCmd[1] == 0xC4 || m_pCmd[1] == 0xEC) && (m_pCmd[2] & 0x03) != 0)
  1890. )
  1891. {
  1892. m_pDisasm->warnings |= DAW_STACK;
  1893. m_pDisasm->cmdtype |= C_RARE;
  1894. };
  1895. // Warn also on MOV SEG,... (8E...). Win32 works in flat mode.
  1896. if (m_pCmd[0] == 0x8E)
  1897. {
  1898. m_pDisasm->warnings |= DAW_SEGMENT;
  1899. }
  1900. // If opcode is 2-byte, adjust command.
  1901. if (pd->len == 2)
  1902. {
  1903. if (m_ulSize == 0)
  1904. {
  1905. m_pDisasm->error = DAE_CROSS;
  1906. }
  1907. else
  1908. {
  1909. if (m_nMode >= DISASM_FILE)
  1910. {
  1911. m_nDump += sprintf(m_pDisasm->dump + m_nDump, ("%02X"), *m_pCmd);
  1912. }
  1913. m_pCmd[0]++;
  1914. srcip++;
  1915. m_ulSize--;
  1916. }
  1917. }
  1918. if (m_ulSize == 0)
  1919. {
  1920. m_pDisasm->error = DAE_CROSS;
  1921. }
  1922. // Some commands either feature non-standard data size or have bit which
  1923. // allowes to select data size.
  1924. if ((pd->bits & WW) != 0 && (*m_pCmd & WW) == 0)
  1925. {
  1926. m_ulDataSize = 1; // Bit W in command set to 0
  1927. }
  1928. else if ((pd->bits & W3) != 0 && (*m_pCmd & W3) == 0)
  1929. {
  1930. m_ulDataSize = 1; // Another position of bit W
  1931. }
  1932. else if ((pd->bits & FF) != 0)
  1933. {
  1934. m_ulDataSize = 2;
  1935. }
  1936. //
  1937. // Some commands either have mnemonics which depend on data size (8/16 bits
  1938. // or 32 bits, like CWD/CDQ), or have several different mnemonics (like
  1939. // JNZ/JNE). First case is marked by either '&' (mnemonic depends on
  1940. // operand size) or '$' (depends on address size). In the second case,
  1941. // there is no special marker and disassembler selects main mnemonic.
  1942. if (m_nMode >= DISASM_FILE)
  1943. {
  1944. //
  1945. if (pd->name[0] == '&')
  1946. {
  1947. mnemosize = m_ulDataSize;
  1948. }
  1949. else if (pd->name[0] == '$')
  1950. {
  1951. mnemosize = m_ulDataSize;
  1952. }
  1953. else
  1954. {
  1955. mnemosize = 0;
  1956. }
  1957. //
  1958. if (mnemosize != 0)
  1959. {
  1960. for (i = 0, j = 1; pd->name[j] != '\0'; j++)
  1961. {
  1962. if (pd->name[j] == ':') // Separator between 16/32 mnemonics
  1963. {
  1964. if (mnemosize == 4)
  1965. {
  1966. i = 0;
  1967. }
  1968. else
  1969. {
  1970. break;
  1971. }
  1972. }
  1973. else if (pd->name[j] == '*') // Substitute by 'W', 'D' or none
  1974. {
  1975. if (mnemosize == 4 && m_nSizeSens != 2)
  1976. {
  1977. name[i++] = 'D';
  1978. }
  1979. else if (mnemosize != 4 && m_nSizeSens != 0)
  1980. {
  1981. name[i++] = 'W';
  1982. }
  1983. }
  1984. else
  1985. {
  1986. name[i++] = pd->name[j];
  1987. }
  1988. }
  1989. name[i] = '\0';
  1990. }
  1991. else
  1992. {
  1993. strcpy(name, pd->name);
  1994. for (i = 0; name[i] != '\0'; i++)
  1995. {
  1996. // Use main mnemonic
  1997. if (name[i] == ',')
  1998. {
  1999. name[i] = '\0';
  2000. break;
  2001. }
  2002. }
  2003. }
  2004. //
  2005. if (nRepPrefix != 0 && m_nTabArguments)
  2006. {
  2007. for (i = 0; name[i] != '\0' && name[i] != ' '; i++)
  2008. {
  2009. m_pDisasm->result[m_nResult++] = name[i];
  2010. }
  2011. if (name[i] == ' ')
  2012. {
  2013. m_pDisasm->result[m_nResult++] = ' ';
  2014. i++;
  2015. }
  2016. while (m_nResult < 8)
  2017. {
  2018. m_pDisasm->result[m_nResult++] = ' ';
  2019. }
  2020. for (; name[i] != '\0'; i++)
  2021. {
  2022. m_pDisasm->result[m_nResult++] = name[i];
  2023. }
  2024. }
  2025. else
  2026. {
  2027. m_nResult += sprintf(m_pDisasm->result + m_nResult, ("%s"), name);
  2028. }
  2029. if (m_nLowercase)
  2030. {
  2031. strlwr(m_pDisasm->result);
  2032. }
  2033. }
  2034. //
  2035. // Decode operands (explicit - encoded in command, implicit - present in
  2036. // mmemonic or assumed - used or modified by command). Assumed operands
  2037. // must stay after all explicit and implicit operands. Up to 3 operands
  2038. // are allowed.
  2039. for (operand = 0; operand < 3; operand++)
  2040. {
  2041. if (m_pDisasm->error)
  2042. {
  2043. break; // Error - no sense to continue
  2044. }
  2045. // If command contains both source and destination, one usually must not
  2046. // decode destination to comment because it will be overwritten on the
  2047. // next step. Global addcomment takes care of this. Decoding routines,
  2048. // however, may ignore this flag.
  2049. if (operand == 0 && pd->arg2 != NNN && pd->arg2 < PSEUDOOP)
  2050. {
  2051. m_nAddComment = 0;
  2052. }
  2053. else
  2054. {
  2055. m_nAddComment = 1;
  2056. }
  2057. // Get type of next argument.
  2058. if (operand == 0)
  2059. {
  2060. arg = pd->arg1;
  2061. }
  2062. else if (operand == 1)
  2063. {
  2064. arg = pd->arg2;
  2065. }
  2066. else
  2067. {
  2068. arg = pd->arg3;
  2069. }
  2070. //
  2071. if (arg == NNN)
  2072. {
  2073. break; // No more operands
  2074. }
  2075. // Arguments with arg>=PSEUDOOP are assumed operands and are not
  2076. // displayed in disassembled result, so they require no delimiter.
  2077. if ((m_nMode >= DISASM_FILE) && arg < PSEUDOOP)
  2078. {
  2079. if (operand == 0)
  2080. {
  2081. m_pDisasm->result[m_nResult++] = ' ';
  2082. if (m_nTabArguments)
  2083. {
  2084. while (m_nResult < 8)
  2085. {
  2086. m_pDisasm->result[m_nResult++] = ' ';
  2087. }
  2088. }
  2089. }
  2090. else
  2091. {
  2092. m_pDisasm->result[m_nResult++] = ',';
  2093. if (m_nExtraSpace)
  2094. {
  2095. m_pDisasm->result[m_nResult++] = ' ';
  2096. }
  2097. }
  2098. }
  2099. //
  2100. // Decode, analyse and comment next operand of the command.
  2101. switch (arg)
  2102. {
  2103. case REG: // Integer register in Reg field
  2104. {
  2105. if (m_ulSize < 2)
  2106. {
  2107. m_pDisasm->error = DAE_CROSS;
  2108. }
  2109. else
  2110. {
  2111. DecodeRG(m_pCmd[1] >> 3, m_ulDataSize, REG);
  2112. }
  2113. m_nHasRM = 1;
  2114. break;
  2115. }
  2116. case RCM: // Integer register in command byte
  2117. {
  2118. DecodeRG(m_pCmd[0], m_ulDataSize, RCM);
  2119. break;
  2120. }
  2121. case RG4: // Integer 4-byte register in Reg field
  2122. {
  2123. if (m_ulSize < 2)
  2124. {
  2125. m_pDisasm->error = DAE_CROSS;
  2126. }
  2127. else
  2128. {
  2129. DecodeRG(m_pCmd[1] >> 3, 4, RG4);
  2130. }
  2131. m_nHasRM = 1;
  2132. break;
  2133. }
  2134. case RAC: // Accumulator (AL/AX/EAX, implicit)
  2135. {
  2136. DecodeRG(REG_EAX, m_ulDataSize, RAC);
  2137. break;
  2138. }
  2139. case RAX: // AX (2-byte, implicit)
  2140. {
  2141. DecodeRG(REG_EAX, 2, RAX);
  2142. break;
  2143. }
  2144. case RDX: // DX (16-bit implicit port address)
  2145. {
  2146. DecodeRG(REG_EDX, 2, RDX);
  2147. break;
  2148. }
  2149. case RCL: // Implicit CL register (for shifts)
  2150. {
  2151. DecodeRG(REG_ECX, 1, RCL);
  2152. break;
  2153. }
  2154. case RS0: // Top of FPU stack (ST(0))
  2155. {
  2156. DecodeST(0, 0);
  2157. break;
  2158. }
  2159. case RST: // FPU register (ST(i)) in command byte
  2160. {
  2161. DecodeST(m_pCmd[0], 0);
  2162. break;
  2163. }
  2164. case RMX: // MMX register MMx
  2165. {
  2166. if (m_ulSize < 2)
  2167. {
  2168. m_pDisasm->error = DAE_CROSS;
  2169. }
  2170. else
  2171. {
  2172. DecodeMX(m_pCmd[1] >> 3);
  2173. }
  2174. m_nHasRM = 1;
  2175. break;
  2176. }
  2177. case R3D: // 3DNow! register MMx
  2178. {
  2179. if (m_ulSize < 2)
  2180. {
  2181. m_pDisasm->error = DAE_CROSS;
  2182. }
  2183. else
  2184. {
  2185. DecodeNR(m_pCmd[1] >> 3);
  2186. }
  2187. m_nHasRM = 1;
  2188. break;
  2189. }
  2190. case MRG: // Memory/register in ModRM byte
  2191. case MRJ: // Memory/reg in ModRM as JUMP target
  2192. case MR1: // 1-byte memory/register in ModRM byte
  2193. case MR2: // 2-byte memory/register in ModRM byte
  2194. case MR4: // 4-byte memory/register in ModRM byte
  2195. case MR8: // 8-byte memory/MMX register in ModRM
  2196. case MRD: // 8-byte memory/3DNow! register in ModRM
  2197. case MMA: // Memory address in ModRM byte for LEA
  2198. case MML: // Memory in ModRM byte (for LES)
  2199. case MM6: // Memory in ModRm (6-byte descriptor)
  2200. case MMB: // Two adjacent memory locations (BOUND)
  2201. case MD2: // Memory in ModRM byte (16-bit integer)
  2202. case MB2: // Memory in ModRM byte (16-bit binary)
  2203. case MD4: // Memory in ModRM byte (32-bit integer)
  2204. case MD8: // Memory in ModRM byte (64-bit integer)
  2205. case MDA: // Memory in ModRM byte (80-bit BCD)
  2206. case MF4: // Memory in ModRM byte (32-bit float)
  2207. case MF8: // Memory in ModRM byte (64-bit float)
  2208. case MFA: // Memory in ModRM byte (80-bit float)
  2209. case MFE: // Memory in ModRM byte (FPU environment)
  2210. case MFS: // Memory in ModRM byte (FPU state)
  2211. case MFX: // Memory in ModRM byte (ext. FPU state)
  2212. {
  2213. DecodeMR(arg);
  2214. break;
  2215. }
  2216. case MMS: // Memory in ModRM byte (as SEG:OFFS)
  2217. {
  2218. DecodeMR(arg);
  2219. m_pDisasm->warnings |= DAW_FARADDR;
  2220. break;
  2221. }
  2222. case RR4: // 4-byte memory/register (register only)
  2223. case RR8: // 8-byte MMX register only in ModRM
  2224. case RRD: // 8-byte memory/3DNow! (register only)
  2225. {
  2226. if ((m_pCmd[1] & 0xC0) != 0xC0)
  2227. {
  2228. m_nSoftError = DAE_REGISTER;
  2229. }
  2230. DecodeMR(arg);
  2231. break;
  2232. }
  2233. case MSO: // Source in string op's ([ESI])
  2234. {
  2235. DecodeSO();
  2236. break;
  2237. }
  2238. case MDE: // Destination in string op's ([EDI])
  2239. {
  2240. DecodeDE();
  2241. break;
  2242. }
  2243. case MXL: // XLAT operand ([EBX+AL])
  2244. {
  2245. DecodeXL();
  2246. break;
  2247. }
  2248. case IMM: // Immediate data (8 or 16/32)
  2249. case IMU: // Immediate unsigned data (8 or 16/32)
  2250. {
  2251. if ((pd->bits & SS) != 0 && (*m_pCmd & 0x02) != 0)
  2252. {
  2253. DecodeIM(1, m_ulDataSize, arg);
  2254. }
  2255. else
  2256. {
  2257. DecodeIM(m_ulDataSize, 0, arg);
  2258. }
  2259. break;
  2260. }
  2261. case VXD: // VxD service (32-bit only)
  2262. {
  2263. DecodeVX();
  2264. break;
  2265. }
  2266. case IMX: // Immediate sign-extendable byte
  2267. {
  2268. DecodeIM(1, m_ulDataSize, arg);
  2269. break;
  2270. }
  2271. case C01: // Implicit constant 1 (for shifts)
  2272. {
  2273. DecodeC1();
  2274. break;
  2275. }
  2276. case IMS: // Immediate byte (for shifts)
  2277. case IM1: // Immediate byte
  2278. {
  2279. DecodeIM(1, 0, arg);
  2280. break;
  2281. }
  2282. case IM2: // Immediate word (ENTER/RET)
  2283. {
  2284. DecodeIM(2, 0, arg);
  2285. if ((m_pDisasm->immconst & 0x03) != 0)
  2286. {
  2287. m_pDisasm->warnings |= DAW_STACK;
  2288. }
  2289. break;
  2290. }
  2291. case IMA: // Immediate absolute near data address
  2292. {
  2293. DecodeIA();
  2294. break;
  2295. }
  2296. case JOB: // Immediate byte offset (for jumps)
  2297. {
  2298. DecodeRJ(1, srcip + 2);
  2299. break;
  2300. }
  2301. case JOW: // Immediate full offset (for jumps)
  2302. {
  2303. DecodeRJ(m_ulDataSize, srcip + m_ulDataSize + 1);
  2304. break;
  2305. }
  2306. case JMF: // Immediate absolute far jump/call addr
  2307. {
  2308. DecodeJF();
  2309. m_pDisasm->warnings |= DAW_FARADDR;
  2310. break;
  2311. }
  2312. case SGM: // Segment register in ModRM byte
  2313. {
  2314. if (m_ulSize < 2)
  2315. {
  2316. m_pDisasm->error = DAE_CROSS;
  2317. }
  2318. DecodeSG(m_pCmd[1] >> 3);
  2319. m_nHasRM = 1;
  2320. break;
  2321. }
  2322. case SCM: // Segment register in command byte
  2323. {
  2324. DecodeSG(m_pCmd[0] >> 3);
  2325. if ((m_pDisasm->cmdtype & C_TYPEMASK) == C_POP)
  2326. {
  2327. m_pDisasm->warnings |= DAW_SEGMENT;
  2328. }
  2329. break;
  2330. }
  2331. case CRX: // Control register CRx
  2332. {
  2333. if ((m_pCmd[1] & 0xC0) != 0xC0)
  2334. {
  2335. m_pDisasm->error = DAE_REGISTER;
  2336. }
  2337. DecodeCR(m_pCmd[1]);
  2338. break;
  2339. }
  2340. case DRX: // Debug register DRx
  2341. {
  2342. if ((m_pCmd[1] & 0xC0) != 0xC0)
  2343. {
  2344. m_pDisasm->error = DAE_REGISTER;
  2345. }
  2346. DecodeDR(m_pCmd[1]);
  2347. break;
  2348. }
  2349. case PRN: // Near return address (pseudooperand)
  2350. {
  2351. break;
  2352. }
  2353. case PRF: // Far return address (pseudooperand)
  2354. {
  2355. m_pDisasm->warnings |= DAW_FARADDR;
  2356. break;
  2357. }
  2358. case PAC: // Accumulator (AL/AX/EAX, pseudooperand)
  2359. {
  2360. DecodeRG(REG_EAX, m_ulDataSize, PAC);
  2361. break;
  2362. }
  2363. case PAH: // AH (in LAHF/SAHF, pseudooperand)
  2364. case PFL: // Lower byte of flags (pseudooperand)
  2365. {
  2366. break;
  2367. }
  2368. case PS0: // Top of FPU stack (pseudooperand)
  2369. {
  2370. DecodeST(0, 1);
  2371. break;
  2372. }
  2373. case PS1: // ST(1) (pseudooperand)
  2374. {
  2375. DecodeST(1, 1);
  2376. break;
  2377. }
  2378. case PCX: // CX/ECX (pseudooperand)
  2379. {
  2380. DecodeRG(REG_ECX, cxsize, PCX);
  2381. break;
  2382. }
  2383. case PDI: // EDI (pseudooperand in MMX extentions)
  2384. {
  2385. DecodeRG(REG_EDI, 4, PDI);
  2386. break;
  2387. }
  2388. default:
  2389. {
  2390. m_pDisasm->error = DAE_INTERN; // Unknown argument type
  2391. break;
  2392. }
  2393. }
  2394. }
  2395. // Check whether command may possibly contain fixups.
  2396. if (m_pPFixup != NULL && m_pDisasm->fixupsize > 0)
  2397. {
  2398. m_pDisasm->fixupoffset = m_pPFixup - src;
  2399. }
  2400. // Segment prefix and address size prefix are superfluous for command which
  2401. // does not access memory. If this the case, mark command as rare to help
  2402. // in analysis.
  2403. if (m_pDisasm->memtype == DEC_UNKNOWN && (m_nSegPrefix != SEG_UNDEF || (m_ulAddrSize != 4 && pd->name[0] != '$')))
  2404. {
  2405. m_pDisasm->warnings |= DAW_PREFIX;
  2406. m_pDisasm->cmdtype |= C_RARE;
  2407. }
  2408. // 16-bit addressing is rare in 32-bit programs. If this is the case,
  2409. // mark command as rare to help in analysis.
  2410. if (m_ulAddrSize != 4)
  2411. {
  2412. m_pDisasm->cmdtype |= C_RARE;
  2413. }
  2414. }
  2415. //
  2416. // Suffix of 3DNow! command is accounted best by assuming it immediate byte
  2417. // constant.
  2418. if (is3dnow)
  2419. {
  2420. if (m_nImmSize != 0)
  2421. {
  2422. m_pDisasm->error = DAE_BADCMD;
  2423. }
  2424. else m_nImmSize = 1;
  2425. }
  2426. // Right or wrong, command decoded. Now dump it.
  2427. if (m_pDisasm->error != 0)
  2428. {
  2429. // Hard error in command detected
  2430. if (m_nMode >= DISASM_FILE)
  2431. {
  2432. m_nResult = sprintf(m_pDisasm->result, ("???"));
  2433. }
  2434. if (m_pDisasm->error == DAE_BADCMD && (*m_pCmd == 0x0F || *m_pCmd == 0xFF) && m_ulSize > 0)
  2435. {
  2436. if (m_nMode >= DISASM_FILE)
  2437. {
  2438. m_nDump += sprintf(m_pDisasm->dump + m_nDump, ("%02X"), *m_pCmd);
  2439. }
  2440. m_pCmd++;
  2441. m_ulSize--;
  2442. }
  2443. if (m_ulSize > 0)
  2444. {
  2445. if (m_nMode >= DISASM_FILE)
  2446. {
  2447. m_nDump += sprintf(m_pDisasm->dump + m_nDump, ("%02X"), *m_pCmd);
  2448. }
  2449. m_pCmd++;
  2450. m_ulSize--;
  2451. }
  2452. }
  2453. else // No hard error, dump command
  2454. {
  2455. if (m_nMode >= DISASM_FILE)
  2456. {
  2457. m_nDump += sprintf(m_pDisasm->dump + m_nDump, ("%02X"), *m_pCmd++);
  2458. if (m_nHasRM)
  2459. {
  2460. m_nDump += sprintf(m_pDisasm->dump + m_nDump, ("%02X"), *m_pCmd++);
  2461. }
  2462. if (m_nHasSIB)
  2463. {
  2464. m_nDump += sprintf(m_pDisasm->dump + m_nDump, ("%02X"), *m_pCmd++);
  2465. }
  2466. if (m_nDispSize != 0)
  2467. {
  2468. m_pDisasm->dump[m_nDump++] = ' ';
  2469. for (i = 0; i < m_nDispSize; i++)
  2470. {
  2471. m_nDump += sprintf(m_pDisasm->dump + m_nDump, ("%02X"), *m_pCmd++);
  2472. }
  2473. }
  2474. if (m_nImmSize != 0)
  2475. {
  2476. m_pDisasm->dump[m_nDump++] = ' ';
  2477. for (i = 0; i < m_nImmSize; i++)
  2478. {
  2479. m_nDump += sprintf(m_pDisasm->dump + m_nDump, "%02X", *m_pCmd++);
  2480. }
  2481. }
  2482. }
  2483. else
  2484. {
  2485. m_pCmd += 1 + m_nHasRM + m_nHasSIB + m_nDispSize + m_nImmSize;
  2486. }
  2487. //
  2488. m_ulSize -= 1 + m_nHasRM + m_nHasSIB + m_nDispSize + m_nImmSize;
  2489. }
  2490. // Check that command is not a dangerous one.
  2491. if (m_nMode >= DISASM_DATA)
  2492. {
  2493. for (pdan = g_Dangerous; pdan->mask != 0; pdan++)
  2494. {
  2495. if (((code ^ pdan->code) & pdan->mask) != 0)
  2496. {
  2497. continue;
  2498. }
  2499. if (pdan->type == C_DANGERLOCK && nLockPrefix == 0)
  2500. {
  2501. break; // Command harmless without LOCK prefix
  2502. }
  2503. if (m_nIsWindowsNT && pdan->type == C_DANGER95)
  2504. {
  2505. break; // Command harmless under Windows NT
  2506. }
  2507. // Dangerous command!
  2508. if (pdan->type == C_DANGER95)
  2509. {
  2510. m_pDisasm->warnings |= DAW_DANGER95;
  2511. }
  2512. else
  2513. {
  2514. m_pDisasm->warnings |= DAW_DANGEROUS;
  2515. }
  2516. break;
  2517. }
  2518. }
  2519. if (m_pDisasm->error == 0 && m_nSoftError != 0)
  2520. {
  2521. m_pDisasm->error = m_nSoftError; // Error, but still display command
  2522. }
  2523. //
  2524. if (m_nMode >= DISASM_FILE)
  2525. {
  2526. if (m_pDisasm->error != DAE_NOERR)
  2527. {
  2528. switch (m_pDisasm->error)
  2529. {
  2530. case DAE_CROSS:
  2531. {
  2532. strcpy(m_pDisasm->comment, ("Command crosses end of memory block"));
  2533. break;
  2534. }
  2535. case DAE_BADCMD:
  2536. {
  2537. strcpy(m_pDisasm->comment, ("Unknown command"));
  2538. break;
  2539. }
  2540. case DAE_BADSEG:
  2541. {
  2542. strcpy(m_pDisasm->comment, ("Undefined segment register"));
  2543. break;
  2544. }
  2545. case DAE_MEMORY:
  2546. {
  2547. strcpy(m_pDisasm->comment, ("Illegal use of register"));
  2548. break;
  2549. }
  2550. case DAE_REGISTER:
  2551. {
  2552. strcpy(m_pDisasm->comment, ("Memory address not allowed"));
  2553. break;
  2554. }
  2555. case DAE_INTERN:
  2556. {
  2557. strcpy(m_pDisasm->comment, ("Internal OLLYDBG error"));
  2558. break;
  2559. }
  2560. default:
  2561. {
  2562. strcpy(m_pDisasm->comment, ("Unknown error"));
  2563. break;
  2564. }
  2565. }
  2566. }
  2567. else if ((m_pDisasm->warnings & DAW_PRIV) != 0 && m_nPrivileged == 0)
  2568. {
  2569. strcpy(m_pDisasm->comment, ("Privileged command"));
  2570. }
  2571. else if ((m_pDisasm->warnings & DAW_IO) != 0 && m_nIOCommand == 0)
  2572. {
  2573. strcpy(m_pDisasm->comment, ("I/O command"));
  2574. }
  2575. else if ((m_pDisasm->warnings & DAW_FARADDR) != 0 && m_nFarCalls == 0)
  2576. {
  2577. if ((m_pDisasm->cmdtype & C_TYPEMASK) == C_JMP)
  2578. {
  2579. strcpy(m_pDisasm->comment, ("Far jump"));
  2580. }
  2581. else if ((m_pDisasm->cmdtype & C_TYPEMASK) == C_CAL)
  2582. {
  2583. strcpy(m_pDisasm->comment, ("Far call"));
  2584. }
  2585. else if ((m_pDisasm->cmdtype & C_TYPEMASK) == C_RET)
  2586. {
  2587. strcpy(m_pDisasm->comment, ("Far return"));
  2588. }
  2589. }
  2590. else if ((m_pDisasm->warnings & DAW_SEGMENT) != 0 && m_nFarCalls == 0)
  2591. {
  2592. strcpy(m_pDisasm->comment, ("Modification of segment register"));
  2593. }
  2594. else if ((m_pDisasm->warnings & DAW_SHIFT) != 0 && m_nBadShift == 0)
  2595. {
  2596. strcpy(m_pDisasm->comment, ("Shift constant out of range 1..31"));
  2597. }
  2598. else if ((m_pDisasm->warnings & DAW_PREFIX) != 0 && m_nExtraPrefix == 0)
  2599. {
  2600. strcpy(m_pDisasm->comment, ("Superfluous prefix"));
  2601. }
  2602. else if ((m_pDisasm->warnings & DAW_LOCK) != 0 && m_nLockedbus == 0)
  2603. {
  2604. strcpy(m_pDisasm->comment, ("LOCK prefix"));
  2605. }
  2606. else if ((m_pDisasm->warnings & DAW_STACK) != 0 && m_nStackAlign == 0)
  2607. {
  2608. strcpy(m_pDisasm->comment, ("Unaligned stack operation"));
  2609. }
  2610. }
  2611. return (srcsize - m_ulSize); // Returns number of recognized bytes
  2612. }