NPDM KAC improvements #2

This commit is contained in:
Dmitry Isaenko 2019-08-31 00:00:35 +03:00
parent 91f33b6d48
commit 6e760d9a30

View file

@ -3,6 +3,10 @@ package konogonka.Tools.NPDM.ACID;
import konogonka.LoperConverter; import konogonka.LoperConverter;
import konogonka.RainbowHexDump; import konogonka.RainbowHexDump;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.LinkedList;
/* /*
NOTE: NOTE:
KAC is set of 4-byes blocks KAC is set of 4-byes blocks
@ -22,18 +26,26 @@ Example:
9 32-33-34-35 9 32-33-34-35
Possible patterns are: Possible patterns are:
Where '+' is useful data; '0' and '1' in low bytes are pattern.
Octal | Decimal Octal | Decimal
00000000000000000000000000000111 | 7 <- KernelFlags ++++++++++++++++++++++++++++0111 | 7 <- KernelFlags
00000000000000000000000000001111 | 15 <- SyscallMask +++++++++++++++++++++++++++01111 | 15 <- SyscallMask
00000000000000000000000000111111 | 63 <- MapIoOrNormalRange +++++++++++++++++++++++++0111111 | 63 <- MapIoOrNormalRange
00000000000000000000000001111111 | 127 <- MapNormalPage (RW) ++++++++++++++++++++++++01111111 | 127 <- MapNormalPage (RW)
00000000000000000000011111111111 | 2047 <- InterruptPair ++++++++++++++++++++011111111111 | 2+47 <- InterruptPair
00000000000000000001111111111111 | 8191 <- ApplicationType ++++++++++++++++++01111111111111 | 8191 <- ApplicationType
00000000000000000011111111111111 | 16383 <- KernelReleaseVersion +++++++++++++++++011111111111111 | 16383 <- KernelReleaseVersion
00000000000000000111111111111111 | 32767 <- HandleTableSize ++++++++++++++++0111111111111111 | 32767 <- HandleTableSize
00000000000000001111111111111111 | 65535 <- DebugFlags +++++++++++++++01111111111111111 | 65535 <- DebugFlags
Other masks could be implemented by N in future (?). Other masks could be implemented by N in future (?).
Calculation example:
Dec 1 = 00000000000000000000000000000001
00100000000000000000000000000111 & 1 = 1
00010000000000000000000000000011 & 1 = 1
00001000000000000000000000000001 & 1 = 1
00000100000000000000000000000000 & 1 = 0
TIP: Generate TIP: Generate
int j = 0xFFFFFFFF; int j = 0xFFFFFFFF;
for (byte i = 0; i < 16; i++){ for (byte i = 0; i < 16; i++){
@ -44,36 +56,80 @@ for (byte i = 0; i < 16; i++){
public class KernelAccessControlProvider { public class KernelAccessControlProvider {
private static final int KERNELFLAGS = 3;
private static final int SYSCALLMASK = 4;
private static final int MAPIOORNORMALRANGE = 6;
private static final int MAPNORMALPAGE_RW = 7;
private static final int INTERRUPTPAIR = 11;
private static final int APPLICATIONTYPE = 13;
private static final int KERNELRELEASEVERSION = 14;
private static final int HANDLETABLESIZE = 15;
private static final int DEBUGFLAGS = 16;
private boolean kernelFlagsAvailable;
private int kernelFlagCpuIdHi;
private int kernelFlagCpuIdLo;
private int kernelFlagThreadPrioHi;
private int kernelFlagThreadPrioLo;
KernelAccessControlProvider(byte[] bytes) throws Exception{ KernelAccessControlProvider(byte[] bytes) throws Exception{
if (bytes.length < 4) if (bytes.length < 4)
throw new Exception("ACID-> KernelAccessControlProvider: too small size of the Kernel Access Control"); throw new Exception("ACID-> KernelAccessControlProvider: too small size of the Kernel Access Control");
final int pattrnKernFlags = 7;
final int pattrnSyscallMsk = 15;
final int pattrnMapIoNormalRange = 63;
final int pattrnRw = 127;
final int pattrnInterrPair = 2047;
final int pattrnAppType = 8191;
final int pattrnKernRelVer = 16383;
final int pattrnHandlTblSize = 32767;
final int pattrnDbgFlags = 65535;
RainbowHexDump.hexDumpUTF8(bytes); int position = 0;
for (int o = 0; o < bytes.length; o += 4) { // Collect all blocks
RainbowHexDump.octDumpInt(LoperConverter.getLEint(bytes, o)); for (int i = 0; i < bytes.length / 4; i++) {
int block = LoperConverter.getLEint(bytes, position);
position += 4;
int type = getMinBitCnt(block);
switch (type){
case KERNELFLAGS:
System.out.println("KERNELFLAGS\t\t"+block+" "+type);
kernelFlagsAvailable = true;
break;
case SYSCALLMASK:
System.out.println("SYSCALLMASK\t\t"+block+" "+type);
break;
case MAPIOORNORMALRANGE:
System.out.println("MAPIOORNORMALRANGE\t\t"+block+" "+type);
break;
case MAPNORMALPAGE_RW:
System.out.println("MAPNORMALPAGE_RW\t\t"+block+" "+type);
break;
case INTERRUPTPAIR:
System.out.println("INTERRUPTPAIR\t\t"+block+" "+type);
break;
case APPLICATIONTYPE:
System.out.println("APPLICATIONTYPE\t\t"+block+" "+type);
break;
case KERNELRELEASEVERSION:
System.out.println("KERNELRELEASEVERSION\t"+block+" "+type);
break;
case HANDLETABLESIZE:
System.out.println("HANDLETABLESIZE\t\t"+block+" "+type);
break;
case DEBUGFLAGS:
System.out.println("DEBUGFLAGS\t\t"+block+" "+type);
break;
default:
System.out.println("UNKNOWN\t\t"+block+" "+type);
}
RainbowHexDump.octDumpInt(block);
} }
System.out.println(); System.out.println();
RainbowHexDump.octDumpInt(pattrnKernFlags);
RainbowHexDump.octDumpInt(pattrnSyscallMsk);
RainbowHexDump.octDumpInt(pattrnMapIoNormalRange);
RainbowHexDump.octDumpInt(pattrnRw);
RainbowHexDump.octDumpInt(pattrnInterrPair);
RainbowHexDump.octDumpInt(pattrnAppType);
RainbowHexDump.octDumpInt(pattrnKernRelVer);
RainbowHexDump.octDumpInt(pattrnHandlTblSize);
RainbowHexDump.octDumpInt(pattrnDbgFlags);
int KernelFlagsHiCpuId; // 7 31-24 int KernelFlagsHiCpuId; // 7 31-24
int KernelFlagsLoCpuId; // 7 23-16 int KernelFlagsLoCpuId; // 7 23-16
int KernelFlagsHiThreadPrio; // 5 15-10 int KernelFlagsHiThreadPrio; // 5 15-10
@ -87,4 +143,14 @@ public class KernelAccessControlProvider {
int HandleTableSize ; int HandleTableSize ;
int DebugFlags; int DebugFlags;
} }
private int getMinBitCnt(int value){
int minBitCnt = 0;
while ((value & 1) != 0){
value >>= 1;
minBitCnt++;
}
return minBitCnt;
}
} }