------------------------------------------------------------------------------------ Set Auto Comment only if a comment isn't already set ------------------------------------------------------------------------------------
| 1183 | // Set Auto Comment only if a comment isn't already set |
| 1184 | // ------------------------------------------------------------------------------------ |
| 1185 | void SetAutoCommentIfCommentIsEmpty(INSTRUCTIONSTACK *inst, char *CommentString, size_t CommentStringCount, bool apiCALL) |
| 1186 | { |
| 1187 | char szComment[MAX_COMMENT_SIZE] = ""; |
| 1188 | char szConstComment[MAX_COMMENT_SIZE] = ""; |
| 1189 | bool isHeaderConst = false; |
| 1190 | |
| 1191 | if (apiCALL) // set the API name definition comment |
| 1192 | { |
| 1193 | DbgSetCommentAt(inst->Address, szOriginalCharsetAPIFunction.c_str()); |
| 1194 | procSummary.totalCommentsSet++; // get record of comments amount |
| 1195 | } |
| 1196 | else // set the API param comment |
| 1197 | { |
| 1198 | isHeaderConst = IsHeaderConstant(CommentString, szConstComment, inst->SourceRegister, inst->GuiInstruction); |
| 1199 | |
| 1200 | // avoid BoF for longer comments than MAX_COMMENT_SIZE (FIXED!) |
| 1201 | duint spaceleft = MAX_COMMENT_SIZE - strlen(CommentString); |
| 1202 | if (spaceleft <= 1) |
| 1203 | return; |
| 1204 | |
| 1205 | //string memStr = ""; |
| 1206 | if (DbgGetCommentAt(inst->Address, szComment)/* || (memStr = GetMemoryString(inst)) != ""*/) |
| 1207 | { |
| 1208 | /*if (!*szComment && memStr != "") |
| 1209 | strcpy_s(szComment, memStr.c_str());*/ |
| 1210 | |
| 1211 | if (*szComment) |
| 1212 | { |
| 1213 | StripDbgCommentAddress(szComment); // get rid of the comment address id used by the dbg |
| 1214 | DbgClearAutoCommentRange(inst->Address, inst->Address); // Delete the prev comment |
| 1215 | if ((strlen(szComment) + 10) <= spaceleft - 1) // avoid BoF for longer comments than MAX_COMMENT_SIZE (FIXED!) |
| 1216 | { |
| 1217 | if (isHeaderConst) |
| 1218 | { |
| 1219 | strcpy_s(CommentString, CommentStringCount, szConstComment); |
| 1220 | if (CommentString[strlen(CommentString) - 1] == ' ') // if comment is of the form "TYPE varName = " |
| 1221 | strcat_s(CommentString, CommentStringCount, szComment); |
| 1222 | } |
| 1223 | else |
| 1224 | { |
| 1225 | strcat_s(CommentString, CommentStringCount, " = "); |
| 1226 | strcat_s(CommentString, CommentStringCount, szComment); |
| 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | if (!*szComment) |
| 1233 | { |
| 1234 | // if no prev comment and is a push copy then the argument |
| 1235 | if (!apiCALL) |
| 1236 | { |
| 1237 | char *nullstr = "NULL\0"; |
| 1238 | string boolstr[] = { "TRUE", "FALSE" }; |
| 1239 | |
| 1240 | if (inst->SourceRegister != NULL && ((strlen(inst->SourceRegister) + 10) <= spaceleft - 1)) // avoid BoF for longer comments than MAX_COMMENT_SIZE (FIXED!) |
| 1241 | { |
| 1242 | bool instHex = IsHex(inst->SourceRegister); |
no test coverage detected