Inversions of diminished 7th chords

I have the following passage in D minor which features two diminished 7th chords:

I have labelled most of the chords, but I am at a loss of how to label these two diminished 7th chords.

If I could distil these two 7th chords into triads it would be easier to label them. I would label the first as vii°6 since that would imply a dominant function leading to tonic (vii°6 - i6). The second I would label as ii°6 since that would imply subdominant function moving to dominant where ii°6 leads to i6/4.

As for the 7th chords, I would prefer if the two chords were labelled as "vii ?" and "ii ?" since I think that would preserve their dominant and subdominant functions. However, because of the symmetry within a diminished 7th chord, I am unsure whether or not it is possible to label different inversions.

How can I best label these two chords?

Remember that figured-bass inversions (the Arabic numerals next to the Roman numeral) just measure the intervals above the bass. So if you're ever at a loss, just count the intervals above the lowest note and list them from largest number to smallest.

But this process only gives us the full version of the figured bass:

• Root position: 7 5 3
• First inversion: 6 5 3
• Second inversion: 6 4 3
• Third inversion: 6 4 2

We can simplify this just as we simplify the figured bass for triads:

• Root position: 7
• First inversion: 6 5
• Second inversion: 4 3
• Third inversion: 4 2 (and some only teach/use 2)

The C♯ is the root for the viio7 chord in your example, meaning that the first one, with E in the bass, is in first inversion. This chord should thus be labeled viio65.

The second chord, with G in the bass (the chordal fifth), is in second inversion. It should be labeled viio43.

That second chord would be a ii half-diminished 65 if the tenor were a D instead of a C♯; I think this is a big reason why you're hearing it as a type of iio6 moving to the cadential six-four. But since it has a C♯, the viio43 is really the correct label.

If you want to show this chord's function as a predominant, you'll need another type of analysis other than Roman numerals to do so.