C
C#2y ago
Barvier

❔ Converting String to an integer with a Hexadecimal Value

Hello Folks, I got a process with a prefered imagebase equal to 002E0000. I would like to store that value assigned to an integer since its a hexadecimal value which can be stored as it. What is more I would like the value to be have a prefix "0x" so in full format the integer should look like this
C#
public static int PROCESSBASEADRESS_INT = 0x002E0000
C#
public static int PROCESSBASEADRESS_INT = 0x002E0000
I have a following code that gets the value from process and saves it as an integer however here is my issues: - it does not store it in hexadecimal value - I need it stored as an hexadecimal integer value with pre-fix "0x"
C#

Process process = Process.GetProcessesByName(testprocess)[0];
ProcessModule mainModule = process.MainModule;
int baseAddressInt = int.Parse(mainModule.BaseAddress.ToString("X"), NumberStyles.HexNumber);
PROCESSBASEADRESS_INT = baseAddressInt;
Console.WriteLine(PROCESSBASEADRESS_INT);
C#

Process process = Process.GetProcessesByName(testprocess)[0];
ProcessModule mainModule = process.MainModule;
int baseAddressInt = int.Parse(mainModule.BaseAddress.ToString("X"), NumberStyles.HexNumber);
PROCESSBASEADRESS_INT = baseAddressInt;
Console.WriteLine(PROCESSBASEADRESS_INT);
It prints it out as a INT32 value. I need to print out hexadecimal value with a prefix "0x" I tried converting it to string and adding "0x" but after that I cant convert it back to hexadecimal integer that represent exactly what string was showing.
8 Replies
Barvier
BarvierOP2y ago
its converting string to hex-string. I need hex-int. for an example
C#

public static int BaseAddress = 0x2B58DF0;
C#

public static int BaseAddress = 0x2B58DF0;
Relevant
Relevant2y ago
Barvier
BarvierOP2y ago
Checking it out. Since a lot of these answers where posted back in 2015 the languaged developed and I guess we dont have to use such a complicated method anymore.
C#

// GETTING THE BASE ADDRESS OF A PROCESS
Process process = Process.GetProcessesByName(testprocess)[0];
ProcessModule mainModule = process.MainModule;
string hexBaseAddress = mainModule.BaseAddress.ToString("X");
int baseAddress = int.Parse(hexBaseAddress, System.Globalization.NumberStyles.HexNumber);
Console.WriteLine(hexBaseAddress);
Console.WriteLine(baseAddress);
C#

// GETTING THE BASE ADDRESS OF A PROCESS
Process process = Process.GetProcessesByName(testprocess)[0];
ProcessModule mainModule = process.MainModule;
string hexBaseAddress = mainModule.BaseAddress.ToString("X");
int baseAddress = int.Parse(hexBaseAddress, System.Globalization.NumberStyles.HexNumber);
Console.WriteLine(hexBaseAddress);
Console.WriteLine(baseAddress);
First print, prints out correctly - still without prefix but its not a big issue. I can solve it later. Second print, after conversion to int it prints out still INT32 number.
MODiX
MODiX2y ago
troy236#2361
REPL Result: Success
32 == 0x20
32 == 0x20
Result: bool
True
True
Compile: 300.657ms | Execution: 24.072ms | React with ❌ to remove this embed.
troy236
troy2362y ago
They are the same thing, theres no hex int Passing 32 is the same as 0x20 to a function. its seen no differently
Angius
Angius2y ago
No such thing as a "hexadecimal integer" An integer is an integer Ah, it's already been mentioned I see
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server