0
int __cdecl sub_920(char *s1)
{
  void *v1; // esi
  char *ptr; // esi
  int v3; // edi

  v1 = off_2048;
  strlen((const char *)off_2048);
  ptr = (char *)__strdup(v1);
  memfrob(ptr);
  v3 = strcmp(s1, ptr);
  free(ptr);
  return v3;
}

This code was written by IDA, and I am not sure what ptr = (char *)__strdup(v1); actually does?

klutt
  • 30,332
  • 17
  • 55
  • 95
tuyen dangminh
  • 116
  • 1
  • 4
  • 2
    Related: https://stackoverflow.com/questions/252782/strdup-what-does-it-do-in-c but it's not a dupe, since this question is about `__strdup` and not `strdup`. – klutt Sep 09 '18 at 17:29

2 Answers2

1

As can be read here: http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/baselib---strdup-1.html

__strdup -- alias for strdup

What strdup does can be read in this answer: https://stackoverflow.com/a/252802/6699433

The short version is, it creates a copy of the string passed as argument and returns a pointer to the copy.

klutt
  • 30,332
  • 17
  • 55
  • 95
0

strdup returns char * so I can't see the point for typecasting that explicitly, apart from that the ___ part in the beginning might suggest a user defined version of strdup which has been typecasted.

Anyways it is used to duplicate a string.

Gaurav
  • 1,570
  • 5
  • 17
  • 3
    The `__` (double underscore) prefix means the name is reserved for use by the implementation; users should not create any functions (or macros, or variables, or labels, or anything else) that start with a double underscore. So, `__strdup()` should not be a user-defined function — it is most probably a system defined function and the name `strdup()` is probably something like a 'weak alias' for the `__strdup()` function. It could be that there is something loosely similar to `static inline char *strdup(const char *s) { return __strdup(s); }` — but the generated code uses `__strdup()` directly. – Jonathan Leffler Sep 09 '18 at 19:08