Browse Source

Allow user to pick a PNG embedding method

pull/46/head
coomdev 2 years ago
parent
commit
e91e692def
  1. 14
      src/Components/App.svelte
  2. 28
      src/pngv3.ts

14
src/Components/App.svelte

@ -34,7 +34,6 @@
function appendBooru() { function appendBooru() {
if (execution_mode != "userscript") { if (execution_mode != "userscript") {
request(newbooru.domain!); request(newbooru.domain!);
alert("Requested! Please click the PEE icon to validate");
} }
$settings.rsources = [...$settings.rsources, newbooru as any]; $settings.rsources = [...$settings.rsources, newbooru as any];
@ -119,6 +118,7 @@
<Tab>File Host</Tab> <Tab>File Host</Tab>
<Tab on:select={() => updateThreads()}>Thread Watcher</Tab> <Tab on:select={() => updateThreads()}>Thread Watcher</Tab>
<Tab on:select={() => updateNews()}>Reminder</Tab> <Tab on:select={() => updateNews()}>Reminder</Tab>
<Tab>Advanced</Tab>
{#if $appState.akValid} {#if $appState.akValid}
<Tab>Hydrus</Tab> <Tab>Hydrus</Tab>
{/if} {/if}
@ -395,6 +395,16 @@
{/if} {/if}
</div> </div>
</TabPanel> </TabPanel>
<TabPanel>
<label>
PNG Embedding method
<select bind:value={$settings.pmeth}>
{#each [0, 1, 2, 3, 4] as m}
<option value={m}>Method {m}</option>
{/each}
</select>
</label>
</TabPanel>
{#if $appState.akValid} {#if $appState.akValid}
<TabPanel> <TabPanel>
<HydrusSearch /> <HydrusSearch />
@ -445,7 +455,7 @@
text-align: center; text-align: center;
margin: 0; margin: 0;
} }
.form { .form {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

28
src/pngv3.ts

@ -57,6 +57,8 @@ const extract = async (png: Buffer) => {
const sneed = new PNGDecoder(reader); const sneed = new PNGDecoder(reader);
const ret: EmbeddedFile[] = []; const ret: EmbeddedFile[] = [];
let w: Buffer | undefined; let w: Buffer | undefined;
if (!csettings)
throw new Error("Settings uninit");
try { try {
for await (const [name, chunk, crc, offset] of sneed.chunks()) { for await (const [name, chunk, crc, offset] of sneed.chunks()) {
@ -103,7 +105,7 @@ const extract = async (png: Buffer) => {
}).join(' '); }).join(' ');
const k = await decodeCoom3Payload(Buffer.from(decoded)); const k = await decodeCoom3Payload(Buffer.from(decoded));
ret.push(...k.filter(e => e).map(e => e as EmbeddedFile)); ret.push(...k.filter(e => e).map(e => e as EmbeddedFile));
} catch(e) { } catch (e) {
// //
} }
} }
@ -144,6 +146,8 @@ export const BufferWriteStream = () => {
}; };
export const inject_data = async (container: File, injb: Buffer) => { export const inject_data = async (container: File, injb: Buffer) => {
if (!csettings)
throw new Error("Settings uninit");
let magic = false; let magic = false;
const [writestream, extract] = BufferWriteStream(); const [writestream, extract] = BufferWriteStream();
const encoder = new PNGEncoder(writestream); const encoder = new PNGEncoder(writestream);
@ -154,8 +158,24 @@ export const inject_data = async (container: File, injb: Buffer) => {
break; break;
if (!magic && name == "IDAT") { if (!magic && name == "IDAT") {
const passed = Buffer.from(injb); const passed = Buffer.from(injb);
//xor(passed, password2); switch (csettings.pmeth) {
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", Buffer.concat([CUM7, passed])), () => Promise.resolve(0), 0]); case 0:
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", Buffer.concat([CUM3, passed])), () => Promise.resolve(0), 0]);
break;
case 1:
xor(passed, password);
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", Buffer.concat([CUM4, Buffer.from(Buffer.from(passed).toString("base64"))])), () => Promise.resolve(0), 0]);
break;
case 2:
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", Buffer.concat([CUM5, Buffer.from(Buffer.from(passed).toString("base64"))])), () => Promise.resolve(0), 0]);
break;
case 3:
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", Buffer.concat([CUM6, Buffer.from(Buffer.from(passed).toString("base64"))])), () => Promise.resolve(0), 0]);
break;
case 4:
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", Buffer.concat([CUM7, Buffer.from(bs58.encode(passed))])), () => Promise.resolve(0), 0]);
break;
}
magic = true; magic = true;
} }
await encoder.insertchunk([name, chunk, crc, offset]); await encoder.insertchunk([name, chunk, crc, offset]);
@ -178,7 +198,7 @@ const inject = async (container: File, links: string[]) => {
} }
return ''; return '';
}); });
const injb = Buffer.from(bs58.encode(Buffer.from(links.join(' ')))); const injb = Buffer.from(links.join(' '));
return inject_data(container, injb); return inject_data(container, injb);
}; };

Loading…
Cancel
Save