From 54501afb1fa54c32dc06cec6a7f18690710a8855 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 17 Apr 2024 08:31:26 +0800 Subject: [PATCH 1/5] Update main_test.js --- lab3/main_test.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lab3/main_test.js b/lab3/main_test.js index 096fd421..3b22f558 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -3,3 +3,50 @@ const assert = require('assert'); const { Calculator } = require('./main'); // TODO: write your tests here + +describe('Calculator', () => { + + describe('exp', () => { + // 檢查 exp 方法在輸入 0、1 和 -1 時。 + it('Calculate correctly', () => { + const calculator = new Calculator(); + assert.strictEqual(calculator.exp(0), 1); + assert.strictEqual(calculator.exp(1), Math.exp(1)); + assert.strictEqual(calculator.exp(-1), 1 / Math.exp(1)); + }); + // 檢查 exp 方法在Infinity(-) 時。 + it('Calculate error', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.exp(NaN), Error); + assert.throws(() => calculator.exp(Infinity), Error); + assert.throws(() => calculator.exp(-Infinity), Error); + }); + // 檢查 exp 方法在 overflow 時。 + it('overflows', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.exp(9999), Error); + }); + }); + + describe('log', () => { + // 檢查 log 方法在輸入 1 和 Math.E 時 + it('calculate orrectly', () => { + const calculator = new Calculator(); + assert.strictEqual(calculator.log(1), 0); + assert.strictEqual(calculator.log(Math.E), 1); + }); + //檢查 log 方法在輸入 NaN、Infinity時 + it('Calculate error', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(NaN), Error); + assert.throws(() => calculator.log(Infinity), Error); + assert.throws(() => calculator.log(-Infinity), Error); + }); + // 檢查 log 方法在輸入 0 和 -1 時 + it('negative infinity or NaN', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(0), Error); + assert.throws(() => calculator.log(-1), Error); + }); + }); +}); From 9f5f9f427e188411f9949238ce6ff410f4e7a846 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:27:40 +0800 Subject: [PATCH 2/5] Update main_test.js --- lab4/main_test.js | 50 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a5..249841e6 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -1,22 +1,44 @@ const puppeteer = require('puppeteer'); (async () => { - // Launch the browser and open a new blank page + // 啟動瀏覽器並打開一個新的空白頁面 const browser = await puppeteer.launch(); const page = await browser.newPage(); + try{ + // 導航至指定網址 + await page.goto('https://pptr.dev/'); + await new Promise(resolve => setTimeout(resolve, 1000)); - // Navigate the page to a URL - await page.goto('https://pptr.dev/'); + // 點擊搜尋按鈕 + await page.click('button.DocSearch.DocSearch-Button'); + await new Promise(resolve => setTimeout(resolve, 1000)); - // Hints: - // Click search button - // Type into search box - // Wait for search result - // Get the `Docs` result section - // Click on first result in `Docs` section - // Locate the title - // Print the title + // 在搜尋框中輸入文字 + await page.waitForSelector('#docsearch-input'); + await page.type('#docsearch-input', 'chipi chipi chapa chapa', { delay: 1000 }); + await new Promise(resolve => setTimeout(resolve, 1000)); - // Close the browser - await browser.close(); -})(); \ No newline at end of file + // 等待搜尋結果 + await page.waitForSelector('#docsearch-item-5'); + await new Promise(resolve => setTimeout(resolve, 1000)); + + // 點擊「Docs」部分的第一個結果 + await page.click('#docsearch-item-5'); + await new Promise(resolve => setTimeout(resolve, 1000)); + + // 定位標題 + await page.waitForSelector('h1'); + + // 獲取標題元素的文字內容 + const title = await page.evaluate(() => { + const titleElement = document.querySelector('h1'); + return titleElement.textContent; + }); + console.log(title); + await browser.close(); + }catch(error){ + console.error('An error occurred:', error); + }finally{ + // 最後都會關閉瀏覽器 + await browser.close();} +})(); From c95ed2fa447a2aad1be05405ed642ad0d74a5df0 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:45:23 +0800 Subject: [PATCH 3/5] Update main_test.js --- lab4/main_test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index 249841e6..1ff2fcf8 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -35,7 +35,6 @@ const puppeteer = require('puppeteer'); return titleElement.textContent; }); console.log(title); - await browser.close(); }catch(error){ console.error('An error occurred:', error); }finally{ From 259ecb6832615c7a0242d674d7caf55bbe82ccf3 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:13:11 +0800 Subject: [PATCH 4/5] Update main_test.js --- lab4/main_test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index 1ff2fcf8..491f0b83 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -7,24 +7,24 @@ const puppeteer = require('puppeteer'); try{ // 導航至指定網址 await page.goto('https://pptr.dev/'); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 點擊搜尋按鈕 await page.click('button.DocSearch.DocSearch-Button'); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 在搜尋框中輸入文字 await page.waitForSelector('#docsearch-input'); await page.type('#docsearch-input', 'chipi chipi chapa chapa', { delay: 1000 }); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 等待搜尋結果 await page.waitForSelector('#docsearch-item-5'); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 點擊「Docs」部分的第一個結果 await page.click('#docsearch-item-5'); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 定位標題 await page.waitForSelector('h1'); From 9e7ebf9833631cbfd57c5bcf005961f264fa3c4c Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 29 May 2024 17:06:30 +0800 Subject: [PATCH 5/5] Update sol.py --- lab7/sol.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lab7/sol.py b/lab7/sol.py index e69de29b..18083edf 100644 --- a/lab7/sol.py +++ b/lab7/sol.py @@ -0,0 +1,14 @@ +import angr, sys + +def success_condition(state): + return b"Login successful" in state.posix.dumps(sys.stdout.fileno()) +def fail_condition(state): + return b"Login failed" in state.posix.dumps(sys.stdout.fileno()) + +proj = angr.Project('./login') +init_state = proj.factory.entry_state() +simulation = proj.factory.simgr(init_state) +simulation.explore(find = success_condition, avoid = fail_condition) +solution = simulation.found[0] + +print(solution.posix.dumps(sys.stdin.fileno()))