Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

Calculate CRC for strings [solved]

Featured Replies

  • Author
  • Localization

StreamThread, posted Sun Sep 30, 2018 6:35 pm (38908)


Quote:
Hello

How to use Encryption command for calculate CRC32 of string?

I tried next code:
...


Well, i solved my objective with the next method:

Code:
set MEMORY_FILE binary "
// Reverses (reflects) bits in a 32-bit word.
unsigned reverse(unsigned x) {
   x = ((x & 0x55555555) <<  1) | ((x >>  1) & 0x55555555);
   x = ((x & 0x33333333) <<  2) | ((x >>  2) & 0x33333333);
   x = ((x & 0x0F0F0F0F) <<  4) | ((x >>  4) & 0x0F0F0F0F);
   x = (x << 24) | ((x & 0xFF00) << 8) |
       ((x >> 8) & 0xFF00) | (x >> 24);
   return x;
}

unsigned int crc32a(unsigned char *message) {
   int i, j;
   unsigned int byte, crc;

   i = 0;
   crc = 0xFFFFFFFF;
   while (message[i] != 0) {
      byte = message[i];            // Get next byte.
      byte = reverse(byte);         // 32-bit reversal.
      for (j = 0; j <= 7; j ) {    // Do eight times.
         if ((int)(crc ^ byte) < 0)
              crc = (crc << 1) ^ 0x04C11DB7;
         else crc = crc << 1;
         byte = byte << 1;          // Ready next msg bit.
      }
      i = i 1;
   }
   return reverse(~crc);
}
"

callDLL MEMORY_FILE "crc32a" "tcc" RET "my_message"

print "My CRC: %RET|h%"


But still interesting, maybe there's a way do same even easier with QuckBMS commands like Encryption or String 'e' operator? )
  • Author
  • Localization

aluigi, posted Wed Oct 03, 2018 1:00 pm (38987)


If you want to calculate the CRC on a variable (NULL delimited string):
Code:
encryption crc 0x04c11db7 "32 -1 -1 0 1 0"
string DUMMY E "my_message"
encryption "" ""
print "My CRC: %QUICKBMS_CRC|h%"

If you want to calculate it on a file just replace the second line with:
Code:
get SIZE asize
log MEMORY_FILE 0 SIZE


Finding the parameters for the CRC method of the Encryption command is really a joke, just dump the string in a new file and use the following script on it:
http://aluigi.org/bms/crc_scan.bms

quickbms.exe crc_scan.bms input_string.txt > output.txt

In your case we had the following results:
Code:
...
0x3c449c53 0x539c443c - CONFIG 0x04c11db7  32 -1 -1 0 1 0
...
0x3c449c53 0x539c443c - CONFIG 0xedb88320  32 -1 -1 0 0 1

The KEY argument of Encryption must be the polynomial while the IVEC field is the rest of the configuration.

As you can see the result obtained from crc_scan.bms has the crc in both endianess so you don't have to care about "swapping" your expected result for finding it :)
  • Author
  • Localization

StreamThread, posted Thu Oct 04, 2018 11:53 am (39049)


Sometimes are differences in crc generation. First column - previous function, Second - QUICKBMS_SRC with Poly 0x04C11DB7:


Code:
[Fn CRC32]      [QUICKBMS_CRC]

0x82e7bb5f      0x82e7bb5f      \animations\characters\branch\branch.mac.mrg.bin
0x6795d953      0xe6694177**      \animations\characters\branch\branch.xba
0x8ef67c66      0x8ef67c66      \animations\characters\branch\branch.xbg
0xfd44eff1      0xfd44eff1         \animations\characters\branch\branchtrap_nt_start_c.man.mrg.bin
0xd747174a      0xd747174a      \animations\characters\branch\branchtrap_nt_start_c.mcl.mrg.bin
0xe82d9056      0x4fba9ba2**      \animations\characters\branch\branchtrap_pull.man.mrg.bin
0xc22e68ed      0xc22e68ed      \animations\characters\branch\branchtrap_pull.mcl.mrg.bin
0xd7a4242e      0xd7a4242e      \animations\characters\branch\branchtrap_pull_nt.man.mrg.bin
0xfda7dc95      0xfda7dc95      \animations\characters\branch\branchtrap_pull_nt.mcl.mrg.bin
0xd150fb65      0xdf42fb0a**      \animations\characters\branch\branchtrap_wip.man.mrg.bin
0xfb5303de      0xfb5303de      \animations\characters\branch\branchtrap_wip.mcl.mrg.bin
0xcc62b3d9      0x04344ce8**      \animations\characters\branch\trp_bwhip00_df.xbt
0x01729feb      0x01729feb      \animations\characters\carver_3rd\carver_3rd_armsonly_human.mac.mrg.bin
0xff4dddd6      0x16e61c49**      \animations\characters\carver_3rd\carver_3rd_armsonly_human.xbg
0xed818071      0xefd134aa**      \animations\characters\carver_3rd\carver_shadow.mac.mrg.bin
0x3bc300eb      0xfa1503d3**      \animations\characters\carver_3rd\carver_shadow.xbg
0x89e2b043      0x89e2b043      \animations\characters\carver_first\carver_first_hands_human_df.xbt
0x325957c7      0x325957c7      \animations\characters\carver_first\carver_first_hands_human_nt.xbt
0x6ade1f4b      0x6ade1f4b      \animations\characters\carver_first\carver_first_hands_mutant_df.xbt
0xd165f8cf      0xd165f8cf      \animations\characters\carver_first\carver_first_hands_mutant_nt.xbt
0x16075c5a      0x1600f599**      \animations\characters\carver_first\cf_assault_getgun.man.mrg.bin
0x3c04a4e1      0x3c04a4e1      \animations\characters\carver_first\cf_assault_getgun.mcl.mrg.bin


Online CRC with poly 0x04C11DB7 give results simular to function.
Now i guess, the problem with nameCRC command, about i posted in "QuickBMS errors" topic, also linked with that.
  • Author
  • Localization

aluigi, posted Thu Oct 04, 2018 1:25 pm (39053)


Here everything works perfectly and \animations\characters\branch\branch.xba returns 0x6795d953 using both Encryption and Namecrc.
  • Author
  • Localization

beedy, posted Fri Nov 09, 2018 9:12 am (40207)


Hello,
I want to know how these crc values are calculated? I have tried online crc calculator and quickbms crc-scanner with no luck.
It's strings from EA's NHL .big archive and I can't add some new files in the archive if the crc is wrong. There are also same named files in Fifa bh-files with same crc.

Here is some examples:
attribdb/renddb.bin should be 0x3C12BC16
attribdb/renddb.opt should be 0x3C12F450
rendering/effects/powerring_0_0.rx2 should be 0xE91BE626
  • Author
  • Localization

aluigi, posted Fri Nov 09, 2018 11:15 am (40213)


There is a detailed explanation here:
viewtopic.php?p=40031#p40031

Regarding your examples there is no matching result for the provided strings, maybe they are calculated on all toupper strings or with / converted to \ or probably it's just a custom crc algorithm.
  • Author
  • Localization

beedy, posted Fri Nov 09, 2018 12:05 pm (40219)


I have tried do this for strings but did not match. I have tried to find info about crc in .xex-file but all I found is something about EASTL hash, but it don't know anything about it. Yes It's probably a EA's custom crc or something and maybe It will too hard to try to reverse-engineer it?
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.