public unsafe uint CustomExtractBits(AU3_Resource res) { uint ret = 0; var r = ExtractBits(res, 2); if (r == 3) { ret = 3; r = ExtractBits(res, 3); if (r == 7) { ret = 10; r = ExtractBits(res, 5); if (r == 0x1f) { ret = 0x29; while ((r = ExtractBits(res, 8)) == 0xff) { ret += 0xff; } } } } return(ret + r + 3); }
public unsafe uint ExtractBits(AU3_Resource res, int nBits) { res.ans &= 0xffff; while (nBits-- > 0) { if (res.count == 0) { uint temp = NextByte(res); res.ans |= temp << 8 | NextByte(res); res.count = 0x10; } res.ans <<= 1; res.count--; } return(res.ans >> 0x10); }
public override void Decompress(AU3_Resource res) { res.State = "Extracted"; res.DoUpdate(); res.count = 0; //form.SetText("Decompressing...", form.lblStatus); if (res.CompressedSize == res.DecompressedSize) { //form.SetText("Not Compressed.", form.lblStatus); //res.evtDecompressed.Set(); return; } res.pMem = new byte[res.DecompressedSize]; res.spos = 0; res.pos = 8; // "EA06/EA05/JB??", p32(size) if (!Utils.AU3_SIGN.Contains(BitConverter.ToUInt32(res.RawData, 0))) { res.Status = Utils.STATUS.InvalidCompressedHeader; res.State = "Invalid Compressed File Format!"; res.DoUpdate(); //res.evtDecompressed.Set(); return; // invalid signature } if (BitConverter.ToUInt32(res.RawData, 0) == 0x3130424a) { try { res.JB01_Decompress(this); } catch (Exception) { res.count = 0; res.pos = 8; res.DecompressorInitLegacy(); while (res.spos < res.DecompressedSize) { res.r = res.sub_417518(this); if (res.r < 0x100) { res.pMem[res.spos++] = (byte)res.r; } else { res.v = res.sub_417665(res.r, this) + 3; res.delta = res.spos - res.sub_4176a5(this); while (res.spos < res.pMem.Length && res.v-- > 0) { res.pMem[res.spos++] = res.pMem[res.delta++]; } } } } } else { res.count = 0; res.pos = 8; res.DecompressorInitLegacy(); while (res.spos < res.DecompressedSize) { res.r = res.sub_417518(this); if (res.r < 0x100) { res.pMem[res.spos++] = (byte)res.r; } else { res.v = res.sub_417665(res.r, this) + 3; res.delta = res.spos - res.sub_4176a5(this); while (res.spos < res.pMem.Length && res.v-- > 0) { res.pMem[res.spos++] = res.pMem[res.delta++]; } } } } res.RawDataSize = res.DecompressedSize; res.RawData = res.pMem; if (this.IsUnicode) { res.SourceCode = Encoding.Unicode.GetString(res.pMem); } else { res.SourceCode = Encoding.ASCII.GetString(res.pMem); } res.Status = Utils.STATUS.OK; res.State = "Decompressed"; res.Type = Utils.TYPE.Text; res.SourceState = Utils.SOURCE_STATE.Decompressed; //form.SetText("Decompressed.", form.lblStatus); //res.evtDecompressed.Set(); //form.UpdateStatus(null, null); if (!res.Tag.Contains("SCRIPT")) { res.MarkComplete(); } else { res.DoUpdate(); } }
internal byte NextByte(AU3_Resource res) { return(res.RawData[res.pos++]); }
public abstract void Decompress(AU3_Resource res);
public override void Decompress(AU3_Resource res) { res.State = "Extracted"; res.count = 0; res.DoUpdate(); //form.SetText("Decompressing...", form.lblStatus); if (res.CompressedSize == res.DecompressedSize) { //form.SetText("Not Compressed.", form.lblStatus); //res.evtNotify.Set(); if (!res.Tag.Contains("SCRIPT<")) { res.MarkComplete(); } else { res.DoUpdate(); } return; } var mem = new byte[res.DecompressedSize]; int i = 0; res.pos = 8; // "EA06", p32(size) if (!Utils.AU3_SIGN.Contains(BitConverter.ToUInt32(res.RawData, 0))) { res.Status = Utils.STATUS.InvalidCompressedHeader; res.State = "Invalid Compressed File Format!"; //res.evtNotify.Set(); return; // invalid signature } while (i < res.DecompressedSize) { var r = ExtractBits(res, 1); if (r == 1) { mem[i++] = (byte)ExtractBits(res, 8); } else { var v = ExtractBits(res, 0xf); r = CustomExtractBits(res); var delta = i - v; while (r-- > 0) { mem[i++] = mem[delta++]; } } } res.RawDataSize = res.DecompressedSize; res.RawData = mem; res.Status = Utils.STATUS.OK; res.State = "Decompressed"; res.Type = Utils.TYPE.Binary; res.SourceState = Utils.SOURCE_STATE.Decompressed; //form.SetText("Decompressed.", form.lblStatus); //res.evtNotify.Set(); //form.UpdateStatus(null, null); if (!res.Tag.Contains("SCRIPT<")) { res.MarkComplete(); } else { res.DoUpdate(); } }
private List <AU3_Resource> Unpack(byte[] script, bool bLegacy, string subtype, out string status) { int pos = 0x28; var ans = new List <AU3_Resource>(); keys = KeyFactory.GetKeys(subtype); if (keys == null) { status = "Unsupported AutoIt Type - " + subtype; return(ans); } byte[] password = null; bool oldAutoIt = false; if (bLegacy) { var passLen = BitConverter.ToInt32(script, 0x11) ^ 0xfac1; password = new byte[passLen]; Array.Copy(script, 0x15, password, 0, passLen); keys.ShittyEncoder(password, 0xc3d2, true, oldAutoIt); //password = keys.DecodeString(script, 0x15, passLen, (0xc3d2 + passLen) - passLen, true, oldAutoIt); if (!password.All(e => Utils.PRINTABLE.Contains((char)e))) { oldAutoIt = true; //password = keys.DecodeString(script, 0x15, passLen, (0xc3d2 + passLen) - passLen, true, oldAutoIt); Array.Copy(script, 0x15, password, 0, passLen); keys.ShittyEncoder(password, 0xc3d2, true, oldAutoIt); } pos = 0x15 + passLen; } while (pos < script.Length) { pos += 4; // "FILE" AU3_Resource res = new AU3_Resource(); res.Update += (sender, evArgs) => { var r = sender as AU3_Resource; SetAttr("ForeColor", System.Drawing.Color.Green, lblStatus); SetAttr("Text", r.State, lblStatus); }; res.IsUnicode = keys.IsUnicode; if (pos >= script.Length) { break; } int temp = BitConverter.ToInt32(script, pos); temp ^= keys.TagSize; pos += 4; int len = temp; if (keys.IsUnicode) { len += temp; } if (len >= script.Length) { status = "Invalid Tag Length"; return(ans); } res.Tag = keys.DecodeString(script, pos, len, keys.Tag, true, oldAutoIt); pos += len; if (pos >= script.Length) { break; } temp = BitConverter.ToInt32(script, pos); temp ^= keys.PathSize; pos += 4; len = temp; if (keys.IsUnicode) { len += temp; } if (len >= script.Length) { status = "Invalid Path Length"; return(ans); } res.Path = keys.DecodeString(script, pos, len, keys.Path, true, oldAutoIt); pos += len; if (pos >= script.Length) { break; } res.IsCompressed = BitConverter.ToBoolean(script, pos); pos++; if (pos >= script.Length) { break; } temp = BitConverter.ToInt32(script, pos); temp ^= keys.CompressedSize; pos += 4; res.CompressedSize = (uint)temp; if (res.CompressedSize >= script.Length) { status = "Invalid Size of Compressed Resource"; return(ans); } if (pos >= script.Length) { break; } temp = BitConverter.ToInt32(script, pos); temp ^= keys.DecompressedSize; pos += 4; res.DecompressedSize = (uint)temp; if (!bLegacy) { temp = BitConverter.ToInt32(script, pos); temp ^= keys.Checksum; pos += 4; res.CheckSum = temp; } if (!oldAutoIt) { ulong time = BitConverter.ToUInt32(script, pos); pos += 4; time <<= 32; time |= BitConverter.ToUInt32(script, pos); pos += 4; res.CreationTime = time; time = BitConverter.ToUInt32(script, pos); pos += 4; time <<= 32; time |= BitConverter.ToUInt32(script, pos); pos += 4; res.LastWriteTime = time; } if (res.CompressedSize > 0) { // get data var buf = new byte[res.CompressedSize]; Array.Copy(script, pos, buf, 0, buf.Length); var l = keys.Data; if (bLegacy) { l -= 0x849; foreach (var x in password) { l += (int)(sbyte)x; } } keys.ShittyEncoder(buf, l, false, oldAutoIt); res.RawData = buf; res.RawDataSize = res.CompressedSize; pos += (int)res.CompressedSize; } res.OnComplete += (o, args) => { SetAttr("Text", ((AU3_Resource)o).Dump(), txtResData); SetAttr("Text", ((AU3_Resource)o).State, lblStatus); }; res.SourceState = Utils.SOURCE_STATE.Extracted; ans.Add(res); } status = "OK"; return(ans); }
private void LstResources_SelectedValueChanged(object sender, EventArgs e) { if (lstResources.SelectedItem == null) { return; } var item = (string)lstResources.SelectedItem; AU3_Resource entry = null; if (table.ContainsKey(item)) { entry = table[item]; } if (entry == null) { txtResCSize.Text = ""; txtResDSize.Text = ""; txtResTag.Text = ""; txtResPath.Text = ""; txtResCTime.Text = ""; txtResMTime.Text = ""; txtResData.Text = ""; return; } btnDump.Enabled = entry.CompressedSize > 0; txtResCSize.Text = entry.CompressedSize.ToString() + " bytes"; txtResDSize.Text = entry.DecompressedSize.ToString() + " bytes"; txtResTag.Text = entry.Tag; txtResPath.Text = entry.Path; txtResCTime.Text = DateTime.FromFileTime((long)entry.CreationTime).ToString("ddd, MMM dd yyyy, hh:mm:ss tt"); txtResMTime.Text = DateTime.FromFileTime((long)entry.LastWriteTime).ToString("ddd, MMM dd yyyy, hh:mm:ss tt"); if (entry.CompressedSize > 0 && !entry.IsComplete) { txtResData.Text = "Loading ..."; } /*if (! entry.IsCompressed) * { * entry.SourceCode = Encoding.ASCII.GetString(entry.RawData); * }*/ if (entry.SourceState == Utils.SOURCE_STATE.Extracted) { new Thread(() => { entry.count = 0; keys.Decompress(entry); if (entry.Tag.Contains("SCRIPT")) { entry.Tidy(); } }).Start(); } if (entry.IsComplete) { SetAttr("Text", entry.Dump(), txtResData); } /*if (entry.IsCompressed) * { * new Thread(() => keys.Decompress(this, entry)).Start(); * } * else * { * entry.SourceCode = Encoding.ASCII.GetString(entry.RawData); * } * if (entry.Tag.Contains("SCRIPT<")) * { * new Thread(() => entry.Tidy(this)).Start(); * }*/ if (entry.State.Contains("Invalid")) { lblStatus.ForeColor = System.Drawing.Color.Red; } else { lblStatus.ForeColor = System.Drawing.Color.Green; } lblStatus.Text = entry.State; }