Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Increase DWORD by one?

Featured Replies

Posted

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 by FastLife

value[0] +=1;

perhaps...

considering value is a pointer...

  • Author

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.


Try this


 


*value += 1;


  • Author

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.


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 by metr0

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 by atom0s

  • Author

Awesome atm0s, it works now! Thank you very much.


also thanks to metr0 for the information and others who replied here, thank you guys!


Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.