{"type": "func", "start": 6443740584, "end": 6443741383, "name": "common_set_variable_in_environment_nolock<char>", "pseudocode": "// \n// common_set_variable_in_environment_nolock<char> from 0x18013ada8 to 0x18013b0c7 (799 bytes)\n// \n// 2 xrefs:\n// > common_set_variable_in_environment_nolock<char> @ 0x18013b5c4\n// > <???> @ 0x1802038cc\n// \n// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!\n// \n// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA\n// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings\n// Generated at Fri, 27 Nov 2026 10:55:02 +0000\n// \n\n__int64 __fastcall common_set_variable_in_environment_nolock<char>(const char *Block, int a2)\n{\n  unsigned int v2; // esi\n  char *v6; // rdi\n  char *v7; // rax\n  char *v8; // r13\n  _QWORD *v9; // r14\n  char v10; // bp\n  int v11; // ebp\n  const char *v12; // rax\n  signed __int64 v13; // r12\n  _QWORD *v14; // rbx\n  signed __int64 v15; // rbx\n  void *v16; // rbx\n  unsigned __int64 v17; // rbx\n  size_t v18; // rdx\n  int v19; // ebp\n  _QWORD *v20; // r14\n  __int64 v21; // r14\n  char *v22; // rax\n  char *v23; // rbx\n  __int64 v24; // rcx\n\n  v2 = 0;\n  if ( !Block )\n  {\n    *errno() = 22;\n    return -1;\n  }\n  v6 = (char *)Block;\n  v7 = strchr(Block, 61);\n  v8 = v7;\n  if ( !v7 || v7 == Block )\n  {\nLABEL_51:\n    v2 = -1;\n    *errno() = 22;\n    goto LABEL_52;\n  }\n  v9 = qword_1801F4CF8;\n  v10 = v7[1];\n  if ( qword_1801F4CF8 == qword_1801F4D10 )\n  {\n    v9 = (_QWORD *)copy_environment<char>(qword_1801F4CF8);\n    qword_1801F4CF8 = v9;\n  }\n  if ( v9 )\n    goto LABEL_20;\n  if ( a2 && qword_1801F4D00 )\n  {\n    if ( unknown_libname_64() )\n    {\n      v9 = qword_1801F4CF8;\n      if ( qword_1801F4CF8 == qword_1801F4D10 )\n      {\n        v9 = (_QWORD *)copy_environment<char>(qword_1801F4CF8);\n        qword_1801F4CF8 = v9;\n      }\n      goto LABEL_19;\n    }\n    goto LABEL_51;\n  }\n  if ( !v10 )\n  {\nLABEL_52:\n    v11 = v2;\n    goto LABEL_53;\n  }\n  qword_1801F4CF8 = calloc_base(1u, 8u);\n  free_base(nullptr);\n  v9 = qword_1801F4CF8;\n  if ( !qword_1801F4CF8 )\n    goto LABEL_15;\n  if ( qword_1801F4D00 )\n    goto LABEL_19;\n  qword_1801F4D00 = calloc_base(1u, 8u);\n  free_base(nullptr);\n  if ( !qword_1801F4D00 )\n  {\nLABEL_15:\n    v11 = -1;\nLABEL_53:\n    v2 = v11;\nLABEL_54:\n    v19 = v2;\n    goto LABEL_55;\n  }\n  v9 = qword_1801F4CF8;\nLABEL_19:\n  if ( !v9 )\n    goto LABEL_15;\nLABEL_20:\n  v12 = (const char *)*v9;\n  v13 = v8 - Block;\n  v14 = v9;\n  while ( v12 )\n  {\n    if ( !strnicoll(Block, v12, v8 - Block) && (*(_BYTE *)(v13 + *v14) == 61 || !*(_BYTE *)(v13 + *v14)) )\n    {\n      v15 = v14 - v9;\n      goto LABEL_28;\n    }\n    v12 = (const char *)*++v14;\n  }\n  v15 = -(v14 - v9);\nLABEL_28:\n  if ( v15 >= 0 && *v9 )\n  {\n    free_base((void *)v9[v15]);\n    if ( !v10 )\n    {\n      while ( v9[v15] )\n      {\n        v9[v15] = v9[v15 + 1];\n        ++v15;\n      }\n      v16 = recalloc_base(v9, v15, 8u);\n      free_base(nullptr);\n      if ( v16 )\n        qword_1801F4CF8 = v16;\n      goto LABEL_43;\n    }\n    v9[v15] = Block;\nLABEL_42:\n    v6 = nullptr;\nLABEL_43:\n    if ( a2 )\n    {\n      v21 = -1;\n      do\n        ++v21;\n      while ( Block[v21] );\n      v22 = (char *)calloc_base(v21 + 2, 1u);\n      v23 = v22;\n      if ( v22 )\n      {\n        if ( strcpy_s(v22, v21 + 2, Block) )\n          invoke_watson(nullptr, nullptr, nullptr, 0, 0);\n        v24 = (__int64)&v8[v23 - Block + 1];\n        *(_BYTE *)(v24 - 1) = 0;\n        if ( !(unsigned int)_acrt_SetEnvironmentVariableA(v23, v24 & -(__int64)(v10 != 0)) )\n        {\n          v2 = -1;\n          *errno() = 42;\n        }\n      }\n      free_base(v23);\n    }\n    goto LABEL_56;\n  }\n  if ( !v10 )\n    goto LABEL_54;\n  v17 = -v15;\n  v18 = v17 + 2;\n  if ( v17 + 2 >= v17 && v18 < 0x1FFFFFFFFFFFFFFFLL )\n  {\n    v20 = recalloc_base(v9, v18, 8u);\n    free_base(nullptr);\n    if ( v20 )\n    {\n      v20[v17] = Block;\n      v20[v17 + 1] = 0;\n      qword_1801F4CF8 = v20;\n      goto LABEL_42;\n    }\n  }\n  v19 = -1;\nLABEL_55:\n  v2 = v19;\nLABEL_56:\n  free_base(v6);\n  return v2;\n}", "assembly": "; \n; common_set_variable_in_environment_nolock<char> from 0x18013ada8 to 0x18013b0c7 (799 bytes)\n; \n; 2 xrefs:\n; > common_set_variable_in_environment_nolock<char> @ 0x18013b5c4\n; > <???> @ 0x1802038cc\n; \n; This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!\n; \n; Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA\n; Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings\n; Generated at Fri, 27 Nov 2026 10:55:02 +0000\n; \nmov     [rsp+arg_10], rbx                                              ; +0x0, 0x18013ada8\nmov     [rsp+arg_8], edx                                               ; +0x5, 0x18013adad\npush    rbp                                                            ; +0x9, 0x18013adb1\npush    rsi                                                            ; +0xa, 0x18013adb2\npush    rdi                                                            ; +0xb, 0x18013adb3\npush    r12                                                            ; +0xc, 0x18013adb4\npush    r13                                                            ; +0xe, 0x18013adb6\npush    r14                                                            ; +0x10, 0x18013adb8\npush    r15                                                            ; +0x12, 0x18013adba\nsub     rsp, 30h                                                       ; +0x14, 0x18013adbc\nxor     esi, esi                                                       ; +0x18, 0x18013adc0\nmov     ebx, edx                                                       ; +0x1a, 0x18013adc2\nmov     r15, rcx                                                       ; +0x1c, 0x18013adc4\ntest    rcx, rcx                                                       ; +0x1f, 0x18013adc7\njnz     short loc_18013ADE0                                            ; +0x22, 0x18013adca\ncall    _errno                                                         ; +0x24, 0x18013adcc\nmov     dword ptr [rax], 16h                                           ; +0x29, 0x18013add1\nor      rax, 0FFFFFFFFFFFFFFFFh                                        ; +0x2f, 0x18013add7\njmp     loc_18013B09B                                                  ; +0x33, 0x18013addb\nmov     edx, 3Dh ; '='; Val                                            ; +0x38, 0x18013ade0\nmov     rdi, r15                                                       ; +0x3d, 0x18013ade5\ncall    strchr                                                         ; +0x40, 0x18013ade8\nmov     r13, rax                                                       ; +0x45, 0x18013aded\ntest    rax, rax                                                       ; +0x48, 0x18013adf0\njz      loc_18013B07A                                                  ; +0x4b, 0x18013adf3\ncmp     rax, r15                                                       ; +0x51, 0x18013adf9\njz      loc_18013B07A                                                  ; +0x54, 0x18013adfc\nmov     r14, cs:qword_1801F4CF8                                        ; +0x5a, 0x18013ae02\ncmp     r14, cs:qword_1801F4D10                                        ; +0x61, 0x18013ae09\nmov     bpl, [rax+1]                                                   ; +0x68, 0x18013ae10\nmov     [rsp+68h+arg_0], bpl                                           ; +0x6c, 0x18013ae14\njnz     short loc_18013AE2D                                            ; +0x71, 0x18013ae19\nmov     rcx, r14                                                       ; +0x73, 0x18013ae1b\ncall    ??$copy_environment@D@@YAPEAPEADQEAPEAD@Z                      ; +0x76, 0x18013ae1e\nmov     r14, rax                                                       ; +0x7b, 0x18013ae23\nmov     cs:qword_1801F4CF8, rax                                        ; +0x7e, 0x18013ae26\nmov     r12d, 1                                                        ; +0x85, 0x18013ae2d\ntest    r14, r14                                                       ; +0x8b, 0x18013ae33\njnz     loc_18013AEF1                                                  ; +0x8e, 0x18013ae36\ntest    ebx, ebx                                                       ; +0x94, 0x18013ae3c\njz      short loc_18013AE7F                                            ; +0x96, 0x18013ae3e\ncmp     cs:qword_1801F4D00, rsi                                        ; +0x98, 0x18013ae40\njz      short loc_18013AE7F                                            ; +0x9f, 0x18013ae47\ncall    unknown_libname_64; Microsoft VisualC 64bit universal runtime  ; +0xa1, 0x18013ae49\ntest    rax, rax                                                       ; +0xa6, 0x18013ae4e\njz      loc_18013B07A                                                  ; +0xa9, 0x18013ae51\nmov     r14, cs:qword_1801F4CF8                                        ; +0xaf, 0x18013ae57\ncmp     r14, cs:qword_1801F4D10                                        ; +0xb6, 0x18013ae5e\njnz     loc_18013AEEC                                                  ; +0xbd, 0x18013ae65\nmov     rcx, r14                                                       ; +0xc3, 0x18013ae6b\ncall    ??$copy_environment@D@@YAPEAPEADQEAPEAD@Z                      ; +0xc6, 0x18013ae6e\nmov     r14, rax                                                       ; +0xcb, 0x18013ae73\nmov     cs:qword_1801F4CF8, rax                                        ; +0xce, 0x18013ae76\njmp     short loc_18013AEEC                                            ; +0xd5, 0x18013ae7d\ntest    bpl, bpl                                                       ; +0xd7, 0x18013ae7f\njz      loc_18013B089                                                  ; +0xda, 0x18013ae82\nmov     edx, 8; Size                                                   ; +0xe0, 0x18013ae88\nmov     rcx, r12; Count                                                ; +0xe5, 0x18013ae8d\ncall    _calloc_base                                                   ; +0xe8, 0x18013ae90\nxor     ecx, ecx; Block                                                ; +0xed, 0x18013ae95\nmov     cs:qword_1801F4CF8, rax                                        ; +0xef, 0x18013ae97\ncall    _free_base                                                     ; +0xf6, 0x18013ae9e\nmov     r14, cs:qword_1801F4CF8                                        ; +0xfb, 0x18013aea3\ntest    r14, r14                                                       ; +0x102, 0x18013aeaa\njnz     short loc_18013AEB8                                            ; +0x105, 0x18013aead\nor      rbp, 0FFFFFFFFFFFFFFFFh                                        ; +0x107, 0x18013aeaf\njmp     loc_18013B08B                                                  ; +0x10b, 0x18013aeb3\ncmp     cs:qword_1801F4D00, rsi                                        ; +0x110, 0x18013aeb8\njnz     short loc_18013AEEC                                            ; +0x117, 0x18013aebf\nmov     edx, 8; Size                                                   ; +0x119, 0x18013aec1\nmov     rcx, r12; Count                                                ; +0x11e, 0x18013aec6\ncall    _calloc_base                                                   ; +0x121, 0x18013aec9\nxor     ecx, ecx; Block                                                ; +0x126, 0x18013aece\nmov     cs:qword_1801F4D00, rax                                        ; +0x128, 0x18013aed0\ncall    _free_base                                                     ; +0x12f, 0x18013aed7\ncmp     cs:qword_1801F4D00, rsi                                        ; +0x134, 0x18013aedc\njz      short loc_18013AEAF                                            ; +0x13b, 0x18013aee3\nmov     r14, cs:qword_1801F4CF8                                        ; +0x13d, 0x18013aee5\ntest    r14, r14                                                       ; +0x144, 0x18013aeec\njz      short loc_18013AEAF                                            ; +0x147, 0x18013aeef\nmov     rax, [r14]                                                     ; +0x149, 0x18013aef1\nmov     r12, r13                                                       ; +0x14c, 0x18013aef4\nsub     r12, r15                                                       ; +0x14f, 0x18013aef7\nmov     rbx, r14                                                       ; +0x152, 0x18013aefa\ntest    rax, rax                                                       ; +0x155, 0x18013aefd\njz      short loc_18013AF36                                            ; +0x158, 0x18013af00\nmov     r8, r12; MaxCount                                              ; +0x15a, 0x18013af02\nmov     rdx, rax; String2                                              ; +0x15d, 0x18013af05\nmov     rcx, r15; String1                                              ; +0x160, 0x18013af08\ncall    _strnicoll                                                     ; +0x163, 0x18013af0b\ntest    eax, eax                                                       ; +0x168, 0x18013af10\njnz     short loc_18013AF24                                            ; +0x16a, 0x18013af12\nmov     rax, [rbx]                                                     ; +0x16c, 0x18013af14\ncmp     byte ptr [r12+rax], 3Dh ; '='                                  ; +0x16f, 0x18013af17\njz      short loc_18013AF2D                                            ; +0x174, 0x18013af1c\ncmp     [r12+rax], sil                                                 ; +0x176, 0x18013af1e\njz      short loc_18013AF2D                                            ; +0x17a, 0x18013af22\nadd     rbx, 8                                                         ; +0x17c, 0x18013af24\nmov     rax, [rbx]                                                     ; +0x180, 0x18013af28\njmp     short loc_18013AEFD                                            ; +0x183, 0x18013af2b\nsub     rbx, r14                                                       ; +0x185, 0x18013af2d\nsar     rbx, 3                                                         ; +0x188, 0x18013af30\njmp     short loc_18013AF40                                            ; +0x18c, 0x18013af34\nsub     rbx, r14                                                       ; +0x18e, 0x18013af36\nsar     rbx, 3                                                         ; +0x191, 0x18013af39\nneg     rbx                                                            ; +0x195, 0x18013af3d\ntest    rbx, rbx                                                       ; +0x198, 0x18013af40\njs      short loc_18013AF9C                                            ; +0x19b, 0x18013af43\ncmp     [r14], rsi                                                     ; +0x19d, 0x18013af45\njz      short loc_18013AF9C                                            ; +0x1a0, 0x18013af48\nmov     rcx, [r14+rbx*8]; Block                                        ; +0x1a2, 0x18013af4a\ncall    _free_base                                                     ; +0x1a6, 0x18013af4e\ntest    bpl, bpl                                                       ; +0x1ab, 0x18013af53\njz      short loc_18013AF6D                                            ; +0x1ae, 0x18013af56\nmov     [r14+rbx*8], r15                                               ; +0x1b0, 0x18013af58\njmp     loc_18013AFF6                                                  ; +0x1b4, 0x18013af5c\nmov     rax, [r14+rbx*8+8]                                             ; +0x1b9, 0x18013af61\nmov     [r14+rbx*8], rax                                               ; +0x1be, 0x18013af66\ninc     rbx                                                            ; +0x1c2, 0x18013af6a\ncmp     [r14+rbx*8], rsi                                               ; +0x1c5, 0x18013af6d\njnz     short loc_18013AF61                                            ; +0x1c9, 0x18013af71\nmov     r8d, 8; Size                                                   ; +0x1cb, 0x18013af73\nmov     rdx, rbx; Count                                                ; +0x1d1, 0x18013af79\nmov     rcx, r14; Block                                                ; +0x1d4, 0x18013af7c\ncall    _recalloc_base                                                 ; +0x1d7, 0x18013af7f\nxor     ecx, ecx; Block                                                ; +0x1dc, 0x18013af84\nmov     rbx, rax                                                       ; +0x1de, 0x18013af86\ncall    _free_base                                                     ; +0x1e1, 0x18013af89\ntest    rbx, rbx                                                       ; +0x1e6, 0x18013af8e\njz      short loc_18013AFF9                                            ; +0x1e9, 0x18013af91\nmov     cs:qword_1801F4CF8, rbx                                        ; +0x1eb, 0x18013af93\njmp     short loc_18013AFF9                                            ; +0x1f2, 0x18013af9a\ntest    bpl, bpl                                                       ; +0x1f4, 0x18013af9c\njz      loc_18013B08D                                                  ; +0x1f7, 0x18013af9f\nneg     rbx                                                            ; +0x1fd, 0x18013afa5\nlea     rdx, [rbx+2]; Count                                            ; +0x200, 0x18013afa8\ncmp     rdx, rbx                                                       ; +0x204, 0x18013afac\njnb     short loc_18013AFBA                                            ; +0x207, 0x18013afaf\nor      rbp, 0FFFFFFFFFFFFFFFFh                                        ; +0x209, 0x18013afb1\njmp     loc_18013B08F                                                  ; +0x20d, 0x18013afb5\nmov     rax, 1FFFFFFFFFFFFFFFh                                         ; +0x212, 0x18013afba\ncmp     rdx, rax                                                       ; +0x21c, 0x18013afc4\njnb     short loc_18013AFB1                                            ; +0x21f, 0x18013afc7\nmov     r8d, 8; Size                                                   ; +0x221, 0x18013afc9\nmov     rcx, r14; Block                                                ; +0x227, 0x18013afcf\ncall    _recalloc_base                                                 ; +0x22a, 0x18013afd2\nxor     ecx, ecx; Block                                                ; +0x22f, 0x18013afd7\nmov     r14, rax                                                       ; +0x231, 0x18013afd9\ncall    _free_base                                                     ; +0x234, 0x18013afdc\ntest    r14, r14                                                       ; +0x239, 0x18013afe1\njz      short loc_18013AFB1                                            ; +0x23c, 0x18013afe4\nmov     [r14+rbx*8], r15                                               ; +0x23e, 0x18013afe6\nmov     [r14+rbx*8+8], rsi                                             ; +0x242, 0x18013afea\nmov     cs:qword_1801F4CF8, r14                                        ; +0x247, 0x18013afef\nmov     rdi, rsi                                                       ; +0x24e, 0x18013aff6\ncmp     [rsp+68h+arg_8], esi                                           ; +0x251, 0x18013aff9\njz      loc_18013B091                                                  ; +0x255, 0x18013affd\nor      rbp, 0FFFFFFFFFFFFFFFFh                                        ; +0x25b, 0x18013b003\nmov     r14, rbp                                                       ; +0x25f, 0x18013b007\ninc     r14                                                            ; +0x262, 0x18013b00a\ncmp     [r15+r14], sil                                                 ; +0x265, 0x18013b00d\njnz     short loc_18013B00A                                            ; +0x269, 0x18013b011\nmov     edx, 1; Size                                                   ; +0x26b, 0x18013b013\nlea     rcx, [r14+2]; Count                                            ; +0x270, 0x18013b018\ncall    _calloc_base                                                   ; +0x274, 0x18013b01c\nmov     rbx, rax                                                       ; +0x279, 0x18013b021\ntest    rax, rax                                                       ; +0x27c, 0x18013b024\njz      short loc_18013B070                                            ; +0x27f, 0x18013b027\nmov     r8, r15; Source                                                ; +0x281, 0x18013b029\nlea     rdx, [r14+2]; SizeInBytes                                      ; +0x284, 0x18013b02c\nmov     rcx, rax; Destination                                          ; +0x288, 0x18013b030\ncall    strcpy_s                                                       ; +0x28b, 0x18013b033\ntest    eax, eax                                                       ; +0x290, 0x18013b038\njnz     short loc_18013B0B3                                            ; +0x292, 0x18013b03a\nmov     rax, rbx                                                       ; +0x294, 0x18013b03c\nlea     rcx, [r13+1]                                                   ; +0x297, 0x18013b03f\nsub     rax, r15                                                       ; +0x29b, 0x18013b043\nadd     rcx, rax                                                       ; +0x29e, 0x18013b046\nneg     [rsp+68h+arg_0]                                                ; +0x2a1, 0x18013b049\nsbb     rdx, rdx                                                       ; +0x2a5, 0x18013b04d\nand     rdx, rcx                                                       ; +0x2a8, 0x18013b050\nmov     [rcx-1], sil                                                   ; +0x2ab, 0x18013b053\nmov     rcx, rbx                                                       ; +0x2af, 0x18013b057\ncall    __acrt_SetEnvironmentVariableA                                 ; +0x2b2, 0x18013b05a\ntest    eax, eax                                                       ; +0x2b7, 0x18013b05f\njnz     short loc_18013B070                                            ; +0x2b9, 0x18013b061\ncall    _errno                                                         ; +0x2bb, 0x18013b063\nmov     esi, ebp                                                       ; +0x2c0, 0x18013b068\nmov     dword ptr [rax], 2Ah ; '*'                                     ; +0x2c2, 0x18013b06a\nmov     rcx, rbx; Block                                                ; +0x2c8, 0x18013b070\ncall    _free_base                                                     ; +0x2cb, 0x18013b073\njmp     short loc_18013B091                                            ; +0x2d0, 0x18013b078\ncall    _errno                                                         ; +0x2d2, 0x18013b07a\nor      rsi, 0FFFFFFFFFFFFFFFFh                                        ; +0x2d7, 0x18013b07f\nmov     dword ptr [rax], 16h                                           ; +0x2db, 0x18013b083\nmov     ebp, esi                                                       ; +0x2e1, 0x18013b089\nmov     esi, ebp                                                       ; +0x2e3, 0x18013b08b\nmov     ebp, esi                                                       ; +0x2e5, 0x18013b08d\nmov     esi, ebp                                                       ; +0x2e7, 0x18013b08f\nmov     rcx, rdi; Block                                                ; +0x2e9, 0x18013b091\ncall    _free_base                                                     ; +0x2ec, 0x18013b094\nmov     eax, esi                                                       ; +0x2f1, 0x18013b099\nmov     rbx, [rsp+68h+arg_10]                                          ; +0x2f3, 0x18013b09b\nadd     rsp, 30h                                                       ; +0x2fb, 0x18013b0a3\npop     r15                                                            ; +0x2ff, 0x18013b0a7\npop     r14                                                            ; +0x301, 0x18013b0a9\npop     r13                                                            ; +0x303, 0x18013b0ab\npop     r12                                                            ; +0x305, 0x18013b0ad\npop     rdi                                                            ; +0x307, 0x18013b0af\npop     rsi                                                            ; +0x308, 0x18013b0b0\npop     rbp                                                            ; +0x309, 0x18013b0b1\nretn                                                                   ; +0x30a, 0x18013b0b2\nxor     r9d, r9d; LineNo                                               ; +0x30b, 0x18013b0b3\nmov     [rsp+68h+Reserved], rsi; Reserved                              ; +0x30e, 0x18013b0b6\nxor     r8d, r8d; FileName                                             ; +0x313, 0x18013b0bb\nxor     edx, edx; FunctionName                                         ; +0x316, 0x18013b0be\nxor     ecx, ecx; Expression                                           ; +0x318, 0x18013b0c0\ncall    _invoke_watson                                                 ; +0x31a, 0x18013b0c2", "xrefs": ["common_set_variable_in_environment_nolock<char> @ 0x18013b5c4", "<???> @ 0x1802038cc"], "is_objc": false, "is_32_bit": false, "is_64_bit": true, "idp_name": "pc", "bida_info": "8.3.0 @ https://github.com/Stazzical/BromaIDA", "bindings_info": "commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings"}