HexEdit/Misc.cpp
const char * mpz_set_bytes(mpz_ptr p, FILE_ADDRESS addr, int count)
{
	CHexEditView *pview = GetView();
	if (pview == NULL)
		return "No file open to read from";

	FILE_ADDRESS dummy;
	switch (addr)
	{
	case -2:   // address of mark
		addr = pview->GetMark();
		break;
	case -3:   // address of start of selection
		pview->GetSelAddr(addr, dummy);
		break;
	}

	if (addr + count > pview->GetDocument()->length())
		return "Not enough bytes before end of file";

	int units = (count + 3)/4; // number of DWORDs required
	mp_limb_t * buf = new mp_limb_t[units];
	buf[units - 1] = 0;          // make sure end bytes are zero in case not used

	if (pview->GetDocument()->GetData((unsigned char *)buf, count, addr) < count)
		return "Could not read from file";

	// Make sure view and calculator endianness are in sync
	if (pview->BigEndian())
		flip_bytes((unsigned char *)buf, count);   // Reverse the byte order to match that used internally (Intel=little-endian)

	// This assumes 4-byte units and little-endian order
	mpz_import(p, units, -1, 4, -1, 0, buf);
	delete[] buf;

	return NULL;
}
// Get bytes from active file and set an mpz var
// p = ptr to initialised mpz struct
// addr = file address that must be between 0 and length of active file - count OR
//  -2 to get bytes at the mark OR
//  -3 to get bytes at the cursor (ie, caret or start of selection)
// count = the number of bytes

Get bytes from active file and set an mpz var
p = ptr to initialised mpz struct
addr = file address that must be between 0 and length of active file - count OR
2 to get bytes at the mark OR
3 to get bytes at the cursor
count = the number of bytes
Get bytes from active file and set an mpz var p = ptr to initialised mpz struct addr = file address that must be between 0 and length of active file - count OR 2 to get bytes at the mark OR 3 to get bytes at the cursor count = the number of bytes
const char * mpz_set_bytes(mpz_ptr p, FILE_ADDRESS addr, int count)
{
	CHexEditView *pview = GetView();
	if (pview == NULL)
		return "No file open to read from";
	FILE_ADDRESS dummy;
	switch (addr)
	{
	case -2:   
		addr = pview->GetMark();
		break;
	case -3:   
		pview->GetSelAddr(addr, dummy);
		break;
	}
	if (addr + count > pview->GetDocument()->length())
		return "Not enough bytes before end of file";
	int units = (count + 3)/4; 
	mp_limb_t * buf = new mp_limb_t[units];
	buf[units - 1] = 0;          
	if (pview->GetDocument()->GetData((unsigned char *)buf, count, addr) < count)
		return "Could not read from file";
	if (pview->BigEndian())
		flip_bytes((unsigned char *)buf, count);   
	mpz_import(p, units, -1, 4, -1, 0, buf);
	delete[] buf;
	return NULL;
}
const char * mpz_set_bytes ( mpz_ptr p , FILE_ADDRESS addr , int count ) { CHexEditView * pview = GetView ( ) ; if ( pview == NULL ) return " " ; FILE_ADDRESS dummy ; switch ( addr ) { case -2 : addr = pview -> GetMark ( ) ; break ; case -3 : pview -> GetSelAddr ( addr , dummy ) ; break ; } if ( addr + count > pview -> GetDocument ( ) -> length ( ) ) return " " ; int units = ( count + 3 ) / 4 ; mp_limb_t * buf = new mp_limb_t [ units ] ; buf [ units - 1 ] = 0 ; if ( pview -> GetDocument ( ) -> GetData ( ( unsigned char * ) buf , count , addr ) < count ) return " " ; if ( pview -> BigEndian ( ) ) flip_bytes ( ( unsigned char * ) buf , count ) ; mpz_import ( p , units , -1 , 4 , -1 , 0 , buf ) ; delete [ ] buf ; return NULL ; }
Get bytes from active file and set an mpz var
p = ptr to initialised mpz struct
addr = file address that must be between 0 and length of active file - count OR
2 to get bytes at the mark OR
3 to get bytes at the cursor (ie, caret or start of selection)
count = the number of bytes
Get bytes from active file and set an mpz var p = ptr to initialised mpz struct addr = file address that must be between 0 and length of active file - count OR 2 to get bytes at the mark OR 3 to get bytes at the cursor ( ie caret or start of selection ) count = the number of bytes
// address of mark
 // address of start of selection
 // number of DWORDs required
 // make sure end bytes are zero in case not used
 // Make sure view and calculator endianness are in sync
 // Reverse the byte order to match that used internally (Intel=little-endian)
 // This assumes 4-byte units and little-endian order
