Sunday, October 20, 2024

Fix Microsoft Defender Antivirus Offline Scan

Windows 10 and later has "Microsoft Defender Antivirus Offline Scan", which can remove some malware that cannot be removed without restarting Windows. First, you click on the "Scan Options":


Then you select "Microsoft Defender Antivirus (offline scan)", and click "Scan now":


Windows will then prompt you to confirm, and restart Windows.

But after migrating Windows to a larger SSD, somehow I lost the recovery partition on my boot drive, and after getting prompted to restart Windows, Windows does not actually restart.

Then I found online that when the recovery partition is not present, this feature will not work. So I started to restore the recovery partition on my boot drive.

First I ran "reagentc /info" on the command line, and confirmed that "Windows RE" was disabled:

reagentc /info

Then I confirmed that "Windows RE" could not be simply enabled by running "reagentc /enable":

reagentc /enable

After that, I started to re-create the recovery partition.

1. In the Windows Disk Management tool, I shrank the main Windows partition to make room at the end of the disk to create a new partition:


The partition size was set to 1024MB, or 1GB. A simple volume was created, and a drive letter "R" was temporarily assigned.  Then I create the directory "R:\Recovery\WindowsRE".

2. I mounted Windows installation iso file as drive "F". I then used the following command to list all the Windows images available:

    dism /Get-WimInfo /WimFile:D:\sources\install.wim

I then picked the index in the result list that matched my installation, created a directory "C:\Mount", and then ran

  dism /Mount-Wim /WimFile:F:\sources\install.wim /Index:<IndexNumber> /MountDir:C:\Mount /ReadOnly

3. I then copied the hidden, protected operating system file "C:\Mount\Windows\System32\Recovery\Winre.wim" into "R:\Recovery\WindowsRE" as well as "C:\Windows\System32\Recovery".

4. I then unmounted the image: 

   dism /Unmount-Wim /MountDir:C:\Mount /Discard

5. Then I ran the following:

   reagentc /setreimage /path R:\Recovery\WindowsRE
   reagentc /enable

6. At this point, Windows RE has been enabled:


7. The drive letter "R" was removed.

8. Finally, to turn the new partition into a recovery partition, I used "diskpart":

  diskpart
  list disk
  select disk <DiskNumber>  (replace <DiskNumber> with the number of your disk)
  list partition
  select partition <PartitionNumber>  (replace <PartitionNumber> with the number of the recovery partition)
  set id=27 override ("set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac override" for GPT drive)

After that, the "Microsoft Defender Antivirus Offline Scan" is working again.

Disclaimer and Caution: Be very careful with "diskpart" and the Windows Disk Management tool! Serious data loss could occur if you execute anything wrong!




Saturday, January 20, 2024

Proof That (a^2+b^2)/(ab+1) Is a Square When It is an Integer

Let a, b be positive integers. When 

k = a2 + b2
ab + 1

is an integer, it is a square.

Proof:

We will refer to this as Equation (*) hereafter.

We will first prove the trivial case where a = b. If a = b, this becomes

k = 2a2
a2 + 1
or

k = 2
1 + 1/(a2)

Because a > 0, the denominator is greater than 1, so k < 2. Since k is a positive integer, k can only be 1. This means that a = 1. Since a = b,  b = 1. The statement is trivially true. Conversely, if k = 1, we have

a2 + b2 = ab + 1

(a − b)2 = 1 − ab

1 − ab  ≥  0

ab  ≤  1

which can be true only if a = 1, b = 1.

To further simplify the proof, we can exclude the special case a > b = 1, and k > 1 as well. When b = 1, we have
k = a2 + 1 = a + 1 − 2a
a + 1 a + 1
This means that 2a is divisible by a + 1. In other words, 2a = m (a + 1), (2  m)a = m for some positive integer m. But from  m > 0 we conclude that 2 > m, m = 1, so 2a = a + 1, and a = 1, k = 1 as well.

Therefore, without losing generality, we can assume that a > b > 1, and k > 1.

Multiply both sides of Equation (*) by b, we have

a2b + b3 = kb
ab + 1

Perform long division by (ab + 1), we get:

(ab + 1 − 1)a + b3 = kb
ab + 1

(ab + 1)a + b3 − a = kb
ab + 1

a + b3 − a = kb
ab + 1
"Move" a to the right:
b3 − a = kb  a
ab + 1

This leads to

b3 − a = (kb − a)(ab + 1)


There are three possible cases: 1. (kb − a) > 0, 2. (kb − a) < 0, and 3. (kb − a) = 0.

Case 3 means that b3 − a = 0, a = b3. Substitute this into Equation (*), we get k = b2, which proves the original statement to be true. So we only need to prove that Case 1 and Case 2 are either not possible or yield a k = c2 for some integer c.

Case 2 is not possible because if (kb − a) < 0, we have

b3 − a = (kb − a)(ab + 1) < 0

a − b3 = (a − kb)(ab + 1) > 0

But (a − kb) > 0 means that (a − kb) ≥ 1 since a, k, and b are all integers. So

a − b3  ≥  ab + 1

a − b3 > ab

This contradicts the fact that > 1. So case 2 is not possible.

Case 1 is complicated. From (kb − a) > 0, (ab + 1) > 0 we also get b3 − a > 0. This in turn would mean that (kb − a) < b, because otherwise we would have

b3 − a = (kb − a)(ab + 1) ≥ b(ab + 1) > bab > b3

which is not possible when a > 0. Therefore, combine (kb − a) < b and kb > a, we get that (k − 1)b < a < kb, or

c = kb − a, where 0 < c < b.

Substitute a = kb − c into Equation (*), we have

(kb − c)2 + b2 = k((kb − c)b + 1)

(k2 + 1)b2 − 2kcb + c2 = k2b2 − kbc + k

b2 − kcb + c2 − k = 0

k = c2 + b2
cb + 1

Please note that here the value of k is the same as the original, we have not re-defined k. Repeat the same argument above, we again have three possibilities. While kc − b < 0 remains impossible, kc − b = 0 leads to k = c2, b = c3 (in which case the original assertion is true), and we are left with kc − b > 0, a recursive Case 1. However, this recursion cannot continue indefinitely, because a and b are both finite, yet at each step we have a > b > 1, and k > 1, and each time when we swap the roles of a and b, we are reducing the value of the smaller number by at least one.
In other words, Case 1 either does not hold, or can be reduced to k = c2 for some integer 0 < c < b.

QED


In this proof, I have produced a formula for generating a > b > 1, and k > 1 where Equation (*) holds.

Start with any b > 1, let a = b3, Equation (*) will be satisfied:

k = (b3)2 + b2 = b6 + b2 = b2(b4 + 1) = b2
b3b + 1 b4 + 1 b4 + 1

Let a1 = ka  b = b5  b, we will have

k = a12 + a2 = b10 − 2b6 + b2 + b6 = b2(b8 − b4 + 1) = b2
a1a + 1 b8 − b4 + 1 b8 − b4 + 1

This process can be repeated indefinitely.