|
Other than strID not being null terminated, your code works fine for me.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hello, i wanted to get an idea of some basic memory editing so i thought writing a simple trainer for my favorite game would be a good idea.
So i found out how to get the pointer, now when i use cheat engine it gives the correct value if i add the baseaddress + offset.
But if i try that in my program it wont work for some reason.
int offset = 0x804;
int address = 0x818794;
int totalhp = offset + address;
int value;
ReadProcessMemory(hProcess, (LPCVOID)totalhp, &value, sizeof(value), NULL );
std::cout << value << std::endl;
value always returns zero for god knows what reason.
Any idea what iam doing wrong?
|
|
|
|
|
How are you initializing hProcess ?
|
|
|
|
|
The problem is not the handle, the problem is the wrong value i get.
HWND hWnd = FindWindow(0, "AOEII");
if(hWnd == 0)
{
std::cout << "Cant find handle." << std::endl;
_getch();
}
else
{
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
if(!hProcess)
{
std::cout << "Cant open process." << std::endl;
_getch();
}
else
{
Readprocessstuff...
|
|
|
|
|
Well found the solution, not exactly sure why i have to do it this way but iam reading about it right now, just thought id post the solution before i forget about it.
int offset = 0x804;
int baseaddress;
int value;
ReadProcessMemory(hProcess, (LPCVOID)0x00818794, (LPVOID)&baseaddress, sizeof(value), NULL );
ReadProcessMemory(hProcess, (LPCVOID)(baseaddress+offset), &value, sizeof(value), NULL );
Thanks for trying to help
|
|
|
|
|
Hello
I want to change the color of text in c(win32 console).
but not entire text only a piece of text that is in the middle.
what can I do?
best regards...
|
|
|
|
|
Look in documents for the console programming API functions. I would but you can do it just as easily as I can and I don't need to.
You can also search for articles on the console here. Most of them use C++ but at least you can see the API functions in action.
|
|
|
|
|
Looks like you're after the SetConsoleTextAttribute[^] function in combination with GetStdHandle[^] with code like this:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
Steve
|
|
|
|
|
Hi guys i wrote a program that connects to a DB that is in a LAN, and i have others PCs accessing it, the problems is how do i notify all the programs that are connected to that DB of a change in it?
Or maybe i am not using a good approach can someone help me please?
|
|
|
|
|
You can't reliably notify all interested PCs as some of them could be off-line or powered down. What you can do however is have a special table, row and field that contains say the "generation" number. And each of your applications could:
1. hold a copy of the generation number in a local file;
2. at start-up compare the database generation with the local copy, and when different, act on it.
It isn't clear what you want this for. There may be other and more appropriate ways depending on your goals.
|
|
|
|
|
Thanks Luc.
This program is a stock/selling system for a store. Problem is this i have for example 2 PCs that handle sells and the 3rd one is only watching the storage contents, there can be this issue when some items are not anymore in stock.
The only way is to use a timer then?
|
|
|
|
|
It depends on how you want to run the store I guess. You can't sell what isn't in stock, so your points of sale have to know and update stock quantities; how often do you order? how about running the order program once a day, checking all items are sufficiently stocked?
|
|
|
|
|
Hi all,
I was recently working on a C++ application in Xcode (free Mac developer tool) and started running into some really weird BUS errors. What happened was that the code would compile and run fine in terminal up until I initialized two new variables just like this --> int r, c;
After going back and getting rid of that line of code I tried a few new initialization but found that virtually any new initialization I wrote into the code caused the same problem. I would recompile and execute the code only to find that the terminal was still throwing BUS errors. Yet when I got rid of those new initializations it went back to running perfectly well.
All the code I have written and compiled is included below and I have commented some of relevant sections where the problem occurs. If anyone could help me that would be much obliged because I have no clue what could be causing these errors.
-----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*-------STRUCTURES---------*/
typedef struct {
int rows;
int cols;
int num_colors;
int file_size;
int vector_size;
int* data;
} sImage;
/*----------GET IMAGE INFO SUBPROGRAM--------------*/
long get_info(FILE* inputFile, long offset, int numberOfChars)
{
unsigned char dummy = '0';
unsigned char *ptrC = &dummy;
long value = 0;
fseek(inputFile, offset, SEEK_SET);
for(int i = 0; i < numberOfChars; i++) {
fread(ptrC, sizeof(char), 1, inputFile);
/* calculate value based on adding bytes */
value = (long)(value + (*ptrC)*(pow(256, (i))));
}
return(value);
}
/*-----------SET IMAGE DATA SUBPROGRAM----------------*/
void set_image_data(FILE* inputFile, sImage* bmp) {
bmp->cols = (int)get_info(inputFile, 18, 4);
bmp->rows = (int)get_info(inputFile, 22, 4);
bmp->file_size = (int)get_info(inputFile, 2, 4);
bmp->num_colors = (int)get_info(inputFile, 46, 4);
bmp->vector_size = (int)(bmp->file_size - (14 + 40 + 4*(bmp->num_colors)));
}
/*------------PRINT IMAGE DATA SUBPROGRAM-------------*/
void print_image_data(sImage* bmp){
printf("Width: %d\n", bmp->cols);
printf("Height: %d\n", bmp->rows);
printf("File size: %ld\n", bmp->file_size);
printf("# Colors: %d\n", bmp->num_colors);
printf("Vector size: %d\n", bmp->vector_size);
}
int main(int argc, char* argv[])
{
// Check that correct file path entered
if(argc < 2)
{
printf("Usage: %s bmpInput.bmp\n", argv[0]);
exit(0);
}
printf("Reading filename %s\n", argv[1]);
// Variable Declarations
FILE *bmpInput, *rasterOutput; /* Input file and text file with raster output */
sImage *original; /* Original BMP image data */
/*--------READ INPUT FILE------------*/
bmpInput = fopen(argv[1], "rb");
fseek(bmpInput, 0L, SEEK_END);
/*--------DECLARE OUTPUT TEXT FILE--------*/
rasterOutput = fopen("data.txt", "w");
/*--------SET AND PRINT IMAGE DATA--------*/
set_image_data(bmpInput,original);
print_image_data(original);
/*
*
* TRYING TO ACCESS ORIGINAL->NUM_COLORS IN THIS LINE CAUSES A BUS ERROR TO BE THROWN
* WHEN EXECUTED IN TERMINAL, EVEN THOUGH IT IS CLEARLY ACCESSED IN THE NEXT LINE OF CODE
*
*/
// SHOULD THROW BUS ERROR WHEN UNCOMMENTED
// original->num_colors++;
/*----START AT BEGINNING OF RASTER DATA-----*/
fseek(bmpInput, (54 + 4*original->num_colors), SEEK_SET);
/*
*
* INITIALIZING TWO NEW INTEGER VARIABLES WILL ALSO CAUSE THE PROGRAM TO THROW A BUS ERROR
*
*/
// SHOULD THROW BUS ERROR WHEN UNCOMMENTED
// int r, c;
/*
*
* WAS WRITTING THE BELLOW BIT OF CODE WHEN I FIRST NOTICED THE PROBLEM WITH THE BUS ERRORS
*
*/
/*----------READ RASTER DATA----------*/
//for(int r = 0; r < original->rows; r++) {
//for(int c = 0; c < original->cols; c++) {
/*-----read data and print in (row,column) form----*/
//fread(pChar, sizeof(char), 1, bmpInput);
//fprintf(rasterOutput, "(%d, %d) = %d\n", r, c, *pChar);
//}
//}
fclose(bmpInput);
fclose(rasterOutput);
}
-----------------------------------------------------------------------
|
|
|
|
|
We did some development on mac with Xcode ages ago but i have a faint memory about you having to set the maximum size of the stack for your application, and if you would set this to a too small value then, yepp, you guessed it, BUS error when adding variables. I might be completely off the track but try looking for this setting (i think it was somewhere along the project settings but this is an even fainter memory), increase it and see if it helps.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Don't suppose you have any further idea about how to increase the stack size do you? I've already tried adding in something to the effect of -Wl,-stack_size,0x10000000 as a linker flag but it doesn't seem to be having any effect.
|
|
|
|
|
No, sorry, as said, it was ages ago...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
I'm not a Mac developer but the first thing I'd look into would be the use of original . I can't see anywhere where you initialise the thing OR that would cause it to be initialised to the address of a real object. It looks like set_image_data is just writing data over some random bit of memory.
Cheers,
Ash
|
|
|
|
|
Thank you so much that was the problem. The code works fine now and I don't get any more BUS errors
|
|
|
|
|
how i can save dc of onpaint in MFC SDI c++?
when i draw a rectangle with mouse,i can draw only on rectangle at a time??: confused:
|
|
|
|
|
You shouldn't save the dc. If you need to paint multiple rectangles then do draw multiple rectangles in a single OnPaint
body.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
okay but which fuctions i have to use to save dc & load dc again??
|
|
|
|
|
i'm drawing rectangle with a mouse.but 1 rectangle is replaced by another...
|
|
|
|
|
You must NOT save (or load) the device context. On the other hand, you must save the state of your drawing. For instance, once a rectangle has been draw (on mouse action) you should save it somewhere in you class. Whenever the OnPaint call occurs you have to redraw all the saved rectangles.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
okay but which functions i have to use to save the state of rectangles....plzz tell me the complete way..
|
|
|
|
|
There's no function to do such a thing. You have to store all the rectangle information in a container (like for instance a std::list). If you don't know what a std::vector is, it is a kind of array of objects but which can grow dynamically. It is much easire to work with than C arrays.
So, the principle is: once you moved the mouse to show an additional rectangle, instead of drawing it directly, you create an instance of your rectangle class and you add it to the vector, then you call Invalidate() in your view, which will force a redraw of the view. In the OnPaint method, you simply iterate over all your elements in your vector and draw them one by one.
|
|
|
|
|