|
|
OK, you DO know what pointers are, we're just using different terminology, and if you want to use C# then there's no reason to use them. The "master" that you're referencing leaves out something very important about pointers and memory: those "Static memory addresses" and "Dynamic memory locations" aren't just pulled out of thin air. Those addresses MUST be reserved by your application in some way so that nothing overwrites your data there. The example he's using seems to be using Intel Assembly - assembly language is a whole different ballgame from any high level language. In assembly you have to know the address of all your data because there isn't the same concept of a variable like there is C/C++/C#/JAVA/etc. See here[^] for the proper usage of pointers in C++. In C# forget about pointers entirely until you're Marshaling data between managed and unmanaged code.
|
|
|
|
|
Well he did it in Delphi coding, and I've seen it done in c++...but i guess c# is different...thanks for the help anyways...
Edit:Since pointers are out of the question, I need to know how to edit OpCodes directly, this can be done by simply editing the Array of Byte of that address, also known as the Hex Dump. It is usually a long hexidecimal number, divided up in segments of 2. Example: 0e 85 fe 8a 9d ba 80. The opcode and Array of Byte are directly connected.
|
|
|
|
|
I guarantee you in whatever high level language he did it in (whoever "he" is) he preallocated the memory region using some form of new or by creating variables or he's reading/writing to a some file.
I think you're still missing the point that I'm trying to get across here - forget about addresses entirely in C#. Store your data in objects!!! The opcode thing is an array of bytes? So create a byte[] named opCodes and store your opcodes in it. It's easier to use the hex value? Then create an Int64 named opCodeHexDump and use that to modify it's value. There's absolutely no reason whatsoever to have to know the address where the data is stored in memory.
What are the OpCodes, anyway? Do you mean assembly level operation codes - as in the translation of assembly into machine code? Or are they just some internal op codes in your game?
|
|
|
|
|
Opcodes and Array of Bytes are what you get when you disassemble and look at the memory of a process.
Here's a pic:
http://www.tonyschr.net/images/ollydbg.png
the opcodes are the PUSH DWORD, PUSH EDI, JNE notepad.exe, CALL DWORD, and ect...
the arrays of bytes are the hexidecimal values right between the opcodes and the addresses.
and by editing the array of bytes, you can change the opcodes, thus doing anything you want to an external process.
Edit: May have forgotten to mention this, but you can change the opcode by changing the value of an address too, but changing the array of byte, is easier.
|
|
|
|
|
That's what I was afraid of. There is absolutely no acceptable reason to modify the execution of an external process like this. This is called hacking, stop it now.
|
|
|
|
|
Call it what you want...there's nothing wrong with it.
|
|
|
|
|
Alright kiddo, here's the last reply that you're going to get from me because now you're just wasting my time.
I'm glad that you have no idea what the f*** you're doing because changing external processes by modifying their op codes is bad. Like I said before: there is absolutely no justifiable reason to do this. The only applications that behave this way are classifiable as viruses, and if you think there's nothing wrong with it wait until one f***s you over - or modifies the op codes of something that you wrote without your permission. It'll be a big deal then.
Look, you're profile says that you're 15 so take a lesson from somebody that's been using computers longer than you've been on this Earth. Learn Some Ethics. You know how marijuana is the gateway drug? well innocent little programs like you're doing are the gateway hack. Maybe it's for a game now but later on when you finish your education and get a real job you won't be writing the next evolution of Tetris. When you're working on sh*t that matters you won't get away with crap like this.
Or totally forget that you're doing something that's unethical. You're also writing code that is by design destabilizing your operating system. Bugs that arise from this stuff are near impossible to track down because their side effects are completely random. Doing this is just plain bad coding practice.
My involvement in this is now over.
|
|
|
|
|
That's OK, I was only doing this for fun. I can just use OllyDbg to permanently modify the opcodes, or use cheat engine to temporally modify them...but I've figured it out, and yes it is useless to do it in c#...there are much easier ways.
|
|
|
|
|
By the way, you can access pointers directly using an unsafe context -- look into this if you still feel like doing it in C#.
As for accessing certain bytes directly, you can use a mask and do a bitwise-AND and then bit-shift to move it into position.
uint x = 9;
uint MASK = 0xFFFFFFF8;
uint result = (x & MASK) >> 3;
if (result == 1)
{
Console.WriteLine("4th bit is a 1!");
}
else
{
Console.WriteLine("4th bit is a 0!");
}
|
|
|
|
|
what you call a pointer is not a pointer to the majority of us.
I think most assembly languages would call your operation "offset indirect
addressing" or something of that nature. In text: take the given address, load
an address from where it points, add the offset to it, and consider that the
effective address of the operation at hand.
That is quite different from a pointer, which offers no more than one level
of indirection: take the pointer value and consider that the effective address of
the operation at hand. See for isntance here.[^], maybe not the most technical reference, but good
enough in this matter.
The pointers that exist in C, C++, C# and many other languages obey the definition
above. Whereas the former definition is implemented in most (but not all)
handles used by Windows (all with an offset of zero, hence just a double
indirection)
FYI if the offset is to be multiplied by the size of the operand (in bytes),
then it is called "indexed indirect addressing" instead of "offset indirect
addressing".
Hope this clarifies why you could not recognize all the correct answers
given to you.
|
|
|
|
|
Could you give me a link to something that could help me with reading/writing to pointers? Or whatever it is that I am exactly talking about. Thanks...
|
|
|
|
|
whatever clever addressing modes have been defined, you must implement them
yourself. The only basic operations are read direct (i.e. from a given address)
and write direct. All indirections, double indirections, offsets, indexing,
have to be programmed from that, step by step, unlike assembly code
where they exist as basic functionality to improve code density and execution time.
Of course there is nothing that stops you from putting complex addressing modes
in separate methods; example: IntPtr eaOffsetIndirect(IntPtr base, int ofs) could
use base, read an int thru it, add offset, and return that as an IntPtr, so
the caller can immediately operate on the intended operand.
Before you ask, yes you could write a native code function that performs any
complex addressing scheme your CPU provides, but calling it (which requires
P/Invoke to cross the managed/unmanaged boundary) is likely to cause more
overhead than executing it step-by-step in a higher-level language (such as C#).
|
|
|
|
|
The problem for me is that I can't use assembly for this application, I need to do some other things such as sending keystrokes, mouse commands, moving the mouse, checking global hotkeys, and I've already written 80% of the code...so I'd like to finish it in C#...it's not a very large application so I'm not worried about causing too much clutter, and I'm only reading two pointers. So I'd like some more info on it PLEASE KTHX!;)
|
|
|
|
|
Communicating with another process takes one of three routes:
- use an appropriate CLR class, when available; no warries here
- for simple things: use an existing Win32 function, call it with P/Invoke;
works fine as long as the function does not need pointers (so SetWindowText
is fine, SendMessage may be fine depending on the message code, i.e. do
wParam/lParam hold values or pointers ?)
- for complex things: allocate memory in the other process (this requires the
use of several Win32 functions such as VirtualAllocEx), transfer data
to/from your process address space from/to the other process' address space
(using ReadProcessMemory or WriteProcessMemory), and call the intended
Win32 function (all in appropriate order!). There are some examples of this
on CodeProject, at least one article describes a C++ class that facilitates
this; I wont repeat it all.
What you were talking about before (offset indirect addressing and the like) is
not applicable to the above; at most data is read/written somewhere, and a
pointer (a real one, not something fancy) to it gets passed back/forth.
|
|
|
|
|
Hi,
Can you tell me how to import a file in other file?
thanks.
|
|
|
|
|
What types of files? What do they contain? How do you want to 'merge' them? Are they text files and you want to append one to the other? Need more information.
|
|
|
|
|
Depends on the format of the file. Would you like to tell us more about these files?
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Adding to what the others said, while it's true that, for example, merging two XML files is not as simple as appending one to the other, it's also true that it's not possible to append a file at all, no matter what, you need to read your two files, merge them in memory and write them back out, either overwriting one of your existing files, or to a new file.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I'm allways surpriesed how there can be no reacton from the one who has a problem, after a response 9 minutes later.
But maybe it's because the question had no "urgent" in the subject line!
All the best,
Martin
|
|
|
|
|
Martin# wrote: I'm allways surpriesed how there can be no reacton from the one who has a problem, after a response 9 minutes later.
It just goes to show you that too many people haven't got even the most basic of manners. Possibly they found the answer but just don't have the common courtesy to respond back to say they've got a solution. Or they really don't understand their own problem and are embarrased that they can't articulate themselves.
Martin# wrote: But maybe it's because the question had no "urgent" in the subject line!
Just like this one[^]
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(@"C:\file1.txt")
{
using (StreamReader sr = new StreamReader(@"c:\file1.txt")
{
sw.Write(sr.ReadToEnd);
}
}
Simple solution for text files...
Hogan
|
|
|
|
|
using (StreamReader sr = new StreamReader(@"c:\file2.txt")<br />
{<br />
File.AppendAllText(@"c:\file1.txt", sr.ReadToEnd());<br />
}
|
|
|
|
|
File.AppendAllText("file1.txt", File.ReadAllText("file2.txt"));
|
|
|
|
|
Nice; a real compact framework would offer
File.Append("file1.txt", "file2.txt");
|
|
|
|