death function() { ... } help request menu

Shout-Out

User Tag List

Results 1 to 4 of 4
  1. #1
    abuckau907's Avatar Active Member
    Reputation
    49
    Join Date
    May 2009
    Posts
    225
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    death function() { ... } help request

    Just taking a poll of how many ppl are active here (well, the # of active members that would check out a dumb post like mine lol sry)

    by reading this, you upped the view count. thank you


    ^^thnx & sry


    ----------------------------------------------------------------------------------------------------------------
    @devs - sry, if this goes how I think i'll be gone in a week anyway. My post can't hurt any more than the the rest of [some] these silly posts. Plz leave it. sry.
    Last edited by abuckau907; 12-30-2012 at 07:26 PM.
    Some things that can be counted, don't matter. And some things that matter, can't be counted.

    death function() { ... } help request
  2. #2
    abuckau907's Avatar Active Member
    Reputation
    49
    Join Date
    May 2009
    Posts
    225
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    appears I was wrong: 14 views / 2 hours. maybe dead is the wrong word. sorry admins. I guess thnx to anyone who checks in regularly.


    ---------------------------------------------------------------------------------------------------------------------------------------------------

    to sort-of save this post..at least I do have a real question, about .Net framework :/

    I'm working on my MemoryManager class (Read/Write processmemory) and I'm trying to learn generics..but frankly keep messing up as far as..suing GetType vs. typeof etc etc. I know the differences, but I still mess up because I don't understand it very well yet.

    So..I have this function (vb.net)..it works fine. Any comments/suggestions? <-- if you call that a question.

    Code:
    Public Function ReadStructure(Of T)(ByVal addr As IntPtr, ByRef yourVal As T) As Boolean
            Dim _tSizeInBytes As Int32 = Marshal.SizeOf(GetType(T))
            Dim _tBuffer(_tSizeInBytes) As Byte
            Dim _bytesRead As Int32 = 0
            If ReadProcessMemory(_targetProcessHandle, addr, _tBuffer, _tSizeInBytes, _bytesRead) Then
                If _bytesRead <> _tSizeInBytes Then
                    'not all bytes read, rpm fail
                    modPublic.DoOutput("MemReader::ReadStructure() _bytesRead != size , 0x" & addr.ToString("X"))
                    Return False
                Else
                    'all success
                    Dim _tBuffPtr As IntPtr = Marshal.AllocHGlobal(_tSizeInBytes) 'double memory usage. o well :/
                    Marshal.Copy(_tBuffer, 0, _tBuffPtr, _tSizeInBytes)
                    yourVal = CType(Marshal.PtrToStructure(_tBuffPtr, GetType(T)), T)
                    Marshal.FreeHGlobal(_tBuffPtr)
                    Return True
                End If
            Else
                modPublic.DoOutput("MemReader::ReadStructure() ReadProcessMemory() FAIL , 0x" & addr.ToString("X"))
    
                Return False
            End If
        End Function 'experimental
    basically i know it's bad because it allocated too much memory --> i declare the local buffer, andalso, use marshal.alloc() --> this is because in my declarations, rpm() expect a byte array, not a pointer to a byte array. So I can't pass in the IntPtr from Marshal.Alloc To Rpm() ..so instead I, declare the buff, rpm into the buff, marshal.alloc(), copy the buff into the new alloc, then use Marshal.PtrToStructure().
    It's wasteful. But the only way I see to fix it is to make RPM expect a byte pointer --> but then that means I have to use marshal.alloc for all of my reads --> I think for "doing a scan for int32" would require thousands of calls to Marshal.Alloc() and that can't be as fast as creating the buffer locally? I guess I could just malloc one big chunk and manage it myself inside my read functions, but that's another level of complexity I didn't want to add. so, any suggestions? I guess it really* doesn't matter..since currently I barely use the function ( I don't really..just a couple debug functions ): so for as often as I call it, it's not really a performance hit, but I'm curious if there is anything obviously wrong with the logic behind it, etc. thnx.
    Last edited by abuckau907; 12-31-2012 at 01:49 AM.
    Some things that can be counted, don't matter. And some things that matter, can't be counted.

  3. #3
    Cromon's Avatar Legendary


    Reputation
    840
    Join Date
    Mar 2008
    Posts
    714
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    About your function:
    Possibility 1:
    Use C# and fixed with pointers, that spares you the second allocation in unmanaged memory.

    Result:
    Code:
            [DllImport("Kernel32.dll", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            private static extern bool ReadProcessMemory(SafeHandle hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, uint nSize, out uint lpNumberOfBytesRead);
    
            public unsafe T ReadMemory<T>(IntPtr address) where T : struct
            {
                int size = Marshal.SizeOf(typeof(T));
                byte[] buffer = new byte[size];
                uint numBytesRead = 0;
    
                if (!ReadProcessMemory(mProcessHandle, address, buffer, (uint)size, out numBytesRead) || numBytesRead != (uint)size)
                    throw new Exception();
    
                fixed (byte* ptr = buffer)
                    return (T)Marshal.PtrToStructure((IntPtr)ptr, typeof(T));
            }
    Possibility 2:
    Do your own marshalling which can be optimized for your specialized needs instead of beeing generic for all possible cases which usually means beeing restricted by the worst case.
    Last edited by Cromon; 01-01-2013 at 05:19 PM.

  4. #4
    abuckau907's Avatar Active Member
    Reputation
    49
    Join Date
    May 2009
    Posts
    225
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe I will switch to C# soon. been reading my book on it for the last week or so, not really motivated to switch tho.

    I was thinking there might be something in the marshal class, but as I don't really use the code, i haven't been motivated to look.

    Thanks.
    Last edited by abuckau907; 01-01-2013 at 05:25 PM.
    Some things that can be counted, don't matter. And some things that matter, can't be counted.

Similar Threads

  1. It keeps DCing me.Help request!
    By sirios in forum World of Warcraft Emulator Servers
    Replies: 12
    Last Post: 01-20-2008, 01:40 AM
  2. [Help/request/crazy] Look inside please.
    By jokerjokes in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 01-01-2008, 07:26 PM
  3. [help/request] I need trainers for 2.3 lol
    By jokerjokes in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 12-28-2007, 12:39 PM
  4. Getting A Friend Connected (Help Request)
    By Magnusvermis in forum World of Warcraft Emulator Servers
    Replies: 9
    Last Post: 12-07-2007, 11:57 PM
  5. Help Request
    By sirios in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 10-14-2007, 12:47 PM
All times are GMT -5. The time now is 05:44 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search