Compare commits

..

No commits in common. "8cb275da75a4894996ad2d1f232d27f1919e1264" and "cc885164c10c7d48a0560198c95fa162ca3e027a" have entirely different histories.

12 changed files with 28 additions and 195 deletions

1
.gitattributes vendored
View File

@ -1 +0,0 @@
*.mmkv binary

View File

@ -1,10 +0,0 @@
import { Code, Text } from '@chakra-ui/react';
import React from 'react';
export function FilePathBlock({ children }: { children: React.ReactNode }) {
return (
<Text as="pre" whiteSpace="pre-wrap" wordBreak="break-all">
<Code>{children}</Code>
</Text>
);
}

View File

@ -4,8 +4,6 @@ import {
Center, Center,
Flex, Flex,
HStack, HStack,
Icon,
IconButton,
Menu, Menu,
MenuButton, MenuButton,
MenuItem, MenuItem,
@ -23,7 +21,7 @@ import {
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { PanelQMCv2Key } from './panels/PanelQMCv2Key'; import { PanelQMCv2Key } from './panels/PanelQMCv2Key';
import { useState } from 'react'; import { useState } from 'react';
import { MdExpandMore, MdMenu, MdOutlineSettingsBackupRestore } from 'react-icons/md'; import { MdExpandMore, MdMenu } from 'react-icons/md';
import { useAppDispatch } from '~/hooks'; import { useAppDispatch } from '~/hooks';
import { commitStagingChange, discardStagingChanges } from './settingsSlice'; import { commitStagingChange, discardStagingChanges } from './settingsSlice';
@ -106,14 +104,9 @@ export function Settings() {
</Center> </Center>
<Spacer /> <Spacer />
<HStack gap="2" justifyContent="flex-end"> <HStack gap="2" justifyContent="flex-end">
<IconButton <Button onClick={handleResetSettings} colorScheme="red" variant="ghost" title="还原为更改前的状态">
icon={<Icon as={MdOutlineSettingsBackupRestore} />}
onClick={handleResetSettings} </Button>
colorScheme="red"
variant="ghost"
title="放弃未储存的更改,将设定还原为储存前的状态。"
aria-label="放弃未储存的更改"
/>
<Button onClick={handleApplySettings}></Button> <Button onClick={handleApplySettings}></Button>
</HStack> </HStack>
</Flex> </Flex>

View File

@ -45,25 +45,22 @@ export function PanelQMCv2Key() {
QMCv2 QMCv2
</Heading> </Heading>
<Text> <Text>QQ QMCv2 Mac </Text>
QQ QMCv2使QQ Mac iOS
线
</Text>
<Box pb={2} pt={2}> <Box pb={2} pt={2}>
<ButtonGroup isAttached colorScheme="purple" variant="outline"> <ButtonGroup isAttached variant="outline">
<Button onClick={addKey} leftIcon={<Icon as={MdAdd} />}> <Button onClick={addKey} leftIcon={<Icon as={MdAdd} />}>
</Button> </Button>
<Menu> <Menu>
<MenuButton as={IconButton} icon={<MdExpandMore />}></MenuButton> <MenuButton as={IconButton} icon={<MdExpandMore />}></MenuButton>
<MenuList> <MenuList>
<MenuItem onClick={() => setShowImportModal(true)} icon={<Icon as={MdFileUpload} boxSize={5} />}> <MenuItem onClick={() => setShowImportModal(true)} icon={<Icon as={MdFileUpload} boxSize={5} />}>
</MenuItem> </MenuItem>
<MenuDivider /> <MenuDivider />
<MenuItem color="red" onClick={clearAll} icon={<Icon as={MdDeleteForever} boxSize={5} />}> <MenuItem color="red" onClick={clearAll} icon={<Icon as={MdDeleteForever} boxSize={5} />}>
</MenuItem> </MenuItem>
</MenuList> </MenuList>
</Menu> </Menu>

View File

@ -12,7 +12,6 @@ import {
TabPanel, TabPanel,
TabPanels, TabPanels,
Tabs, Tabs,
Text,
useToast, useToast,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
@ -25,8 +24,6 @@ import { InstructionsAndroid } from './InstructionsAndroid';
import { MMKVParser } from '~/util/MMKVParser'; import { MMKVParser } from '~/util/MMKVParser';
import { getFileName } from '~/util/pathHelper'; import { getFileName } from '~/util/pathHelper';
import { InstructionsMac } from './InstructionsMac'; import { InstructionsMac } from './InstructionsMac';
import { InstructionsIOS } from './InstructionsIOS';
import { InstructionsPC } from './InstructionsPC';
export interface ImportFileModalProps { export interface ImportFileModalProps {
show: boolean; show: boolean;
@ -55,7 +52,7 @@ export function ImportFileModal({ onClose, show }: ImportFileModalProps) {
alert(`不是支持的 SQLite 数据库文件。\n表名${qmc2Keys}`); alert(`不是支持的 SQLite 数据库文件。\n表名${qmc2Keys}`);
return; return;
} }
} else if (/MMKVStreamEncryptId|filenameEkeyMap/i.test(file.name)) { } else if (/MMKVStreamEncryptId/i.test(file.name)) {
const fileBuffer = await file.arrayBuffer(); const fileBuffer = await file.arrayBuffer();
const map = MMKVParser.toStringMap(new DataView(fileBuffer)); const map = MMKVParser.toStringMap(new DataView(fileBuffer));
qmc2Keys = Array.from(map.entries(), ([name, key]) => ({ name: getFileName(name), key })); qmc2Keys = Array.from(map.entries(), ([name, key]) => ({ name: getFileName(name), key }));
@ -91,28 +88,18 @@ export function ImportFileModal({ onClose, show }: ImportFileModalProps) {
<FileInput onReceiveFiles={handleFileReceived}></FileInput> <FileInput onReceiveFiles={handleFileReceived}></FileInput>
</Center> </Center>
<Text mt={2}>QQ </Text> <Flex as={Tabs} variant="enclosed" flexDir="column" mt={4} flex={1} minH={0}>
<Flex as={Tabs} variant="enclosed" flexDir="column" flex={1} minH={0}>
<TabList> <TabList>
<Tab></Tab> <Tab></Tab>
<Tab>iOS</Tab> <Tab>Mac </Tab>
<Tab>Mac</Tab>
<Tab>Windows</Tab>
</TabList> </TabList>
<TabPanels flex={1} overflow="auto"> <TabPanels flex={1} overflow="auto">
<TabPanel> <TabPanel>
<InstructionsAndroid /> <InstructionsAndroid />
</TabPanel> </TabPanel>
<TabPanel>
<InstructionsIOS />
</TabPanel>
<TabPanel> <TabPanel>
<InstructionsMac /> <InstructionsMac />
</TabPanel> </TabPanel>
<TabPanel>
<InstructionsPC />
</TabPanel>
</TabPanels> </TabPanels>
</Flex> </Flex>
</Flex> </Flex>

View File

@ -1,101 +0,0 @@
import { Box, Code, Heading, ListItem, OrderedList, Text, UnorderedList } from '@chakra-ui/react';
import { FilePathBlock } from '~/components/FilePathBlock';
const EXAMPLE_MEDIA_ID = '0011wjLv1bIkvv';
const EXAMPLE_NAME_IOS = '333407709-0011wjLv1bIkvv-1.mgalaxy';
const EXAMPLE_NAME_DB = 'Q0M00011wjLv1bIkvv.mflac';
export function InstructionsIOS() {
return (
<>
<Text>使 iOS </Text>
<Heading as="h3" size="md" mt="3">
</Heading>
<Text></Text>
<OrderedList>
<ListItem>
<Text>使 iOS </Text>
</ListItem>
<ListItem>
<Text></Text>
<FilePathBlock>/AppDomain-com.tencent.QQMusic/Documents/mmkv/</FilePathBlock>
</ListItem>
<ListItem>
<Text>
<Code>filenameEkeyMap</Code>
</Text>
</ListItem>
<ListItem>
<Text>
<Code>filenameEkeyMap</Code>
</Text>
</ListItem>
<ListItem>
<Text></Text>
</ListItem>
</OrderedList>
<Heading as="h3" size="md" mt="3">
线
</Heading>
<Box>
<Text></Text>
<Code>/AppDomain-com.tencent.QQMusic/Library/Application Support/com.tencent.QQMusic/iData/iMusic</Code>
<Text>
<Code>*.mgalaxy</Code>
</Text>
<Text>
<Code>[]-[id]-[].mgalaxy</Code>
</Text>
<Text>
&#x3000;<Code>{EXAMPLE_NAME_IOS}</Code>
</Text>
</Box>
<Heading as="h3" size="md" mt="3">
线
</Heading>
<OrderedList>
<ListItem>
<Text>
id <Code>{EXAMPLE_MEDIA_ID}</Code>
</Text>
</ListItem>
<ListItem>
<Text>
<Code>{EXAMPLE_NAME_DB}</Code>
</Text>
</ListItem>
<ListItem>
<Text>
<Code>{EXAMPLE_NAME_IOS}</Code>
<Code>{EXAMPLE_NAME_DB}</Code>
</Text>
</ListItem>
<ListItem>
<Text>
线<Code>{EXAMPLE_NAME_DB}</Code>
</Text>
</ListItem>
</OrderedList>
<Heading as="h3" size="md" mt="3">
</Heading>
<Text></Text>
<UnorderedList>
<ListItem>
<Text></Text>
<FilePathBlock>
/var/mobile/Containers/Data/Application/&lt;&gt;/Documents/mmkv/filenameEkeyMap
</FilePathBlock>
</ListItem>
<ListItem>
<Text>线</Text>
<FilePathBlock>
/var/mobile/Containers/Data/Application/&lt;&gt;/Library/Application
Support/com.tencent.QQMusic/iData/iMusic
</FilePathBlock>
</ListItem>
</UnorderedList>
</>
);
}

View File

@ -1,5 +1,4 @@
import { Heading, Text, Code, Kbd, OrderedList, ListItem } from '@chakra-ui/react'; import { Heading, Text, Code, Kbd, OrderedList, ListItem } from '@chakra-ui/react';
import { FilePathBlock } from '~/components/FilePathBlock';
import { MacCommandKey } from '~/components/Key/MacCommandKey'; import { MacCommandKey } from '~/components/Key/MacCommandKey';
import { ShiftKey } from '~/components/Key/ShiftKey'; import { ShiftKey } from '~/components/Key/ShiftKey';
@ -8,9 +7,12 @@ export function InstructionsMac() {
<> <>
<Text>Mac 使 mmkv </Text> <Text>Mac 使 mmkv </Text>
<Text></Text> <Text></Text>
<FilePathBlock> <Text as="pre" whiteSpace="pre-wrap" wordBreak="break-word" lang="en">
~/Library/Containers/com.tencent.QQMusicMac/Data/Library/Application Support/QQMusicMac/mmkv/MMKVStreamEncryptId <Code>
</FilePathBlock> ~/Library/Containers/com.tencent.QQMusicMac/Data/Library/Application
Support/QQMusicMac/mmkv/MMKVStreamEncryptId
</Code>
</Text>
<Heading as="h3" size="md" mt="4"> <Heading as="h3" size="md" mt="4">

View File

@ -1,9 +0,0 @@
import { Text } from '@chakra-ui/react';
export function InstructionsPC() {
return (
<>
<Text>使 Windows </Text>
</>
);
}

View File

@ -1,29 +1,28 @@
import { formatHex } from './formatHex';
const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }); const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
export class MMKVParser { export class MMKVParser {
private offset = 4; private offset = 8;
private length: number; private length: number;
constructor(private view: DataView) { constructor(private view: DataView) {
const payloadLength = view.getUint32(0, true); const payloadLength = view.getUint32(0, true);
this.length = 4 + payloadLength; this.length = 4 + payloadLength;
// skip unused str
this.readInt();
} }
toString() { toString() {
const offset = formatHex(this.offset, 8); const offset = this.offset.toString(16).padStart(8, '0');
const length = formatHex(this.length, 8); const length = this.length.toString(16).padStart(8, '0');
return `<MMKVParser offset=${offset} len=${length}>`; return `<MMKVParser offset=0x${offset} len=0x${length}>`;
} }
get eof() { get eof() {
return this.offset >= this.length; return this.offset >= this.length;
} }
peek() {
return this.view.getUint8(this.offset);
}
public readByte() { public readByte() {
return this.view.getUint8(this.offset++); return this.view.getUint8(this.offset++);
} }
@ -78,9 +77,7 @@ export class MMKVParser {
const newOffset = this.offset + containerLen; const newOffset = this.offset + containerLen;
const result = this.readString(); const result = this.readString();
if (newOffset !== this.offset) { if (newOffset !== this.offset) {
const expected = formatHex(newOffset); throw new Error('readVariantString failed: offset does not match');
const actual = formatHex(this.offset);
throw new Error(`readVariantString failed: offset does mismatch (expect: ${expected}, actual: ${actual})`);
} }
return result; return result;
} }

View File

@ -1,19 +0,0 @@
import { MMKVParser } from '../MMKVParser';
import { readFileSync } from 'node:fs';
test('parse mmkv file as expected', () => {
const buff = readFileSync(__dirname + '/__fixture__/test.mmkv');
const view = new DataView(buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength));
expect(MMKVParser.toStringMap(view)).toEqual(
new Map([
['key', 'value'],
[
'Lorem Ipsum',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' +
'Vestibulum congue volutpat metus non molestie. Quisque id est sapien. ' +
'Fusce eget tristique sem. Donec tellus lacus, viverra sed lectus eget, elementum ultrices dolor. ' +
'Integer non urna justo.',
],
])
);
});

View File

@ -1,3 +0,0 @@
export function formatHex(value: number, len = 8) {
return '0x' + (value | 0).toString(16).padStart(len, '0');
}