我正在尋找一種方法來逆轉a CRC32 checksum。有解決方案,但它們是badly written,extremely technical和/或in Assembly。大會(當前)超出了我的看法,所以我希望有人能夠用更高級的語言拼湊出一個實現。 Ruby是理想的,但我可以解析PHP,Python,C,Java等。逆向CRC32
任何接受者?
我正在尋找一種方法來逆轉a CRC32 checksum。有解決方案,但它們是badly written,extremely technical和/或in Assembly。大會(當前)超出了我的看法,所以我希望有人能夠用更高級的語言拼湊出一個實現。 Ruby是理想的,但我可以解析PHP,Python,C,Java等。逆向CRC32
任何接受者?
如果原始字符串爲4個字節或更少,則CRC32是唯一可逆的。
Cade Roux對翻轉CRC32是正確的。
您提到的鏈接提供了一個解決方案,通過更改原始字節流來修復已變爲無效的CRC。此修復通過更改一些(不重要的)字節並重新創建原始CRC值來實現。
或者黑客入侵這個數據流,以便在重要數據(如反盜版代碼)發生變化時,CRC不會發生變化。 – 2009-10-03 16:14:55
這是C#:
public class Crc32
{
public const uint poly = 0xedb88320;
public const uint startxor = 0xffffffff;
static uint[] table = null;
static uint[] revtable = null;
public void FixChecksum(byte[] bytes, int length, int fixpos, uint wantcrc)
{
if (fixpos + 4 > length) return;
uint crc = startxor;
for (int i = 0; i < fixpos; i++) {
crc = (crc >> 8)^table[(crc^bytes[i]) & 0xff];
}
Array.Copy(BitConverter.GetBytes(crc), 0, bytes, fixpos, 4);
crc = wantcrc^startxor;
for (int i = length - 1; i >= fixpos; i--) {
crc = (crc << 8)^revtable[crc >> (3 * 8)]^bytes[i];
}
Array.Copy(BitConverter.GetBytes(crc), 0, bytes, fixpos, 4);
}
public Crc32()
{
if (Crc32.table == null) {
uint[] table = new uint[256];
uint[] revtable = new uint[256];
uint fwd, rev;
for (int i = 0; i < table.Length; i++) {
fwd = (uint)i;
rev = (uint)(i) << (3 * 8);
for (int j = 8; j > 0; j--) {
if ((fwd & 1) == 1) {
fwd = (uint)((fwd >> 1)^poly);
} else {
fwd >>= 1;
}
if ((rev & 0x80000000) != 0) {
rev = ((rev^poly) << 1) | 1;
} else {
rev <<= 1;
}
}
table[i] = fwd;
revtable[i] = rev;
}
Crc32.table = table;
Crc32.revtable = revtable;
}
}
}
您可以通過備份出位,如果你知道它是與創建聚生成原始32位扭轉它。但是,如果你正在尋找從給定的文件反轉CRC32,並追加一系列的字節在文件的末尾來匹配原來的CRC我張貼代碼在這個線程在PHP:
我花了一點時間所以我希望它能幫助有人在更棘手的問題上工作: Reversing CRC32 乾杯!
你究竟是什麼意思'反向' – 2009-10-03 15:53:11
只是將一個C實現移植到Python上:https://github.com/jellever/Pwnage/blob/master/reversecrc.py – 2016-05-02 22:30:07
@JelleVergeer你能指出需要的表嗎爲您的代碼工作。我可以在這裏添加什麼: #Custom CRC表,用你自己的替換 table = [] – 2017-02-26 03:37:50