Jump to content

C# use command dllstructgetdata


SeKaSoft
 Share

Recommended Posts

I have a code like this

But I can't get the result I want, so I need a command like DllStructGetData. If I knew exactly what this command does, I could do it myself.

 

Autoit Coding

Quote

Func _memorypointerwrite($address, $handle, $offset, $data, $type = "dword", $8byte = False) 
        $pointercount = UBound($offset) - 1        
        If $8byte Then
            $buffer = DllStructCreate("LONG_PTR")
        Else
            $buffer = DllStructCreate("dword")
        EndIf
        For $i = 0 To $pointercount
            If ($i == $pointercount) Then
                $buffer = DllStructCreate($type)
                DllStructSetData($buffer, 1, $data)                
                $address = "0x" & Hex(Int(($buffer_data) + $offset[$i])) <===== i need buffer_data because change memory address
                $pointerwrite = _winapi_writeprocessmemory($handle, $address, DllStructGetPtr($buffer), DllStructGetSize($buffer), $v_data)
                Return $address
            ElseIf ($i == 0) Then
                _winapi_readprocessmemory($handle, $address, DllStructGetPtr($buffer), DllStructGetSize($buffer), $v_data)
                $buffer_data = DllStructGetData($buffer, 1)  <===== i need buffer_data              
            Else
                $address = "0x" & Hex(Int(($buffer_data) + $offset[$i])) <===== i need buffer_data because change memory address
                _winapi_readprocessmemory($handle, $address, DllStructGetPtr($buffer), DllStructGetSize($buffer), $v_data)
                $buffer_data = DllStructGetData($buffer, 1) <===== i need buffer_data
            EndIf
        Next
        If @error Then
            Return -1
        EndIf
        Return True
    EndFunc

C# Coding

Quote

      public string DecimalToHex(int Value)
      {
          return Value.ToString("x2").ToUpper();
      }

        IntPtr GetIntPtr(Byte[] byteBuf)
        {
            IntPtr ptr = Marshal.AllocHGlobal(byteBuf.Length);
            for (int i = 0; i < byteBuf.Length; i++)
            {
                Marshal.WriteByte(ptr, i, byteBuf);
            }
            return ptr;
        }

        private void MemoryPointerWrite(Int32 adres, Int32[] offset_a, int nSize)
       {
           byte[] buffer = new byte[4];
           string dectohex;
           int pointercount = Information.UBound(offset_ctrlf);

           for (int i = 0; i <= pointercount; i++)
           {
               if (i == pointercount)
               {
                   dectohex = DecimalToHex((int)buffer_data + offset_a);
                   adrr = new IntPtr(Convert.ToInt32(dectohex.Replace("0x", ""), 16));
                   //WriteProcessMemory(GameProcessHandle, adrr, buffer, 4, 0);
                   MyAdres = adrr;
                   listBox1.Items.Add("i equal to pointercount /" + adrr.ToString("X"));
               }
               else if (i == 0)
               {
                   ReadProcessMemory(GameProcessHandle, (IntPtr)adres, buffer, nSize, 0);      
                   buffer_data=GetIntPtr(buffer);
                   listBox1.Items.Add("if equal to zero " + adres.ToString("X") + " / " + buffer_data);
               }
               else
               {
                   dectohex = DecimalToHex((int)buffer_data + offset_a);
                   adrr = new IntPtr(Convert.ToInt32(dectohex.Replace("0x", ""), 16));
                   ReadProcessMemory(GameProcessHandle, adrr, buffer, nSize, 0);
                   buffer_data = GetIntPtr(buffer);
                   listBox1.Items.Add("if not equal to zero /" + adrr.ToString("X") + " / " + buffer_data);
               }
           }
       }

 

Link to comment
Share on other sites

..I don't know the first thing about C# but maybe this may give you a clue ?
 https://stackoverflow.com/questions/17562295/if-i-allocate-some-memory-with-allochglobal-do-i-have-to-free-it-with-freehglob

The next forum user coming to help is going to want to know what is that you need to get done due to forum rules :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

18 hours ago, argumentum said:

..C# hakkında pek bir şey bilmiyorum ama belki bu size bir ipucu verebilir?
 https://stackoverflow.com/questions/17562295/if-i-allocate-some-memory-with-allochglobal-do-i-have-to-free-it-with-freehglob

Yardıma gelecek bir sonraki forum kullanıcısı , forum kuralları gereği ne yapmanız gerektiğini bilmek isteyecektir. :) 

First Thank you for the information you provided.

But May I know what rule mistake I made?

Link to comment
Share on other sites

You made no mistake but those reading memory tend to use it for game cheat and that is a topic not allowed on this forum, hence the disclosure of your purpose.
Knowing your use case may bring about a better solution too so, no mistake. Plus am not a moderator in this forum, just a user.

42 minutes ago, SeKaSoft said:

First Thank you for the information you provided.

Glad it was useful to you.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...