473,830 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding a variable in a non managed running executable's memory space.

Some time ago I enquired about how I interface with a program written
in an old version of C++

Any terms i use like list that follow are used in their common everyday
usuage!

One of the programmes features is that it displays a list. The contents
of this list are the names of people that are logged into the
programme.

I am writing a programme in C# which will extract this data from the
programme, and allow me to query the list. I must stress I have no
access to any libraries etc.. that the program may/may not have been
written with. I have no documentation. All i have is a running exe
programme. That functions fine in itself.

So. From my investigations to date I have figured that I will need to
use P/Invoke with the kernel32.dll's memory functions to read the
memory. The problem is I don't know where to look in the memory. I have
been told that the address in memory i am after is likely to be a
'fourth level' pointer. But I do not know what this means very well.

Could someone explain how I should best tackle this problem please.

Thankyou,

Gary-

Dec 8 '06 #1
3 1582
Basically you can have pointers that point at pointers. One use for
this as an example is on the old 68x mac's. Coding in C++ using the OS
meant using handles, which are pointers to pointers. The idea being the
OS can move resources around memory to keep things tidy, you just worry
about the handle.
So a fourth level pointer would suggest you'll have a pointer to a
pointer to a pointer to a pointer...
What you'd need to do is get the address of the first pointer and find
out where it points and follow the chain. As for how you find the
pointer. My suggestion would be to use a debugger to pause it with one
user logged on (so it's the first item in the list) and then search for
any address which contains that address. Repeat until you can't get any
further back.
The chances are they've used a linked list, possibly of user objects,
which may contain further objects like an indentity object that
contains the name.
A linked list in case you don't know is a data structure where you have
an item object (or struct) which contains a pointer to the next object
in the list. The last object contains null in the pointer to the next
element. For added complexity, remember what I said about handles on
the mac's? Each node could hold a handle to the next node, although I
think it's fairly unlikely.
This is relevant as it may be a doubly linked list where each node
contains a pointer both to the next object and the previous object. In
that situation the head end will be the one where something points at
one of the two nodes with null in one of the two pointers. You should
be able to figure out where you because the data is layed out
sequentially so you can spot patterns.

That's a real brief overview and abstracts away a lot of the
complexity, but I hope it helps a little.

ga********@mywa y.com wrote:
Some time ago I enquired about how I interface with a program written
in an old version of C++

Any terms i use like list that follow are used in their common everyday
usuage!

One of the programmes features is that it displays a list. The contents
of this list are the names of people that are logged into the
programme.

I am writing a programme in C# which will extract this data from the
programme, and allow me to query the list. I must stress I have no
access to any libraries etc.. that the program may/may not have been
written with. I have no documentation. All i have is a running exe
programme. That functions fine in itself.

So. From my investigations to date I have figured that I will need to
use P/Invoke with the kernel32.dll's memory functions to read the
memory. The problem is I don't know where to look in the memory. I have
been told that the address in memory i am after is likely to be a
'fourth level' pointer. But I do not know what this means very well.

Could someone explain how I should best tackle this problem please.

Thankyou,

Gary-
Dec 8 '06 #2
Thankyou for that, can you tell me.

Can you tell me would you expect me to find the users name if i
searched the memory for it in plain text, or is it likely to be in some
other form?

If it's likely to be in some other form, do you know which you would
guess it to be in?

Thanks,

Gary-

DeveloperX wrote:
Basically you can have pointers that point at pointers. One use for
this as an example is on the old 68x mac's. Coding in C++ using the OS
meant using handles, which are pointers to pointers. The idea being the
OS can move resources around memory to keep things tidy, you just worry
about the handle.
So a fourth level pointer would suggest you'll have a pointer to a
pointer to a pointer to a pointer...
What you'd need to do is get the address of the first pointer and find
out where it points and follow the chain. As for how you find the
pointer. My suggestion would be to use a debugger to pause it with one
user logged on (so it's the first item in the list) and then search for
any address which contains that address. Repeat until you can't get any
further back.
The chances are they've used a linked list, possibly of user objects,
which may contain further objects like an indentity object that
contains the name.
A linked list in case you don't know is a data structure where you have
an item object (or struct) which contains a pointer to the next object
in the list. The last object contains null in the pointer to the next
element. For added complexity, remember what I said about handles on
the mac's? Each node could hold a handle to the next node, although I
think it's fairly unlikely.
This is relevant as it may be a doubly linked list where each node
contains a pointer both to the next object and the previous object. In
that situation the head end will be the one where something points at
one of the two nodes with null in one of the two pointers. You should
be able to figure out where you because the data is layed out
sequentially so you can spot patterns.

That's a real brief overview and abstracts away a lot of the
complexity, but I hope it helps a little.

ga********@mywa y.com wrote:
Some time ago I enquired about how I interface with a program written
in an old version of C++

Any terms i use like list that follow are used in their common everyday
usuage!

One of the programmes features is that it displays a list. The contents
of this list are the names of people that are logged into the
programme.

I am writing a programme in C# which will extract this data from the
programme, and allow me to query the list. I must stress I have no
access to any libraries etc.. that the program may/may not have been
written with. I have no documentation. All i have is a running exe
programme. That functions fine in itself.

So. From my investigations to date I have figured that I will need to
use P/Invoke with the kernel32.dll's memory functions to read the
memory. The problem is I don't know where to look in the memory. I have
been told that the address in memory i am after is likely to be a
'fourth level' pointer. But I do not know what this means very well.

Could someone explain how I should best tackle this problem please.

Thankyou,

Gary-
Dec 8 '06 #3
ga********@mywa y.com wrote:
>One of the programmes features is that it displays a list. The contents
of this list are the names of people that are logged into the
programme.
I think you'll find it easiest to hook into the program's display
routines. Is it a console program? -- then just redirect its stdin and
stdout. Is it a windows program that displays lin a listbox? -- then
disassemble it and search for a call to SendMessage/LB_ADDSTRING. Does
it display the list in a normal window? -- then disassembl and search
for a call to DrawText.

My instinct would be to use a modified executable where you've
rewritten some bytes of assembly code around this call. Or your
program could invoke the program as a debugger and set a breakpoint
there (I don't know what the implications are of this).

Or you could make your own "shim" dll, so that when the program
attempts to invoke DrawText it instead invokes the DrawText inside
your own shim dll. Your dll will call the normal win32 DrawText, but
it will also tell your program what the value was.

Or you can use this point just as the starting poiint for debugging.
Well, more like the "ending point" for debugging, because you'll be
trying to figure out how the program GOT TO this DrawText point,
working backwards, to figure out the chain of pointers.
--
Lucian
Dec 8 '06 #4

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

Similar topics

83
6545
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in C. It can cause very ugly errors,like this: epsilon=0 S=0 while epsilon<10: S=S+epsilon
17
2199
by: Filipe Martins | last post by:
Hello. I've read somewhere that the executable is smaller if we use a source file for each function! So, I tested this with gcc and it seams to confirm! What seams to happen is that if we call a function from a source-files that defines 3 others, the linkers includes the code of all the 4 functions, even if the on we call doesn't rely on the others! What do you people think about this?
3
3939
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /* in above case where is variable k and j mapped in memory layout ? */
19
2150
by: Skybuck Flying | last post by:
Hi, I think I might have just invented the variable bit cpu :) It works simply like this: Each "data bit" has a "meta data bit". The meta data bit describes if the bit is the ending bit of a possibly large structure/field.
4
1979
by: Nadav | last post by:
Hi, I hope this post will find it's way to some MS technical authority... I am experienced with bought Unmanaged C++ and Managed code ( C# ), There are some issues with the .NET framework that make me wonder... Take in mind the following points: 1. Managed objects are managed by the GC through the managed heap. 2. The GC moves the physical data representation of managed objects to
3
1417
by: against.inex | last post by:
Hi, The following code snippet when compiled using gcc 3.3.5 creates an executable which is 6.9 KB in size. int main(){ int arr={0}; long arr2={0}; double arr3={0}; }
53
26416
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global variable? My answer: static variable in function and global variable are allocated in head, and automatic variable is allocated in stack. Right?
4
2472
by: sam_cit | last post by:
Hi Everyone, When is memory allocated for a global variable declared in sample.c file? Is it during compile time or loading time or linking time? And is it correct to understand that the resulting exe will have the memory for the global variable? Thanks in advance!!!
275
12472
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10491
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...
0
10206
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
9315
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...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3076
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.