Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Convert code to Vb.net from c#

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
jumar
How do I cheat?
Reputation: 0

Joined: 10 Feb 2017
Posts: 1

PostPosted: Fri Feb 10, 2017 3:34 pm    Post subject: Convert code to Vb.net from c# Reply with quote

Could anyone help me convert this function into vb.net? :
Code:

using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;

[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(IntPtr hProcess, int lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesRead);

        public static int ReadAddress(string Process_Name, string Address_Offsets)
        {
            Process[] P;
            if ((P = Process.GetProcessesByName(Process_Name)).Length == 0) return -1;
            int Addy = -1;
            while (Address_Offsets.Contains("  "))
                Address_Offsets = Address_Offsets.Replace("  ", " ");

            int Index = -1;
            while ((Index = Address_Offsets.IndexOf("0x", StringComparison.OrdinalIgnoreCase)) != -1)
                Address_Offsets = Address_Offsets.Replace(Address_Offsets.Substring(Index, 2), "");

            string[] tmp = Address_Offsets.Split(' ');
            if (tmp[0].Contains("+"))
            {
                string[] AD = tmp[0].Split('+');
                foreach (ProcessModule M in P[0].Modules)
                    if (M.ModuleName.ToLower() == AD[0].ToLower())
                        Addy = M.BaseAddress.ToInt32() + int.Parse(AD[1], NumberStyles.HexNumber);
            }
            else Addy = int.Parse(tmp[0], NumberStyles.HexNumber);

            if (tmp.Length == 1) return Addy;
            byte[] buff = new byte[4];
            ReadProcessMemory(P[0].Handle, Addy, buff, 4, 0);
            Addy = BitConverter.ToInt32(buff, 0);
            for (int i = 1; i < tmp.Length; i++)
            {
                int Off = int.Parse(tmp[i], NumberStyles.HexNumber);
                ReadProcessMemory(P[0].Handle, Addy + Off, buff, 4, 0);
                Addy = i != (tmp.Length - 1) ? BitConverter.ToInt32(buff, 0) : Addy += Off;
            }
            return Addy;
        }
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sun Feb 12, 2017 2:26 pm    Post subject: Reply with quote

Google for C# to VB.NET converter. There are a handful of online sites that can do the conversion for you for free since the languages use the same code bases (.NET).
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
frogster
How do I cheat?
Reputation: 0

Joined: 08 Feb 2015
Posts: 6

PostPosted: Fri Feb 24, 2017 7:52 am    Post subject: Reply with quote

your conversion is like:

Code:
Imports System.Diagnostics
Imports System.Globalization
Imports System.Runtime.InteropServices

<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Ansi)> _
    Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByVal buffer As Byte(), ByVal size As Integer, ByVal lpNumberOfBytesRead As Integer) As Boolean
    End Function

    Public Shared Function ReadAddress(ByVal Process_Name As String, ByVal Address_Offsets As String) As Integer
        Dim P As Process()
        If (P Is Process.GetProcessesByName(Process_Name)) = 0 Then
            Return -1
        End If
        Dim Addy As Integer = -1
        While (Address_Offsets.Contains("  "))
            Address_Offsets = Address_Offsets.Replace("  ", " ")
        End While

        Dim Index As Integer = -1
        While ((Index = Address_Offsets.IndexOf("0x", StringComparison.OrdinalIgnoreCase)) <> -1)
            Address_Offsets = Address_Offsets.Replace(Address_Offsets.Substring(Index, 2), "")
        End While
        Dim tmp As String() = Address_Offsets.Split(" "c)
        If (tmp(0).Contains("+")) Then
            Dim AD As String() = tmp(0).Split("+"c)
            For Each M As ProcessModule In P(0).Modules
                If (M.ModuleName.ToLower().Equals(AD(0).ToLower())) Then
                    Addy = M.BaseAddress.ToInt32() + Integer.Parse(AD(1), NumberStyles.HexNumber)
                End If
            Next

        Else
            Addy = Integer.Parse(tmp(0), NumberStyles.HexNumber)
        End If

        If (tmp.Length = 1) Then Return Addy

        Dim buff(4) As Byte
        ReadProcessMemory(P(0).Handle, Addy, buff, 4, 0)
        Addy = BitConverter.ToInt32(buff, 0)
        For i As Integer = 1 To tmp.Length

            Dim Off As Integer = Integer.Parse(tmp(i), NumberStyles.HexNumber)
            ReadProcessMemory(P(0).Handle, Addy + Off, buff, 4, 0)
            Addy = If(i <> (tmp.Length - 1), BitConverter.ToInt32(buff, 0), Addy + Off)
        Next
        Return Addy
    End Function


But this line:
Code:
if ((P = Process.GetProcessesByName(Process_Name)).Length == 0) return -1;

might not be accurate.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites