|
// how can I execute a jmp instruction when I need to?
1. Organize a buffer for the JMP executing
enum {
#ifndef _WIN64
jmpAddrIdx = 2, jmpLen = 10, #else
jmpAddrIdx = 3, jmpLen = 16, #endif
};
static BYTE jmp[jmpLen] = {
#ifdef _WIN64
0x50, 0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x48, 0x87, 0x04, 0x24, 0xc3 #else
0x50, 0xb8, 0x00, 0x00, 0x00, 0x00,
0x87, 0x04, 0x24, 0xc3 #endif
};
2. Fill the address part there in (low Bytes first)
memcpy(&jmp[jmpAddrIdx], YOUR_DESIRED_ADDRESS, sizeof(DWORD_PTR));
3. Take the pointer of an existing global function(void) (Long enough: see jmpLen above)
4. Mark the addressed space of the function as writeable
DWORD dwOldMode(0);
if (VirtualProtect(pfnYourShellFcn, jmpLen, PAGE_EXECUTE_READWRITE, &dwOldMode)) {
5. Write the jump into the function
memcpy(pfnOriginal, jmp, jmpLen);
6. Mark the space as original
VirtualProtect(pfnYourShellFcn, jmpLen, dwOldMode, &dwOldMode);
7. Call the pointed function
(*pfnYourShellFcn)()
8. Be thrilled.
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
modified 13-Dec-13 7:25am.
|
|
|
|
|
That's a great answer. Thanks!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I'm thrilled.
Veni, vidi, vici.
|
|
|
|
|
|
I did think of that, however I don't know if it works across functions.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hey hi to all.....I am looking for some basic C tutorials for gaining C language knowledge.
Thanks.
|
|
|
|
|
A Google search[^] finds you plenty. Although your time may be better spent learning C++, or even C#. It is largely a question of what area of development you plan to work in.
Veni, vidi, abiit domum
|
|
|
|
|
A android-phone connect to PC by USB line, I hope to get the nowtime screen picture and show it on the dialog. Are there any ideas to do this??
Now, I get "dev/fb0" file(by "adb push /dev/graphics/fb0"), how should I do to convert to an image?
If my way is wrong, please tell me how to do this??
This is my first question on the Codeproject, please help me !!
|
|
|
|
|
|
Hi,
I am using MFC. I want to draw a color filled object (for example, circle) to show on the top of everything else?
Best,
|
|
|
|
|
this will draw a circle on top of everything:
HDC hdcDesktop = GetDC(NULL);
Ellipse(hdcDesktop, 100, 100, 200, 200);
|
|
|
|
|
Look up GDI (or GDI+), it is the simple MS way of drawing things. Usually works pretty efficiently too so if you learn it enough, you'll figure out the tricks to doing high-speed graphics. Making complex object in GDI can be a pain though, so there are other graphics libraries for more complex objects. You can however, build up on GDI and make complex objects.
|
|
|
|
|
I am using Visual Studio 2010 Pro, and have a unique issue that I'm hoping someone can help with. I overloaded the move operator = on a class, with the following code:
template<class T>
MyClass<T> &MyClass<T>::operator =(MyClass &&other) {
if (this != &other) {
std::swap(m_Data , other.m_Data ); std::swap(m_Size1, other.m_Size1); std::swap(m_Size2, other.m_Size2); std::swap(m_Size3, other.m_Size3); std::swap(m_Bool1, other.m_Bool1); std::swap(m_Bool2, other.m_Bool2); }
return *this;
}
When I enter this method in the debugger, all of the fields of both *this and other are what I expect. In case it matters, the values are:
*this other
m_Data 0 0x15E4D2EC0
m_Size1 0 5041
m_Size2 0 5041
m_Size3 0 1
m_Bool1 true false
m_Bool2 true true
My expectation is that the calls to std::swap exchange the values of all the aforementioned fields. However, on the first call to swap, when I step into the function, I get that _Left = 0 and _Right = 0x7FEF5B07EDF. WTF? Why did the value of _Right change from 0x15E4D2EC0? Even more confusing, is that at the end of the function, _Left = 0x7FEF5B07EDF, _Right = 0, but upon returning, the value of other.m_Data has NOT changed to 0. Additionally, the following fields in the "other" object changed to the values indicated (after only executing the first std::swap):
other
m_Data 0x7FEF5B07EDF (should be 0)
m_Size1 67251472 (should be 5041)
m_Size2 0 (should be 5041)
m_Size3 67257296 (should be 1)
m_Bool1 true (should be false)
m_Bool2 true (should be true) WTF? Why does calling std::swap on a single field totally hose my entire object? It is as if the first call somehow changed the type of other. Can anyone shed some light onto what is happening here? Additionally, when the future calls of std::swap are executed (all but the first), they copy the value from other to *this, but don't change the value of other (for example, after executing std::swap(m_Size1, other.m_Size1), I would expect m_Size1 = 67251472 (which it does), and other.m_Size1 = 0 (it is still equal to 67251472). Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
modified 11-Dec-13 14:35pm.
|
|
|
|
|
Nevermind: I'm an idiot. I didn't realize that rvalue references are returned automatically, and had a function declared similar to the following:
MyClass<double> &&Foo() {
MyClass<double> result();
return std::move(result);
} I simply had to remove the double ampersand from the return type, and my move constructor/assignment operator were correctly called.
The reason that I saw this weird behavior was because the object that I had a reference to was allocated on the stack. Once enough functions were called (overwriting any pre-existing, invalid stuff on the stack), the object I was using was overwritten. Thanks for anyone who looked into this!
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hello. I have got couple of basic questions about thread. I request if they are too simple, please excuse me.
1 - By default, every thread has one megabyte of stack space. Therefore, you can create at most 2,048 threads ( copied From MSDN ). How do I maximize or minimize stack size and how do I calculate max number of threads for this stack size.
2 - Lets say I create 10 threads using CreateThread() and each of them returns a valid handle. What is the best technique to store all these handles and then use them to close/terminate those threads.
Thanks for sharing your thoughts on this one.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
AmbiguousName wrote: How do I maximize or minimize stack size and how do I calculate max number of threads for this stack size.
Why? If you try to create that many threads you are probably going to fail. More would be worse.
AmbiguousName wrote: What is the best technique to store all these handles and then use them to close/terminate those threads.
That is a little bit imprecise but presumably you are asking about a thread pool.
|
|
|
|
|
1. CreateThread lets you set the stack size. to maximize, set it to an ungodly huge number. to minimize, set it to zero. either way, the thread won't run.
i guess i don't understand the question.
2. create a std::vector<HANDLE> array, populate it with your HANDLEs. when you're done, run through it and close the threads. but, yes, it sounds like what you want is a thread pool. best to find one that's already written, since they can be quite challenging to write from scratch.
|
|
|
|
|
Chris Losinger wrote: to maximize, set it to an ungodly huge number. to minimize, set it to zero. either way, the thread won't run.
Always on the lookout to learn something new...Why do you say the thread won't run? I can understand it won't run if it has no stack space, but what about a large stack space?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
AmbiguousName wrote: 1 - By default, every thread has one megabyte of stack space. Therefore, you can create at most 2,048 threads ( copied From MSDN ). How do I maximize or minimize stack size and how do I calculate max number of threads for this stack size.
Don't think it's beneficial to even be considering changing the maximum number of threads. If you have to be concerned about that, then your process design is probably not well thought out.
AmbiguousName wrote: 2 - Lets say I create 10 threads using CreateThread() and each of them returns a valid handle. What is the best technique to store all these handles and then use them to close/terminate those threads.
You can store the handles any way you want (simple array or any container). Look at the WaitForSingleObject() (and corresponding WaitForMultipleObjects()) call for tracking when a thread has finished his task. You can also use signaling... such as events for tracking when the threads are finishing up doing their work.
Additionally, there's a concept for managing multiple worker threads without the overhead of constantly restarting them called a "thread pool". In certain cases, that can be beneficial since the overhead of starting threads can be rather significant.
|
|
|
|
|
How do I calculate number of threads for a particular stack size (2048 for 1MB) ?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Its too slow when I open -> write -> close a file (see code below).
Are they a way of opening the file and always writing at the top of the file; e.g. I do not want to Append text, just write the same 100 lines of text each time at the top of the file.
#include <stdio.h>
FILE * pFile;
if ((pFile = fopen("myfile.txt", "w")) == NULL)
{
}
else
{
fclose(pFile);
}
Waiting in hope!
grahamfff
|
|
|
|
|
No, there is no way, since all the data that you write would overwrite whatever is already there. You would need to hold the data in memory, and rewrite all of it every time.
Veni, vidi, abiit domum
|
|
|
|
|
I just want to append to the TOP of the file each time. Its too slow doing an open -> write -> close.
In a 20 msec loop and sometimes two files need to hav data written to them.
No timing problems with the append, but this could result in large files if I do not overwirie.
grahamfff
|
|
|
|
|
Grahamfff wrote: I just want to append to the TOP of the file each time. As I said before, you cannot do it; the system just does not work that way. Perhaps it would be better if you explained why you want to do this.
Veni, vidi, abiit domum
|
|
|
|
|
In a 20 msec loop and sometimes two files need to have data written to them and the open -> write -> close takes about 8-10 msec each and sometimes get an overrun.
grahamfff
|
|
|
|
|