Skip to content

Commit

Permalink
7thWrapperLib: Use the Util.CopyToIntptr function instead of unsafe p…
Browse files Browse the repository at this point in the history
…ointers
  • Loading branch information
julianxhokaxhiu committed Nov 28, 2022
1 parent 3e86ad8 commit 197dde9
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions 7thWrapperLib/Wrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ The original developer is Iros <irosff@outlook.com>
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
using Iros._7th;

namespace _7thWrapperLib {
public static unsafe class Wrap {
public static class Wrap {
//private static Dictionary<IntPtr, LGPWrapper> _hMap = new Dictionary<IntPtr, LGPWrapper>();
//private static Dictionary<IntPtr, string> _hNames = new Dictionary<IntPtr, string>();
//private static Dictionary<IntPtr, VStreamFile> _streamFiles = new Dictionary<IntPtr, VStreamFile>();
Expand Down Expand Up @@ -238,8 +239,8 @@ public static int HReadFile(IntPtr handle, IntPtr bytes, uint numBytesToRead, In
if (_varchives.TryGetValue(handle, out va))
{
ret = va.ReadFile(bytes, numBytesToRead, ref _numBytesRead);
uint* ptrNumBytesRead = (uint*)numBytesRead.ToPointer();
*ptrNumBytesRead = _numBytesRead;
byte[] tmp = BitConverter.GetBytes(_numBytesRead);
Util.CopyToIntPtr(tmp, numBytesRead, tmp.Length);
return ret;
}

Expand Down Expand Up @@ -395,11 +396,16 @@ public static int HGetFileInformationByHandle(IntPtr hFile, IntPtr lpFileInforma
if (result && _varchives.TryGetValue(hFile, out va))
{
DebugLogger.DetailedWriteLine($"Overriding GetFileInformationByHandle for dummy file {hFile}");
Win32.BY_HANDLE_FILE_INFORMATION* ptr = (Win32.BY_HANDLE_FILE_INFORMATION*)lpFileInformation;

*ptr = _lpFileInformation;
ptr->FileSizeHigh = (uint)(va.Size >> 32);
ptr->FileSizeLow = (uint)(va.Size & 0xffffffff);
byte[] tmp = null;

// FileSizeHigh
tmp = BitConverter.GetBytes((uint)(va.Size >> 32));
Util.CopyToIntPtr(tmp, IntPtr.Add(lpFileInformation, 32), 4);

// FileSizeLow
tmp = BitConverter.GetBytes((uint)(va.Size & 0xffffffff));
Util.CopyToIntPtr(tmp, IntPtr.Add(lpFileInformation, 36), 4);
}

return result ? 1 : 0;
Expand Down Expand Up @@ -440,7 +446,10 @@ public static int HGetFileSizeEx(IntPtr hFile, IntPtr lpFileSize)
{
DebugLogger.WriteLine($"GetFileSizeEx on dummy handle {hFile}");

*(long*)lpFileSize.ToPointer() = va.Size;
byte[] tmp = null;
tmp = BitConverter.GetBytes(va.Size);
Util.CopyToIntPtr(tmp, lpFileSize, tmp.Length);

ret = 1;
}
//else
Expand Down

0 comments on commit 197dde9

Please sign in to comment.