MCPcopy Create free account
hub / github.com/HyperDbg/HyperDbg / HandleError

Function HandleError

hyperdbg/script-engine/code/script-engine.c:4251–4353  ·  view source on GitHub ↗

* @brief Prints some information about the error * * @param Error * @param str * @return char* */

Source from the content-addressed store, hash-verified

4249 * @return char*
4250 */
4251char *
4252HandleError(PSCRIPT_ENGINE_ERROR_TYPE Error, char * str)
4253{
4254 //
4255 // calculate position of current line
4256 //
4257 unsigned int LineEnd;
4258 for (int i = InputIdx;; i++)
4259 {
4260 if (str[i] == '\n' || str[i] == '\0')
4261 {
4262 LineEnd = i;
4263 break;
4264 }
4265 }
4266
4267 //
4268 // allocate required memory for message, 16 for line, 100 for error information,
4269 // (CurrentTokenIdx - CurrentLineIdx) for space and,
4270 // (LineEnd - CurrentLineIdx) for input string
4271 //
4272 int MessageSize = 16 + 100 + (CurrentTokenIdx - CurrentLineIdx) + (LineEnd - CurrentLineIdx);
4273 char * Message = (char *)malloc(MessageSize);
4274
4275 if (Message == NULL)
4276 {
4277 printf("err, could not allocate buffer");
4278 return NULL;
4279 }
4280
4281 //
4282 // add line number
4283 //
4284 strcpy(Message, "Line ");
4285 char Line[16] = {0};
4286 sprintf(Line, "%d:\n", CurrentLine);
4287 strcat(Message, Line);
4288
4289 //
4290 // add the line which error happened at
4291 //
4292 strncat(Message, (str + CurrentLineIdx), LineEnd - CurrentLineIdx);
4293
4294 strcat(Message, "\n");
4295
4296 //
4297 // add pointer
4298 //
4299 char Space = ' ';
4300 int n = (CurrentTokenIdx - CurrentLineIdx);
4301 for (int i = 0; i < n; i++)
4302 {
4303 strncat(Message, &Space, 1);
4304 }
4305 strcat(Message, "^\n");
4306
4307 //
4308 // add error cause and details

Callers 1

ScriptEngineParseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected