Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's break it down shall we, one step at a time.</p> <pre><code>void CryptoBuffer(unsigned char *Buffer, unsigned short length) { unsigned short i; for(i=0; i &lt; length; i++) { *Buffer ^= 0xAA; *Buffer++ += 0xC9; } } </code></pre> <p>Regardless of some other remarks, this <em>is</em> how you normally do these things in C/C++. There's nothing fancy about this code, and it isn't overly complicated, but I think it is good to break it down to show you what happens.</p> <p>Things to note:</p> <ol> <li>unsigned char is basically the same as byte in c#</li> <li>unsigned length has a value between 0-65536. Int should do the trick.</li> <li>Buffer has a post-increment</li> <li>The byte assignment (+= 0xC9) will overflow. If it overflows it's truncated to 8 bits in this case.</li> <li>The buffer is passed by ptr, so the pointer in the calling method will stay the same.</li> <li>This is just basic C code, no C++. It's quite safe to assume people don't use operator overloading here.</li> </ol> <p>The only "difficult" thing here is the Buffer++. Details can be read in the book "Exceptional C++" from Sutter, but a small example explains this as well. And fortunately we have a perfect example at our disposal. A <strong>literal</strong> translation of the above code is:</p> <pre><code>void CryptoBuffer(unsigned char *Buffer, unsigned short length) { unsigned short i; for(i=0; i &lt; length; i++) { *Buffer ^= 0xAA; unsigned char *tmp = Buffer; *tmp += 0xC9; Buffer = tmp + 1; } } </code></pre> <p>In this case the temp variable can be solved trivially, which leads us to:</p> <pre><code>void CryptoBuffer(unsigned char *Buffer, unsigned short length) { unsigned short i; for(i=0; i &lt; length; i++) { *Buffer ^= 0xAA; *Buffer += 0xC9; ++Buffer; } } </code></pre> <p>Changing this code to C# now is pretty easy:</p> <pre><code>private void CryptoBuffer(byte[] Buffer, int length) { for (int i=0; i&lt;length; ++i) { Buffer[i] = (byte)((Buffer[i] ^ 0xAA) + 0xC9); } } </code></pre> <p><strong>This is basically the same as your ported code.</strong> This means that somewhere down the road something else went wrong... So let's hack the cryptobuffer shall we? :-)</p> <p>If we assume that the first byte isn't used (as you stated) and that the '0xAA' and/or the '0xC9' are wrong, we can simply try all combinations:</p> <pre><code>static void Main(string[] args) { byte[] orig = new byte[] { 0x03, 0x18, 0x01 }; byte[] target = new byte[] { 0x6F, 0x93, 0x8b }; for (int i = 0; i &lt; 256; ++i) { for (int j = 0; j &lt; 256; ++j) { bool okay = true; for (int k = 0; okay &amp;&amp; k &lt; 3; ++k) { byte tmp = (byte)((orig[k] ^ i) + j); if (tmp != target[k]) { okay = false; break; } } if (okay) { Console.WriteLine("Solution for i={0} and j={1}", i, j); } } } Console.ReadLine(); } </code></pre> <p>There we go: <strong>oops</strong> there are no solutions. That means that the cryptobuffer is not doing what you think it's doing, or part of the C code is missing here. F.ex. do they really pass 'Buffer' to the CryptoBuffer method or did they change the pointer before?</p> <p>Concluding, I think the only good answer here is that critical information for solving this question is missing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload