FastLife Posted November 1, 2014 Posted November 1, 2014 (edited) hello you i want to increase a dword value by 1.So using c++ to get a value of a pointer, and using inline asm to increase this value by one. so far it works. now i want to remove that inline asm, and increasing the value by one in c++ itself. but that doesn't work because somehow it increase the value by 4 instead of 1. working with inline asm DWORD *value = (DWORD*)(VAaddress); __asm{ inc value }not working in fully c++ DWORD *value = (DWORD*)(VAaddress); value++;and ideas? Edited November 1, 2014 by FastLife
evlncrn8 Posted November 1, 2014 Posted November 1, 2014 value[0] +=1;perhaps...considering value is a pointer... 1
ragdog Posted November 1, 2014 Posted November 1, 2014 (edited) http://www.tutorialspoint.com/cplusplus/cpp_increment_decrement_operators.htm I hope it help Edited November 1, 2014 by ragdog 1
FastLife Posted November 1, 2014 Author Posted November 1, 2014 thanks for helping but unfortunately it didn't work. this Pointer *pointerOfAddress = (Pointer*)(VAaddress); pointerOfAddress[0] += 1;will result in the error Size of the type 'void' is unknown or zero.
FastLife Posted November 1, 2014 Author Posted November 1, 2014 thanks deathway, this time no errors. however, it increments the value of 4, instead of one, like before.probably because a dword is 4 bytes so thats why it adds 4. but don't know how to add just 1 byte.
metr0 Posted November 2, 2014 Posted November 2, 2014 (edited) Yes. Increments use the factor sizeof(source_type), so it increments by sizeof(DWORD), which equals 4. You can use a cast to make your intent clear by casting to unsigned char*. Eventually you'll want to have a macro for adding values to pointers.. Edit: Above assumes one wants to increment the pointer by one, not the value itself. Edited November 3, 2014 by metr0 1
atom0s Posted November 2, 2014 Posted November 2, 2014 (edited) You can just do: *value += 1; For example: // Create some fake memory to store our value.. auto lpAddr = ::VirtualAlloc(NULL, 4, MEM_COMMIT, PAGE_EXECUTE_READWRITE); // Set the first dword in the allocated memory to 4.. *(DWORD*)lpAddr = 4; // Create pointer to the address.. DWORD* value = (DWORD*)lpAddr; // Read the current value.. (Value is currently 4.) DWORD currValue = *value; // Increment the value by 1.. *value += 1; // Read the new value.. DWORD newValue = *value; (Value is now 5.) Also if you want to just use ++, then with Visual Studio, at least, you must surround the pointer in parenthesis first before you attempt to alter it to ensure the actual object being altered is the pointed value, and not the pointer address. Like this: (*value)++; Edited November 2, 2014 by atom0s 1
FastLife Posted November 2, 2014 Author Posted November 2, 2014 Awesome atm0s, it works now! Thank you very much.also thanks to metr0 for the information and others who replied here, thank you guys!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now