Here are the examples of the csharp api System.BitConverter.GetBytes(double) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1061 Examples
19
View Source File : UiHelper.Textures.cs
License : GNU Affero General Public License v3.0
Project Creator : 0ceal0t
License : GNU Affero General Public License v3.0
Project Creator : 0ceal0t
private unsafe static string GetResolvedPath(string texPath) {
var pathBytes = Encoding.ASCII.GetBytes(texPath);
var bPath = stackalloc byte[pathBytes.Length + 1];
Marshal.Copy(pathBytes, 0, new IntPtr(bPath), pathBytes.Length);
var pPath = (char*)bPath;
var typeBytes = Encoding.ASCII.GetBytes("xet");
var bType = stackalloc byte[typeBytes.Length + 1];
Marshal.Copy(typeBytes, 0, new IntPtr(bType), typeBytes.Length);
var pResourceType = (char*)bType;
// TODO: might need to change this based on path
var categoryBytes = BitConverter.GetBytes((uint)6);
var bCategory = stackalloc byte[categoryBytes.Length + 1];
Marshal.Copy(categoryBytes, 0, new IntPtr(bCategory), categoryBytes.Length);
var pCategoryId = (uint*)bCategory;
Crc32.Init();
Crc32.Update(pathBytes);
var hashBytes = BitConverter.GetBytes(Crc32.Checksum);
var bHash = stackalloc byte[hashBytes.Length + 1];
Marshal.Copy(hashBytes, 0, new IntPtr(bHash), hashBytes.Length);
var pResourceHash = (uint*)bHash;
var resource = (TextureResourceHandle*) GetResourceSync(GetFileManager(), pCategoryId, pResourceType, pResourceHash, pPath, (void*)IntPtr.Zero);
var resolvedPath = resource->ResourceHandle.FileName.ToString();
resource->ResourceHandle.DecRef(); // not actually using this
PluginLog.Log($"RefCount {texPath} {resource->ResourceHandle.RefCount}");
return resolvedPath;
}
19
View Source File : Form1.cs
License : Apache License 2.0
Project Creator : 1694439208
License : Apache License 2.0
Project Creator : 1694439208
private void button5_Click(object sender, EventArgs e)
{
byte[] jmp_inst =
{
233,0,0,0,0,//JMP Address
};
int Method = NativeAPI.GetMethodPTR(typeof(WeChetHook), "Callback");
textBox3.Text = (3212659 + int.Parse(label1.Text)).ToString();
List<byte> byteSource = new List<byte>();
byteSource.AddRange(new byte[] { 199, 134, 236, 2, 0, 0 });//mov dword [esi+0x000002EC],
byteSource.AddRange(BitConverter.GetBytes(int.Parse(textBox3.Text) + 5));//0x00000000 把hook的后五个字节地址压进寄存器
byteSource.AddRange(jmp_inst);//让他跳到跳板函数
//这部分根据实际情况填写
byteSource.Add(185);//补充替换的汇编指令
byteSource.AddRange(BitConverter.GetBytes(int.Parse(label1.Text) + 19255272));//补充替换的汇编指令地址
//开始hook
Inline_Hook.InlineHook(int.Parse(textBox3.Text),5, byteSource.ToArray(), getInt(Method),11+10,"接收消息",(obj) =>{
StringBuilder sb = new StringBuilder();
sb.Append("接收消息:");
int a = 0x68;
//System.Windows.Forms.MessageBox.Show("esp:"+a.ToString());
try
{
if (obj.ESP == 0)
return;
int MsgPtr = NativeAPI.ReadMemoryValue(obj.ESP);
if (MsgPtr == 0)
return;
MsgPtr = NativeAPI.ReadMemoryValue(MsgPtr);
if (MsgPtr == 0)
return;
MsgPtr = NativeAPI.ReadMemoryValue(MsgPtr + 0x68);
if (MsgPtr == 0)
return;
int len = NativeAPI.lstrlenW(MsgPtr);
if (len == 0)
return;
sb.Append(NativeAPI.ReadMemoryStrValue(MsgPtr, len*2+2));
sb.Append("\r\n");
listBox1.Items.Add(sb.ToString());
}
catch (Exception es)
{
File.AppendAllText("error.txt", es.Message);
}
});
}
19
View Source File : NetworkUtils.cs
License : MIT License
Project Creator : 1ZouLTReX1
License : MIT License
Project Creator : 1ZouLTReX1
public static void SerializeVector2(List<byte> byteList, Vector2 data)
{
byteList.AddRange(BitConverter.GetBytes(data.x));
byteList.AddRange(BitConverter.GetBytes(data.y));
}
19
View Source File : NetworkUtils.cs
License : MIT License
Project Creator : 1ZouLTReX1
License : MIT License
Project Creator : 1ZouLTReX1
public static void SerializeVector3(List<byte> byteList, Vector3 data)
{
byteList.AddRange(BitConverter.GetBytes(data.x));
byteList.AddRange(BitConverter.GetBytes(data.y));
byteList.AddRange(BitConverter.GetBytes(data.z));
}
19
View Source File : MD5.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
internal static byte[] GetHashFinalBlock(byte[] input, int ibStart, int cbSize, ABCDStruct ABCD, long len)
{
byte[] destinationArray = new byte[0x40];
byte[] bytes = BitConverter.GetBytes(len);
Array.Copy(input, ibStart, destinationArray, 0, cbSize);
destinationArray[cbSize] = 0x80;
if (cbSize <= 0x38)
{
Array.Copy(bytes, 0, destinationArray, 0x38, 8);
GetHashBlock(destinationArray, ref ABCD, 0);
}
else
{
GetHashBlock(destinationArray, ref ABCD, 0);
destinationArray = new byte[0x40];
Array.Copy(bytes, 0, destinationArray, 0x38, 8);
GetHashBlock(destinationArray, ref ABCD, 0);
}
byte[] buffer3 = new byte[0x10];
Array.Copy(BitConverter.GetBytes(ABCD.A), 0, buffer3, 0, 4);
Array.Copy(BitConverter.GetBytes(ABCD.B), 0, buffer3, 4, 4);
Array.Copy(BitConverter.GetBytes(ABCD.C), 0, buffer3, 8, 4);
Array.Copy(BitConverter.GetBytes(ABCD.D), 0, buffer3, 12, 4);
return buffer3;
}
19
View Source File : TestAmf3Reader.cs
License : MIT License
Project Creator : a1q123456
License : MIT License
Project Creator : a1q123456
public bool TryEncodeData(ByteBuffer buffer)
{
var b1 = BitConverter.GetBytes(v1);
var b2 = BitConverter.GetBytes(v2);
buffer.WriteToBuffer(b1);
buffer.WriteToBuffer(b2);
return true;
}
19
View Source File : MessageBuilder.cs
License : MIT License
Project Creator : Abaudat
License : MIT License
Project Creator : Abaudat
static byte[] Vector3ToByteArray(Vector3 vector)
{
byte[] bytes = new byte[sizeof(float) * 3];
Buffer.BlockCopy(BitConverter.GetBytes(vector.x), 0, bytes, 0 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(vector.y), 0, bytes, 1 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(vector.z), 0, bytes, 2 * sizeof(float), sizeof(float));
return bytes;
}
19
View Source File : CommandInterpreter.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public void HandleKeyboardCommand(CmdStruct cmdStruct, MotionCommand command)
{
// vfptr[12] - IsActive
if (!IsActive()) return;
bool start;
if (cmdStruct.Command == MotionCommand.AutoRun)
{
start = Convert.ToBoolean(cmdStruct.Args[cmdStruct.Curr]);
cmdStruct.Curr++;
if (cmdStruct.Curr >= cmdStruct.Size)
{
AutoRunSpeed = 1.0f;
}
else
{
AutoRunSpeed = BitConverter.ToSingle(BitConverter.GetBytes(cmdStruct.Args[cmdStruct.Curr]));
cmdStruct.Curr++;
}
// vfptr[16].OnLoseFocus - ToggleAutoRun
ToggleAutoRun();
// vfptr[6].OnAction - SendMovementEvent
SendMovementEvent();
return;
}
if (((uint)cmdStruct.Command & (uint)CommandMask.UI) != 0)
return;
start = Convert.ToBoolean(cmdStruct.Args[cmdStruct.Curr]);
cmdStruct.Curr++;
var speed = 1.0f;
if (cmdStruct.Curr < cmdStruct.Size)
{
speed = BitConverter.ToSingle(BitConverter.GetBytes(cmdStruct.Args[cmdStruct.Curr]));
cmdStruct.Curr++;
}
if (ControlledByServer && !start)
{
// vfptr[1].OnLoseFocus - MovePlayer?
MovePlayer((MotionCommand)cmdStruct.Command, start, speed, false, false);
return;
}
// vfptr[8].OnLoseFocus(a2) - ACCmdInterp::TakeControlFromServer?
TakeControlFromServer();
if (cmdStruct.Command == MotionCommand.HoldRun)
{
// vfptr[2].OnLoseFocus
if (!IsStandingStill())
SendMovementEvent();
return;
}
if (cmdStruct.Command == MotionCommand.HoldSidestep)
{
// vfptr[3]
if (!IsStandingStill())
SendMovementEvent();
return;
}
// vfptr[2] - Bookkeep
if (!BookkeepCommandAndModifyIfNecessary(cmdStruct.Command, start, speed, false, false))
{
SendMovementEvent();
return;
}
// vfptr[4].OnAction - ApplyHoldKeysToCommand
ApplyHoldKeysToCommand(ref cmdStruct.Command, speed);
// vfptr[13].OnAction - MovePlayer
MovePlayer(cmdStruct.Command, start, speed, false, false);
// vfptr[6].OnAction - SendMovementEvent
if (cmdStruct.Command != MotionCommand.Jump)
SendMovementEvent();
}
19
View Source File : Program.cs
License : MIT License
Project Creator : adospace
License : MIT License
Project Creator : adospace
private static async Task<bool> SendreplacedemblyToEmulatorAsync(string replacedemblyPath, bool debugging = true)
{
//ThreadHelper.ThrowIfNotOnUIThread();
//outputPane.OutputString($"Sending to emulator new replacedembly (debugging={debugging})...");
//outputPane.Activate(); // Brings this pane into view
var client = new TcpClient
{
ReceiveTimeout = 15000,
SendTimeout = 15000
};
try
{
await client.ConnectAsync(IPAddress.Loopback, 45820);
var replacedemblyRaw = await FileUtil.ReadAllFileAsync(replacedemblyPath);
var networkStream = client.GetStream();
var lengthBytes = BitConverter.GetBytes(replacedemblyRaw.Length);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.WriteAsync(replacedemblyRaw, 0, replacedemblyRaw.Length);
await networkStream.FlushAsync();
var replacedemblySymbolStorePath = Path.Combine(Path.GetDirectoryName(replacedemblyPath), Path.GetFileNameWithoutExtension(replacedemblyPath) + ".pdb");
if (File.Exists(replacedemblySymbolStorePath) && debugging)
{
var replacedemblySynmbolStoreRaw = await FileUtil.ReadAllFileAsync(replacedemblySymbolStorePath);
lengthBytes = BitConverter.GetBytes(replacedemblySynmbolStoreRaw.Length);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.WriteAsync(replacedemblySynmbolStoreRaw, 0, replacedemblySynmbolStoreRaw.Length);
await networkStream.FlushAsync();
}
else
{
lengthBytes = BitConverter.GetBytes(0);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.FlushAsync();
}
var booleanBuffer = new byte[1];
if (await networkStream.ReadAsync(booleanBuffer, 0, 1) == 0)
throw new SocketException();
Console.WriteLine($"Sent new replacedembly ({replacedemblyRaw.Length} bytes) to emulator{Environment.NewLine}");
}
catch (Exception ex)
{
Console.WriteLine([email protected]"
Unable to connect to ReactorUI Hot Reload module
Please ensure that:
1) Only one device is running among emulators and physical devices
2) Application is running either in debug or release mode
3) RxApplication call WithHotReload()
Socket exception: {ex.Message}
");
return false;
}
finally
{
client.Close();
}
return true;
}
19
View Source File : Serializer.cs
License : MIT License
Project Creator : ADeltaX
License : MIT License
Project Creator : ADeltaX
public static byte[] FromDouble(double data, DateTimeOffset? timestamp = null)
=> BitConverter.GetBytes(data).AppendTimestamp(timestamp);
19
View Source File : HotReloadCommand.cs
License : MIT License
Project Creator : adospace
License : MIT License
Project Creator : adospace
private static async Task<bool> SendreplacedemblyToEmulatorAsync(ProgressMonitor progressMonitor, string replacedemblyPath, bool debugging)
{
var client = new TcpClient
{
ReceiveTimeout = 15000,
SendTimeout = 15000
};
try
{
await client.ConnectAsync(IPAddress.Loopback, 45820);
var replacedemblyRaw = await FileUtil.ReadAllFileAsync(replacedemblyPath);
var networkStream = client.GetStream();
var lengthBytes = BitConverter.GetBytes(replacedemblyRaw.Length);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.WriteAsync(replacedemblyRaw, 0, replacedemblyRaw.Length);
await networkStream.FlushAsync();
var replacedemblySymbolStorePath = Path.Combine(Path.GetDirectoryName(replacedemblyPath), Path.GetFileNameWithoutExtension(replacedemblyPath) + ".pdb");
if (File.Exists(replacedemblySymbolStorePath) && debugging)
{
var replacedemblySynmbolStoreRaw = await FileUtil.ReadAllFileAsync(replacedemblySymbolStorePath);
lengthBytes = BitConverter.GetBytes(replacedemblySynmbolStoreRaw.Length);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.WriteAsync(replacedemblySynmbolStoreRaw, 0, replacedemblySynmbolStoreRaw.Length);
await networkStream.FlushAsync();
}
else
{
lengthBytes = BitConverter.GetBytes(0);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.FlushAsync();
}
var booleanBuffer = new byte[1];
if (await networkStream.ReadAsync(booleanBuffer, 0, 1) == 0)
throw new SocketException();
await progressMonitor.Log.WriteLineAsync($"Sent new replacedembly ({replacedemblyRaw.Length} bytes) to emulator");
}
catch (Exception ex)
{
await progressMonitor.ErrorLog.WriteLineAsync([email protected]"
Unable to connect to ReactorUI Hot Reload module
Please ensure that:
1) Only one device is running among emulators and physical devices
2) Application is running either in debug or release mode
3) RxApplication call WithHotReload()
Socket exception: {ex.Message}");
return false;
}
finally
{
client.Close();
}
return true;
}
19
View Source File : ReloadCommand.cs
License : MIT License
Project Creator : adospace
License : MIT License
Project Creator : adospace
private static async Task<bool> SendreplacedemblyToEmulatorAsync(string replacedemblyPath, IVsOutputWindowPane outputPane, bool debugging)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
//ThreadHelper.ThrowIfNotOnUIThread();
//outputPane.OutputString($"Sending to emulator new replacedembly (debugging={debugging})...");
//outputPane.Activate(); // Brings this pane into view
var client = new TcpClient
{
ReceiveTimeout = 15000,
SendTimeout = 15000
};
try
{
await client.ConnectAsync(IPAddress.Loopback, 45820);
var replacedemblyRaw = await FileUtil.ReadAllFileAsync(replacedemblyPath);
var networkStream = client.GetStream();
var lengthBytes = BitConverter.GetBytes(replacedemblyRaw.Length);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.WriteAsync(replacedemblyRaw, 0, replacedemblyRaw.Length);
await networkStream.FlushAsync();
var replacedemblySymbolStorePath = Path.Combine(Path.GetDirectoryName(replacedemblyPath), Path.GetFileNameWithoutExtension(replacedemblyPath) + ".pdb");
if (File.Exists(replacedemblySymbolStorePath) && debugging)
{
var replacedemblySynmbolStoreRaw = await FileUtil.ReadAllFileAsync(replacedemblySymbolStorePath);
lengthBytes = BitConverter.GetBytes(replacedemblySynmbolStoreRaw.Length);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.WriteAsync(replacedemblySynmbolStoreRaw, 0, replacedemblySynmbolStoreRaw.Length);
await networkStream.FlushAsync();
}
else
{
lengthBytes = BitConverter.GetBytes(0);
await networkStream.WriteAsync(lengthBytes, 0, lengthBytes.Length);
await networkStream.FlushAsync();
}
var booleanBuffer = new byte[1];
if (await networkStream.ReadAsync(booleanBuffer, 0, 1) == 0)
throw new SocketException();
outputPane.OutputStringThreadSafe($"Sent new replacedembly ({replacedemblyRaw.Length} bytes) to emulator{Environment.NewLine}");
}
catch (Exception ex)
{
outputPane.OutputStringThreadSafe([email protected]"
Unable to connect to ReactorUI Hot Reload module
Please ensure that:
1) Only one device is running among emulators and physical devices
2) Application is running either in debug or release mode
3) RxApplication call WithHotReload()
Socket exception: {ex.Message}
");
return false;
}
finally
{
client.Close();
}
return true;
}
19
View Source File : FsBufferedReaderWriter.cs
License : MIT License
Project Creator : Adoxio
License : MIT License
Project Creator : Adoxio
protected void WriteLength(long value)
{
var raw = BitConverter.GetBytes(this.fileSize);
this.fileStream.Seek(this.lengthOffset, SeekOrigin.Begin);
this.fileStream.Write(raw, 0, raw.Length);
this.commitedFileSize = this.fileSize;
}
19
View Source File : BytesWriter.cs
License : MIT License
Project Creator : adrenak
License : MIT License
Project Creator : adrenak
public BytesWriter WriteDouble(double value) {
var bytes = BitConverter.GetBytes(value);
EndianUtility.EndianCorrection(bytes);
WriteBytes(bytes);
return this;
}
19
View Source File : BytesWriter.cs
License : MIT License
Project Creator : adrenak
License : MIT License
Project Creator : adrenak
public BytesWriter WriteVector3(Vector3 value) {
var xbytes = BitConverter.GetBytes(value.x);
var ybytes = BitConverter.GetBytes(value.y);
var zbytes = BitConverter.GetBytes(value.z);
EndianUtility.EndianCorrection(xbytes);
EndianUtility.EndianCorrection(ybytes);
EndianUtility.EndianCorrection(zbytes);
WriteBytes(xbytes);
WriteBytes(ybytes);
WriteBytes(zbytes);
return this;
}
19
View Source File : BytesWriter.cs
License : MIT License
Project Creator : adrenak
License : MIT License
Project Creator : adrenak
public BytesWriter WriteVector2(Vector2 value) {
var xbytes = BitConverter.GetBytes(value.x);
var ybytes = BitConverter.GetBytes(value.y);
EndianUtility.EndianCorrection(xbytes);
EndianUtility.EndianCorrection(ybytes);
WriteBytes(xbytes);
WriteBytes(ybytes);
return this;
}
19
View Source File : BytesWriter.cs
License : MIT License
Project Creator : adrenak
License : MIT License
Project Creator : adrenak
public BytesWriter WriteRect(Rect rect) {
var xbytes = BitConverter.GetBytes(rect.x);
var ybytes = BitConverter.GetBytes(rect.y);
var wbytes = BitConverter.GetBytes(rect.width);
var hbytes = BitConverter.GetBytes(rect.height);
EndianUtility.EndianCorrection(xbytes);
EndianUtility.EndianCorrection(ybytes);
EndianUtility.EndianCorrection(wbytes);
EndianUtility.EndianCorrection(hbytes);
WriteBytes(xbytes);
WriteBytes(ybytes);
WriteBytes(wbytes);
WriteBytes(hbytes);
return this;
}
19
View Source File : Extensions.cs
License : MIT License
Project Creator : adrenak
License : MIT License
Project Creator : adrenak
public static byte[] GetBytes(this double value) {
return BitConverter.GetBytes(value);
}
19
View Source File : FrameCountStreamingDemo.cs
License : MIT License
Project Creator : adrenak
License : MIT License
Project Creator : adrenak
void Update() {
if (node != null) {
if (node.CurrentMode == APNode.Mode.Server) {
node.SendPacket(node.Peers, new Packet()
.WithPayload(System.BitConverter.GetBytes(Time.frameCount)));
msg2.text = "Sending " + Time.frameCount.ToString();
}
}
}
19
View Source File : Form1.cs
License : GNU General Public License v3.0
Project Creator : Aemony
License : GNU General Public License v3.0
Project Creator : Aemony
private void buttonSave_Click(object sender, EventArgs e)
{
DialogResult dialogResult;
if (_byteInventoryImportedActive != null || _byteInventoryImportedCorpse != null)
{
dialogResult = MessageBox.Show("You currently have an imported inventory list active that have overwritten the original inventory list of the opened slot file. Saving will make the change permanent.\n\nAre you sure you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
} else {
dialogResult = MessageBox.Show("Are you sure you want to save your changes to the slot file?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
}
if(dialogResult == DialogResult.Yes)
{
byte[] byteInventoryChanged = new byte[_intBlockLength];
for (int i = 0; i < 256; i++)
{
BitConverter.GetBytes(_itemInventoryActive[i].ID).CopyTo(byteInventoryChanged, i * 12);
BitConverter.GetBytes(_itemInventoryActive[i].Status).CopyTo(byteInventoryChanged, i * 12 + 4);
BitConverter.GetBytes(_itemInventoryActive[i].Amount).CopyTo(byteInventoryChanged, i * 12 + 8);
}
for (int i = 256; i < 512; i++)
{
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].ID).CopyTo(byteInventoryChanged, i * 12);
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].Status).CopyTo(byteInventoryChanged, i * 12 + 4);
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].Amount).CopyTo(byteInventoryChanged, i * 12 + 8);
}
#if DEBUG
Console.WriteLine("Wrote:");
Console.WriteLine(BitConverter.ToString(byteInventoryChanged));
#endif
// Create a backup first
File.Copy(_filePath, _filePath + DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss.bak"));
// Now overwrite the data
using (Stream stream = File.Open(_filePath, FileMode.Open, FileAccess.Write))
{
stream.Position = _intBlockOffset;
stream.Write(byteInventoryChanged, 0, _intBlockLength);
}
// Finally update the background stuff to reflect the new file
_byteInventory = byteInventoryChanged;
_byteInventoryImportedActive = null;
_byteInventoryImportedCorpse = null;
textBoxInventoryPath.Text = "No inventory list imported...";
MessageBox.Show("Changes were saved!", "Save complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
19
View Source File : Form1.cs
License : GNU General Public License v3.0
Project Creator : Aemony
License : GNU General Public License v3.0
Project Creator : Aemony
private void buttonExport_Click(object sender, EventArgs e)
{
byte[] byteInventoryExport = new byte[_intBlockLength];
for (int i = 0; i < 256; i++)
{
BitConverter.GetBytes(_itemInventoryActive[i].ID).CopyTo(byteInventoryExport, i * 12);
BitConverter.GetBytes(_itemInventoryActive[i].Status).CopyTo(byteInventoryExport, i * 12 + 4);
BitConverter.GetBytes(_itemInventoryActive[i].Amount).CopyTo(byteInventoryExport, i * 12 + 8);
}
for (int i = 256; i < 512; i++)
{
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].ID).CopyTo(byteInventoryExport, i * 12);
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].Status).CopyTo(byteInventoryExport, i * 12 + 4);
BitConverter.GetBytes(_itemInventoryCorpse[i - 256].Amount).CopyTo(byteInventoryExport, i * 12 + 8);
}
SaveFileDialog saveFileDialog = new SaveFileDialog
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDoreplacedents) + "\\My Games\\NieR_Automata",
replacedle = "Export inventory to file",
Filter = "Binary Data (*.bin)|*.bin|All Files|*",
FileName = "inventory.bin"
};
if(saveFileDialog.ShowDialog() == DialogResult.OK)
{
// Now export the data
using (Stream stream = saveFileDialog.OpenFile())
{
stream.Position = 0;
stream.Write(byteInventoryExport, 0, _intBlockLength);
}
#if DEBUG
Console.WriteLine("Wrote:");
Console.WriteLine(BitConverter.ToString(byteInventoryExport));
#endif
MessageBox.Show("Inventory was exported!", "Export complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
19
View Source File : MainForm.cs
License : GNU General Public License v3.0
Project Creator : AgentRev
License : GNU General Public License v3.0
Project Creator : AgentRev
private void TimerVerif_Tick(object sender, EventArgs e)
{
if (proc != null && mem != null && isRunning(false))
{
if (btnStartGame.Enabled) ToggleButton(false);
proc.Refresh();
if (proc.PagedMemorySize64 > 0x2000000)
{
byte step = 0;
try
{
mem.FindFoVOffset(ref pFoV, ref step);
if (!isOffsetWrong(pFoV)) progStart();
else if (proc.PagedMemorySize64 > memSearchRange)
{
TimerVerif.Stop();
TimerCheck.Stop();
//bool offsetFound = false;
//int ptrSize = IntPtr.Size * 4;
/*for (int i = -0x50000; i < 0x50000 && !offsetFound; i += 16)
{
if (mem.ReadFloat(true, pFoV + i) == 65f && !isOffsetWrong(pFoV + i))
{
pFoV += i;
offsetFound = true;
}
if (i % 50000 == 0)
{
label1.Text = i.ToString();
Update();
}
}*/
//Console.Beep(5000, 100);
//MessageBox.Show("find " + pFoV.ToString("X8"));
if (isRunning(false) && !mem.FindFoVOffset(ref pFoV, ref step))
{
string memory = BitConverter.ToString(BitConverter.GetBytes(mem.ReadFloat(pFoV)));
MessageBox.Show("The memory research pattern wasn't able to find the FoV offset in your " + c_supportMessage + ".\n" +
"Please look for an updated version of this FoV Changer tool.\n\n" +
"If you believe this might be a bug, please send me an email at [email protected], and include a screenshot of this:\n\n" + c_toolVer +
"\n0x" + Convert.ToInt32(proc.WorkingSet64).ToString("X8") +
"\n0x" + Convert.ToInt32(proc.PagedMemorySize64).ToString("X8") +
"\n0x" + Convert.ToInt32(proc.VirtualMemorySize64).ToString("X8") +
"\nStep = " + step.ToString() +
"\n0x" + (pFoV - 0xC).ToString("X8") + " = " + memory,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
pFoV = c_pFoV;
Application.Exit();
}
else
{
//Console.Beep(5000, 100);
SaveData();
proc = null;
TimerCheck.Start();
}
}
}
catch (Exception err)
{
ErrMessage(err);
Application.Exit();
}
}
}
}
19
View Source File : MainForm.cs
License : GNU General Public License v3.0
Project Creator : AgentRev
License : GNU General Public License v3.0
Project Creator : AgentRev
private void TimerVerif_Tick(object sender, EventArgs e)
{
if (proc != null && mem != null && isRunning(false))
{
if (btnStartGame.Enabled) ToggleButton(false);
proc.Refresh();
try
{
if (proc.PagedMemorySize64 > 0x2000000)
{
byte step = 0;
try
{
mem.FindFoVOffset(ref pFoV, ref step);
if (!isOffsetWrong(pFoV)) progStart();
else if (proc.PagedMemorySize64 > (dword_ptr)gameMode.GetValue("c_memSearchRange"))
{
TimerVerif.Stop();
TimerCheck.Stop();
//bool offsetFound = false;
//int ptrSize = IntPtr.Size * 4;
/*for (int i = -0x50000; i < 0x50000 && !offsetFound; i += 16)
{
if (mem.ReadFloat(true, pFoV + i) == 65f && !isOffsetWrong(pFoV + i))
{
pFoV += i;
offsetFound = true;
}
if (i % 50000 == 0)
{
label1.Text = i.ToString();
Update();
}
}*/
//Console.Beep(5000, 100);
//MessageBox.Show("find " + pFoV.ToString("X8"));
if (isRunning(false) && !mem.FindFoVOffset(ref pFoV, ref step))
{
string memory = BitConverter.ToString(BitConverter.GetBytes(mem.ReadFloat(pFoV)));
MessageBox.Show(this, "The memory research pattern wasn't able to find the FoV offset in your " + gameMode.GetValue("c_supportMessage") + ".\n" +
"Please look for an updated version of this FoV Changer tool.\n\n" +
"If you believe this might be a bug, please send me an email at [email protected], and include a screenshot of this:\n" +
"\n" + c_toolVer +
"\nWorking Set: 0x" + proc.WorkingSet64.ToString("X8") +
"\nPaged Memory: 0x" + proc.PagedMemorySize64.ToString("X8") +
"\nVirtual Memory: 0x" + proc.VirtualMemorySize64.ToString("X8") +
"\nStep: " + step.ToString() +
"\nFoV pointer: 0x" + (pFoV - c_pOffset).ToString("X8") + " = " + memory,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
pFoV = (dword_ptr)gameMode.GetValue("c_pFoV");
Application.Exit();
}
else
{
//Console.Beep(5000, 100);
SaveSettings();
proc = null;
TimerCheck.Start();
}
}
}
catch (Exception ex)
{
ErrMessage(ex);
Application.Exit();
}
}
}
catch (InvalidOperationException) { }
}
}
19
View Source File : MainForm.cs
License : GNU General Public License v3.0
Project Creator : AgentRev
License : GNU General Public License v3.0
Project Creator : AgentRev
private void TimerVerif_Tick(object sender, EventArgs e)
{
if (proc != null && mem != null && isRunning(false))
{
if (btnStartGame.Enabled) ToggleButton(false);
proc.Refresh();
if (proc.PagedMemorySize64 > 0x2000000)
{
byte step = 0;
try
{
mem.FindFoVOffset(ref pFoV, ref step);
if (!isOffsetWrong(pFoV)) progStart();
else if (proc.PagedMemorySize64 > (long)gameMode.GetValue("c_memSearchRange"))
{
TimerVerif.Stop();
TimerCheck.Stop();
//bool offsetFound = false;
//int ptrSize = IntPtr.Size * 4;
/*for (int i = -0x50000; i < 0x50000 && !offsetFound; i += 16)
{
if (mem.ReadFloat(true, pFoV + i) == 65f && !isOffsetWrong(pFoV + i))
{
pFoV += i;
offsetFound = true;
}
if (i % 50000 == 0)
{
label1.Text = i.ToString();
Update();
}
}*/
//Console.Beep(5000, 100);
//MessageBox.Show("find " + pFoV.ToString("X8"));
if (isRunning(false) && !mem.FindFoVOffset(ref pFoV, ref step))
{
string memory = BitConverter.ToString(BitConverter.GetBytes(mem.ReadFloat(pFoV)));
MessageBox.Show(this, "The memory research pattern wasn't able to find the FoV offset in your " + gameMode.GetValue("c_supportMessage") + ".\n" +
"Please look for an updated version of this FoV Changer tool.\n\n" +
"If you believe this might be a bug, please send me an email at [email protected], and include a screenshot of this:\n\n" + c_toolVer +
"\n0x" + Convert.ToInt32(proc.WorkingSet64).ToString("X8") +
"\n0x" + Convert.ToInt32(proc.PagedMemorySize64).ToString("X8") +
"\n0x" + Convert.ToInt32(proc.VirtualMemorySize64).ToString("X8") +
"\nStep = " + step.ToString() +
"\n0x" + (pFoV - 0xC).ToString("X8") + " = " + memory,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
pFoV = (int)gameMode.GetValue("c_pFoV");
Application.Exit();
}
else
{
//Console.Beep(5000, 100);
SaveSettings();
proc = null;
TimerCheck.Start();
}
}
}
catch (Exception ex)
{
ErrMessage(ex);
Application.Exit();
}
}
}
}
19
View Source File : HashExtension.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public static byte[] Twox64Concat(byte[] bytes)
{
return BitConverter.GetBytes(XXHash.XXH64(bytes)).Concat(bytes).ToArray().ToArray();
}
19
View Source File : HashExtension.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public static byte[] Twox128(byte[] bytes)
{
return BitConverter.GetBytes(XXHash.XXH64(bytes, 0))
.Concat(BitConverter.GetBytes(XXHash.XXH64(bytes, 1)))
.ToArray();
}
19
View Source File : HashExtension.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public static byte[] Twox256(byte[] bytes)
{
return BitConverter.GetBytes(XXHash.XXH64(bytes, 0))
.Concat(BitConverter.GetBytes(XXHash.XXH64(bytes, 1)))
.Concat(BitConverter.GetBytes(XXHash.XXH64(bytes, 2)))
.Concat(BitConverter.GetBytes(XXHash.XXH64(bytes, 3)))
.ToArray();
}
19
View Source File : ParameterAssembler.cs
License : MIT License
Project Creator : Akaion
License : MIT License
Project Creator : Akaion
internal static void replacedembleFastCallParameters(CallDescriptor callDescriptor, ref List<byte> shellcode)
{
var stackParameters = new List<byte>();
var parameterIndex = 0;
if (callDescriptor.IsWow64Call)
{
foreach (var parameter in callDescriptor.Parameters)
{
switch (parameterIndex)
{
case 0:
{
if (parameter == 0)
{
// xor ecx, ecx
shellcode.AddRange(new byte[] {0x31, 0xC9});
}
else
{
// mov ecx, parameter
shellcode.Add(0xB9);
shellcode.AddRange(BitConverter.GetBytes((int) parameter));
}
parameterIndex += 1;
break;
}
case 1:
{
if (parameter == 0)
{
// xor edx, edx
shellcode.AddRange(new byte[] {0x31, 0xD2});
}
else
{
// mov edx, parameter
shellcode.Add(0xBA);
shellcode.AddRange(BitConverter.GetBytes((int) parameter));
}
parameterIndex += 1;
break;
}
default:
{
if (parameter <= 0x7F)
{
// push parameter
stackParameters.InsertRange(0, new byte[] {0x6A, (byte) parameter});
}
else
{
// push parameter
var operation = new List<byte> {0x68};
operation.AddRange(BitConverter.GetBytes((int) parameter));
stackParameters.InsertRange(0, operation);
}
break;
}
}
}
}
else
{
foreach (var parameter in callDescriptor.Parameters)
{
switch (parameterIndex)
{
case 0:
{
if (parameter == 0)
{
// xor ecx, ecx
shellcode.AddRange(new byte[] {0x31, 0xC9});
}
else
{
// mov rcx, parameter
shellcode.AddRange(new byte[] {0x48, 0xB9});
shellcode.AddRange(BitConverter.GetBytes(parameter));
}
parameterIndex += 1;
break;
}
case 1:
{
if (parameter == 0)
{
// xor edx, edx
shellcode.AddRange(new byte[] {0x31, 0xD2});
}
else
{
// mov rdx, parameter
shellcode.AddRange(new byte[] {0x48, 0xBA});
shellcode.AddRange(BitConverter.GetBytes(parameter));
}
parameterIndex += 1;
break;
}
case 2:
{
if (parameter == 0)
{
// xor r8, r8
shellcode.AddRange(new byte[] {0x4D, 0x31, 0xC0});
}
else
{
// mov r8, parameter
shellcode.AddRange(new byte[] {0x49, 0xB8});
shellcode.AddRange(BitConverter.GetBytes(parameter));
}
parameterIndex += 1;
break;
}
case 3:
{
if (parameter == 0)
{
// xor r9, r9
shellcode.AddRange(new byte[] {0x4D, 0x31, 0xC9});
}
else
{
// mov r9, parameter
shellcode.AddRange(new byte[] {0x49, 0xB9});
shellcode.AddRange(BitConverter.GetBytes(parameter));
}
parameterIndex += 1;
break;
}
default:
{
if (parameter <= 0x7F)
{
// push parameter
stackParameters.InsertRange(0, new byte[] {0x6A, (byte) parameter});
}
else
{
var operation = new List<byte>();
if (parameter < int.MaxValue)
{
// push parameter
operation.Add(0x68);
operation.AddRange(BitConverter.GetBytes((int) parameter));
}
else
{
// mov rax, parameter
operation.AddRange(new byte[] {0x48, 0xB8});
operation.AddRange(BitConverter.GetBytes(parameter));
// push rax
operation.Add(0x50);
}
stackParameters.InsertRange(0, operation);
}
break;
}
}
}
}
shellcode.AddRange(stackParameters);
}
19
View Source File : UnnyNetPacker.cs
License : MIT License
Project Creator : alerdenisov
License : MIT License
Project Creator : alerdenisov
static public byte[] PackObject(out int size, params object []arg)
{
byte [] bytes = m_Buffer;//new byte[HeaderSize];
size = HeaderSize;
for (int i = 0; i < arg.Length; i++)
{
if (arg[i] is int)
{
int intValue = (int)arg[i];
// System.Array.Resize(ref bytes, size + 5);
bytes[size++] = (byte)TypeTags.IntTag;
bytes[size++] = (byte)intValue;
bytes[size++] = (byte)(intValue >> 8);
bytes[size++] = (byte)(intValue >> 16);
bytes[size++] = (byte)(intValue >> 24);
}
else if (arg[i] is float)
{
var floatValue = (float)arg[i];
var floatBytes = System.BitConverter.GetBytes(floatValue);
// System.Array.Resize(ref bytes, size + 5);
bytes[size++] = (byte)TypeTags.FloatTag;
bytes[size++] = floatBytes[0];
bytes[size++] = floatBytes[1];
bytes[size++] = floatBytes[2];
bytes[size++] = floatBytes[3];
}
else if(arg[i] is Vector3)
{
var vecValue = (Vector3)arg[i];
bytes[size++] = (byte)TypeTags.Vector3Tag;
for (int axis = 0; axis < 3; axis++)
{
var floatBytes = System.BitConverter.GetBytes(vecValue[axis]);
bytes[size++] = floatBytes[0];
bytes[size++] = floatBytes[1];
bytes[size++] = floatBytes[2];
bytes[size++] = floatBytes[3];
}
}
else if (arg[i] is uint)
{
uint intValue = (uint)arg[i];
// System.Array.Resize(ref bytes, size + 5);
bytes[size++] = (byte)TypeTags.UIntTag;
bytes[size++] = (byte)intValue;
bytes[size++] = (byte)(intValue >> 8);
bytes[size++] = (byte)(intValue >> 16);
bytes[size++] = (byte)(intValue >> 24);
}
else if (arg[i] is short)
{
short shortValue = (short)arg[i];
// System.Array.Resize(ref bytes, size + 3);
bytes[size++] = (byte)TypeTags.ShortTag;
bytes[size++] = (byte)shortValue;
bytes[size++] = (byte)(shortValue >> 8);
}
else if (arg[i] is ushort)
{
ushort shortValue = (ushort)arg[i];
// System.Array.Resize(ref bytes, size + 3);
bytes[size++] = (byte)TypeTags.UShortTag;
bytes[size++] = (byte)shortValue;
bytes[size++] = (byte)(shortValue >> 8);
}
else if (arg[i] is byte)
{
// System.Array.Resize(ref bytes, size + 2);
bytes[size++] = (byte)TypeTags.ByteTag;
bytes[size++] = (byte)arg[i];
}
else if (arg[i] is sbyte)
{
// System.Array.Resize(ref bytes, size + 2);
bytes[size++] = (byte)TypeTags.SByteTag;
bytes[size++] = (byte)(sbyte)arg[i];
}
else if (arg[i] is long)
{
long intValue = (long)arg[i];
// System.Array.Resize(ref bytes, size + 1+8);
bytes[size++] = (byte)TypeTags.LongTag;
bytes[size++] = (byte)intValue;
bytes[size++] = (byte)(intValue >> 8);
bytes[size++] = (byte)(intValue >> 16);
bytes[size++] = (byte)(intValue >> 24);
bytes[size++] = (byte)(intValue >> 32);
bytes[size++] = (byte)(intValue >> 40);
bytes[size++] = (byte)(intValue >> 48);
bytes[size++] = (byte)(intValue >> 56);
}
else if (arg[i] is ulong)
{
ulong intValue = (ulong)arg[i];
// System.Array.Resize(ref bytes, size + 1+8);
bytes[size++] = (byte)TypeTags.ULongTag;
bytes[size++] = (byte)intValue;
bytes[size++] = (byte)(intValue >> 8);
bytes[size++] = (byte)(intValue >> 16);
bytes[size++] = (byte)(intValue >> 24);
bytes[size++] = (byte)(intValue >> 32);
bytes[size++] = (byte)(intValue >> 40);
bytes[size++] = (byte)(intValue >> 48);
bytes[size++] = (byte)(intValue >> 56);
}
else if (arg[i] is bool)
{
// System.Array.Resize(ref bytes, size + 2);
bytes[size++] = (byte)TypeTags.BoolTag;
bytes[size++] = ((bool)arg[i]) ? (byte)1 : (byte)0;
}
else if (arg[i] is ushort[])
{
ushort[] shortValue = (ushort[])arg[i];
if (shortValue.Length <= byte.MaxValue)
{
// System.Array.Resize(ref bytes, size + 1 + 1 + 2*shortValue.Length);
bytes[size++] = (byte)TypeTags.UShortArraySmall;
bytes[size++] = (byte)shortValue.Length;
}
else
{
// System.Array.Resize(ref bytes, size + 1 + 2 + 2*shortValue.Length);
bytes[size++] = (byte)TypeTags.UShortArrayBig;
bytes[size++] = (byte)shortValue.Length;
bytes[size++] = (byte)(shortValue.Length >> 8);
}
for (int j = 0; j < shortValue.Length; j++)
{
bytes[size++] = (byte)shortValue[j];
bytes[size++] = (byte)(shortValue[j] >> 8);
}
}
else if (arg[i] is string)
{
string str = (string)arg[i];
byte[] strBytes = System.Text.Encoding.UTF8.GetBytes(str);
int newSize = strBytes.Length;
// System.Array.Resize(ref bytes, size + newSize + 3);
bytes[size++] = (byte)TypeTags.StringTag;
ushort shortValue = (ushort)newSize;
bytes[size++] = (byte)shortValue;
bytes[size++] = (byte)(shortValue >> 8);
System.Buffer.BlockCopy(strBytes, 0, bytes, size, newSize);
size += newSize;
}
}
return bytes;
}
19
View Source File : AnonymousIdEncoder.cs
License : MIT License
Project Creator : aleripe
License : MIT License
Project Creator : aleripe
internal static string Encode(AnonymousIdData data)
{
if (data == null || string.IsNullOrWhiteSpace(data.AnonymousId))
{
return null;
}
byte[] bufferId = Encoding.UTF8.GetBytes(data.AnonymousId);
byte[] bufferIdLenght = BitConverter.GetBytes(bufferId.Length);
byte[] bufferDate = BitConverter.GetBytes(data.ExpireDate.ToFileTimeUtc());
byte[] buffer = new byte[12 + bufferId.Length];
Buffer.BlockCopy(bufferDate, 0, buffer, 0, 8);
Buffer.BlockCopy(bufferIdLenght, 0, buffer, 8, 4);
Buffer.BlockCopy(bufferId, 0, buffer, 12, bufferId.Length);
return Base64UrlEncoder.Encode(buffer);
}
19
View Source File : WebassemblyModule.cs
License : MIT License
Project Creator : alexanderkyte
License : MIT License
Project Creator : alexanderkyte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void StoreDouble (double input, int align, int offset) {
var bytes = BitConverter.GetBytes (input);
this.memory [offset + 0] = bytes [0];
this.memory [offset + 1] = bytes [1];
this.memory [offset + 2] = bytes [2];
this.memory [offset + 3] = bytes [3];
this.memory [offset + 4] = bytes [4];
this.memory [offset + 5] = bytes [5];
this.memory [offset + 6] = bytes [6];
this.memory [offset + 7] = bytes [7];
}
19
View Source File : ProcessMemory.cs
License : MIT License
Project Creator : altskop
License : MIT License
Project Creator : altskop
public float CallFunctionFloat(IntPtr functionPtr, IntPtr param)
{
float ret = 0;
byte[] inline = { 0x68,0,0,0,0,0xFF, 0x15, 0, 0, 0, 0, 0xD9, 0x1D, 0, 0, 0, 0, 0xA1, 0, 0, 0, 0,0x59, 0xC3,0,0,0,0,0,0,0,0 };
IntPtr destination = this.MemAlloc((uint)inline.Length);
Buffer.BlockCopy(BitConverter.GetBytes((int)param), 0, inline, 1, 4);
Buffer.BlockCopy(BitConverter.GetBytes((int)functionPtr), 0, inline, 24, 4);
Buffer.BlockCopy(BitConverter.GetBytes((int)destination + 24), 0, inline, 7, 4);
byte[] pReturnValue = BitConverter.GetBytes((int)destination + 28);
Buffer.BlockCopy(pReturnValue, 0, inline, 13, 4);
Buffer.BlockCopy(pReturnValue, 0, inline, 18, 4);
this.Write(destination, inline);
int littleEndian = this.CallFunction(destination, IntPtr.Zero);
ret = BitConverter.ToSingle(BitConverter.GetBytes(littleEndian).ToArray(), 0);
bool success = this.MemFree(destination);
return ret;
}
19
View Source File : ProcessMemory.cs
License : MIT License
Project Creator : altskop
License : MIT License
Project Creator : altskop
public int SecureCallFunction(IntPtr functionPtr, IntPtr param)
{
byte[] SEHBegin = {
0x68, 0, 0, 0, 0, // PUSH [ERRORHANDLER]-
0x64, 0xFF, 0x35, 0, 0, 0 ,0, // PUSH DWORD PTR FS:[0]
0x64, 0x89, 0x25, 0, 0, 0, 0 // MOV DWORD PTR FS:[0],ESP
};
byte[] inline = {
0x68, 0, 0, 0, 0, // PUSH [param]
0xFF, 0x15, 0, 0, 0, 0, // CALL DWORD PTR DS:[0] -
0x59, // POP ECX -
0xEB, 0x09 // JUMP SHORT +9 -
};
byte[] SEHEnd = {
0x8B, 0x64, 0xE4, 0x08, // MOV ESP,DWORD PTR SS:[ESP+8]
0x31, 0xC0, // XOR EAX,EAX - set eax
0x83, 0xE8, 0x01, // SUB EAX,1 to -1
0x64, 0x8F, 0x5, 0, 0, 0, 0, // POP DWORD PTR FS:[0
0x83, 0xC4, 0x4, // ADD ESP,4
0xC3 // RETN
};
int codeLen = SEHBegin.Length + inline.Length + SEHEnd.Length;
IntPtr destination = this.MemAlloc((uint) codeLen + 4);
Buffer.BlockCopy(BitConverter.GetBytes((int)param), 0, inline, 1, 4);
int SEHandler = (int)destination + SEHBegin.Length + inline.Length; //ㅇ
Buffer.BlockCopy(BitConverter.GetBytes(SEHandler), 0, SEHBegin, 1, 4);
this.Write((IntPtr)((int)destination + codeLen), BitConverter.GetBytes((int)functionPtr));
Buffer.BlockCopy(BitConverter.GetBytes((int)destination + codeLen), 0, inline, 7, 4);
this.Write(destination, SEHBegin);
this.Write((IntPtr)((int)destination + SEHBegin.Length), inline);
this.Write((IntPtr)((int)destination + SEHBegin.Length + inline.Length), SEHEnd);
int ret = this.CallFunction(destination, IntPtr.Zero);
bool success = this.MemFree(destination);
return ret;
}
19
View Source File : SettingsKey.cs
License : Apache License 2.0
Project Creator : AmpScm
License : Apache License 2.0
Project Creator : AmpScm
public void SetDouble(string strName, double dValue)
{
byte[] arBytes = BitConverter.GetBytes(dValue);
m_Key.SetValue(strName, arBytes);
}
19
View Source File : DataBuffer.cs
License : MIT License
Project Creator : AndreasAmMueller
License : MIT License
Project Creator : AndreasAmMueller
public void AddDouble(double value)
{
byte[] blob = BitConverter.GetBytes(value);
InternalSwap(blob);
AddBytes(blob);
}
19
View Source File : Extensions.cs
License : MIT License
Project Creator : AndreasAmMueller
License : MIT License
Project Creator : AndreasAmMueller
public static ModbusObject[] ToModbusRegister(this double value, ushort address, bool inverseRegisters = false)
{
byte[] bytes = BitConverter.GetBytes(value);
if (BitConverter.IsLittleEndian)
Array.Reverse(bytes);
var registers = new ModbusObject[bytes.Length / 2];
if (inverseRegisters)
{
int startAddress = address + registers.Length - 1;
for (int i = 0; i < registers.Length; i++)
{
registers[i] = new ModbusObject
{
Address = (ushort)(startAddress - i),
Type = ModbusObjectType.HoldingRegister,
HiByte = bytes[i * 2],
LoByte = bytes[i * 2 + 1]
};
}
}
else
{
for (int i = 0; i < registers.Length; i++)
{
registers[i] = new ModbusObject
{
Address = (ushort)(address + i),
Type = ModbusObjectType.HoldingRegister,
HiByte = bytes[i * 2],
LoByte = bytes[i * 2 + 1]
};
}
}
return registers;
}
19
View Source File : Register.cs
License : MIT License
Project Creator : AndreasAmMueller
License : MIT License
Project Creator : AndreasAmMueller
public static List<Register> Create(double value, ushort address, bool isInput = false)
{
if (address + 3 > Consts.MaxAddress)
throw new ArgumentOutOfRangeException(nameof(address));
byte[] blob = BitConverter.GetBytes(value);
if (BitConverter.IsLittleEndian)
Array.Reverse(blob);
var list = new List<Register>();
for (int i = 0; i < blob.Length / 2; i++)
{
int bytePos = i * 2;
list.Add(new Register
{
Type = isInput ? ModbusObjectType.InputRegister : ModbusObjectType.HoldingRegister,
Address = Convert.ToUInt16(address + i),
HiByte = blob[bytePos],
LoByte = blob[bytePos + 1]
});
}
return list;
}
19
View Source File : StreamUtils.cs
License : MIT License
Project Creator : ansel86castro
License : MIT License
Project Creator : ansel86castro
public static void WriteDouble(Stream stream, double d)
{
byte[] bytes = Convert(BitConverter.GetBytes(d));
stream.Write(bytes, 0, bytes.Length);
}
19
View Source File : DoubleSchema.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
public ReadOnlySequence<byte> Encode(double message)
{
var array = BitConverter.GetBytes(message);
if (BitConverter.IsLittleEndian)
Array.Reverse(array);
return new(array);
}
19
View Source File : ExtendedBinaryWriter.cs
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
public void WriteReverse(double value)
{
this.WriteReverse(BitConverter.GetBytes(value));
}
19
View Source File : ExtendedBinaryReader.cs
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
public double ReadFloat64Reverse()
{
return this.ReadReverse<double>(BitConverter.GetBytes(this.ReadDouble()));
}
19
View Source File : ZipEntry.Write.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
private byte[] ConstructExtraField(bool forCentralDirectory)
{
var listOfBlocks = new System.Collections.Generic.List<byte[]>();
byte[] block;
// Conditionally emit an extra field with Zip64 information. If the
// Zip64 option is Always, we emit the field, before knowing that it's
// necessary. Later, if it turns out this entry does not need zip64,
// we'll set the header ID to rubbish and the data will be ignored.
// This results in additional overhead metadata in the zip file, but
// it will be small in comparison to the entry data.
//
// On the other hand if the Zip64 option is AsNecessary and it's NOT
// for the central directory, then we do the same thing. Or, if the
// Zip64 option is AsNecessary and it IS for the central directory,
// and the entry requires zip64, then emit the header.
if (_container.Zip64 == Zip64Option.Always ||
(_container.Zip64 == Zip64Option.AsNecessary &&
(!forCentralDirectory || _entryRequiresZip64.Value)))
{
// add extra field for zip64 here
// workitem 7924
int sz = 4 + (forCentralDirectory ? 28 : 16);
block = new byte[sz];
int i = 0;
if (_presumeZip64 || forCentralDirectory)
{
// HeaderId = always use zip64 extensions.
block[i++] = 0x01;
block[i++] = 0x00;
}
else
{
// HeaderId = dummy data now, maybe set to 0x0001 (ZIP64) later.
block[i++] = 0x99;
block[i++] = 0x99;
}
// DataSize
block[i++] = (byte)(sz - 4); // decimal 28 or 16 (workitem 7924)
block[i++] = 0x00;
// The actual metadata - we may or may not have real values yet...
// uncompressed size
Array.Copy(BitConverter.GetBytes(_UncompressedSize), 0, block, i, 8);
i += 8;
// compressed size
Array.Copy(BitConverter.GetBytes(_CompressedSize), 0, block, i, 8);
i += 8;
// workitem 7924 - only include this if the "extra" field is for
// use in the central directory. It is unnecessary and not useful
// for local header; makes WinZip choke.
if (forCentralDirectory)
{
// relative offset
Array.Copy(BitConverter.GetBytes(_RelativeOffsetOfLocalHeader), 0, block, i, 8);
i += 8;
// starting disk number
Array.Copy(BitConverter.GetBytes(0), 0, block, i, 4);
}
listOfBlocks.Add(block);
}
#if AESCRYPTO
if (Encryption == EncryptionAlgorithm.WinZipAes128 ||
Encryption == EncryptionAlgorithm.WinZipAes256)
{
block = new byte[4 + 7];
int i = 0;
// extra field for WinZip AES
// header id
block[i++] = 0x01;
block[i++] = 0x99;
// data size
block[i++] = 0x07;
block[i++] = 0x00;
// vendor number
block[i++] = 0x01; // AE-1 - means "Verify CRC"
block[i++] = 0x00;
// vendor id "AE"
block[i++] = 0x41;
block[i++] = 0x45;
// key strength
int keystrength = GetKeyStrengthInBits(Encryption);
if (keystrength == 128)
block[i] = 1;
else if (keystrength == 256)
block[i] = 3;
else
block[i] = 0xFF;
i++;
// actual compression method
block[i++] = (byte)(_CompressionMethod & 0x00FF);
block[i++] = (byte)(_CompressionMethod & 0xFF00);
listOfBlocks.Add(block);
}
#endif
if (_ntfsTimesAreSet && _emitNtfsTimes)
{
block = new byte[32 + 4];
// HeaderId 2 bytes 0x000a == NTFS times
// Datasize 2 bytes 32
// reserved 4 bytes ?? don't care
// timetag 2 bytes 0x0001 == NTFS time
// size 2 bytes 24 == 8 bytes each for ctime, mtime, atime
// mtime 8 bytes win32 ticks since win32epoch
// atime 8 bytes win32 ticks since win32epoch
// ctime 8 bytes win32 ticks since win32epoch
int i = 0;
// extra field for NTFS times
// header id
block[i++] = 0x0a;
block[i++] = 0x00;
// data size
block[i++] = 32;
block[i++] = 0;
i += 4; // reserved
// time tag
block[i++] = 0x01;
block[i++] = 0x00;
// data size (again)
block[i++] = 24;
block[i++] = 0;
Int64 z = _Mtime.ToFileTime();
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 8);
i += 8;
z = _Atime.ToFileTime();
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 8);
i += 8;
z = _Ctime.ToFileTime();
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 8);
i += 8;
listOfBlocks.Add(block);
}
if (_ntfsTimesAreSet && _emitUnixTimes)
{
int len = 5 + 4;
if (!forCentralDirectory) len += 8;
block = new byte[len];
// local form:
// --------------
// HeaderId 2 bytes 0x5455 == unix timestamp
// Datasize 2 bytes 13
// flags 1 byte 7 (low three bits all set)
// mtime 4 bytes seconds since unix epoch
// atime 4 bytes seconds since unix epoch
// ctime 4 bytes seconds since unix epoch
//
// central directory form:
//---------------------------------
// HeaderId 2 bytes 0x5455 == unix timestamp
// Datasize 2 bytes 5
// flags 1 byte 7 (low three bits all set)
// mtime 4 bytes seconds since unix epoch
//
int i = 0;
// extra field for "unix" times
// header id
block[i++] = 0x55;
block[i++] = 0x54;
// data size
block[i++] = unchecked((byte)(len - 4));
block[i++] = 0;
// flags
block[i++] = 0x07;
Int32 z = unchecked((int)((_Mtime - _unixEpoch).TotalSeconds));
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 4);
i += 4;
if (!forCentralDirectory)
{
z = unchecked((int)((_Atime - _unixEpoch).TotalSeconds));
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 4);
i += 4;
z = unchecked((int)((_Ctime - _unixEpoch).TotalSeconds));
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 4);
i += 4;
}
listOfBlocks.Add(block);
}
// inject other blocks here...
// concatenate any blocks we've got:
byte[] aggregateBlock = null;
if (listOfBlocks.Count > 0)
{
int totalLength = 0;
int i, current = 0;
for (i = 0; i < listOfBlocks.Count; i++)
totalLength += listOfBlocks[i].Length;
aggregateBlock = new byte[totalLength];
for (i = 0; i < listOfBlocks.Count; i++)
{
System.Array.Copy(listOfBlocks[i], 0, aggregateBlock, current, listOfBlocks[i].Length);
current += listOfBlocks[i].Length;
}
}
return aggregateBlock;
}
19
View Source File : ZipEntry.Write.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
internal void PostProcessOutput(Stream s)
{
var s1 = s as CountingStream;
// workitem 8931 - for WriteDelegate.
// The WriteDelegate changes things because there can be a zero-byte stream
// written. In all other cases DotNetZip knows the length of the stream
// before compressing and encrypting. In this case we have to circle back,
// and omit all the crypto stuff - the GP bitfield, and the crypto header.
if (_UncompressedSize == 0 && _CompressedSize == 0)
{
if (this._Source == ZipEntrySource.ZipOutputStream) return; // nothing to do...
if (_Preplacedword != null)
{
int headerBytesToRetract = 0;
if (Encryption == EncryptionAlgorithm.PkzipWeak)
headerBytesToRetract = 12;
#if AESCRYPTO
else if (Encryption == EncryptionAlgorithm.WinZipAes128 ||
Encryption == EncryptionAlgorithm.WinZipAes256)
{
headerBytesToRetract = _aesCrypto_forWrite._Salt.Length + _aesCrypto_forWrite.GeneratedPV.Length;
}
#endif
if (this._Source == ZipEntrySource.ZipOutputStream && !s.CanSeek)
throw new ZipException("Zero bytes written, encryption in use, and non-seekable output.");
if (Encryption != EncryptionAlgorithm.None)
{
// seek back in the stream to un-output the security metadata
s.Seek(-1 * headerBytesToRetract, SeekOrigin.Current);
s.SetLength(s.Position);
// workitem 10178
Ionic.Zip.SharedUtilities.Workaround_Ladybug318918(s);
// workitem 11131
// adjust the count on the CountingStream as necessary
if (s1 != null) s1.Adjust(headerBytesToRetract);
// subtract the size of the security header from the _LengthOfHeader
_LengthOfHeader -= headerBytesToRetract;
__FileDataPosition -= headerBytesToRetract;
}
_Preplacedword = null;
// turn off the encryption bit
_BitField &= ~(0x0001);
// copy the updated bitfield value into the header
int j = 6;
_EntryHeader[j++] = (byte)(_BitField & 0x00FF);
_EntryHeader[j++] = (byte)((_BitField & 0xFF00) >> 8);
#if AESCRYPTO
if (Encryption == EncryptionAlgorithm.WinZipAes128 ||
Encryption == EncryptionAlgorithm.WinZipAes256)
{
// Fix the extra field - overwrite the 0x9901 headerId
// with dummy data. (arbitrarily, 0x9999)
Int16 fnLength = (short)(_EntryHeader[26] + _EntryHeader[27] * 256);
int offx = 30 + fnLength;
int aesIndex = FindExtraFieldSegment(_EntryHeader, offx, 0x9901);
if (aesIndex >= 0)
{
_EntryHeader[aesIndex++] = 0x99;
_EntryHeader[aesIndex++] = 0x99;
}
}
#endif
}
CompressionMethod = 0;
Encryption = EncryptionAlgorithm.None;
}
else if (_zipCrypto_forWrite != null
#if AESCRYPTO
|| _aesCrypto_forWrite != null
#endif
)
{
if (Encryption == EncryptionAlgorithm.PkzipWeak)
{
_CompressedSize += 12; // 12 extra bytes for the encryption header
}
#if AESCRYPTO
else if (Encryption == EncryptionAlgorithm.WinZipAes128 ||
Encryption == EncryptionAlgorithm.WinZipAes256)
{
// adjust the compressed size to include the variable (salt+pv)
// security header and 10-byte trailer. According to the winzip AES
// spec, that metadata is included in the "Compressed Size" figure
// when encoding the zip archive.
_CompressedSize += _aesCrypto_forWrite.SizeOfEncryptionMetadata;
}
#endif
}
int i = 8;
_EntryHeader[i++] = (byte)(_CompressionMethod & 0x00FF);
_EntryHeader[i++] = (byte)((_CompressionMethod & 0xFF00) >> 8);
i = 14;
// CRC - the correct value now
_EntryHeader[i++] = (byte)(_Crc32 & 0x000000FF);
_EntryHeader[i++] = (byte)((_Crc32 & 0x0000FF00) >> 8);
_EntryHeader[i++] = (byte)((_Crc32 & 0x00FF0000) >> 16);
_EntryHeader[i++] = (byte)((_Crc32 & 0xFF000000) >> 24);
SetZip64Flags();
// (i==26) filename length (Int16)
Int16 filenameLength = (short)(_EntryHeader[26] + _EntryHeader[27] * 256);
Int16 extraFieldLength = (short)(_EntryHeader[28] + _EntryHeader[29] * 256);
if (_OutputUsesZip64.Value)
{
// VersionNeededToExtract - set to 45 to indicate zip64
_EntryHeader[4] = (byte)(45 & 0x00FF);
_EntryHeader[5] = 0x00;
// workitem 7924 - don't need bit 3
// // workitem 7917
// // set bit 3 for ZIP64 compatibility with WinZip12
// _BitField |= 0x0008;
// _EntryHeader[6] = (byte)(_BitField & 0x00FF);
// CompressedSize and UncompressedSize - 0xFF
for (int j = 0; j < 8; j++)
_EntryHeader[i++] = 0xff;
// At this point we need to find the "Extra field" that follows the
// filename. We had already emitted it, but the data (uncomp, comp,
// ROLH) was not available at the time we did so. Here, we emit it
// again, with final values.
i = 30 + filenameLength;
_EntryHeader[i++] = 0x01; // zip64
_EntryHeader[i++] = 0x00;
i += 2; // skip over data size, which is 16+4
Array.Copy(BitConverter.GetBytes(_UncompressedSize), 0, _EntryHeader, i, 8);
i += 8;
Array.Copy(BitConverter.GetBytes(_CompressedSize), 0, _EntryHeader, i, 8);
}
else
{
// VersionNeededToExtract - reset to 20 since no zip64
_EntryHeader[4] = (byte)(20 & 0x00FF);
_EntryHeader[5] = 0x00;
// CompressedSize - the correct value now
i = 18;
_EntryHeader[i++] = (byte)(_CompressedSize & 0x000000FF);
_EntryHeader[i++] = (byte)((_CompressedSize & 0x0000FF00) >> 8);
_EntryHeader[i++] = (byte)((_CompressedSize & 0x00FF0000) >> 16);
_EntryHeader[i++] = (byte)((_CompressedSize & 0xFF000000) >> 24);
// UncompressedSize - the correct value now
_EntryHeader[i++] = (byte)(_UncompressedSize & 0x000000FF);
_EntryHeader[i++] = (byte)((_UncompressedSize & 0x0000FF00) >> 8);
_EntryHeader[i++] = (byte)((_UncompressedSize & 0x00FF0000) >> 16);
_EntryHeader[i++] = (byte)((_UncompressedSize & 0xFF000000) >> 24);
// The HeaderId in the extra field header, is already dummied out.
if (extraFieldLength != 0)
{
i = 30 + filenameLength;
// For zip archives written by this library, if the zip64
// header exists, it is the first header. Because of the logic
// used when first writing the _EntryHeader bytes, the
// HeaderId is not guaranteed to be any particular value. So
// we determine if the first header is a putative zip64 header
// by examining the datasize. UInt16 HeaderId =
// (UInt16)(_EntryHeader[i] + _EntryHeader[i + 1] * 256);
Int16 DataSize = (short)(_EntryHeader[i + 2] + _EntryHeader[i + 3] * 256);
if (DataSize == 16)
{
// reset to Header Id to dummy value, effectively dummy-ing out the zip64 metadata
_EntryHeader[i++] = 0x99;
_EntryHeader[i++] = 0x99;
}
}
}
#if AESCRYPTO
if (Encryption == EncryptionAlgorithm.WinZipAes128 ||
Encryption == EncryptionAlgorithm.WinZipAes256)
{
// Must set compressionmethod to 0x0063 (decimal 99)
//
// and then set the compression method bytes inside the extra
// field to the actual compression method value.
i = 8;
_EntryHeader[i++] = 0x63;
_EntryHeader[i++] = 0;
i = 30 + filenameLength;
do
{
UInt16 HeaderId = (UInt16)(_EntryHeader[i] + _EntryHeader[i + 1] * 256);
Int16 DataSize = (short)(_EntryHeader[i + 2] + _EntryHeader[i + 3] * 256);
if (HeaderId != 0x9901)
{
// skip this header
i += DataSize + 4;
}
else
{
i += 9;
// actual compression method
_EntryHeader[i++] = (byte)(_CompressionMethod & 0x00FF);
_EntryHeader[i++] = (byte)(_CompressionMethod & 0xFF00);
}
} while (i < (extraFieldLength - 30 - filenameLength));
}
#endif
// finally, write the data.
// workitem 7216 - sometimes we don't seek even if we CAN. ASP.NET
// Response.OutputStream, or stdout are non-seekable. But we may also want
// to NOT seek in other cases, eg zip64. For all cases, we just check bit 3
// to see if we want to seek. There's one exception - if using a
// ZipOutputStream, and PKZip encryption is in use, then we set bit 3 even
// if the out is seekable. This is so the check on the last byte of the
// PKZip Encryption Header can be done on the current time, as opposed to
// the CRC, to prevent streaming the file twice. So, test for
// ZipOutputStream and seekable, and if so, seek back, even if bit 3 is set.
if ((_BitField & 0x0008) != 0x0008 ||
(this._Source == ZipEntrySource.ZipOutputStream && s.CanSeek))
{
// seek back and rewrite the entry header
var zss = s as ZipSegmentedStream;
if (zss != null && _diskNumber != zss.CurrentSegment)
{
// In this case the entry header is in a different file,
// which has already been closed. Need to re-open it.
using (Stream hseg = ZipSegmentedStream.ForUpdate(this._container.ZipFile.Name, _diskNumber))
{
hseg.Seek(this._RelativeOffsetOfLocalHeader, SeekOrigin.Begin);
hseg.Write(_EntryHeader, 0, _EntryHeader.Length);
}
}
else
{
// seek in the raw output stream, to the beginning of the header for
// this entry.
// workitem 8098: ok (output)
s.Seek(this._RelativeOffsetOfLocalHeader, SeekOrigin.Begin);
// write the updated header to the output stream
s.Write(_EntryHeader, 0, _EntryHeader.Length);
// adjust the count on the CountingStream as necessary
if (s1 != null) s1.Adjust(_EntryHeader.Length);
// seek in the raw output stream, to the end of the file data
// for this entry
s.Seek(_CompressedSize, SeekOrigin.Current);
}
}
// emit the descriptor - only if not a directory.
if (((_BitField & 0x0008) == 0x0008) && !IsDirectory)
{
byte[] Descriptor = new byte[16 + (_OutputUsesZip64.Value ? 8 : 0)];
i = 0;
// signature
Array.Copy(BitConverter.GetBytes(ZipConstants.ZipEntryDataDescriptorSignature), 0, Descriptor, i, 4);
i += 4;
// CRC - the correct value now
Array.Copy(BitConverter.GetBytes(_Crc32), 0, Descriptor, i, 4);
i += 4;
// workitem 7917
if (_OutputUsesZip64.Value)
{
// CompressedSize - the correct value now
Array.Copy(BitConverter.GetBytes(_CompressedSize), 0, Descriptor, i, 8);
i += 8;
// UncompressedSize - the correct value now
Array.Copy(BitConverter.GetBytes(_UncompressedSize), 0, Descriptor, i, 8);
i += 8;
}
else
{
// CompressedSize - (lower 32 bits) the correct value now
Descriptor[i++] = (byte)(_CompressedSize & 0x000000FF);
Descriptor[i++] = (byte)((_CompressedSize & 0x0000FF00) >> 8);
Descriptor[i++] = (byte)((_CompressedSize & 0x00FF0000) >> 16);
Descriptor[i++] = (byte)((_CompressedSize & 0xFF000000) >> 24);
// UncompressedSize - (lower 32 bits) the correct value now
Descriptor[i++] = (byte)(_UncompressedSize & 0x000000FF);
Descriptor[i++] = (byte)((_UncompressedSize & 0x0000FF00) >> 8);
Descriptor[i++] = (byte)((_UncompressedSize & 0x00FF0000) >> 16);
Descriptor[i++] = (byte)((_UncompressedSize & 0xFF000000) >> 24);
}
// finally, write the trailing descriptor to the output stream
s.Write(Descriptor, 0, Descriptor.Length);
_LengthOfTrailer += Descriptor.Length;
}
}
19
View Source File : ZipSegmentedStream.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
private void _SetWriteStream(uint increment)
{
if (_innerStream != null)
{
#if NETCF
_innerStream.Close();
#else
_innerStream.Dispose();
#endif
if (File.Exists(CurrentName))
File.Delete(CurrentName);
File.Move(_currentTempName, CurrentName);
// Console.WriteLine("ZSS: SWS close ({0})",
// Path.GetFileName(CurrentName));
}
if (increment > 0)
CurrentSegment += increment;
SharedUtilities.CreateAndOpenUniqueTempFile(_baseDir,
out _innerStream,
out _currentTempName);
// Console.WriteLine("ZSS: SWS open ({0})",
// Path.GetFileName(_currentTempName));
if (CurrentSegment == 0)
_innerStream.Write(BitConverter.GetBytes(ZipConstants.SplitArchiveSignature), 0, 4);
}
19
View Source File : ZipFile.Save.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
private static byte[] GenCentralDirectoryFooter(long StartOfCentralDirectory,
long EndOfCentralDirectory,
Zip64Option zip64,
int entryCount,
string comment,
ZipContainer container)
{
System.Text.Encoding encoding = GetEncoding(container, comment);
int j = 0;
int bufferLength = 22;
byte[] block = null;
Int16 commentLength = 0;
if ((comment != null) && (comment.Length != 0))
{
block = encoding.GetBytes(comment);
commentLength = (Int16)block.Length;
}
bufferLength += commentLength;
byte[] bytes = new byte[bufferLength];
int i = 0;
// signature
byte[] sig = BitConverter.GetBytes(ZipConstants.EndOfCentralDirectorySignature);
Array.Copy(sig, 0, bytes, i, 4);
i+=4;
// number of this disk
// (this number may change later)
bytes[i++] = 0;
bytes[i++] = 0;
// number of the disk with the start of the central directory
// (this number may change later)
bytes[i++] = 0;
bytes[i++] = 0;
// handle ZIP64 extensions for the end-of-central-directory
if (entryCount >= 0xFFFF || zip64 == Zip64Option.Always)
{
// the ZIP64 version.
for (j = 0; j < 4; j++)
bytes[i++] = 0xFF;
}
else
{
// the standard version.
// total number of entries in the central dir on this disk
bytes[i++] = (byte)(entryCount & 0x00FF);
bytes[i++] = (byte)((entryCount & 0xFF00) >> 8);
// total number of entries in the central directory
bytes[i++] = (byte)(entryCount & 0x00FF);
bytes[i++] = (byte)((entryCount & 0xFF00) >> 8);
}
// size of the central directory
Int64 SizeOfCentralDirectory = EndOfCentralDirectory - StartOfCentralDirectory;
if (SizeOfCentralDirectory >= 0xFFFFFFFF || StartOfCentralDirectory >= 0xFFFFFFFF)
{
// The actual data is in the ZIP64 central directory structure
for (j = 0; j < 8; j++)
bytes[i++] = 0xFF;
}
else
{
// size of the central directory (we just get the low 4 bytes)
bytes[i++] = (byte)(SizeOfCentralDirectory & 0x000000FF);
bytes[i++] = (byte)((SizeOfCentralDirectory & 0x0000FF00) >> 8);
bytes[i++] = (byte)((SizeOfCentralDirectory & 0x00FF0000) >> 16);
bytes[i++] = (byte)((SizeOfCentralDirectory & 0xFF000000) >> 24);
// offset of the start of the central directory (we just get the low 4 bytes)
bytes[i++] = (byte)(StartOfCentralDirectory & 0x000000FF);
bytes[i++] = (byte)((StartOfCentralDirectory & 0x0000FF00) >> 8);
bytes[i++] = (byte)((StartOfCentralDirectory & 0x00FF0000) >> 16);
bytes[i++] = (byte)((StartOfCentralDirectory & 0xFF000000) >> 24);
}
// zip archive comment
if ((comment == null) || (comment.Length == 0))
{
// no comment!
bytes[i++] = (byte)0;
bytes[i++] = (byte)0;
}
else
{
// the size of our buffer defines the max length of the comment we can write
if (commentLength + i + 2 > bytes.Length) commentLength = (Int16)(bytes.Length - i - 2);
bytes[i++] = (byte)(commentLength & 0x00FF);
bytes[i++] = (byte)((commentLength & 0xFF00) >> 8);
if (commentLength != 0)
{
// now actually write the comment itself into the byte buffer
for (j = 0; (j < commentLength) && (i + j < bytes.Length); j++)
{
bytes[i + j] = block[j];
}
i += j;
}
}
// s.Write(bytes, 0, i);
return bytes;
}
19
View Source File : ZipFile.Save.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
private static byte[] GenZip64EndOfCentralDirectory(long StartOfCentralDirectory,
long EndOfCentralDirectory,
int entryCount,
uint numSegments)
{
const int bufferLength = 12 + 44 + 20;
byte[] bytes = new byte[bufferLength];
int i = 0;
// signature
byte[] sig = BitConverter.GetBytes(ZipConstants.Zip64EndOfCentralDirectoryRecordSignature);
Array.Copy(sig, 0, bytes, i, 4);
i+=4;
// There is a possibility to include "Extensible" data in the zip64
// end-of-central-dir record. I cannot figure out what it might be used to
// store, so the size of this record is always fixed. Maybe it is used for
// strong encryption data? That is for another day.
long DataSize = 44;
Array.Copy(BitConverter.GetBytes(DataSize), 0, bytes, i, 8);
i += 8;
// offset 12
// VersionMadeBy = 45;
bytes[i++] = 45;
bytes[i++] = 0x00;
// VersionNeededToExtract = 45;
bytes[i++] = 45;
bytes[i++] = 0x00;
// offset 16
// number of the disk, and the disk with the start of the central dir.
// (this may change later)
for (int j = 0; j < 8; j++)
bytes[i++] = 0x00;
// offset 24
long numberOfEntries = entryCount;
Array.Copy(BitConverter.GetBytes(numberOfEntries), 0, bytes, i, 8);
i += 8;
Array.Copy(BitConverter.GetBytes(numberOfEntries), 0, bytes, i, 8);
i += 8;
// offset 40
Int64 SizeofCentraldirectory = EndOfCentralDirectory - StartOfCentralDirectory;
Array.Copy(BitConverter.GetBytes(SizeofCentraldirectory), 0, bytes, i, 8);
i += 8;
Array.Copy(BitConverter.GetBytes(StartOfCentralDirectory), 0, bytes, i, 8);
i += 8;
// offset 56
// now, the locator
// signature
sig = BitConverter.GetBytes(ZipConstants.Zip64EndOfCentralDirectoryLocatorSignature);
Array.Copy(sig, 0, bytes, i, 4);
i+=4;
// offset 60
// number of the disk with the start of the zip64 eocd
// (this will change later) (it will?)
uint x2 = (numSegments==0)?0:(uint)(numSegments-1);
Array.Copy(BitConverter.GetBytes(x2), 0, bytes, i, 4);
i+=4;
// offset 64
// relative offset of the zip64 eocd
Array.Copy(BitConverter.GetBytes(EndOfCentralDirectory), 0, bytes, i, 8);
i += 8;
// offset 72
// total number of disks
// (this will change later)
Array.Copy(BitConverter.GetBytes(numSegments), 0, bytes, i, 4);
i+=4;
return bytes;
}
19
View Source File : ZlibStream.cs
License : MIT License
Project Creator : arcusmaximus
License : MIT License
Project Creator : arcusmaximus
protected override void Dispose(bool disposing)
{
Stream baseStream = BaseStream;
base.Dispose(disposing);
byte[] checksum = BitConverter.GetBytes(_adler32.Checksum);
for (int i = 3; i >= 0; i--)
{
baseStream.WriteByte(checksum[i]);
}
}
19
View Source File : Form1.cs
License : MIT License
Project Creator : Arefu
License : MIT License
Project Creator : Arefu
private void ExportToolStripMenuItem_Click(object Sender, EventArgs Args)
{
if (listBox1.Items.Count == 0)
MessageBox.Show("There is nothing to export.", "Nothing To Export!", MessageBoxButtons.OK,
MessageBoxIcon.Information);
using (var Writer = new BinaryWriter(File.Open(LanguageFile, FileMode.Create, FileAccess.Write)))
{
Writer.Write(BitConverter.GetBytes(Utilities.SwapBytes((uint) listBox1.Items.Count + 1)));
long Sum = listBox1.Items.Count * 4 + 4;
foreach (var Item in listBox1.Items)
{
Writer.Write(Utilities.SwapBytes((uint) Sum));
Sum = Sum + LanguageParse(Encoding.BigEndianUnicode.GetBytes(Item.ToString()));
}
foreach (var Item in listBox1.Items) Writer.Write(Encoding.BigEndianUnicode.GetBytes(Item.ToString()));
}
}
19
View Source File : Endian.cs
License : MIT License
Project Creator : Arefu
License : MIT License
Project Creator : Arefu
public static double ConvertDouble(double value)
{
var buffer = BitConverter.GetBytes(value);
Array.Reverse(buffer);
return BitConverter.ToDouble(buffer, 0);
}
19
View Source File : Endian.cs
License : MIT License
Project Creator : Arefu
License : MIT License
Project Creator : Arefu
public static byte[] GetBytes(double value, bool convert)
{
var result = BitConverter.GetBytes(value);
if (convert) Array.Reverse(result);
return result;
}
See More Examples