473,839 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Int Value To Pointer

I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:

void *value = 0x00323c68;

but I get a typecasting error. If I do the following:

void *value = static_cast<voi d *>(0x00323c68) ;

will that get me what I desire?

--Guillaume C.L.--

Jul 14 '06 #1
18 20576

ReaperUnreal wrote:
I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:

void *value = 0x00323c68;

but I get a typecasting error. If I do the following:

void *value = static_cast<voi d *>(0x00323c68) ;

will that get me what I desire?

--Guillaume C.L.--
Come to think of it, I'd need a reinterpret_cas t not a static_cast
wouldn't I?

--Guillaume C.L.--

Jul 14 '06 #2
ReaperUnreal said:
I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:

void *value = 0x00323c68;

but I get a typecasting error.
No, you don't, since there is no cast.
If I do the following:

void *value = static_cast<voi d *>(0x00323c68) ;

will that get me what I desire?
No, because that's a syntax error.

If you do this:

void *value = (void *)0x00323c68;

it'll compile all right, but it won't actually mean anything very much on
most systems. On a protected mode OS, if you try to read through (or write
through!) that pointer, the best you're likely to get is a segfault.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 14 '06 #3
"ReaperUnre al" <re**********@g mail.comwrites:
ReaperUnreal wrote:
I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:

void *value = 0x00323c68;

but I get a typecasting error. If I do the following:

void *value = static_cast<voi d *>(0x00323c68) ;

will that get me what I desire?

--Guillaume C.L.--

Come to think of it, I'd need a reinterpret_cas t not a static_cast
wouldn't I?
The casting you're using is specific to C++.
Depending on the OS the value of that number can or cannot have
meaning.
The standard (C99) also says that an integer may be converted to any
pointer type but the result is implementation-defined.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Jul 14 '06 #4


ReaperUnreal wrote On 07/14/06 12:09,:
I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:

void *value = 0x00323c68;

but I get a typecasting error. If I do the following:

void *value = static_cast<voi d *>(0x00323c68) ;

will that get me what I desire?
Only you know your desires. However, you're in the
wrong newsgroup. In comp.lang.c we discuss Australia;
you should instead go to comp.lang.c++ if you want to
learn about Austria. Despite the superficial similarity
of names, the two have very little to do with each other.

--
Er*********@sun .com

Jul 14 '06 #5
ReaperUnreal posted:
I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:

void *value = 0x00323c68;

but I get a typecasting error. If I do the following:

void *value = static_cast<voi d *>(0x00323c68) ;

will that get me what I desire?

How about something like the following?

#include <stddef.h>
#include <limits.h>
#include <stdio.h>

void PrintBits(void const * const mem, size_t amount_bytes)
{
char static str[CHAR_BIT + 1]; /* Auto null teminator */

unsigned char const *p = (unsigned char const *)mem;

do
{
unsigned char const byte_val = *p++;

char *pos = str;

unsigned char i = 1U << CHAR_BIT - 1;

do *pos++ = byte_val & i ? '1' : '0';
while(i >>= 1U);

printf("%s",str );

} while (--amount_bytes);
}

int main(void)
{
void * const p = (void*)0x00323c 68;

PrintBits( p, 1 );
}

--

Frederick Gotham
Jul 14 '06 #6
On Fri, 14 Jul 2006 19:37:20 GMT, Frederick Gotham
<fg*******@SPAM .comwrote in comp.lang.c:
ReaperUnreal posted:
I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:

void *value = 0x00323c68;

but I get a typecasting error. If I do the following:

void *value = static_cast<voi d *>(0x00323c68) ;

will that get me what I desire?


How about something like the following?

#include <stddef.h>
#include <limits.h>
#include <stdio.h>

void PrintBits(void const * const mem, size_t amount_bytes)
{
char static str[CHAR_BIT + 1]; /* Auto null teminator */

unsigned char const *p = (unsigned char const *)mem;

do
{
unsigned char const byte_val = *p++;

char *pos = str;

unsigned char i = 1U << CHAR_BIT - 1;

do *pos++ = byte_val & i ? '1' : '0';
while(i >>= 1U);
Do you realize that there is absolutely no gain to adding the 'U'
suffix here?
>
printf("%s",str );

} while (--amount_bytes);
}

int main(void)
{
void * const p = (void*)0x00323c 68;

PrintBits( p, 1 );
}
Do you actually this makes the behavior any less undefined? Do you do
realize that without a terminating '\n', there is no guarantee that
any output will appear?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 15 '06 #7

"ReaperUnre al" <re**********@g mail.comwrote in message
news:11******** **************@ 35g2000cwc.goog legroups.com...
I've got a strange problem here. I need to take a value that I have
written down on a sticky-note here, and find what's at that address in
current memory. I've tried the following:

void *value = 0x00323c68;

but I get a typecasting error. If I do the following:

void *value = static_cast<voi d *>(0x00323c68) ;

will that get me what I desire?
I don't mean to sound difficult, but maybe, or maybe not. Your ability to
access memory outside of your application space is environment _and_
compiler specific. I get to this in a bit.

First, let's learn how to cast in C.
void *value = 0x00323c68;
First problem: there is no cast there. If there was a cast, it'd look like
this:

void *value = (void *)0x00323c68;

Second problem: you can't do pointer arithmetic on void's and you can't
obtain a value using a void pointer. So, the cast must be of some other
type (char, long, int,...):

unsigned char *value = (unsigned char *)0x00323c68;

or:

unsigned long *value = (unsigned long *)0x00323c68;

As a practical matter, the first will return a 8-bit "byte" on most modern
systems (C defines a byte as the smallest addressable grouping of bits, not
as 8-bits...). The second will return a 32-bit value on most modern
systems, but may return other sizes (64-bits) depending on the compiler
and/or environment.

Finally, if you are attempting to read memory outside your application
space. You may have to jump through a number of other hurdles:
1) mapping the memory through the MMU or paging mechanism
2) gaining CPU privilege to access the memory
3) adjusting the pointer by an offset (linear vs. physical addressing)
4) etc...
Rod Pemberton


Jul 15 '06 #8
Jack Klein posted:

> while(i >>= 1U);

Do you realize that there is absolutely no gain to adding the 'U'
suffix here?

Option (1)

i >>= 1

The thing on the left is very likely to be promoted to a "signed int". It's
shifted once to the right, then the result is converted to an "unsigned
char".

Option (2)

i >>= 1U

The thing on the left is promoted to "unsigned int". It's shifted once to
the right, then the result is converted to an "unsigned char".
Option (2) sounds more natural to me.

Do you actually this makes the behavior any less undefined?

Obviously, this person knows what's at that memory address.

Do you do realize that without a terminating '\n', there is no guarantee
that
any output will appear?

I recall hearing something along those lines before. Would I have to flush?
--

Frederick Gotham
Jul 15 '06 #9

Frederick Gotham wrote:
Jack Klein posted:

while(i >>= 1U);
Do you realize that there is absolutely no gain to adding the 'U'
suffix here?


Option (1)

i >>= 1

The thing on the left is very likely to be promoted to a "signed int". It's
shifted once to the right, then the result is converted to an "unsigned
char".

Option (2)

i >>= 1U

The thing on the left is promoted to "unsigned int". It's shifted once to
the right, then the result is converted to an "unsigned char".
Option (2) sounds more natural to me.

Do you actually this makes the behavior any less undefined?


Obviously, this person knows what's at that memory address.

Do you do realize that without a terminating '\n', there is no guarantee
that
any output will appear?


I recall hearing something along those lines before. Would I have to flush?
--

Frederick Gotham
Ok, so first off, I got it to work, it was indeed that I either had to
use reinterpret_cas t or a C-style cast. I needed to cast it as a void
pointer because that's what the function takes. This is perfectly
defined for the function ReadProcessMemo ry which I'm using to write a
trainer of sorts. Please stop telling me that it won't work, when I've
tested it, and it does. I do in fact know exactly what's at that memory
address, a double containing my randomly generated number, a proof of
concept basically.

--Guillaume C.L.--

Jul 15 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3253
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert value to a time value' error. It's related to glibc returning an error to a pre-1970 date, I think. My question: /how/ do I go through the Python direction I've created to remove the pre-1970 date objects? Ideally, I would be able to iterate...
41
8348
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by reference?? Thanks, BB
1
1717
by: irvin.hwang | last post by:
Hi, I'm having a problem passing a pointer of a struct. Here is the code that's giving me a trouble. 1. shape *s; 2. s = load_shape(); 3. shape2grammar(s); test.cpp:53: error: no matching function for call to
10
5917
by: dorkrawk | last post by:
I am having an issue with some VC++ I am writing. I have a struct and I'm trying to call a function from it from a function in another object. here is the struct.... struct JNI_Interface { JavaVM *jvm; /* denotes a Java VM */ JNIEnv *env; /* pointer to native method interface */
3
15757
by: mishink7 | last post by:
i am getting this error error C2662: 'std::vector<_Ty>::push_back' : cannot convert 'this' pointer from 'const std::vector<_Ty>' to 'std::vector<_Ty> &' with and and
6
15188
by: Kate77 | last post by:
Hi, Im trying to build simple encryption, I use char d="a" int intASC = System.Convert.ToInt32(d); to convert it, and play with it, now I want to change it (d) back for the original ascii value ("a"), how do I do that ?
1
2313
by: simply123 | last post by:
I doing doing C btw... i have been trying to convert array elements into their respective addresses but Im faced with many problems. eg. int x (array with 7 elements) im trying to set the 3rd element value = address of 3rd element of array eg.
0
10597
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10656
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10299
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7834
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.