Files
Aaru/Aaru.Images/RsIde/Helpers.cs

68 lines
2.3 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Helpers.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Contains helpers for RS-IDE disk images.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
using System;
using System.Text;
namespace Aaru.Images;
2022-03-06 13:29:38 +00:00
public sealed partial class RsIde
{
2022-03-06 13:29:38 +00:00
static byte[] ScrambleAtaString(string text, int length)
{
2022-03-06 13:29:38 +00:00
byte[] inbuf = Encoding.ASCII.GetBytes(text);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(inbuf.Length % 2 != 0)
{
2023-10-03 23:34:59 +01:00
var tmpbuf = new byte[inbuf.Length + 1];
2022-03-06 13:29:38 +00:00
Array.Copy(inbuf, 0, tmpbuf, 0, inbuf.Length);
tmpbuf[^1] = 0x20;
inbuf = tmpbuf;
}
2023-10-03 23:34:59 +01:00
var outbuf = new byte[inbuf.Length];
2023-10-03 23:34:59 +01:00
for(var i = 0; i < length; i += 2)
2022-03-06 13:29:38 +00:00
{
outbuf[i] = inbuf[i + 1];
outbuf[i + 1] = inbuf[i];
}
2023-10-03 23:34:59 +01:00
var retBuf = new byte[length];
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
for(var i = 0; i < length; i++) retBuf[i] = 0x20;
2022-03-06 13:29:38 +00:00
Array.Copy(outbuf, 0, retBuf, 0, outbuf.Length >= length ? length : outbuf.Length);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return retBuf;
}
}