mirror of
				https://github.com/a2x/cs2-dumper.git
				synced 2025-10-31 21:20:03 +08:00 
			
		
		
		
	Allow to add signed integers to Address variables
This commit is contained in:
		| @@ -81,7 +81,7 @@ pub fn dump_offsets( | |||||||
|                     let mut result: usize = 0; |                     let mut result: usize = 0; | ||||||
|  |  | ||||||
|                     process.read_memory_raw( |                     process.read_memory_raw( | ||||||
|                         address.add(start), |                         address.add(start.try_into().unwrap()), | ||||||
|                         &mut result as *mut _ as *mut _, |                         &mut result as *mut _ as *mut _, | ||||||
|                         end - start, |                         end - start, | ||||||
|                     )?; |                     )?; | ||||||
|   | |||||||
| @@ -18,8 +18,12 @@ impl Address { | |||||||
|     /// |     /// | ||||||
|     /// * `Address` - A new `Address` struct with the value of the current address plus the given value. |     /// * `Address` - A new `Address` struct with the value of the current address plus the given value. | ||||||
|     #[inline] |     #[inline] | ||||||
|     pub fn add(&self, value: usize) -> Self { |     pub fn add(&self, value: i64) -> Self { | ||||||
|         Self(self.0 + value) |         if value.is_negative() { | ||||||
|  |             self.sub(value.wrapping_abs() as usize) | ||||||
|  |         } else { | ||||||
|  |             Self(self.0 + value as usize) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Returns true if the value of the address is zero. |     /// Returns true if the value of the address is zero. | ||||||
|   | |||||||
| @@ -322,11 +322,12 @@ impl Process { | |||||||
|         length: Option<usize>, |         length: Option<usize>, | ||||||
|     ) -> Result<Address> { |     ) -> Result<Address> { | ||||||
|         // The displacement value can be negative. |         // The displacement value can be negative. | ||||||
|         let displacement = self.read_memory::<i32>(address.add(offset.unwrap_or(0x1)))?; |         let displacement = | ||||||
|  |             self.read_memory::<i32>(address.add(offset.unwrap_or(0x1).try_into().unwrap()))?; | ||||||
|  |  | ||||||
|         Ok(address |         Ok(address | ||||||
|             .add(length.unwrap_or(0x5)) |             .add(length.unwrap_or(0x5).try_into().unwrap()) | ||||||
|             .add(displacement as usize)) |             .add(displacement.into())) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Resolves the absolute address of a RIP-relative address. |     /// Resolves the absolute address of a RIP-relative address. | ||||||
| @@ -348,11 +349,12 @@ impl Process { | |||||||
|         length: Option<usize>, |         length: Option<usize>, | ||||||
|     ) -> Result<Address> { |     ) -> Result<Address> { | ||||||
|         // The displacement value can be negative. |         // The displacement value can be negative. | ||||||
|         let displacement = self.read_memory::<i32>(address.add(offset.unwrap_or(0x3)))?; |         let displacement = | ||||||
|  |             self.read_memory::<i32>(address.add(offset.unwrap_or(0x3).try_into().unwrap()))?; | ||||||
|  |  | ||||||
|         Ok(address |         Ok(address | ||||||
|             .add(length.unwrap_or(0x7)) |             .add(length.unwrap_or(0x7).try_into().unwrap()) | ||||||
|             .add(displacement as usize)) |             .add(displacement.into())) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Returns the process ID of the first process with the given name. |     /// Returns the process ID of the first process with the given name. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user