repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
aide
github_2023
codestoryai
typescript
SettingsEditor.addUserSettings
async addUserSettings(settings: [key: string, value: string][]): Promise<void> { await this.openUserSettingsFile(); await this.code.dispatchKeybinding('right'); await this.editor.waitForEditorSelection('settings.json', s => s.selectionStart === 1 && s.selectionEnd === 1); await this.editor.waitForTypeInEditor(...
/** * Write several settings faster than multiple calls to {@link addUserSetting}. * * Warning: You will likely also need to set `editor.wordWrap` to `"on"` if `addUserSetting` is * called after this in the test. */
https://github.com/codestoryai/aide/blob/1a8578f21ace8c9381461d295ed31c3500be43bf/test/automation/src/settings.ts#L39-L46
1a8578f21ace8c9381461d295ed31c3500be43bf
aide
github_2023
codestoryai
typescript
Terminal.createTerminal
async createTerminal(expectedLocation?: 'editor' | 'panel'): Promise<void> { await this.runCommand(TerminalCommandId.CreateNew, expectedLocation); await this._waitForTerminal(expectedLocation); }
/** * Creates a terminal using the new terminal command. * @param expectedLocation The location to check the terminal for, defaults to panel. */
https://github.com/codestoryai/aide/blob/1a8578f21ace8c9381461d295ed31c3500be43bf/test/automation/src/terminal.ts#L141-L144
1a8578f21ace8c9381461d295ed31c3500be43bf
aide
github_2023
codestoryai
typescript
Terminal.createEmptyTerminal
async createEmptyTerminal(expectedLocation?: 'editor' | 'panel'): Promise<void> { await this.createTerminal(expectedLocation); // Run a command to ensure the shell has started, this is used to ensure the shell's data // does not leak into the "empty terminal" await this.runCommandInTerminal('echo "initialized"...
/** * Creates an empty terminal by opening a regular terminal and resetting its state such that it * essentially acts like an Pseudoterminal extension API-based terminal. This can then be paired * with `TerminalCommandIdWithValue.WriteDataToTerminal` to make more reliable tests. */
https://github.com/codestoryai/aide/blob/1a8578f21ace8c9381461d295ed31c3500be43bf/test/automation/src/terminal.ts#L151-L166
1a8578f21ace8c9381461d295ed31c3500be43bf
aide
github_2023
codestoryai
typescript
Terminal._waitForTerminal
private async _waitForTerminal(expectedLocation?: 'editor' | 'panel'): Promise<void> { await this.code.waitForElement(Selector.XtermFocused); await this.code.waitForTerminalBuffer(expectedLocation === 'editor' ? Selector.XtermEditor : Selector.Xterm, lines => lines.some(line => line.length > 0)); }
/** * Waits for the terminal to be focused and to contain content. * @param expectedLocation The location to check the terminal for, defaults to panel. */
https://github.com/codestoryai/aide/blob/1a8578f21ace8c9381461d295ed31c3500be43bf/test/automation/src/terminal.ts#L310-L313
1a8578f21ace8c9381461d295ed31c3500be43bf
aide
github_2023
codestoryai
typescript
checkCommandAndOutput
async function checkCommandAndOutput( command: string, exitCode: number, prompt: string = 'Prompt> ', expectedLineCount: number = 1 ): Promise<void> { const data = generateCommandAndOutput(prompt, command, exitCode); await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, ...
// A polling approach is used to avoid test flakiness. While it's not ideal that this
https://github.com/codestoryai/aide/blob/1a8578f21ace8c9381461d295ed31c3500be43bf/test/smoke/src/areas/terminal/terminal-stickyScroll.test.ts#L31-L51
1a8578f21ace8c9381461d295ed31c3500be43bf
bits-ui
github_2023
huntabyte
typescript
setup
function setup(props: ContextMenuTestProps = {}) { const user = userEvent.setup(); const { getByTestId, queryByTestId } = render(ContextMenuTest, { ...props }); const trigger = getByTestId("trigger"); return { getByTestId, queryByTestId, user, trigger, }; }
/** * Helper function to reduce boilerplate in tests */
https://github.com/huntabyte/bits-ui/blob/5d6ad1b82cd9072783676fd5bf5c899636c1d833/packages/bits-ui/src/tests/context-menu/ContextMenu.spec.ts#L14-L24
5d6ad1b82cd9072783676fd5bf5c899636c1d833
bits-ui
github_2023
huntabyte
typescript
getTimeSegments
function getTimeSegments(getByTestId: (...args: any[]) => HTMLElement) { return { hour: getByTestId("hour"), minute: getByTestId("minute"), second: getByTestId("second"), dayPeriod: getByTestId("dayPeriod"), timeZoneName: getByTestId("timeZoneName"), }; }
// eslint-disable-next-line ts/no-explicit-any
https://github.com/huntabyte/bits-ui/blob/5d6ad1b82cd9072783676fd5bf5c899636c1d833/packages/bits-ui/src/tests/date-field/DateField.spec.ts#L520-L528
5d6ad1b82cd9072783676fd5bf5c899636c1d833
bits-ui
github_2023
huntabyte
typescript
setup
function setup(props: DropdownMenuTestProps = {}) { const user = userEvent.setup(); const { getByTestId, queryByTestId } = render(DropdownMenuTest, { ...props }); const trigger = getByTestId("trigger"); return { getByTestId, queryByTestId, user, trigger, }; }
/** * Helper function to reduce boilerplate in tests */
https://github.com/huntabyte/bits-ui/blob/5d6ad1b82cd9072783676fd5bf5c899636c1d833/packages/bits-ui/src/tests/dropdown-menu/DropdownMenu.spec.ts#L15-L25
5d6ad1b82cd9072783676fd5bf5c899636c1d833
bits-ui
github_2023
huntabyte
typescript
setup
function setup(props: Menubar.Props = {}, menuId: string = "1") { const user = userEvent.setup(); const returned = render(MenubarTest, { ...props }); const { getByTestId } = returned; const trigger = getByTestId(`${menuId}-trigger`); return { user, ...returned, trigger }; }
/** * Helper function to reduce boilerplate in tests */
https://github.com/huntabyte/bits-ui/blob/5d6ad1b82cd9072783676fd5bf5c899636c1d833/packages/bits-ui/src/tests/menubar/Menubar.spec.ts#L14-L20
5d6ad1b82cd9072783676fd5bf5c899636c1d833
bits-ui
github_2023
huntabyte
typescript
isCloseEnough
function isCloseEnough(value: number, style: string) { const numStyle = Number.parseFloat(style.replace("%", "")); return Math.abs(numStyle - value) < IS_ENOUGH_CLOSE; }
/** * Unfortunately sometimes floating point arithmetic still strikes * so we need to check that we are close enough rather than precisely */
https://github.com/huntabyte/bits-ui/blob/5d6ad1b82cd9072783676fd5bf5c899636c1d833/packages/bits-ui/src/tests/slider/Slider.spec.ts#L557-L560
5d6ad1b82cd9072783676fd5bf5c899636c1d833
wedges
github_2023
lmsqueezy
typescript
removeTransitionClass
const removeTransitionClass = () => { if (!previewRef.current) { return; } previewRef.current.classList.remove("[&_*]:!transition-none"); };
// This function runs after the render is committed to the screen
https://github.com/lmsqueezy/wedges/blob/f52ebcd23dc55107be48a519d4a6c442475d3462/apps/docs/src/components/PreviewComponent.tsx#L45-L51
f52ebcd23dc55107be48a519d4a6c442475d3462
wedges
github_2023
lmsqueezy
typescript
useButtonGroupContext
function useButtonGroupContext() { const context = React.useContext(ButtonGroupContext); if (!context) { throw new Error("ButtonGroup.Item must be used within a ButtonGroup or ButtonGroup.Root"); } return context; }
/** * Hook to get the current context value for ButtonGroup. * * @returns The current context value for ButtonGroup. * @throws If the context is undefined. */
https://github.com/lmsqueezy/wedges/blob/f52ebcd23dc55107be48a519d4a6c442475d3462/packages/wedges/src/components/ButtonGroup/ButtonGroup.tsx#L47-L55
f52ebcd23dc55107be48a519d4a6c442475d3462
wedges
github_2023
lmsqueezy
typescript
corePlugin
const corePlugin = ( themes: ConfigThemes = {}, defaultTheme: DefaultThemeType, prefix: string, fontSmooth: WedgesOptions["fontSmooth"] ) => { const resolved = resolveConfig(themes, defaultTheme, prefix); const prefixedBaseColors = addPrefix(wedgesPalette, "wg"); const prefixedBoxShadows = addPrefix(boxS...
/** * The core plugin function. */
https://github.com/lmsqueezy/wedges/blob/f52ebcd23dc55107be48a519d4a6c442475d3462/packages/wedges/src/tw-plugin/plugin.ts#L130-L332
f52ebcd23dc55107be48a519d4a6c442475d3462
flatdraw
github_2023
diogocapela
typescript
onPointerDown
const onPointerDown = (event: PointerOrTouchEvent) => { event.preventDefault(); const canvas = canvasRef.current; const context = contextRef.current; if (!canvas || !context) return; const clientX = 'clientX' in event ? event.clientX : event.touches[0]?.clientX; const clientY = 'clientY' in eve...
// On pointer down
https://github.com/diogocapela/flatdraw/blob/26c2a033f199a9afc5f18e478596cbc20f4aa76b/src/components/Canvas.tsx#L85-L253
26c2a033f199a9afc5f18e478596cbc20f4aa76b
flatdraw
github_2023
diogocapela
typescript
onPointerMove
const onPointerMove = (event: PointerOrTouchEvent) => { event.preventDefault(); const canvas = canvasRef.current; const context = contextRef.current; if (!canvas || !context || !actionMode) return; const clientX = 'clientX' in event ? event.clientX : event.touches[0]?.clientX; const clientY = '...
// On pointer move
https://github.com/diogocapela/flatdraw/blob/26c2a033f199a9afc5f18e478596cbc20f4aa76b/src/components/Canvas.tsx#L257-L375
26c2a033f199a9afc5f18e478596cbc20f4aa76b
flatdraw
github_2023
diogocapela
typescript
onPointerUp
const onPointerUp = (event: PointerOrTouchEvent) => { event.preventDefault(); setActionMode(null); const canvas = canvasRef.current; const context = contextRef.current; if (!canvas || !context) return; previousTouchRef.current = null; if ('touches' in event) { distanceBetweenTouchesRe...
// On pointer up
https://github.com/diogocapela/flatdraw/blob/26c2a033f199a9afc5f18e478596cbc20f4aa76b/src/components/Canvas.tsx#L379-L423
26c2a033f199a9afc5f18e478596cbc20f4aa76b
music
github_2023
Sherlockouo
typescript
Main.disableCacheInDev
disableCacheInDev() { if (isDev) { } }
// disable cache in dev
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/index.ts#L105-L108
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
saveBounds
const saveBounds = () => { const bounds = this.win?.getBounds() if (bounds) { store.set('window', bounds) } }
// Save window position
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/index.ts#L233-L238
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
initWindowIpcMain
function initWindowIpcMain(win: BrowserWindow | null) { on(IpcChannels.Minimize, () => { win?.minimize() }) let isMaximized = false let unMaximizeSize: { width: number; height: number } | null = null let windowPosition: { x: number; y: number } | null = null on(IpcChannels.MaximizeOrUnmaximize, () => {...
/** * 处理需要win对象的事件 * @param {BrowserWindow} win */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/ipcMain.ts#L61-L122
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
initTrayIpcMain
function initTrayIpcMain(tray: YPMTray | null) { on(IpcChannels.SetTrayTooltip, (e, { text, coverImg }) => { tray?.setTooltip(text) // console.log('cover ', coverImg) // if (coverImg && coverImg !== '') tray?.setCoverImg(coverImg) }) on(IpcChannels.Like, (e, { isLiked }) => tray?.setLikeState(isLiked...
/** * 处理需要tray对象的事件 * @param {YPMTray} tray */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/ipcMain.ts#L128-L146
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
initTaskbarIpcMain
function initTaskbarIpcMain(thumbar: Thumbar | null) { on(IpcChannels.Play, () => { thumbar?.setPlayState(true) }) on(IpcChannels.Pause, () => thumbar?.setPlayState(false)) }
/** * 处理需要thumbar对象的事件 * @param {Thumbar} thumbar */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/ipcMain.ts#L152-L157
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
initStoreIpcMain
function initStoreIpcMain(win: BrowserWindow | null,store: Store<TypedElectronStore>) { /** * 同步设置到Main */ on(IpcChannels.SyncSettings, (event, settings) => { const lang = store.get('settigns.language') store.set('settings', settings) if(settings.language !== lang ) { main.tray?.updateTr...
/** * 处理需要electron-store的事件 * @param {Store<TypedElectronStore>} store */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/ipcMain.ts#L163-L175
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
initOtherIpcMain
function initOtherIpcMain(win: BrowserWindow | null) { /** * 清除API缓存 */ on(IpcChannels.ClearAPICache, () => { db.truncate(Tables.Track) db.truncate(Tables.Album) db.truncate(Tables.Artist) db.truncate(Tables.Playlist) db.truncate(Tables.ArtistAlbum) db.truncate(Tables.AccountData) ...
/** * 处理其他事件 */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/ipcMain.ts#L180-L393
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
saveBounds
const saveBounds = () => { const bounds = this.win?.getBounds() if (bounds) { store.set('lyricsWindow', bounds) } }
// Save window position
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/lyricsWindow.ts#L75-L80
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
_parseData
function _parseData(data) { const results = { channels: [], playlists: [], streams: [], videos: [], } const isVideo = item => item.videoRenderer && item.videoRenderer.lengthText const getVideoData = item => { const vRender = item.videoRenderer con...
// @credit https://www.npmjs.com/package/@yimura/scraper
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/main/youtube.ts#L61-L96
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
download
async function download(arch: Arch) { console.log(pc.cyan(`Downloading ${arch} binary...`)) if (!electronModuleVersion) { console.log(pc.red('No electron module version found! Skip download.')) return false } const fileName = `better-sqlite3-v${betterSqlite3Version}-electron-v${electronModuleVersion}-${...
// Download better-sqlite library from GitHub Release
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/scripts/build.sqlite3.ts#L66-L121
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
build
async function build(arch: Arch) { const downloaded = await download(arch) if (downloaded) { return } console.log(pc.cyan(`Building for ${arch}...`)) await rebuild({ projectRootPath: projectDir, buildPath: process.cwd(), electronVersion, arch, onlyModules: ['better-sqlite3'], forc...
// Build better-sqlite library on this device
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/desktop/scripts/build.sqlite3.ts#L124-L154
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
stringifyCookie
function stringifyCookie(cookies: string | string[] | undefined) { if (!cookies) return var result = '' for (var i = 0; i < cookies.length; i++) { var cookie = cookies[i] var separatorIndex = cookie.indexOf('=') var name = cookie.substring(0, separatorIndex) var value = cookie.substring(separatorI...
// const getAudioFromYouTube = async (id: number) => {
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/server/src/routes/netease/audio.ts#L126-L138
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
DB.initTables
initTables() { log.info('[db] Initializing database tables...') const init = readSqlFile('init.sql') this.sqlite.exec(init) this.sqlite.pragma('journal_mode=WAL') log.info('[db] Database tables initialized.') }
// }
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/server/src/utils/db.ts#L124-L130
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
scrollToCurrentLine
const scrollToCurrentLine = () => { // 获取所有的歌词行元素 const lines = (containerRef.current as any).querySelectorAll('.lyrics-row') if (lines == null || lines.length == 0) { return } // 获取当前的歌词行元素 const currentLine = lines[currentLineIndex] if (currentLine) { // 如果存在...
// 添加一个钩子函数,在 currentLineIndex 发生变化时,调用一个函数来滚动歌词容器
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/pages/Lyrics/Lyrics.tsx#L63-L80
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
scrollToCurrentLine
const scrollToCurrentLine = () => { // 获取所有的歌词行元素 const lines = (containerRef.current as any).querySelectorAll('.lyrics-row') if (lines == null || lines.length == 0) { return } // 获取当前的歌词行元素 const currentLine = lines[currentLineIndex] if (currentLine) { // 如果存在...
// 添加一个钩子函数,在 currentLineIndex 发生变化时,调用一个函数来滚动歌词容器
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/pages/Lyrics/LyricsDesktop.tsx#L41-L58
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
binarySearch
const binarySearch = (lyric: ParsedLyric) => { const time = lyric.time let low = 0 let high = parsedLyrics.length - 1 while (low <= high) { const mid = Math.floor((low + high) / 2) const midTime = parsedLyrics[mid].time if (midTime === time) { return mid } else if (midT...
// Find the appropriate index to push our parsed lyric.
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/lyric.ts#L29-L48
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player._prevTrackIndex
get _prevTrackIndex(): number | undefined { switch (this.repeatMode) { case RepeatMode.One: return this._trackIndex case RepeatMode.Off: if (this._trackIndex === 0) return 0 return this._trackIndex - 1 case RepeatMode.On: if (this._trackIndex - 1 < 0) return this.tr...
/** * Get prev track index */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L99-L110
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player._nextTrackIndex
get _nextTrackIndex(): number | undefined { switch (this.repeatMode) { case RepeatMode.One: return this._trackIndex case RepeatMode.Off: if (this._trackIndex + 1 >= this.trackList.length) return return this._trackIndex + 1 case RepeatMode.On: if (this._trackIndex + ...
/** * Get next track index */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L115-L126
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.getSongFFT
private getSongFFT() { if (window.env === undefined) return const audioCtx = new window.AudioContext() const analyser = audioCtx.createAnalyser() const source = audioCtx.createMediaElementSource((_howler as any)._sounds[0]._node) if (!invoked) { source.connect(analyser) analyser.connect...
/* @deprecated this will violate CORS rules */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L131-L163
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.nowVolume
get nowVolume(): number { return this._nowVolume }
/** * Get current volume */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L168-L170
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.trackID
get trackID(): TrackID { if (this.mode === Mode.TrackList) { const { trackList, _trackIndex } = this return trackList[_trackIndex] ?? 0 } return this.fmTrackList[0] ?? 0 }
/** * Get current playing track ID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L175-L181
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.trackID
set trackID(value) { const { trackList, _trackIndex } = this trackList[_trackIndex] = value this.fmTrackList[0] = value }
/** * Set current playing track ID * !! */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L187-L191
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.track
get track(): Track | null { return this.mode === Mode.FM ? this.fmTrack : this._track }
/** * Get current playing track */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L196-L198
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.progress
get progress(): number { return this.state === State.Loading ? 0 : this._progress }
/** * Get/Set progress of current track */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L211-L213
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.volume
get volume(): number { return this._volume }
/** * Get/Set current volume */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L222-L224
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player._fetchTrack
private async _fetchTrack(trackID: TrackID) { const response = await fetchTracksWithReactQuery({ ids: [trackID] }) return response?.songs?.length ? response.songs[0] : null }
/** * Fetch track details from Netease based on this.trackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L277-L280
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.setDevice
setDevice(deviceId: MediaDeviceInfo['deviceId']) { // Get the currently playing audio element const audioElement = (_howler as any)._sounds[0]._node audioElement .setSinkId(deviceId) .then(() => { console.log('Audio output device set successfully') }) .catch((error: any) => {...
// set play device
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L283-L294
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player._fetchAudioSource
private async _fetchAudioSource(trackID: TrackID) { try { // console.log(`[player] fetchAudioSourceWithReactQuery `, trackID) const response = await fetchAudioSourceWithReactQuery({ id: trackID }) // console.log(`[player] fetchAudioSourceWithReactQuery `, response) let audio = response.data?...
/** * Fetch track audio source url from Netease * @param {TrackID} trackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L304-L323
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player._playTrack
private async _playTrack() { const id = this.trackID if (!id) return this.state = State.Loading const track = await this._fetchTrack(id) if (!track) { toast('加载歌曲信息失败') return } if (this.mode === Mode.TrackList) this._track = track if (this.mode === Mode.FM) this.fmTrack = tr...
/** * Play a track based on this.trackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L328-L341
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player._playAudio
private async _playAudio(autoplay: boolean = true) { this._progress = 0 const { audio, id } = await this._fetchAudioSource(this.trackID) if (!audio) { toast('无法播放此歌曲') this.nextTrack() return } if (this.trackID !== id) return this._playAudioViaHowler(audio, id, autoplay) }
/** * Play audio via howler */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L346-L357
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.play
play(fade: boolean = false) { if (_howler.playing()) { this.state = State.Playing return } _howler.play() if (fade) { this.state = State.Playing _howler.once('play', () => { _howler.fade(0, this._volume, PLAY_PAUSE_FADE_DURATION) }) } else { this.state = S...
/** * Play current track * @param {boolean} fade fade in */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L440-L454
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.pause
pause(fade: boolean = false) { if (fade) { _howler.fade(this._volume, 0, PLAY_PAUSE_FADE_DURATION) this.state = State.Paused _howler.once('fade', () => { _howler.pause() }) } else { this.state = State.Paused _howler.pause() } }
/** * Pause current track * @param {boolean} fade fade out */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L460-L471
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.playOrPause
playOrPause(fade: boolean = true) { this.state === State.Playing ? this.pause(fade) : this.play(fade) }
/** * Play or pause current track * @param {boolean} fade fade in-out */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L477-L479
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.prevTrack
prevTrack() { this._setStateToLoading() this._progress = 0 if (this.mode === Mode.FM) { toast('Personal FM not support previous track') return } if (this._prevTrackIndex === undefined) { toast('No previous track') return } this._trackIndex = this._prevTrackIndex t...
/** * Play previous track */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L484-L497
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.nextTrack
nextTrack(forceFM: boolean = false) { this._setStateToLoading() this._progress = 0 if (forceFM || this.mode === Mode.FM) { this.mode = Mode.FM this._nextFMTrack() return } if (this._nextTrackIndex === undefined) { toast('没有下一首了') this.pause() return } this...
/** * Play next track */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L502-L518
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.playAList
playAList(list: TrackID[], autoPlayTrackID?: null | number) { this._setStateToLoading() this.mode = Mode.TrackList this.trackList = list this._trackIndex = autoPlayTrackID ? list.findIndex(t => t === autoPlayTrackID) : 0 this._playTrack() }
/** * 播放一个track id列表 * @param {number[]} list * @param {null|number} autoPlayTrackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L525-L531
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.addToFirstPlay
addToFirstPlay(trackID: number) { console.log(`trackID:${trackID}`) // 判重 if (this.trackList.includes(trackID)) { this.trackList = this.trackList.filter(item => item != trackID) this.trackList.splice(0, 0, trackID) return } this.trackList.splice(0, 0, trackID) }
/** * * @param trackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L537-L546
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.addToNextPlay
addToNextPlay(trackID: number) { // 判重 if (this.trackList.includes(trackID)) { this.trackList = this.trackList.filter(item => item != trackID) this.trackList.splice(Number(this._nextTrackIndex), 0, trackID) return } this.trackList.splice(Number(this._nextTrackIndex), 0, trackID) }
/** * * @param trackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L552-L560
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.deleteFromPlaylist
deleteFromPlaylist(trackID: number) { // Check if the song existed in the tracklist if (!this.trackList.includes(trackID)) { return } // Check whether we are deleting the content that we are playing if (this.track?.id != undefined && this.track?.id != trackID){ this.trackList = this.trac...
/** * deleteFromPlaylist() - function to remove a track from current play queue * * @param trackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L568-L582
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.addToPlayList
addToPlayList(trackID: number) { // 判重 if (this.trackList.includes(trackID)) { return } this.trackList.push(trackID) }
/** * * @param trackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L588-L594
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.playPlaylist
async playPlaylist(id: number | undefined, autoPlayTrackID?: null | number) { if (!id) { toast.error('无法播放: 歌单不存在') return } this._setStateToLoading() const playlist = await fetchPlaylistWithReactQuery({ id }) if (!playlist?.playlist?.trackIds?.length) return this.trackListSource = {...
/** * Play a playlist * @param {number} id * @param {null|number=} autoPlayTrackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L601-L617
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.shufflePlayList
async shufflePlayList() { let playingSongID = this.trackList[this._trackIndex] if (this.shuffle) { this.trackList = Array.from(this.originTrackList) this._trackIndex = this.trackList.indexOf(playingSongID) this.shuffle = !this.shuffle return } this.originTrackList = Array.from(th...
/** * shuffle the playList * algorithm: https://bost.ocks.org/mike/shuffle/ */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L623-L644
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.playAlbum
async playAlbum(id: number, autoPlayTrackID?: null | number) { this._setStateToLoading() const album = await fetchAlbumWithReactQuery({ id }) if (!album?.songs?.length) return this.trackListSource = { type: TrackListSourceType.Album, id, } this.playAList( album.songs.map(t => t...
/** * Play an album * @param {number} id * @param {null|number=} autoPlayTrackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L651-L663
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.playArtistPopularTracks
async playArtistPopularTracks(id: number, autoPlayTrackID?: null | number) { this._setStateToLoading() const artist = await fetchArtistWithReactQuery({ id }) if (!artist?.hotSongs.length) { toast('无法播放: 没有热门歌曲') return } this.trackListSource = { type: TrackListSourceType.Artist, ...
/** * Listen artist's popular tracks * @param {number} id * @param {null|number=} autoPlayTrackID */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L670-L685
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.playFM
async playFM() { this._setStateToLoading() this.mode = Mode.FM if (this.fmTrackList.length > 0 && this.fmTrack?.id === this.fmTrackList[0]) { this._track = this.fmTrack this._playAudio() } else { this._playTrack() } }
/** * Play personal fm */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L690-L699
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.fmTrash
async fmTrash() { this.mode = Mode.FM const trashTrackID = this.fmTrackList[0] fmTrash(trashTrackID) this._nextFMTrack() }
/** * Trash current PersonalFMTrack */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L704-L709
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
music
github_2023
Sherlockouo
typescript
Player.playTrack
async playTrack(trackID: TrackID) { this._setStateToLoading() const index = this.trackList.findIndex(t => t === trackID) if (index === -1) toast('播放失败,歌曲不在列表内') this._trackIndex = index this._playTrack() }
/** * Play track in trackList by id */
https://github.com/Sherlockouo/music/blob/dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f/packages/web/utils/player.ts#L714-L720
dc20e3bbf53edf7f4b83e7a8b7cf1abc78e4e20f
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Deobfuscator.constructor
constructor(ast: t.File, config: Config = defaultConfig) { this.ast = ast; this.config = config; }
/** * Creates a new deobfuscator. * @param ast The AST. * @param config The config (optional). */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/deobfuscator.ts#L43-L46
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Deobfuscator.execute
public execute(): string { let types = this.transformationTypes.filter(t => this.config[t.properties.key].isEnabled); let i = 0; while (i < Deobfuscator.MAX_ITERATIONS) { let isModified = false; if (!this.config.silent) { console.log(`\n[${new Date().toI...
/** * Executes the deobfuscator. * @returns The simplified code. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/deobfuscator.ts#L52-L107
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Deobfuscator.clearCache
private clearCache(): void { (traverse as any).cache.clear(); }
/** * Clears the traversal cache to force the scoping to be handled * again on the next traverse. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/deobfuscator.ts#L113-L115
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ConstantDeclarationVariable.constructor
constructor(declaratorPath: NodePath<t.Node>, name: string, binding: Binding, expression: T) { super(name, binding, expression); this.declaratorPath = declaratorPath; }
/** * Creates a new constant variable that is declared and initialised immediately. * @param declaratorPath The path of the variable declarator. * @param name The name of the variable. * @param binding The binding. * @param expression The value the variable holds. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/variable.ts#L37-L40
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ConstantDeclarationVariable.remove
public remove(): void { this.declaratorPath.remove(); }
/** * Removes the variable. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/variable.ts#L45-L47
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ConstantAssignmentVariable.constructor
constructor( declaratorPath: NodePath<t.Node>, assignmentPath: NodePath<t.AssignmentExpression>, name: string, binding: Binding, expression: T ) { super(name, binding, expression); this.declaratorPath = declaratorPath; this.assignmentPath = assignmentP...
/** * Creates a new constant variable that is declared with no value then assigned to later. * @param declaratorPath The path of the variable declarator. * @param assignmentPath The path of the assignment to the variable. * @param name The name of the variable. * @param binding The binding. ...
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/variable.ts#L62-L72
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ConstantAssignmentVariable.remove
public remove(): void { this.declaratorPath.remove(); // only safe to remove an assignment if the parent doesn't rely on it if ( this.assignmentPath.parentPath && this.assignmentPath.parentPath.isExpressionStatement() ) { this.assignmentPath.remove();...
/** * Removes the variable. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/variable.ts#L77-L89
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isConstantBinding
function isConstantBinding(path: NodePath, binding: Binding): boolean { return ( binding.constant || (binding.constantViolations.length == 1 && path.node == binding.path.node && path.node == binding.constantViolations[0].node) ); }
/** * Returns whether a binding is constant for our purposes. Babel views * 'var' declarations within loops as non constants so this acts as a fix * for that. * @param path The path. * @param binding The binding. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/variable.ts#L153-L160
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isConstantAssignedBinding
function isConstantAssignedBinding( path: NodePath<t.AssignmentExpression>, binding: Binding ): boolean { if ( ((binding.path.isVariableDeclarator() && binding.path.node.init == undefined) || binding.path.parentKey === 'params') && // either variable declarator with no initialiser or par...
/** * Returns whether a binding with a single assignment expression (separate * to the declaration) can be treated as constant. * @param path The path. * @param binding The binding. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/variable.ts#L169-L192
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Base64StringDecoder.constructor
constructor(stringArray: string[], indexOffset: number) { super(stringArray, indexOffset); this.stringCache = new Map(); }
/** * Creates a new base 64 string decoder. * @param stringArray The string array. * @param indexOffset The offset used when accessing elements by index. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/base64StringDecoder.ts#L12-L15
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Base64StringDecoder.type
public get type(): DecoderType { return DecoderType.BASE_64; }
/** * Returns the type of the decoder. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/base64StringDecoder.ts#L20-L22
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Base64StringDecoder.getString
public getString(index: number): string { const cacheKey = index + this.stringArray[0]; if (this.stringCache.has(cacheKey)) { return this.stringCache.get(cacheKey) as string; } const encoded = this.stringArray[index + this.indexOffset]; const str = base64Transform(en...
/** * Decodes a string. * @param index The index. * @returns The string. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/base64StringDecoder.ts#L29-L39
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Base64StringDecoder.getStringForRotation
public getStringForRotation(index: number): string { if (this.isFirstCall) { this.isFirstCall = false; throw new Error(); } return this.getString(index); }
/** * Decodes a string for the rotate string call. * @param index The index. * @returns THe string. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/base64StringDecoder.ts#L46-L53
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
BasicStringDecoder.type
public get type(): DecoderType { return DecoderType.BASIC; }
/** * Returns the type of the decoder. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/basicStringDecoder.ts#L7-L9
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
BasicStringDecoder.getString
public getString(index: number): string { return this.stringArray[index + this.indexOffset]; }
/** * Decodes a string. * @param index The index. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/basicStringDecoder.ts#L15-L17
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
BasicStringDecoder.getStringForRotation
public getStringForRotation(index: number): string { return this.getString(index); }
/** * Decodes a string for the rotate string call. * @param index The index. * @returns THe string. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/basicStringDecoder.ts#L24-L26
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Rc4StringDecoder.constructor
constructor(stringArray: string[], indexOffset: number) { super(stringArray, indexOffset); this.stringCache = new Map(); }
/** * Creates a new RC4 string decoder. * @param stringArray The string array. * @param indexOffset The offset used when accessing elements by index. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/rc4StringDecoder.ts#L12-L15
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Rc4StringDecoder.type
public get type(): DecoderType { return DecoderType.RC4; }
/** * Returns the type of the decoder. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/rc4StringDecoder.ts#L20-L22
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Rc4StringDecoder.getString
public getString(index: number, key: string): string { const cacheKey = index + this.stringArray[0]; if (this.stringCache.has(cacheKey)) { return this.stringCache.get(cacheKey) as string; } const encoded = this.stringArray[index + this.indexOffset]; const str = this....
/** * Decodes a string. * @param index The index. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/rc4StringDecoder.ts#L28-L38
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Rc4StringDecoder.getStringForRotation
public getStringForRotation(index: number, key: string): string { if (this.isFirstCall) { this.isFirstCall = false; throw new Error(); } return this.getString(index, key); }
/** * Decodes a string for the rotate string call. * @param index The index. * @returns THe string. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/rc4StringDecoder.ts#L45-L52
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
Rc4StringDecoder.rc4Decode
private rc4Decode(str: string, key: string): string { const s = []; let j = 0; let decoded = ''; str = base64Transform(str); for (var i = 0; i < 256; i++) { s[i] = i; } for (var i = 0; i < 256; i++) { j = (j + s[i] + key.charCodeAt(i % ke...
/** * Decodes a string encoded with RC4. * @param str The RC4 encoded string. * @param key The key. * @returns The decoded string. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/decoders/rc4StringDecoder.ts#L60-L85
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
parseOperation
function parseOperation( expression: t.BinaryExpression | t.UnaryExpression | t.CallExpression | t.NumericLiteral, decoderMap: Map<string, StringDecoder> ): Operation { switch (expression.type) { case 'CallExpression': return parseCallOperation(expression, decoderMap); case 'Unar...
/** * Parses an operation. * @param expression The expression. * @param decoderMap The string decoder map. * @returns The operation. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/rotation/rotation.ts#L45-L59
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
parseCallOperation
function parseCallOperation( expression: t.CallExpression, decoderMap: Map<string, StringDecoder> ): CallOperation { if ( !t.isIdentifier(expression.callee) || expression.callee.name != 'parseInt' || expression.arguments.length != 1 || !t.isCallExpression(expression.arguments...
/** * Parses a call operation. * @param expression The call expression. * @param decoderMap The string decoder map. * @returns The call operation. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/rotation/rotation.ts#L67-L104
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
parseUnaryOperation
function parseUnaryOperation( expression: t.UnaryExpression, decoderMap: Map<string, StringDecoder> ): UnaryOperation { if (!unaryOperatorSet.has(expression.operator)) { throw new Error(`Unsupported unary operator ${expression.operator}`); } else if (!operationSet.has(expression.argument.type)) ...
/** * Parses a unary operation. * @param expression The unary expression. * @param decoderMap The string decoder map. * @returns The unary operation. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/rotation/rotation.ts#L112-L128
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
parseBinaryOperation
function parseBinaryOperation( expression: t.BinaryExpression, decoderMap: Map<string, StringDecoder> ): BinaryOperation { if (!binaryOperatorSet.has(expression.operator)) { throw new Error(`Unsupported binary operator ${expression.operator}`); } else if (!operationSet.has(expression.left.type))...
/** * Parses a binary operation. * @param expression The binary expression. * @param decoderMap The string decoder map. * @returns The binary operation. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/rotation/rotation.ts#L136-L156
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
applyOperation
function applyOperation(operation: Operation): any { switch (operation.type) { case 'CallOperation': return applyCall(operation); case 'UnaryOperation': return applyUnaryOperation(operation); case 'BinaryOperation': return applyBinaryOperation(operation); ...
/** * Applies an operation. * @param operation The operation. * @returns The result. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/rotation/rotation.ts#L163-L174
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
applyCall
function applyCall(call: CallOperation): any { return parseInt( (call.decoder.getStringForRotation as (...args: (number | string)[]) => string)( ...call.args ) ); }
/** * Applies a call of a string decoder. * @param call The call. * @returns The result. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/rotation/rotation.ts#L181-L187
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
applyUnaryOperation
function applyUnaryOperation(operation: UnaryOperation): any { const argument = applyOperation(operation.argument); switch (operation.operator) { case '-': return -argument; } }
/** * Applies a unary operation. * @param operation The unary operation. * @returns The result. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/rotation/rotation.ts#L194-L201
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
applyBinaryOperation
function applyBinaryOperation(operation: BinaryOperation): any { const left = applyOperation(operation.left); const right = applyOperation(operation.right); switch (operation.operator) { case '+': return left + right; case '-': return left - right; case '*': ...
/** * Applies a binary operation. * @param operation The binary operation. * @returns The result. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/helpers/strings/rotation/rotation.ts#L208-L224
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
ControlFlowRecoverer.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { enter(path) { const stateVariable = findConstantVariable<StateArrayExpression>(path, isStateArrayExpression); if (!stateVariable) { return; ...
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/controlFlowRecoverer.ts#L17-L87
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isStateArrayExpression
const isStateArrayExpression = (node: t.Node): node is StateArrayExpression => { return ( t.isCallExpression(node) && t.isMemberExpression(node.callee) && t.isStringLiteral(node.callee.object) && ((t.isStringLiteral(node.callee.property) && node.callee.property.value == 'split') || ...
/** * Returns whether a node is a state array expression. * @param node The node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/controlFlowRecoverer.ts#L100-L110
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isFlatteningLoopBody
const isFlatteningLoopBody = (node: t.Node, statesName: string, counterName: string): node is FlatteningLoopBody => { return ( t.isBlockStatement(node) && node.body.length == 2 && t.isBreakStatement(node.body[1]) && t.isSwitchStatement(node.body[0]) && t.isMemberExpression(no...
/** * Returns whether a node is the body of a control flow flattening loop. * @param node The AST node. * @param statesName The name of the variable containing the states. * @param counterName The name of the block counter variable. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/controlFlowRecoverer.ts#L132-L146
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isFlatteningForLoop
const isFlatteningForLoop = (node: t.Node, statesName: string): node is FlatteningForLoop => { return ( t.isForStatement(node) && node.init != undefined && isDeclarationOrAssignmentExpression(node.init, t.isIdentifier, t.isNumericLiteral) && isFlatteningLoopBody( node.bod...
/** * Returns whether a node is a control flow flattening for loop. * @param node The node. * @param statesName The name of the variable containing the states. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/controlFlowRecoverer.ts#L159-L170
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
isFlatteningWhileLoop
const isFlatteningWhileLoop = (node: t.Node, statesName: string, counterName: string): node is FlatteningWhileLoop => { return ( t.isWhileStatement(node) && t.isBooleanLiteral(node.test) && node.test.value == true && isFlatteningLoopBody(node.body, statesName, counterName) ); };
/** * Returns whether a node is a control flow flattening while loop. * @param node The node. * @param statesName The name of the variable containing the states. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/controlFlowRecoverer.ts#L183-L190
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
DeadBranchRemover.execute
public execute(log: LogFunction): boolean { const self = this; traverse(this.ast, { IfStatement(path) { if (self.isSemiLiteral(path.node.test)) { if (self.isTruthy(path.node.test)) { const statements = t.isBlockStatement(path.node....
/** * Executes the transformation. * @param log The log function. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/deadBranchRemover.ts#L15-L71
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
DeadBranchRemover.isSemiLiteral
private isSemiLiteral(node: t.Node): node is t.Literal | t.ArrayExpression | t.ObjectExpression { return t.isLiteral(node) || t.isArrayExpression(node) || t.isObjectExpression(node); }
/** * Returns whether a node is a literal or can be treated as one in the context of a test expression. * @param node The node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/deadBranchRemover.ts#L78-L80
686b3dce0aeadb100c262ba6cbe1e04812217736
obfuscator-io-deobfuscator
github_2023
ben-sb
typescript
DeadBranchRemover.isTruthy
private isTruthy(literal: t.Literal | t.ArrayExpression | t.ObjectExpression): boolean { return t.isBooleanLiteral(literal) || t.isNumericLiteral(literal) || t.isStringLiteral(literal) ? !!literal.value : true; }
/** * Returns whether a literal node is truthy. * @param literal The literal node. * @returns Whether. */
https://github.com/ben-sb/obfuscator-io-deobfuscator/blob/686b3dce0aeadb100c262ba6cbe1e04812217736/src/deobfuscator/transformations/controlFlow/deadBranchRemover.ts#L87-L91
686b3dce0aeadb100c262ba6cbe1e04812217736