DumpedMethods createDumpedMethods(MyPEImage peImage, byte[] fileData, byte[] methodsData)
        {
            var dumpedMethods = new DumpedMethods();

            var methodsDataReader = MemoryImageStream.Create(methodsData);
            var fileDataReader    = MemoryImageStream.Create(fileData);

            var methodDef = peImage.DotNetFile.MetaData.TablesStream.MethodTable;

            for (uint rid = 1; rid <= methodDef.Rows; rid++)
            {
                var dm = new DumpedMethod();

                peImage.readMethodTableRowTo(dm, rid);
                if (dm.mdRVA == 0)
                {
                    continue;
                }
                uint bodyOffset = peImage.rvaToOffset(dm.mdRVA);

                byte b = peImage.offsetReadByte(bodyOffset);
                uint codeOffset;
                if ((b & 3) == 2)
                {
                    if (b != 2)
                    {
                        continue;                               // not zero byte code size
                    }
                    dm.mhFlags          = 2;
                    dm.mhMaxStack       = 8;
                    dm.mhLocalVarSigTok = 0;
                    codeOffset          = bodyOffset + 1;
                }
                else
                {
                    if (peImage.offsetReadUInt32(bodyOffset + 4) != 0)
                    {
                        continue;                               // not zero byte code size
                    }
                    dm.mhFlags          = peImage.offsetReadUInt16(bodyOffset);
                    dm.mhMaxStack       = peImage.offsetReadUInt16(bodyOffset + 2);
                    dm.mhLocalVarSigTok = peImage.offsetReadUInt32(bodyOffset + 8);
                    codeOffset          = bodyOffset + (uint)(dm.mhFlags >> 12) * 4;
                }
                fileDataReader.Position = codeOffset;

                if (!decrypter.decrypt(fileDataReader, dm))
                {
                    continue;
                }

                dumpedMethods.add(dm);
            }

            return(dumpedMethods);
        }
 byte[] getKeyData(uint baseOffset)
 {
     return(new byte[6] {
         peImage.offsetReadByte(baseOffset + 5),
         peImage.offsetReadByte(baseOffset + 0xF),
         peImage.offsetReadByte(baseOffset + 0x58),
         peImage.offsetReadByte(baseOffset + 0x6D),
         peImage.offsetReadByte(baseOffset + 0x98),
         peImage.offsetReadByte(baseOffset + 0xA6),
     });
 }
예제 #3
0
 byte readByte(uint offset)
 {
     return(peImage.offsetReadByte(methodInfosOffset + offset));
 }
예제 #4
0
        DumpedMethods createDumpedMethods(MyPEImage peImage, byte[] fileData, byte[] methodsData)
        {
            var dumpedMethods = new DumpedMethods();

            var methodsDataReader = MemoryImageStream.Create(methodsData);
            var fileDataReader = MemoryImageStream.Create(fileData);

            var methodDef = peImage.DotNetFile.MetaData.TablesStream.MethodTable;
            for (uint rid = 1; rid <= methodDef.Rows; rid++) {
                var dm = new DumpedMethod();

                peImage.readMethodTableRowTo(dm, rid);
                if (dm.mdRVA == 0)
                    continue;
                uint bodyOffset = peImage.rvaToOffset(dm.mdRVA);

                byte b = peImage.offsetReadByte(bodyOffset);
                uint codeOffset;
                if ((b & 3) == 2) {
                    if (b != 2)
                        continue;	// not zero byte code size

                    dm.mhFlags = 2;
                    dm.mhMaxStack = 8;
                    dm.mhLocalVarSigTok = 0;
                    codeOffset = bodyOffset + 1;
                }
                else {
                    if (peImage.offsetReadUInt32(bodyOffset + 4) != 0)
                        continue;	// not zero byte code size

                    dm.mhFlags = peImage.offsetReadUInt16(bodyOffset);
                    dm.mhMaxStack = peImage.offsetReadUInt16(bodyOffset + 2);
                    dm.mhLocalVarSigTok = peImage.offsetReadUInt32(bodyOffset + 8);
                    codeOffset = bodyOffset + (uint)(dm.mhFlags >> 12) * 4;
                }
                fileDataReader.Position = codeOffset;

                if (!decrypter.decrypt(fileDataReader, dm))
                    continue;

                dumpedMethods.add(dm);
            }

            return dumpedMethods;
        }