title: How to detect UTF16 strings in PE files
body: <p>I need to extract Unicode strings from a PE file. While extracting I need to detect it first. For UTF-8 characters, I used the following link - <a href="https://stackoverflow.com/questions/28270310/how-to-easily-detect-utf8-encoding-in-the-string">How to easily detect utf8 encoding in the string?</a>. Is there any similar way to detect UTF-16 characters. I have tried the following code. Is this right? Please do help or provide suggestions. Thanks in advance!!!</p>
  <pre><code>BYTE temp1 = buf[offset];
  
  BYTE temp2 = buf[offset+1];
  
  while (!(temp1 == 0x00 &amp;&amp; temp2 == 0x00) &amp;&amp; offset &lt;= bufSize)
  {
      if ((temp1 &gt;= 0x00 &amp;&amp; temp1 &lt;= 0xFF) &amp;&amp; (temp2 &gt;= 0x00 &amp;&amp; temp2 &lt;= 0xFF)) 
      {
          tmp += 2;
      }
      else
      {
          break;
      }
  
      offset += 2;
      temp1 = buf[offset];
      temp2 = buf[offset+1];
  
      if (temp1 == 0x00 &amp;&amp; temp2 == 0x00)
      {
          break;
      }
  }
  </code></pre>