tag:blogger.com,1999:blog-11369270383695773352024-03-13T22:57:32.800+08:00CK's IT blogThis is my blog on the development of <br>iPhone & Android in ChromeOS, Mac, Windows & Linux.
<br>Unknownnoreply@blogger.comBlogger244125tag:blogger.com,1999:blog-1136927038369577335.post-26457999232462816232022-11-14T22:41:00.004+08:002022-11-14T22:43:21.236+08:00How to play XBOX games on Mac / PC(1) Download and install the XEMU Emulator from <a href="https://xemu.app/docs/download/" target="_blank">https://xemu.app/docs/download/</a><br><br>
(2) Download the BIOS and everything you need to run XEMU from <a href="https://archive.org/download/xemustarter/XEMU%20FILES.zip" target="_blank">here</a> <br><br>
(3) Download the playable xiso for the XEMU emulator from <a href="https://archive.org/download/metal-gear-solid-2-substance-usa" target="_blank">here</a> and <a href="https://archive.org/download/microsoft-xbox-xemu.xisoready-software-collection-part-2" target="_blank">here</a><br><br>
(4) Set up the controller, BIOS and everything in the app and then load the xiso from step (3) above and then use the app menu to Reset. <br><br>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg72dewYod3MY03CeMigJrVTyatAJ52lcc9M7Pia5BOlrObiw3ycnxzHdI-VU6zImVRNi8NJFyk9djEijM0FPva21vqyrEdGSlKTORGT2KC0GZv6zUbHZUFdyt23DdSwjbTfRL4zaqdIFaeSns79bKOaJmXx8wZL3pQPF4HNv1iApvA2jm6nF1t8aeENg/s3268/xemu_set.jpg" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="600" data-original-height="1256" data-original-width="3268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg72dewYod3MY03CeMigJrVTyatAJ52lcc9M7Pia5BOlrObiw3ycnxzHdI-VU6zImVRNi8NJFyk9djEijM0FPva21vqyrEdGSlKTORGT2KC0GZv6zUbHZUFdyt23DdSwjbTfRL4zaqdIFaeSns79bKOaJmXx8wZL3pQPF4HNv1iApvA2jm6nF1t8aeENg/s600/xemu_set.jpg"/></a></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-59463549120495697752022-11-13T03:58:00.002+08:002022-11-14T22:40:40.672+08:00How to patch Redream x86_64 binary<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH55D210JNAp1q5pFeX_GXxrHyc9xnYNXcTJ9K8wwNtwm0PK-ML04gZZkgdB_MUreL4mMgv0gaktYBVDoLuBGN7cdtUuySfoZj43LIC2rmPOX7eNb92UaaVqeOvu0BfDlUoR66y7D82go2MeSggJWsB4BBpv4rbviDsy9wB0Z2BZVSBRaBoFUqXt1JSw/s1915/redream_game.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="600" data-original-height="961" data-original-width="1915" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH55D210JNAp1q5pFeX_GXxrHyc9xnYNXcTJ9K8wwNtwm0PK-ML04gZZkgdB_MUreL4mMgv0gaktYBVDoLuBGN7cdtUuySfoZj43LIC2rmPOX7eNb92UaaVqeOvu0BfDlUoR66y7D82go2MeSggJWsB4BBpv4rbviDsy9wB0Z2BZVSBRaBoFUqXt1JSw/s400/redream_game.png"/></a></div>
This is how it said <a href="https://arch.b4k.co/vg/thread/264792040/#264802560" target="_blank">here</a> to patch the unzipped executable file in redream.x86_64-windows-v1.5.0-1045-g9f00768.zip
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoogkOEBCZdzENm5lLIy2Yeo7102Ky9acKGhQIDFEqGCbGj50WvePpIpt4M4kgHTqT788cDbgRQXKcTs5jTqq8yY29DNAmq_LaXuQeZ5wQW6RbERgDdYZA-oKldtApi_6MAN7yo81zEI7Yv7Cvh3DoMBm5QYKMMkiFk0IEWzdLTS_dW1rad_BwnDFisw/s1205/redream_1.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="400" data-original-height="312" data-original-width="1205" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoogkOEBCZdzENm5lLIy2Yeo7102Ky9acKGhQIDFEqGCbGj50WvePpIpt4M4kgHTqT788cDbgRQXKcTs5jTqq8yY29DNAmq_LaXuQeZ5wQW6RbERgDdYZA-oKldtApi_6MAN7yo81zEI7Yv7Cvh3DoMBm5QYKMMkiFk0IEWzdLTS_dW1rad_BwnDFisw/s400/redream_1.png"/></a></div>
see the patched file below screen dump with the red hex byte, I use linux tool vbindiff in WSL2 to show the difference of the two binary files <b>vbindiff redream.exe redream_patch.exe</b>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj3Bye9yfYGDRgbBc3JOevQr6_vRO-KLC7p2AVqVwBRGfnWz8JF1ng6kC39sT_dOrx_3dQbCZVphPTTSdJaHB9YKDeJLy7c62Mear_1jsi84X3wxbkkVKq-LqFf-e1JvfJMUBDpk9WvpCa0NkGJdO1ukbMnDxC043t56aFguDW81DIAyyKXyo892YhgA/s1600/redream_patched.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="600" data-original-height="634" data-original-width="1119" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj3Bye9yfYGDRgbBc3JOevQr6_vRO-KLC7p2AVqVwBRGfnWz8JF1ng6kC39sT_dOrx_3dQbCZVphPTTSdJaHB9YKDeJLy7c62Mear_1jsi84X3wxbkkVKq-LqFf-e1JvfJMUBDpk9WvpCa0NkGJdO1ukbMnDxC043t56aFguDW81DIAyyKXyo892YhgA/s1600/redream_patched.png"/></a></div>
Game Rom (GDI format with cheats) can be found <a href="https://archive.org/details/ef_SEGA_GDI_USA" target="_blank">here</a> or <a href="https://archive.org/download/Dreamcast-GDI-Arquivista" target="_blank">here</a>
<br/><br/>
Linux x86_64 patch pattern is here <b>vbindiff redream redream_patched</b>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgXMOGhGf_Th_wRKuJKB-mEylk96YE2BX0KRq_uyLdGmTWpJ0yQoz3ZWRXsjJepSHqqS3KaqTtggPhoCg8Mi_mYpYKshFHmEBT4U0O_FzQaQfkE35BSahzraILQP0wftLFI3XUSg5ugRxjMfFn9O3XkPAoY5JvB5QHMEtz1vPh1CzIWT_IZIReSIKG/s811/redream_patch_linux.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="400" data-original-height="685" data-original-width="811" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgXMOGhGf_Th_wRKuJKB-mEylk96YE2BX0KRq_uyLdGmTWpJ0yQoz3ZWRXsjJepSHqqS3KaqTtggPhoCg8Mi_mYpYKshFHmEBT4U0O_FzQaQfkE35BSahzraILQP0wftLFI3XUSg5ugRxjMfFn9O3XkPAoY5JvB5QHMEtz1vPh1CzIWT_IZIReSIKG/s400/redream_patch_linux.png"/></a></div>
<br/><br/>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-72860067461201155722022-05-08T14:47:00.032+08:002022-07-14T14:15:36.530+08:00How to create React.js app for Google Apps Script WebApp Project in ChromeOS
(1) Goto https://script.google.com/home/usersettings and enable Google Apps Script API<br/>
<br/>
(2) Install nodejs and required packages using Terminal Command<br/>
<dl class="codebox">
<dt>shell script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>sudo apt install nodejs npm
mkdir -p ~/webappreact
cd ~/webappreact
npm init -y
#Change the following file in ~/webappreact/package.json as
cat > ~/webappreact/package.json <<EOF
{
"name": "webappreact",
"version": "1.0.0",
"description": "",
"scripts": {
"glogin": "clasp login",
"glogout": "clasp logout",
"gcreate": "clasp create --title 'React Test Project' --rootDir ./apps-script",
"gpush": "clasp push",
"gpull": "clasp pull",
"gstart": "clasp push --watch",
"build": "parcel build src/index.html --dist-dir ./apps-script",
"start": "parcel src/index.html --dist-dir ./apps-script"
},
"keywords": [],
"author": "",
"license": "ISC"
}
EOF
# install dependencies
npm install -D @google/clasp
npm install -D @types/google-apps-script # if you use VS Code Editor in ChromeOS
npm install -D parcel
npm install react react-dom
mkdir -p ~/webappreact/apps-script
# create ~/webappreact/apps-script/main.js as
cat > ~/webappreact/apps-script/main.js <<EOF
function doGet() {
return HtmlService.createTemplateFromFile("index")
.evaluate()
.addMetaTag("viewport","width=device-width, initial-scale=1.0")
}
EOF
mkdir -p ~/webappreact/src
# create ~/webappreact/src/index.html as
cat > ~/webappreact/src/index.html <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script type="module">
import "./index.js"
</script>
</body>
</html>
EOF
# create ~/webappreact/src/index.js as
cat > ~/webappreact/src/index.js <<EOF
import React from "react"
import App from "./App"
import { createRoot } from 'react-dom/client';
const container = document.getElementById('app');
const root = createRoot(container);
root.render(<App />, app)
EOF
# create ~/webappreact/src/App.js as
cat > ~/webappreact/src/App.js <<EOF
function App() {
return <div>
<h1>First React App</h1>
<p>Hello World</p>
</div>
}
export default App
EOF
</code></dl><br/><br/><br/>
(3) Test building and push to Google Drive using Terminal Command<br/>
<dl class="codebox">
<dt>shell script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code># Testing building
cd ~/webappreact
npm run build
# Testing running in localhost:1234
# For Chrome Browser, please install <a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en" target="_blank">React Developer Tools</a> in chrome web store for testing at localhost
npm run start
# Login in to google apps script
npm run glogin
# Create Project in google apps script and choose <span style="color:blue">spreadsheet</span>
npm run gcreate
mv ~/webappreact/apps-script/.clasp.json ~/webappreact/
# Push to google apps script
npm run gpush
</code></dl><br/><br/><br/>
(4) Browser Go to https://script.google.com/home and deploy the React Test Project as webapp and test<br/><br/><br/><br/>
(5) Add CSS and react-router<br/>
<dl class="codebox">
<dt>shell script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>mkdir -p ~/webappreact/src/styles/
#Add ~/webappreact/src/styles/main.scss as
cat > ~/webappreact/src/styles/main.scss <<EOF
h1 {
color:green;
font-size: 2rem;
}
p {
color:purple;
}
.css-nav {
padding-left: 15px;
padding-right: 15px;
}
EOF
# change ~/webappreact/src/index.html as
cat > ~/webappreact/src/index.html <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
@import "./styles/main.scss";
</style>
</head>
<body>
<div id="app"></div>
<script type="module">
import "./index.js"
</script>
</body>
</html>
EOF
# install dependencies
npm install react-router-dom@6
mkdir -p ~/webappreact/src/components
# create ~/webappreact/src/components/Home.js as
cat > ~/webappreact/src/components/Home.js <<EOF
function Home() {
return <>
<h1>HomePage</h1>
</>
}
export default Home
EOF
# create ~/webappreact/src/components/About.js as
cat > ~/webappreact/src/components/About.js <<EOF
function About() {
return <>
<h1>About</h1>
</>
}
export default About
EOF
# create ~/webappreact/src/components/Nav.js as
cat > ~/webappreact/src/components/Nav.js <<EOF
import { Link } from "react-router-dom"
function Nav() {
return <>
<span className="css-nav"><Link to="/">Home</Link></span>
<span className="css-nav"><Link to="/about">About</Link></span>
</>
}
export default Nav
EOF
# change ~/webappreact/src/index.js as
cat > ~/webappreact/src/index.js <<EOF
import React from "react"
import { BrowserRouter } from "react-router-dom"
import App from "./App"
import { createRoot } from 'react-dom/client';
const container = document.getElementById('app');
const root = createRoot(container);
root.render(<BrowserRouter><App /></BrowserRouter>)
EOF
# change ~/webappreact/src/App.js as
cat > ~/webappreact/src/App.js <<EOF
import { Routes, Route } from "react-router-dom"
import Home from "./components/Home"
import About from "./components/About"
import Nav from "./components/Nav"
function App() {
return <>
<Nav />
<Routes>
<Route path="/" element={<Home />} />
<Route path="about" element={<About />} />
<Route path="*" element={<Home />} />
</Routes>
</>
}
export default App
EOF
</code></dl><br/><br/><br/>
(6) Test building and push to Google Drive using Terminal Command<br/>
<dl class="codebox">
<dt>shell script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code># Testing building
cd ~/webappreact
npm run build
# Testing running in localhost:1234
npm run start
# Push to google apps script
npm run gpush
# test again in webapp of Google Apps Script
</code></dl><br/><br/><br/>
(7) Add google apps script getData() function as backend<br/>
<dl class="codebox">
<dt>shell script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>
# Change ~/webappreact/apps-script/main.js as
cat > ~/webappreact/apps-script/main.js <<EOF
function doGet() {
return HtmlService.createTemplateFromFile("index")
.evaluate()
.addMetaTag("viewport","width=device-width, initial-scale=1.0")
}
function getData() {
return (
[{
"key": "apple",
"value": "green"
},
{
"key": "banana",
"value": "yellow"
}]
);
}
function getSpreadData() {
return SpreadsheetApp
.getActiveSpreadsheet()
.getActiveSheet()
.getDataRange()
.getValues();
}
EOF
# Change ~/webappreact/src/components/About.js as
cat > ~/webappreact/src/components/About.js <<EOF
import React, {useState, useEffect} from "react"
function About() {
const [data,setData] = useState(null)
const [loading, setLoading] = useState(false)
if (typeof google === 'object') {
useEffect(()=>{
setLoading(true)
google.script.run.withSuccessHandler(response => {
setData([...response])
setLoading(false)
}).withFailureHandler(er => {
alert(er)
}).getData()
},[])
}
else {
return <>
<h1>About</h1>
<table>
<tbody>
<tr>
<td><span style={{paddingLeft:'30px',paddingRight:'30px'}}>key: row.key</span></td>
<td><span style={{paddingRight:'30px'}}>value: row.value</span></td>
</tr>
</tbody>
</table>
</>
}
if (loading) return <h1>loading...</h1>
if (!data) return null;
return <>
<h1>About Data</h1>
<table>
<tbody>
{
data.map((row) => (
<tr>
<td><span style={{paddingLeft:'30px',paddingRight:'30px'}}>key: {row.key}</span></td>
<td><span style={{paddingRight:'30px'}}>value: {row.value}</span></td>
</tr>
))
}
</tbody>
</table>
</>
}
export default About
EOF
</code></dl><br/><br/><br/>
(8) Push to Google Drive and test in Google Apps Script Web App<br/>
<dl class="codebox">
<dt>shell script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code># Testing building and Push to google apps script
cd ~/webappreact
npm run build && npm run gpush
# test again in webapp of Google Apps Script
</code></dl><br/><br/><br/>
<!--
https://onlinecode.org/windows-10-product-keys-100-working-activation/#comments
-->
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-26384300895865499382022-03-27T04:47:00.009+08:002022-03-27T17:06:39.924+08:00Install Kali Linux on an external drive without modifying Windows EFI partitionInstall Kali Linux on an external drive without modifying Windows EFI partition<br/>
<br/>
(1) This method on try and modiying the ESP flag does not work on Kali Linux (everything ISO 10.5 GB), because Kali Linux cannot install when you start with try, you have to use the Installer in the grub menu.<br/>
https://www.danbp.org/p/en/node/148<br/>
<br/>
(2) You should unplug the HD or SSD if you try to install to a USB drive for Kali Linux.<br/>
<br/>
(3) That means you should prepare two USB for installing. And when installing the Kali Linux to USB drive, choose force UEFI and let the installer install the grub menu to your new USB stick.<br/>
<br/>
(4) After finishing the installation and let the PC reboot the new USB stick.<br/>
<br/>
(5) After the first boot, remember to <b>turn off the boot and ESP flag</b> in the EFI partition of the new USB stick and reboot to test. This will be a painful experience if not turning it off<br/>
<br/>
(6) To make the USB stick EFI bootable, open root terminal and run<br/>
<pre>
cd /boot/efi/EFI
mkdir -p BOOT
cp /boot/efi/EFI/kali/grubx64.efi /boot/efi/EFI/BOOT/BOOTx64.efi
</pre>
<br/><br/><br/>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-86028407439628744282022-03-23T22:20:00.035+08:002022-04-19T09:38:43.749+08:00How to compile hashcat v5.1 on M1 Apple Silicon MacOn Mac M1 machine, compile<br/>
<br/>
<pre>
# to install hashcat
cd $HOME/Downloads
git clone https://github.com/hashcat/hashcat.git
cd hashcat
git fetch --all --tags
git checkout tags/v5.1.0 -b v5.1.0-branch
make # don't make install
# print version
./hashcat --version
# print help
./hashcat --help
# run benchmark
./hashcat -b -m 2500 -w 3 -d 1
</pre>
<br/>
<pre>
# to install hashcat-utils
cd $HOME/Downloads
git clone https://github.com/hashcat/hashcat-utils.git
cd hashcat-utils/src
make # don't make install
# print help
./cap2hccapx.bin --help
# install hcxdumptool & hcxtools
git clone https://github.com/ZerBea/hcxdumptool
cd hcxdumptool/
make # don't make install
git clone https://github.com/ZerBea/hcxtools
cd hcxtools /
make # don't make install
https://gist.github.com/Nav-Appaiya/b8eb3cbf22642aac2ead12884fb6aa80
</pre>
<br/><br/>
Linux AMD drivers<br/>
https://www.amd.com/en/support/kb/release-notes/rn-amdgpu-unified-linux-20-20<br/>
https://www.amd.com/en/support/kb/faq/amdgpu-installation<br/>
https://www.incredigeek.com/home/unsupported-deb-based-os-etc-os-release-id-kali/<br/>
<pre>
cd ~/Downloads
tar -Jxvf amdgpu-pro-20.20-1098277-ubuntu-20.04.tar.xz
cd amdgpu-pro-20.20-1098277-ubuntu-20.04
# change line 147based on above
./amdgpu-install -y --uninstall
./amdgpu-install -y --opencl=legacy --headless --no-dkms</pre>
<!--
sudo ./amdgpu-install --opencl=rocr --headless --no-dkms
<s>./amdgpu-install -y --no-dkms --opencl=legacy,rocm --headless</s>
-->
<br/>
<br/>
Linux Intel drivers<br/>
https://www.intel.com/content/www/us/en/developer/tools/opencl-cpu-runtime/overview.html<br/>
https://github.com/intel/compute-runtime/releaseshttps://github.com/intel/compute-runtime/releases
<br/>
<br/><br/>
On Windows<br/>
Download and uncompress from <a href="https://hashcat.net/files/hashcat-5.1.0.7z" target="_blank">https://hashcat.net/files/hashcat-5.1.0.7z</a><br/>
or see other old versions here https://hashcat.net/hashcat/#download-older<br/>
<br/>
You might need to install drivers for OpenCL<br/>
AMD GPUs on Windows require "AMD Radeon Adrenalin 2020 Edition" (20.2.2 or later)<br/>
<a href="https://www.amd.com/en/support/kb/release-notes/rn-rad-win-20-3-1" target="_blank">https://www.amd.com/en/support/kb/release-notes/rn-rad-win-20-3-1</a><br/><br/>
Intel CPU only<br/>
Intel® CPU Runtime for OpenCL™ Applications 18.1 for Windows* OS (64bit or 32bit)<br/>
<a href="https://registrationcenter.intel.com/en/forms/?productid=3207" target="_blank">https://registrationcenter.intel.com/en/forms/?productid=3207</a><br/><br/><br/>
<!--
https://stackoverflow.com/questions/53070673/download-opencl-amd-app-sdk-3-0-for-windows-and-linux
reference : https://hashcat.net/wiki/doku.php?id=cracking_wpawpa2
git clone https://github.com/Umio-Yasuno/unofficial-amdgpu-firmware-repo.git
cd unofficial-amdgpu-firmware-repo && cd amdgpu && sudo mv * /lib/firmware/amdgpu/ && sudo apt-get update && clear && sudo apt-get upgrade
-->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-87683862606704363392022-03-22T14:40:00.025+08:002022-03-29T21:21:13.908+08:00How to use Kali Linux for raspberry pi zero W / 2WThis article discribe the the headless installation of Kali Linux on Raspberry Pi Zero W or the new Raspberry Pi Zero2 W. Headless means setup and connect to the Pi Zero without display and keyboard.<br/>
<br/>
(1) Download <span style="color:brown">"<b>Pi-Tail</b>"</span> edition of Kali Linux from https://www.kali.org/get-kali/#kali-arm<br/>
pi zero W <a href="https://kali.download/arm-images/kali-2022.1/kali-linux-2022.1-raspberry-pi-zero-w-pitail-armel.img.xz" target="_blank">https://kali.download/arm-images/kali-2022.1/kali-linux-2022.1-raspberry-pi-zero-w-pitail-armel.img.xz</a><br/>
pi zero2 W <a href="https://kali.download/arm-images/kali-2022.1/kali-linux-2022.1-raspberry-pi-zero-2-w-pitail-armhf.img.xz" target="_blank">https://kali.download/arm-images/kali-2022.1/kali-linux-2022.1-raspberry-pi-zero-2-w-pitail-armhf.img.xz</a><br/>
<br/>
(2) Download balenaEtcher to flash the SD Card, suggest to use 32GB or above.<br/><br/>
If you use the Windows version of balenaEtcher, you don't need to download the image and decompress as it supports get from url, just input the download url and flash the image.<br/>
<br/>
(3.1) After finish flashing, eject the SD card and put it back in order to modify the content for headless setup. Based on this <a href="https://github.com/Re4son/RPi-Tweaks/blob/master/pi-tail/Pi-Tail.HOWTO" target="_blank">https://github.com/Re4son/RPi-Tweaks/blob/master/pi-tail/Pi-Tail.HOWTO</a>, you have to edit the wpa_supplicant.conf in the first partition of the SD Card.<br/>
Existing wpa_supplicant.conf<br/>
<pre>
network={
ssid="homenet"
psk=68002fbdacc8812f89c06a2fb6542b2b1126853983a59e0076e5f56df9c5543b
id_str="home"
priority=2
}
</pre>
Get wpa_passphase from linux package wpasupplicant<br/>
and the command<br/>
<span style="color:blue">wpa_passphrase "MyHomeWifi" "MyPassword"</span>
will give you the required psk reuqired<br/>
Modify to<br/>
<pre>
network={
ssid="MyHomeWifi"
psk=6ac0d834a918dfdb09c7d4581a1665f5f1969ef3967e25cd932eab7c75075d54
id_str="home"
priority=2
}
</pre>
<br/>
Existing interfaces<br/>
<pre>
iface home inet dhcp
</pre>
Modify to fixed IP for home<br/>
<pre>
iface home inet static
address 192.168.1.79
netmask 255.255.255.0
gateway 192.168.1.1
</pre><br/>
<br/>
(3.2) Modify the mobile set-up<br/>
Existing wpa_supplicant.conf<br/>
<pre>
# reading passphrase from stdin
network={
ssid="mobile-1"
psk=2b975ade78236c65480641296127688b223b1270e7ce175e7317b5bf6ca4795a
id_str="mobile-1"
priority=4
}
</pre>
Modify to, after running <span style="color:blue">wpa_passphrase "Samsung S22" "mysecretwords"</span><br/>
<pre>
network={
ssid="Samsung S22"
psk=6136bd9f2dced6eced7ec23dc4abed6d8dcff707a148d150ab97905facb6ca33
id_str="mobile-1"
priority=4
}
</pre>
<br/>
Existing interfaces<br/>
<pre>
iface mobile-1 inet static
address 192.168.43.254
netmask 255.255.255.0
gateway 192.168.43.1
</pre>
Modify to DHCP IP address for mobile-1<br/>
<pre>
iface mobile-1 inet dhcp
</pre><br/>
<br/>
<br/>
After set-up of SD Card put it back to the Raspberry Pi Zero card slot and then power-up to connect.<br/>
<br/>
(4) Use wifi connect to Raspberry pi using ssh, username is <span style="color:blue">kali</span> and password is <span style="color:blue">kali</span><br/>
e.g. connect via home wifi with fixed IP 192.168.1.79 that was setup in Step 3.1 above<br/>
<pre>
ssh kali@192.168.1.79
</pre><br/>
<br/>
e.g. connect via mobile<br/>
First get the IP address for hotspot connection client information on your phone. Then use Terminal App such as Termux on your Android phone to start the ssh session with the IP address obtained.<br/>
<pre>
ssh kali@192.168.99.121
</pre><br/>
<br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuugBQyRu6dHgi69H8HlO0X85UQcnxsXE7QXXzAZI-lL6g1v--QKRTE8v0qdrGaIe16IDcs-2QL0W8u9xmNtiMaMtvDXgbtw1Q1U3zPKMakaTik6ChhRfCc97R671ANelY8ekK-AIR3nkRc1-66lbunWNPY36fsPFnzQE8NcbCD5trvip5qO6xTsIE/s867/pitail2.jpg" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="400" data-original-height="610" data-original-width="867" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuugBQyRu6dHgi69H8HlO0X85UQcnxsXE7QXXzAZI-lL6g1v--QKRTE8v0qdrGaIe16IDcs-2QL0W8u9xmNtiMaMtvDXgbtw1Q1U3zPKMakaTik6ChhRfCc97R671ANelY8ekK-AIR3nkRc1-66lbunWNPY36fsPFnzQE8NcbCD5trvip5qO6xTsIE/s400/pitail2.jpg"/></a></div>
<br/><br/>
<br/>
(5) Additional configurations after connection<br/>
<pre>
sudo apt update
sudo dpkg-reconfigure tzdata
sudo dpkg-reconfigure locales
</pre><br/>
<br/>
(6) HOWTO put wlan0 into monitor mode:<br/>
wlan0 can be used both, in tethering and monitor mode at the same time.<br/>
Monitor on (mon0):<br/>
mon0up #This will create and start up a monitoring interface "mon0"<br/>
Monitor off:<br/>
mon0down #This will bring down and remove mon0<br/>
<br/><pre>
sudo mon0up
sudo airmon-ng
sudo airodump-ng mon0
sudo airodump-ng mon0 --bssid 34:8A:AE:33:74:4E --channel 4 --write mydump
</pre><br/>
<br/>
<div class="separator" style="clear: both;"><a href="https://raspberrytips.com/wp-content/uploads/2019/03/airodump.gif" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" height="400" data-original-height="728" data-original-width="591" src="https://raspberrytips.com/wp-content/uploads/2019/03/airodump.gif"/></a></div>
<br/><br/><br/><br/>
<!--
https://hashcat.net/hashcat/
AMD GPUs on Windows require "AMD Radeon Adrenalin 2020 Edition" (20.2.2 or later)
https://www.amd.com/en/support/kb/release-notes/rn-rad-win-20-3-1
Intel CPUs require "OpenCL Runtime for Intel Core and Intel Xeon Processors" (16.1.1 or later)
Intel® CPU Runtime for OpenCL™ Applications 18.1 for Windows* OS (64bit or 32bit)
https://registrationcenter.intel.com/en/forms/?productid=3207
sudo apt install crunch
crunch 8 8 0123456789 > wordlist.txt
cap2hccapx.bin airodump-02.cap airodump-02b.hccapx "My Home"
hashcat64.exe --self-test-disable -m 2500 -w 3 -d 1 dump\airodump-02b.hccapx dump\8digitBack.txt
https://hashcat.net/files/hashcat-5.1.0.7z
hashcat64.exe --self-test-disable -m 2500 -w 3 -d 1 dump\airodump-02a.hccapx dump\8digitBack.txt
on Mac m1
git clone https://github.com/hashcat/hashcat.git hascat2
cd hascat2
git fetch --all --tags
git checkout tags/v5.1.0 -b v5.1.0-branch
make
cd ../dump
../hashcat2/hashcat -m 2500 -w 3 -d 1 airodump-02a.hccapx 8digitBack.txt
../hashcat2/hashcat -m 2500 airodump-02a.hccapx --show
102d99b6271abe0bfc861b34e635d4fb:60a4b78786b2:38a28c9270a5:My Home:19881988
714 cd Projects/dump
716 crunch 8 8 1234567890 > 8digits.txt
../hashcat-utils/src/cap2hccapx.bin airodump-02.cap airodump-02b.hccapx "My Home"
721 ../hashcat2/hashcat -m 2500 -w 3 -d 1 --potfile-path=myhome.pot airodump-02b.hccapx 8digits.txt
722 cat myhome.pot
../hashcat2/hashcat -m 2500 -w 3 -a 3 -d 1 --potfile-path=myhome.pot -i airodump-02b.hccapx "?d?d?d?d?d?d?d?d"
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmdealr8fz5D07JkkDzQuyqlxcUKZjxBgIvevgCBduSIFl9pdDwMXN_EIsmT2zOrALZZV0s4-UXH4PwCa1KST8wNLkILTtMKfeQCPaxRBkQvlZ1K64b_v6ElNLbZ3H3XKC9JYBtrcbHgm1VgNZfB-sVTClkv-gVk9-MxEorgufajPqIKk2wrNOcfed/s719/andriodx86.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" height="400" data-original-height="719" data-original-width="490" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmdealr8fz5D07JkkDzQuyqlxcUKZjxBgIvevgCBduSIFl9pdDwMXN_EIsmT2zOrALZZV0s4-UXH4PwCa1KST8wNLkILTtMKfeQCPaxRBkQvlZ1K64b_v6ElNLbZ3H3XKC9JYBtrcbHgm1VgNZfB-sVTClkv-gVk9-MxEorgufajPqIKk2wrNOcfed/s400/andriodx86.png"/></a></div>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU1bWpB5OrZBciS8Zo8AsB5-Z2bAyzlG5uYq4PRFjsJbe_pDrrb-oxFUbuuVCoYsAEdrEZuDI8ljnavdOm73UiMsp9p8Z3wplktx0zlEUq-WGsyBGgtlCNGOFB1ABRo9MxKu6gdmXUWDeeXwMz_dC2CDC_CLztLQxLJP2twL2p_AsoXIVe9hkZzTV-/s1115/powershell.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="624" data-original-width="1115" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU1bWpB5OrZBciS8Zo8AsB5-Z2bAyzlG5uYq4PRFjsJbe_pDrrb-oxFUbuuVCoYsAEdrEZuDI8ljnavdOm73UiMsp9p8Z3wplktx0zlEUq-WGsyBGgtlCNGOFB1ABRo9MxKu6gdmXUWDeeXwMz_dC2CDC_CLztLQxLJP2twL2p_AsoXIVe9hkZzTV-/s320/powershell.png"/></a></div>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZV71ytmC4QE9DCYYtIscYzIiioi7I_Hslqt54KqesUXXQtJDxSX9MEse1GktGjIMsdCjg16l9o8kRDTzQnVRcgbm2ImOWxvjatvKN8a10B0oxC3aFxTCm-0XQcBVSGzuqpGNdcHUB7B1FrXjttkTwTfufm_nDKQedqVXf5eyRixHFdjSje2_qe13i/s1920/sdcard.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="200" data-original-height="1080" data-original-width="1920" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZV71ytmC4QE9DCYYtIscYzIiioi7I_Hslqt54KqesUXXQtJDxSX9MEse1GktGjIMsdCjg16l9o8kRDTzQnVRcgbm2ImOWxvjatvKN8a10B0oxC3aFxTCm-0XQcBVSGzuqpGNdcHUB7B1FrXjttkTwTfufm_nDKQedqVXf5eyRixHFdjSje2_qe13i/s200/sdcard.png"/></a></div>
https://www.mediafire.com/file/xsy8twd05r1nph9/data.zip/file
-->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-47431854302647216412022-03-18T16:15:00.012+08:002022-03-22T07:08:14.498+08:00How to create bootable USB for Linux with persistence (1) Download Ventoy from <a href="https://github.com/ventoy/Ventoy/releases" target="_blank">https://github.com/ventoy/Ventoy/releases</a> e.g. ventoy-1.0.71-windows.zip<br/>
<br/>
(2) Unzip it and in step (3) run Ventoy2Disk.exe to create bootable USB<br/>
<br/>
(3) Download an iso image from say (3.1GB) ubuntu-20.04.4-desktop-amd64.iso from <a href="https://ubuntu.com/download/desktop" target="_blank">https://ubuntu.com/download/desktop</a><br/>
<br/>
(4) Open the Ventoy2Disk.exe program (after unzip in step (2) above) and click install to an USB flash drive (say 16GB or above), you can choose Secure boot and/or GPT if you want to. For me, I choose GPT and without Secure Boot. But for older hardware say MBR and without Secure boot, you might want to choose the default.<br/>Attention that the USB drive will be formatted and all the data will be lost after install.<br/>
<br/>
(5) Copy the downloaded <span style="color:blue">ubuntu-20.04.4-desktop-amd64.iso</span> to the USB drive in /iso/ folder of the USB drive. You have to create a new folder /iso in the USB drive first.<br/>
<br/>
(6) Follow the instruction to create /ventoy/ventoy.json (step 9 below) in the USB drive as per format in <a href="https://www.ventoy.net/en/plugin_persistence.html" target="_blank">/ventoy/ventoy.json</a>. You might need to create /ventoy folder first in USB drive.<br/>
(7) Download the pre-created persistence image files from <a href="https://github.com/ventoy/backend/releases" target="_blank">https://github.com/ventoy/backend/releases</a> and uncompress it using <a href="https://www.pkware.com/zip/downloads/software/pkzip-for-windows-desktop" target="_blank">pkzip for Windows</a> or in wsl use p7zip package. For ubuntu persistence file you have to use the casper-rw file e.g. uncompress the file <span style="color:blue">persistence_ext4_4GB_casper-rw.dat.7z</span>.<br/>
<br/>
(8) put the uncompressed image <span style="color:blue">persistence_ext4_4GB_casper-rw.dat</span> to /persistence/ folder of the USB drive<br/>
<br/>
(9) Copy the iso grub menu to USB disk and save as /ventoy/ubuntu.cfg and edit it so as to skip the file check and skip the try ubuntu<br/>
<pre>
if loadfont /boot/grub/font.pf2 ; then
set gfxmode=auto
insmod efi_gop
insmod efi_uga
insmod gfxterm
terminal_output gfxterm
fi
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
set timeout=5
menuentry "Ubuntu 20.04 persistence" {
set gfxpayload=keep
linux /casper/vmlinuz file=/cdrom/preseed/ubuntu.seed persistent fsck.mode=skip quiet splash ---
initrd /casper/initrd
}
menuentry "Ubuntu (safe graphics)" {
set gfxpayload=keep
linux /casper/vmlinuz file=/cdrom/preseed/ubuntu.seed maybe-ubiquity quiet splash nomodeset ---
initrd /casper/initrd
}
menuentry "OEM install (for manufacturers)" {
set gfxpayload=keep
linux /casper/vmlinuz file=/cdrom/preseed/ubuntu.seed only-ubiquity quiet splash oem-config/enable=true ---
initrd /casper/initrd
}
grub_platform
if [ "$grub_platform" = "efi" ]; then
menuentry 'Boot from next volume' {
exit 1
}
menuentry 'UEFI Firmware Settings' {
fwsetup
}
fi
</pre><br/>
<br/>
(10) Add the conf_replace to replace the default grub menu the json file in /ventoy/ventoy.json will become
<pre>
{
"persistence": [
{
"image": "/iso/ubuntu-20.04.4-desktop-amd64.iso",
"backend": [
"/persistence/persistence_ext4_4GB_casper-rw.dat"
],
"autosel": 1,
"timeout": 10
}
] ,
"conf_replace": [
{
"iso": "/iso/ubuntu-20.04.4-desktop-amd64.iso",
"org": "/boot/grub/grub.cfg",
"new": "/ventoy/ubuntu.cfg"
}
]
}
</pre><br/>
<br/>
(10) Bootup the USB drive and you might need to enter BIOS (e.g. F2 and choose the USB drive as first bootup option and disable Secure boot) in your computer and choose "<span style="color:red"><b>Try Ubuntu</b></span>" and don't choose Install.<br/><br/>
<br/>
<!-- https://code.google.com/archive/p/reaver-wps/
https://raspberrytips.com/hacking-wifi-raspberry-pi/
-->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-24988661205111182062022-03-09T15:45:00.018+08:002022-03-16T02:59:46.815+08:00How to decompile and repack Android App on ChromeOS (Part 3)(1) This continues to discuss -> How to decompile android app, previous articles are here <a href="/2022/03/how-to-decompile-and-repack-android-app.html" target="_blank">(part 1)</a> & <a href="/2022/03/how-to-decompile-and-repack-android-app_3.html" target="_blank">(part2)</a><br/>
<br/><br/>
(2) <a href="/2022/03/how-to-decompile-and-repack-android-app.html" target="_blank">Part 1</a> is to demo the use of ChromeOS (devloper mode on) plus the decompile tools and the process of decode and edit some resource files then rebuild the apk using apktool. And <a href="/2022/03/how-to-decompile-and-repack-android-app_3.html" target="_blank">Part 2</a> is to use the jadx tool to decode the apk to java source file and compile it again in Android Studio.<br/>
<br/><br/>
(3) There are possibilities that the jadx tool can not decompile the complete java scources or ending with error. Even if it can be decoded, the project is maybe too complex to rebuild it in Android Studio.<br/>
<br/><br/>
(4) If we can decompile using apktool, we can edit the resource file and smali code, then repack it into apk file. However, this method is only for small modifications in code<br/>
<br/><br/>
(5) For example<br/>
<code>cd ~/DecompileProjects
# decompile the apk using apktool<br/>
apktool.bat d yourapp.apk -o yourapp_out<br/>
# edit the smali file, how ? see point(6) below<br/>
vim yourapp_out\smali_classes2\com\yourapp\MyService.smali<br/>
# build the apk using apktool<br/>
apktool b sjbot2 -o yourapp2.apk<br/>
# use jadx to decode it to gradle java source files so that you can check for any errors.<br/>
jadx --export-gradle yourapp2.apk -d yourapp2_gradle<br/>
# check the decompile java scource code before deployment<br/>
vim yourapp2_gradle\app\src\main\java\yourapp\MyService.java<br/>
# code sign and align the apk<br/>
jarsigner -verbose -sigalg SHA256withRSA -keystore my-release-key256.keystore -storepass 123456 yourapp2.apk mykey256<br/>
jarsigner -verify -verbose -certs -keystore my-release-key256.keystore yourapp2.apk<br/>
zipalign -v 4 yourapp2.apk yourapp2-aligned.apk<br/>
# install to emulator or device for testing<br/>
adb -s emulator-5556 install yourapp2-aligned.apk<br/>
</code><br/><br/>
(6) The problem here is how to edit the smali code, the syntax is so complex and like bytecode. So there is no easy path, and either you <a href="https://www.programmerall.com/article/9200827288" target="_blank">learn the smali language</a>, or you can use <a href="https://plugins.jetbrains.com/plugin/7385-java2smali" target="_blank">java2smali plug-in</a> for Android Studio to convert java code to smali code and try and error to modify it bit by bit. So using git version control and branching to keep track of your modification is very important in this case. The limitation of java2smali is that it can only be done on a complete project not a single java file, so you have to put a function that is compilable and put it in a project to compile and then convert to smali code.<br/><br/>
<a href="magnet:?xt=urn:btih:7C2A8A5072CB110BCCC334A1A879E0617BEB36E6&dn=Introduction%20to%20Android%20Reverse%20Engineering&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce">Get this torrent</a> to learn more on Reverse Engineering.
<br/>
<!--
USB Key 8GB above
https://www.microsoft.com/zh-hk/software-download/windows11 (5.1GB)
Win11_Chinese(Traditional)_x64v1.iso
https://rufus.ie/downloads/#google_vignette
rufus-3.18_BETA.exe
C:\Users\choil>wmic path softwarelicensingservice get OA3xOriginalProductKey
OA3xOriginalProductKey
PS C:\Users\user> wmic path softwarelicensingservice get OA3xOriginalProductKey
OA3xOriginalProductKey
https://developers.google.com/apps-script/guides/services/quotas#current_limitations
-->
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-30421976015679127762022-03-04T21:35:00.037+08:002022-03-13T09:23:19.488+08:00How to create Android app-signing key for Google Play(1) (1) Signup with Google Play and pay US$25 as a registration fee for non-business users (comparing Apple is charging US$99 for non-business users). The annual fee with Google Play will depend on your income from playstore.<br/>
<br/>
There is no free app sigening authority in this world. The free certificates out there are for SSL web servers and not for app signing. For Android App and Google Play Store signup her <a href="https://play.google.com/console/u/0/signup" target="_blank">https://play.google.com/console/u/0/signup</a></a><br/>
<br/>
(2) Create the first app for testing in the console after verification of phone and email and upon successful payment of the first registration fee.<br/>
<br/>
(2.1) There are 4 options for <a href="https://support.google.com/googleplay/android-developer/answer/9842756?hl=en" target="_blank">Application Signing Preferences for Play Store</a> for your first app, choose the first option (a) which is the default called Play App Signing if you don't change it.<br/>
(a) <a href="https://developer.android.com/studio/publish/app-signing#app-signing-google-play" target="_blank">Let Google manage and protect your app signing keys (recommended)</a><br/>
(b) Use the same key as other apps in this developer account<br/>
(c) Export and upload keys from Java KeyStore<br/>
(d) Export and upload keys (without using Java KeyStore)<br/>
<br/>
(3) Use Android Studio to create two keystores<br/>
see here <a href="https://developer.android.com/studio/publish/app-signing" target="_blank">https://developer.android.com/studio/publish/app-signing</a><br/>
<br/>
(4) You have to create two keystores <b><u>upload-keystore.jks</u></b> (and with alias of uploadkey) and <b><u>deployment-keystore.jks</u></b> (and with alias deploymentkey) for easy reference.<br/>
<b><u>upload-keystore.jks</u></b> is for signing your artifacts (App Bundle or APKs) to be uploaded to Google Play console. After review and approval, Google will then sign your uploaded App Bundle and distribute via the Play Store for testing or publication.<br/>
<b><u>deployment-keystore.jks</u></b> is the public certificate of the application signing key. Google uses this certificate to sign the release version of the applications. Use this credential to register your key with the API provider. If you are currently using Google APIs, you can upload keys for application registration and application signing key certificates in the Google Cloud Console.<br/>
<br/>
What is App Bundle ? After August 2021, all new apps and games will be required to publish in Google Play Store with the Android App Bundle format and require new apps to target API level 30 (Android 11) or above.<br/>
<br/>
(5) By choosing your first created app, and on the Release > Setup > App Integrity page (after chosing the option of "Let Google manage and protect your app signing key (recommended)"), you can download two <b><u>certificates</u></b> as <b><u>upload_cert.der</u></b> and <b><u>deployment_cert.der</u></b>.<br/>
<div class="separator" style="clear: both;"><a href="https://developer.zebra.com/sites/default/files/signing%20certificates%20-%20highlight.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="400" data-original-height="402" data-original-width="800" src="https://developer.zebra.com/sites/default/files/signing%20certificates%20-%20highlight.png"/></a></div>
<br/>
In the Google Play Console App Signing page, you just choose the first option <b>"Let Google manage and protect your app signing key (recommended)"</b>, if you are new to Google Play as this method is an upgraded secure key managed by Google. For the recommended option, Google will manage your app signing key, and you don't need to export and upload your private key and instead you need to use the certificate downloaded from Google in the next step(6)and import the certificate to your generated keystore in step (4). Other signing options are for existing developers and has to upload their private key to Google Play console. However, if you lose your keystore (private key in there) or it becomes compromised, you won't be able to update your app without publishing a new app with a new package name.<br/>
<a href="https://play.google.com/console/u/0/developers/app/keymanagement" target="_blank">https://play.google.com/console/u/0/developers/app/keymanagement</a><br/>
<br/>
(6) Import the two certificates to <b><u>upload-keystore.jks</u></b> and <b><u>deployment-keystore.jks</u></b> by using the following commands in Terminal.<br/>
<code># keytool can be found in your installed Android Studio folder e.g. /opt/android-studio/jre/bin/keytool or /usr/lib/jvm/java-11-openjdk-amd64/bin/keytool/<br/>
or in Windows OS "C:\Program Files\Android\Android Studio\jre\bin\keytool.exe"<br/>
# assume the 2 .der certificates are in the same folder as your 2 keystores.
keytool -importcert -file upload_cert.der -keystore upload-keystore.jks<br/>
keytool -importcert -file deployment_cert.der -keystore deployment-keystore.jks<br/>
<br/>
# You can review your upload_cert SHA1 signature by using this command and it should match with the sha1 signature kept by Google<br/>
cat upload_cert.der | openssl sha1 -c<br/>
</code><br/>
The download certificates contain the public key of Google and combined with the private key in your self created keystore, you will sign the app and Google will then verify your upload_cert SHA1 signature when uploading to Google for review or distribution.
<br/>
(7) Use Android Studio to sign the App Bundle or apk by choosing the appropriate keystore to sign (upload-keystore.jks for App Bundle signing and uploading to Google and deployment-keystore.jks for application signing key certificate by API provider). For app id, you should use your identifier in order not to conflict with the existing ones in Google Play Store. App ID starting with "com.mycompany" or using an App ID from the public domain or GitHub will likely to cause problems when uploading to Google Play Store<br/>
<br/>
(8) Choose <b><u>release</u></b> build type in Android Studio to sign the app bundle. Make sure to change "debuggable to false" in build.gradle file of your gradle.build file, otherwise you will get "Upload Failed. The Android Bundle was not Signed".<br/>
<br/>
So (a) using <b><u>upload-keystore.jks</u></b> and (b) <b><u>Release</u></b> build type with "debuggable to <b><u>false</u></b>" are important for an app bundle to be uploaded successfully and then you can start <b><u>Roll Out</u></b> the release for the Internal Test version and "the online link will be in the Testers tab as https://play.google.com/apps/internaltest/XXXXXXXXXXXXXXX" for download. ChromeOS without Developer mode or other Android devices can also download it from Google Play Store and install if they are named internal testers include you.<br/>Moreover, On the Application Dashboard, you can see the <b><u>Google Play Link</u></b> for the latest published version.<br/><br/>
<div class="separator" style="clear: both;"><a href="https://i.stack.imgur.com/YivNa.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="112" data-original-width="800" src="https://i.stack.imgur.com/YivNa.png"/></a></div>
<br/>
<br/>
(9) Google Play requirements<br/>
Starting in August 2021, Google Play will require all Android apps to be submitted as Android App Bundles, and to use a target API level of 30 or higher. Verify that the engine you want to use can meet these requirements.<br/><br/><br/>
<!--
https://developers.google.com/apps-script/guides/services/quotas#current_limitations
-->
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-79759360357214273912022-03-03T16:52:00.023+08:002022-03-12T14:53:36.978+08:00How to decompile and repack Android App on ChromeOS (Part 2)(1) This is the sequel to <a href="https://tungchingkai.blogspot.com/2022/03/how-to-decompile-and-repack-android-app.html" target="_blank">How to decompile android app (part 1)</a><br/> And the demo apk can be download from here. <a href="https://mega.nz/file/6sp3zKwY#mLIEiZjqsq5r6F-9ZXmk95uDaNJd25inr6BhjUXw-8c" target="_blank">TouchCalculator_1.0-debug.apk</a><br/>
<br/>
(2) Part 1 is to demo the use of ChromeOS (devloper mode on) plus the decompile tools and the process of decode and edit some resource files then rebuild the apk using apktool.<br/> If you have Windows machine, you can also download the required <a href="https://tungchingkai.blogspot.com/2022/01/decompile-and-recompile-android-apk.html" target="_blank">decompile tools as demo here</a>.<br/>
<br/>
(3) This part 2 is to continue to modify the logic in the Android App which involved the source code. I will use the JADX tools and Android Studio to edit the code.<br/>
<br/>
<code>cd ~/DecompileProjects<br/>
# Use jadx to decode the apk and export gradle project file and java source code<br/>
jadx --export-gradle TouchCalculator_1.0-debug.apk -d TouchCalculator2<br/>
</code><br/>
<br/>
(4) Then, launch Android Studio and open the project in ~/DecompileProjects/TouchCalculator2 and wait for the gradle to sync. If you try to Build -> Make Project (Ctrl F9), you will notice it has a lot of errors and these errors are mainly partial packages download from repo and many of them are not linkable. So we have to study the code, to see what are the actual code files needed for this project.<br/>
<br/>
(5) Then create a new Android Studio project file with <b><u>Empty Activity</u></b> and with the following parameters.
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhnM8Xa0AI0ofltzOICNi37EPOOkWeWJnTvjZIMQ5vciQVoVyysdlcDm2ovunV-7osgCagnzEvH98P9UXxFuiSIvaQdmt1_8jb_5PbMcPj-y_zym0O-PEAVgH7TCxaynjPooILOf624VK7JWABuc020YWv23kaoLKXJATmzVVG7ptcNXUK0bqsnP_JU=s1329" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="400" data-original-height="1012" data-original-width="1329" src="https://blogger.googleusercontent.com/img/a/AVvXsEhnM8Xa0AI0ofltzOICNi37EPOOkWeWJnTvjZIMQ5vciQVoVyysdlcDm2ovunV-7osgCagnzEvH98P9UXxFuiSIvaQdmt1_8jb_5PbMcPj-y_zym0O-PEAVgH7TCxaynjPooILOf624VK7JWABuc020YWv23kaoLKXJATmzVVG7ptcNXUK0bqsnP_JU=s400"/></a></div><br/>
<br/>
(6) After creation of the new project, copy the decompiled java source code and resource files to the New Project as below:<br/>
<dl class="codebox">
<dt>shell script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>cp ~/DecompileProjects/TouchCalculator2/app/src/main/java/com/pragmatouch/calculator/*.java ~/DecompileProjects/TouchCalculator3/app/src/main/java/com/pragmatouch/calculator/.
cp ~/DecompileProjects/TouchCalculator2/app/src/main/res/drawable/k*.xml ~/DecompileProjects/TouchCalculator3/app/src/main/res/drawable/.
cp ~/DecompileProjects/TouchCalculator2/app/src/main/res/drawable/stackview1.xml ~/DecompileProjects/TouchCalculator3/app/src/main/res/drawable/.
cp ~/DecompileProjects/TouchCalculator2/app/src/main/res/drawable/inputview1.xml ~/DecompileProjects/TouchCalculator3/app/src/main/res/drawable/.
cp ~/DecompileProjects/TouchCalculator2/app/src/main/res/drawable/appvertical1.xml ~/DecompileProjects/TouchCalculator3/app/src/main/res/drawable/.
cp ~/DecompileProjects/TouchCalculator2/app/src/main/res/values/colors.xml ~/DecompileProjects/TouchCalculator3/app/src/main/res/values/.
cp ~/DecompileProjects/TouchCalculator2/app/src/main/res/values/strings.xml ~/DecompileProjects/TouchCalculator3/app/src/main/res/values/.
cp ~/DecompileProjects/TouchCalculator2/app/src/main/res/layout/activity_main.xml ~/DecompileProjects/TouchCalculator3/app/src/main/res/layout/
cp ~/DecompileProjects/TouchCalculator2/app/src/main/res/layout/calutor.xml ~/DecompileProjects/TouchCalculator3/app/src/main/res/layout/
</code></dl><br/>
<br/>
<br/>
(7) Then, there are several changes to the build.gradle settings. Target Sdk should be set to 30 in order to build as App Bundle format.<br/>
# Sdk should not use 32 and change to 30<br/>
compileSdk 30<br/>
targetSdk 30<br/>
<br/>
# dependencies package change to lower version as below<br/>
implementation 'androidx.appcompat:appcompat:1.3.0'<br/>
implementation 'com.google.android.material:material:1.3.0'<br/>
<br/>
For Release build type add<br/>
debuggable false<br/>
<br/>
<br/>
(8) Then, we try to Build -> Make Project (Ctrl F9) again in the New Project and see if there are any errors to solve. For complex project, it is not possible to have a full project file to build after decompile. So there is a part 3 for this topic.<br/>
<br/>
(9) In fact, the <a href="https://www.codeproject.com/Articles/104931/Introduction-to-Android-development-TouchCalculato" target="_blank">project code was from here</a>, so I can find out the required project files easily. However, there are still some features of this app which have not been implemented yet and with the decompiled java source code, you can modify the decompiled code and rebuild it to apk and test again. ALternatively, you can <a href="https://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=104931" target="_blank">copy the original source code from here</a> and paste them to the relevant java source code files of your new project.<br/>
<br/>
(10) Change the resource files as in <a href="/2022/03/how-to-decompile-and-repack-android-app.html" target="_blank">Part 1 of this artcile</a> and add the following lines in MainActivity.java to implement the PERCENT, SQRT and RRECIPROC functions. And then Run the app in Android Studio or rebuild the apk to test on real Android device.
<dl class="codebox">
<dt>diff results <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>
# diff ./TouchCalculator2/app/src/main/java/com/pragmatouc
h/calculator/MainActivity.java ./TouchCalculator3/app/src/main/java/com/pragmatouch/calculator/MainActivity.java
192a193,236
> case 16: // PERCENT
> double userInputValue4 = tryParseUserInput();
> if (!Double.isNaN(userInputValue4)) {
> if (Double.isNaN(this.memoryValue)) {
> this.memoryValue = 0.0d;
> }
> this.memoryValue = (userInputValue4/100);
> this.userInputText.setText(doubleToString(this.memoryValue));
> this.hasFinalResult = true;
> return;
> }
> return;
> case 17: // SQRT
> // reject negative num
> if (currentInputLen > 0 && currentInput.charAt(0) == '-') {
> return;
> }
> double userInputValue5 = tryParseUserInput();
> if (!Double.isNaN(userInputValue5)) {
> if (Double.isNaN(this.memoryValue)) {
> this.memoryValue = 0.0d;
> }
> this.memoryValue = Math.sqrt(userInputValue5);
> this.userInputText.setText(doubleToString(this.memoryValue));
> this.hasFinalResult = true;
> return;
> }
> return;
> case 18: // RECIPROC
> // reject zero
> if (currentInputLen == 1 && currentInput.charAt(0) == '0') {
> return;
> }
> double userInputValue6 = tryParseUserInput();
> if (!Double.isNaN(userInputValue6)) {
> if (Double.isNaN(this.memoryValue)) {
> this.memoryValue = 0.0d;
> }
> this.memoryValue = (1/userInputValue6);
> this.userInputText.setText(doubleToString(this.memoryValue));
> this.hasFinalResult = true;
> return;
> }
> return;
276a321,332
> }
> try {
> $SwitchMap$com$pragmatouch$calculator$KeypadButton[KeypadButton.PERCENT.ordinal()] = 16;
> } catch (NoSuchFieldError e16) {
> }
> try {
> $SwitchMap$com$pragmatouch$calculator$KeypadButton[KeypadButton.SQRT.ordinal()] = 17;
> } catch (NoSuchFieldError e17) {
> }
> try {
> $SwitchMap$com$pragmatouch$calculator$KeypadButton[KeypadButton.RECIPROC.ordinal()] = 18;
> } catch (NoSuchFieldError e18) {
</code></dl><br/>
<br/><br/>
There are still bugs here and please feel free to correct them plus any new enhancements of this calculator and Enjoy Android Studio Programming.
<br/><br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiwTqVNkeXI-TVgL5qSOCPRLuwVXTEVgzq6pIjW20WXsz0BfGKjP8eEv9qTOKPs6wTGL0liFRRxcWXSxaYnyhovaKqfqYt5PSU8oWOTJvTvVLMMZBQbxo84fVhUjcW18BbubyMIO1t4EGfMWfrVFxuMf3QlPYFb_t9cVZvP0z0gHqcf_n712LGgW4-N=s1514" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" height="400" data-original-height="1514" data-original-width="1080" src="https://blogger.googleusercontent.com/img/a/AVvXsEiwTqVNkeXI-TVgL5qSOCPRLuwVXTEVgzq6pIjW20WXsz0BfGKjP8eEv9qTOKPs6wTGL0liFRRxcWXSxaYnyhovaKqfqYt5PSU8oWOTJvTvVLMMZBQbxo84fVhUjcW18BbubyMIO1t4EGfMWfrVFxuMf3QlPYFb_t9cVZvP0z0gHqcf_n712LGgW4-N=s400"/></a></div>
<br/><br/>
(11) When decompiling some apks that was compiled with old sdk or converting some old android projects to the at least using SDK 30, some conversion of libraries are needed as below:<br/>
<code>
In build.gradle, you should use androidx instead of old Android Support Libraries<br/>
compileSdkVersion 30<br/>
implementation 'androidx.appcompat:appcompat:1.3.0'<br/>
instead of 'com.android.support:appcompat-v7:28.0.0' or something like 'com.android.support:support-v13:26.0.2'<br/>
You also should use kotlin library if the decompiled project was converted from kotlin to Java<br/>
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"<br/>
<br/>
See here for reference. <a href="https://developer.android.com/jetpack/androidx" target="_blank">https://developer.android.com/jetpack/androidx</a><br/>
<br/>
In gradle.properties, you should setup useAndroidX and enableJetifier<br/>
android.useAndroidX=true<br/>
android.enableJetifier=true<br/>
<br/>
For converted/decompiled Java classes source, don't use old android support libraries, use androidx instead.<br/>
Full class-mapping here <a href="https://developer.android.com/jetpack/androidx/migrate/class-mappings" target="_blank">https://developer.android.com/jetpack/androidx/migrate/class-mappings</a><br/>
//import android.support.v4.app.NotificationCompat;<br/>
//import android.support.v7.app.AppCompatActivity;<br/>
//import android.support.v4.app.RemoteInput;<br/>
//import android.support.v4.app.Fragment;<br/>
import androidx.core.app.NotificationCompat;<br/>
import androidx.appcompat.app.AppCompatActivity;<br/>
import androidx.core.app.RemoteInput;<br/>
import androidx.fragment.app.Fragment;<br/>
import androidx.annotation.RequiresApi;<br/>
import android.annotation.TargetApi;<br/>
import android.annotation.SuppressLint;<br/>
<br/>
</code>
<br/><br/><br/>
(12) If you really want to support old devices and not using androidx, you should use SdkVersion 28 and compatible appcompat version as below:<br/>
<code>
compileSdkVersion 28<br/>
<br/>
implementation 'com.android.support:appcompat-v7:28.0.0'<br/>
<br/>
</code>
<!--
I can do :%s/<search_string>/<replace_string>/g for replacing a string across a file, or :s/<search_string>/<replace_string>/ to replace in current line.
Replace All:
:%s/foo/bar/g
Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.
For specific lines:
:6,10s/foo/bar/g
-->
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-23879680994374749132022-03-03T11:24:00.016+08:002023-04-30T22:32:57.627+08:00How to decompile and repack Android App on ChromeOS(1) You need ChromeOS with developer mode turn on for your machine. Either use a Chromebook (after powerwash) or install a recovery image on your old pc, with developer mode on (see here <a href="https://tungchingkai.blogspot.com/2022/02/how-to-install-chromeos-to-your-usb.html" target="_blank">How to install ChromeOS to your USB stick for your old PC</a>)<br/>
<br/>
(2) You have to install Android Studio and decompile tools on your ChromeOS machine (see here <a href="https://tungchingkai.blogspot.com/2022/03/how-to-run-android-emulator-in-chromeos.html" target="_blank">How to run Android Emulator on ChromeOS</a>)<br/>
<br/>
(3) Here is the walkthrough on how to decompile apk and change the resource file and repack and sign the apk file again. Assume you don't have the source code project file. The original demo apk can be download from here. <a href="https://mega.nz/file/6sp3zKwY#mLIEiZjqsq5r6F-9ZXmk95uDaNJd25inr6BhjUXw-8c" target="_blank">TouchCalculator_1.0-debug.apk</a><br/>
<br/>
(4) The problem of this TouchCalculator app has two problems on the interface: a) The memory text on the left should be smaller in size b) The key (on the right) with a comma is wrong and it should be a dot for input decimal point. Without the source project file, and in order to modify it, you have to decompile it and study the code and repack it to apk file to run.<br>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEggp7EmAlQg7qGH_jf-MAVPovL_I188BOu20GaMFeQhENrS7oNTmEtCJ0-ATsQftwl2_-JQz1kTVJcLXK4MQturxxbAL3nu9ORqGswk6uB4nOjh4SrETbvGYOZS882r7w5CzY0m_SQuzNp50O0NNQ-fIyrZ45mZxa4pHqUwoDNo0h9sG44pCGqiB05Z=s1140" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" height="400" data-original-height="1140" data-original-width="852" src="https://blogger.googleusercontent.com/img/a/AVvXsEggp7EmAlQg7qGH_jf-MAVPovL_I188BOu20GaMFeQhENrS7oNTmEtCJ0-ATsQftwl2_-JQz1kTVJcLXK4MQturxxbAL3nu9ORqGswk6uB4nOjh4SrETbvGYOZS882r7w5CzY0m_SQuzNp50O0NNQ-fIyrZ45mZxa4pHqUwoDNo0h9sG44pCGqiB05Z=s400"/></a></div>
<br/>
(5) Assume, you have the ChromeOS machine and installed software and also setup the decompile tools as in Steps (1) and (2). And In Linux Terminal execute these steps:<br/><br/>
<code>mkdir ~/DecompileProjects<br/>
cd ~/DecompileProjects<br/>
# Then copy the download apk file to this Linux folder DecompileProjects<br/>
# Use apktool to decode the apk<br/>
apktool decode TouchCalculator_1.0-debug.apk -o TouchCalculator<br/>
<br/>
# After studying the xml files in the res/layout folder<br/>
# modify the file: TouchCalculator/res/layout/activity_main.xml<br/>
# and change from 25.0sp to a smaller textSize of 12.0sp<br/>
<TextView android:textSize="<span style="color:red"><b>25.0sp</b></span>" android:textColor="@color/lightyellow" android:gravity="right" android:id="@id/txtMemory"<br/>
#<u>to</u><br/>
<TextView android:textSize="<span style="color:blue"><u><b>12.0sp</b></u></span>" android:textColor="@color/lightyellow" android:gravity="right" android:id="@id/txtMemory"<br/>
<br/>
# modify the file: TouchCalculator/smali_classes3/com/pragmatouch/calculator/KeypadButton.smali<br/>
<br>
# line 453 and change the button label from "," to "•" <br/>
const-string v3, "<span style="color:red"><b>,</b></span>"<br/>
# <u>to</u><br>
const-string v3, "<span style="color:blue"><u><b>\u2022</b></u></span>"<br/>
<br/>
# Use apktool to build the apk after modification of the resource files<br/>
apktool build TouchCalculator -o TouchCalculator_1.01.apk<br/>
# generate a keystore with SHA256RSA (if not yet generated) and remember the storepassword<br/>
keytool -genkey -v -keystore my-release-key256.keystore -alias mykey256 -sigalg SHA256withRSA -keyalg RSA -keysize 2048 -validity 10000 -deststoretype pkcs12<br>
# sign the apk with self-signed certificate and enter the storepassword<br/>
jarsigner -verbose -sigalg SHA256withRSA -keystore my-release-key256.keystore TouchCalculator_1.01.apk mykey256<br/>
# verify the signature<br/>
jarsigner -verify -verbose -certs -keystore my-release-key256.keystore TouchCalculator_1.01.apk <br/>
# zipalign the apk<br/>
zipalign -v 4 TouchCalculator_1.01.apk TouchCalculator_1.01-aligned.apk<br/>
</code>
<br/>
(6) Install the TouchCalculator_1.01-aligned.apk on your ChromeOS (with developer mode on) machine or your Android device (With Unknown Sources on) for testing. For ChromeOS, please uninstall the previous apk version before installation of the new one.<br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiwTqVNkeXI-TVgL5qSOCPRLuwVXTEVgzq6pIjW20WXsz0BfGKjP8eEv9qTOKPs6wTGL0liFRRxcWXSxaYnyhovaKqfqYt5PSU8oWOTJvTvVLMMZBQbxo84fVhUjcW18BbubyMIO1t4EGfMWfrVFxuMf3QlPYFb_t9cVZvP0z0gHqcf_n712LGgW4-N=s1514" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" height="400" data-original-height="1514" data-original-width="1080" src="https://blogger.googleusercontent.com/img/a/AVvXsEiwTqVNkeXI-TVgL5qSOCPRLuwVXTEVgzq6pIjW20WXsz0BfGKjP8eEv9qTOKPs6wTGL0liFRRxcWXSxaYnyhovaKqfqYt5PSU8oWOTJvTvVLMMZBQbxo84fVhUjcW18BbubyMIO1t4EGfMWfrVFxuMf3QlPYFb_t9cVZvP0z0gHqcf_n712LGgW4-N=s400"/></a></div>
<br/>
(7) This is just a proof of concept that using apktool can decompile then modify and repack again to an apk file. To further modify the java / smali code in the decompile source, just stay tune for my next article.<br/>
<br/><br/><br/>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-2422103321854612752022-03-01T10:59:00.041+08:002022-03-02T14:40:16.756+08:00How to run Android Emulator on ChromeOS(1) You need a ChromeOS machine with x86_64 CPU, 8GB RAM or above and for Intel CPU say i5 or above and <span style="color:blue">128GB storage</span>.<br/>
<br/>
(2) <a href="https://support.google.com/chromebook/answer/9145439" target="_blank">Setup Linux Environment (here)</a> in ChromeOS with <b><u>at least 20GB</u></b> linux file size and <a href="https://developer.android.com/studio" target="_blank">Download the installation file here</a> and while downloading the file Open the Terminal app then do step 3 below and then follow the <a href="https://developer.android.com/studio/install#chrome-os" target="_blank">Installation Steps of Android Studio in ChromeOS (here)</a>.<br/>
<br/>
(3) In Linux Terminal, you have to install libnns3<br/>
<code>sudo apt update && sudo apt upgrade<br/>
sudo apt install libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev<br/></code><br/>
<br/>
(4) After the acceptance of the license and <span style="color:blue"><b>Finish</b></span> with the download of SDK platform and tools and this might take some time to download and unzip. Then start Android Studio and with create a new blank project or import a project from github and wait for the update of gradle sync then goto Tools -> <span style="color:blue"><b>SDK Manager</b></span> to check whether the required SDK are proerly installed and then goto Tools -> <span style="color:blue"><b>Device Manager</b></span> and click <span style="color:blue"><b>Create device</b></span>.<br/>
<br/>
(5) Choose a Hardware layout e.g. Phone Pixel 4 XL and then click <span style="color:blue"><b>Next</b></span> to select a system image e.g. Release Name <span style="color:blue"><b>S, API 31, x86_64 Andoird 12.0 (Google APIs)</b></span> and then click the <span style="color:blue"><u>Download</u></span> next to Release Name. This may take a much longer time to download and unzip and would occupy a lot of Linux System storage space if you download more than one image.<br/>
<br/>
(6) After download is done, click <span style="color:blue"><b>Finish</b></span> and then <span style="color:blue"><b>Next</b></span> to name the device and fill in Advanced Settings if any and then click <span style="color:blue"><b>Finish</b></span> to create.<br/>
<br/>
(7) Then start the emulator by Running your project to the emulator and check whether the compileSdkVersion (e.g. 32) in build.gradle for Module match with your download and first click the Build -> <span style="color:blue"><b>Make Project (Ctrl+F9)</b></span> to see if there is any error. Then, start the project by clicking the Run -> <span style="color:blue"><b>Run App (Shift+F10)</b></span> or start the Emulator manually in Device Manager. After this step your ChromeOS will experience a significant slow down when the Emulator is running. My testing is that Intel 10th generation i5 CPU with 8GB Ram and 128 GB storage can run reasonably well for the simple project in Android Emulator.<br/>
<br/>
(8) If you want a larger screen or floating window for the Emulator, you can click the Settings button of the elumlator window and set it to <span style="color:blue"><b>View Mode -> Window</b></span> and then resize the detached window.<br/>
<br/>
(9) You can debug the project source code with the Emulator if you click Run -> <span style="color:blue"><b>Debug App (Shift+F9)</b></span>. If you have enabled Developer Mode in ChromeOS (which is default for Brunch framework). Alternatively, you could build the apk and side load it to the ChromeOS or real device for test run, but debugging on ChromeOS or real device has to first powerwash the ChromeOS machine and then open the ADB port<br/>
<br/>
(10) If you like to have this android studio project (written in Java) for testing, you can download it from here <a href="https://mega.nz/file/SgZ2BZxQ#Na-jK69_SFZzhQfSJ0o9sLy-LGGkbgP_C30kR0J1sPI" target="_blank">PeamonCalculator.zip</a><br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjKlFchsNeTnkVKNmxmLIVnpgQ9aX6Z88ONLJDZSA5IvAR4wqhyr-wFYO_iBc9LIh-l22rpTya_qhNWdpPg36BMBtk83ioryRwhYnawXLJDoBObq1ODPZWnMEcTdnauWN-UYko6PC_PbNhj6NyPgktDRZjz7x24hlH3Z4hou0RZRoqtaHWH3uqDap89=s992" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="400" data-original-height="724" data-original-width="992" src="https://blogger.googleusercontent.com/img/a/AVvXsEjKlFchsNeTnkVKNmxmLIVnpgQ9aX6Z88ONLJDZSA5IvAR4wqhyr-wFYO_iBc9LIh-l22rpTya_qhNWdpPg36BMBtk83ioryRwhYnawXLJDoBObq1ODPZWnMEcTdnauWN-UYko6PC_PbNhj6NyPgktDRZjz7x24hlH3Z4hou0RZRoqtaHWH3uqDap89=s400"/></a></div>
<br/>
There is another Android Studio Project on Calculator which is written in Kotlin <a href="https://github.com/codeWithCal/KotlinCalculator" target="_blank">GitHub project source code download here</a>. You might have to change the build SDK version for this project to your Settings in SDK, e.g. <b>compileSdkVersion 32</b> which is the default SDK version currently for newly installed Android Studio.<br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgn40ZkVZ949OXanjEoYCF5b9mXyCPk8SDcqfEhyNmh-M5swW1S-gfh-sNS3Ph15TzfqvQi-QG-zhLLLS8tRRN9sG6C956GQehN_f_YPyPiyjibD4SJThwKrwsUS0W5ERPI_Vskj6zX_FPCYVIvrsvXVdNxTY-tr_Gi8N4q7WTaioF2D9yZa7vK2DzL=s835" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" height="400" data-original-height="835" data-original-width="625" src="https://blogger.googleusercontent.com/img/a/AVvXsEgn40ZkVZ949OXanjEoYCF5b9mXyCPk8SDcqfEhyNmh-M5swW1S-gfh-sNS3Ph15TzfqvQi-QG-zhLLLS8tRRN9sG6C956GQehN_f_YPyPiyjibD4SJThwKrwsUS0W5ERPI_Vskj6zX_FPCYVIvrsvXVdNxTY-tr_Gi8N4q7WTaioF2D9yZa7vK2DzL=s400"/></a></div>
<br/><br/>
(11) If you want to use the JRE from Android Studio in Terminal, add these lines in your ~/.profile<br/>
<code>
# set JAVA_HOME for Android Studio<br/>
export JAVA_HOME=/opt/android-studio/jre<br/>
export ANDROID_HOME="$HOME/Android"<br/>
export ANDROID_SDK_ROOT="$ANDROID_HOME/Sdk"<br/>
PATH="$JAVA_HOME/bin:$ANDROID_SDK_ROOT/build-tools/30.0.3:$PATH"<br/>
</code>
<br/><br/>
(12) If you want to install decompile tools on ChromeOS<br/>
<code>
sudo apt install -y curl unzip<br/>
export ANDROID_DECOMPILE_TOOLS=="$ANDROID_HOME/DecompileTools"<br/>
# install apktool (d) decompile apk file to smali and resource folders or (b) build them to apk file<br/>
mkdir -p $ANDROID_DECOMPILE_TOOLS/apktool && pushd $ANDROID_DECOMPILE_TOOLS/apktool && curl -OL https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.6.0.jar && ln -s apktool_2.6.0.jar apktool.jar && curl -OL https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool && chmod +x apktool && popd<br/>
# install jadx (to compile smali file to java source code and support whole project or single file conversion)<br/>
curl -OL https://github.com/skylot/jadx/releases/download/v1.3.3/jadx-1.3.3.zip && unzip jadx-1.3.3.zip -d $ANDROID_DECOMPILE_TOOLS/jadx && rm -v jadx-1.3.3.zip<br/>
PATH="$ANDROID_HOME/DecompileTools/apktool:$ANDROID_HOME/DecompileTools/jadx/bin:$PATH"<br/>
</code><br/>
<br/>
# install jadx (to compile java/kotlin project files to smali code, but does not support single file conversion)<br/>
For <a href="https://github.com/ollide/intellij-java2smali" target="_blank">Java2Smali</a>, install the plugin version in Android Studio. File -> Settings (Ctrl-ALt-S ) -> Plugins and search <b>java2smali</b> to install. <br/>
<br/><br/>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-5866034213270341142022-02-27T12:39:00.012+08:002022-04-03T14:44:06.569+08:00How to install ChromeOS to your USB stick for your old PC(1) Prepare an USB stick with at least 16G. I am using 64G for demo and you need this size to download and install Linux in ChromeOS. Your PC should x86_64 based computer with UEFI boot support and ave Intel gen 1 to 9 to download rammus recovery image. For detail requirements see here <a href="https://github.com/sebanc/brunch" target="_blank">https://github.com/sebanc/brunch</a>.<br/>
<br/>
(2) For Windows OS, first install WSL2 and Ubuntu 20.04 and you must enable this in "Turn On Windows features on and off"<br/>
<br/>
(3) Alternativey, you can use Linux machine with Ubuntu 20.04 to do this<br/>
<br/>
(4) According to the <a href="https://github.com/sebanc/brunch/blob/master/install-with-windows.md" target="_blank">Brunch USB guide</a>
The ChromeOS recovery image is based on your CPU of your PC.<br/>
For Intel<br/>
"rammus" is suggested for 1st gen -> 9th gen.<br/>
"volteer" is suggested for 10th & 11th gen.<br/>
11th gen (and some 10th gen) may need kernel 5.10<br/>
For AMD<br/>
"grunt" is suggested for Stoney Ridge & Bristol Ridge.<br/>
"zork" is suggested for Ryzen.<br/>
Ryzen 4xxx devices need kernel 5.10 when Brunch Framework boot up<br/><br/>
(5) After setting up the Ubuntu user and password run these scripts to create the image file (e.g. rammus for USB 64G drive)
<br/>
<code>
sudo apt update<br/>
sudo apt -y install pv cgpt tar unzip<br/>
mkdir rammus<br/>
cd rammus<br/>
wget https://github.com/sebanc/brunch/releases/download/r97-stable-20220121/brunch_r97_stable_20220121.tar.gz<br/>
tar xzvf brunch_r97_stable_20220121.tar.gz<br/>
wget https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_14388.61.0_rammus_recovery_stable-channel_mp-v2.bin.zip<br/>
unzip chromeos_14388.61.0_rammus_recovery_stable-channel_mp-v2.bin.zip<br/>
# 64G USB has only about 58G for actual usage, so the size parameter here is 58.<br/>
sudo bash chromeos-install.sh -src chromeos_14388.61.0_rammus_recovery_stable-channel_mp-v2.bin -dst /mnt/c/Users/Public/Downloads/chromeos_rammus_58g.bin -s 58<br/>
</code><br/><br/>
(6) Then use ChromeOS Recovery Utility to flash the images, Use local image in Settings and select the "C:/Users/Public/Downloads/chromeos_rammus_58g.bin" image.
<a href="https://community.acer.com/en/kb/articles/11288-create-a-chromebook-recovery-drive-using-a-local-chrome-os-image" target="_blank">See here</a>
<br/><br/>
(7) If you are lazy to create this image, you can use mine and download it from <a href="https://mega.nz/file/K4ATlSba#cFqXuf28Ls-Bs4PTOx7nT5hutmaE92G6mywGePjFIew" target="_blank">chromeos_rammus_58g.bin.zip (3.61GB)</a>. You don't need to unzip it for creation of USB flash drive in ChromeOS Recovery Utility or <a href="https://rufus.ie/en/" target="_blank">Rufus</a><br/><br/>
(8) If your PC has secure boot enabled, either disable it (ig you have set the supervisor password) or import the key from USB. To enroll the key directly from a USB, select OK -> Enroll key from disk -> EFI-SYSTEM -> brunch.der -> Continue and reboot. Moreoover, enable of UEFI support and change the boot order to USB is needed in BIOS.<br/><br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgcfCgU_kcEcIiHSS9QDtWR3bOjSv6AWf75PnGMxBddCQ3VAvIuWIAxeLYwjuJGFH1vy3s0h0j2DTolZLzkkX52QiPeVGxixcilKpmcZUKVv5RijgCurQAqOKYOi5Htrb_7IWSCZbLMp6lgTFVHz6K4TgtBf6pkpXPqiASN8XM9ksnjPrdaufsC-svj=s1197" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="400" data-original-height="750" data-original-width="1197" src="https://blogger.googleusercontent.com/img/a/AVvXsEgcfCgU_kcEcIiHSS9QDtWR3bOjSv6AWf75PnGMxBddCQ3VAvIuWIAxeLYwjuJGFH1vy3s0h0j2DTolZLzkkX52QiPeVGxixcilKpmcZUKVv5RijgCurQAqOKYOi5Htrb_7IWSCZbLMp6lgTFVHz6K4TgtBf6pkpXPqiASN8XM9ksnjPrdaufsC-svj=s400"/></a></div>
<!--
sudo apt update
sudo apt -y install pv cgpt tar unzip wget
mkdir rammus99
cd rammus99
wget https://github.com/sebanc/brunch/releases/download/r100-stable-20220402/brunch_r100_stable_20220402.tar.gz
tar xzvf brunch_r100_stable_20220402.tar.gz
wget https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_14469.59.0_rammus_recovery_stable-channel_mp-v2.bin.zip
unzip chromeos_14469.59.0_rammus_recovery_stable-channel_mp-v2.bin.zip
lsblk
bash chromeos-install.sh -src chromeos_14469.59.0_rammus_recovery_stable-channel_mp-v2.bin -dst /dev/sdc -s 232
-->
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-38702458100710288062022-02-25T17:04:00.049+08:002022-04-15T18:06:20.691+08:00How to download and resize Chrome OS Flex Image for USB boot InstallWhile you can live boot Chrome OS Flex from the USB installer, Google recommends that you fully install it on devices. When you live-boot Chrome OS Flex, limited storage (4GB) is available because of the layout of Chrome OS Flex's partition table. To overcome this limitation, we have to resize the partition to fully utilise your USB storage space.<br/><br/>
<code>How to download and resize Chrome OS Flex Image to 20GB, which is suitable to be use on a 32GB USB drive.<br/>
# use a linux machine, or Windows WSL Ubuntu 20.04
# see here <a href="https://github.com/sebanc/brunch/blob/master/install-with-windows.md" target="_blank">https://github.com/sebanc/brunch/blob/master/install-with-windows.md</a><br/>
</code> <br/>
<dl class="codebox">
<dt>shell script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>sudo apt update
sudo apt -y install pv cgpt tar unzip curl cloud-guest-utils
mkdir -p ~/Downloads
cd ~/Downloads
# download ChromeOS Flex image based on this conf file <a href="https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery.conf" target="_blank">https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery.conf</a>
# curl -OL https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_14516.0.0_reven_recovery_dev-channel_mp-v2.bin.zip
curl -OL https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_14574.0.0_reven_recovery_dev-channel_mp-v2.bin.zip
unzip chromeos_14574.0.0_reven_recovery_dev-channel_mp-v2.bin.zip
ls -lh chromeos_14574.0.0_reven_recovery_dev-channel_mp-v2.bin
# 20G is seek=20971520
# 28G is seek=29360128 (there is only 28G for 32G USB stick)
# 58G is seek=60817408 (there is only 58G for 64G USB stick)
# <b>don't do method 1 on removable HD</b>
# grow image method 1
dd if=/dev/zero of=chromeos_14516.0.0_reven_recovery_dev-channel_mp-v2.bin seek=20971520 obs=1024 count=0
# grow image method 2, slower but works on removeable HD
# 58G is count=52452 (there is only 58G for 64G USB stick)
expr 20 \* 1024 - 6940 # calculate 20G = 13540
expr 28 \* 1024 - 6940 # calculate 28G = 21732
expr 58 \* 1024 - 6940 # calculate 58G = 52452
dd if=/dev/zero bs=1M count=13540 >> ./chromeos_14574.0.0_reven_recovery_dev-channel_mp-v2.bin
# rename the file
mv chromeos_14574.0.0_reven_recovery_dev-channel_mp-v2.bin chromeosflex20g.bin
# grow partition 1, growpart is part of cloud-guest-utils package
growpart chromeosflex20g.bin 1
# show new data partition 1, start is 5152768 , size is now 36790239 (17G)
cgpt show chromeosflex20g.bin | grep -B 5 STATE
cgpt repair chromeosflex20g.bin
</code></dl><br/>
<br/><br/>
Then use ChromeOS Recovery Utility to flash the images, Use local image in Settings and select the chromeosflex20g.bin image.<br/>
<a href="https://community.acer.com/en/kb/articles/11288-create-a-chromebook-recovery-drive-using-a-local-chrome-os-image" target="_blank"> See here</a><br/><br/>
<br/><br/>
<span style="background-color:red; color:white;
font-size:140%;"><b>IMPORTANT</b></span><br/>
The final step is to put the USB drive to linux system and check the drive using<br/>
<code>
sudo fdisk -l<br/>
# e.g. the USB drive partition 1 is sda1<br/>
<br/>
# first check<br/>
sudo e2fsck -f /dev/sda1<br/>
# then resize it<br/>
sudo resize2fs /dev/sda1<br/>
</code><br/><br/>
However, one of the limitations of live-boot USB is that the ChromeOS cannot be updated live. So your work has to be able to backup to Google Drive, Dropbox (using File System for Dropbox), OneDrive (using File System for OneDrive) or your LAN network share drive.<br/><br/>
<!--
https://forums.kali.org/showthread.php?27350-Chromebook-expand-resize-grow-partition-rootfs
sudo apt install cgpt cloud-guest-utils
1890 cd Downloads/
1892 unxz FydeOS_for_PC_v14.0-stable.img.xz
1895 dd if=/dev/zero of=FydeOS_for_PC_v14.0-stable.img seek=20971520 obs=1024 count=0
1896 growpart FydeOS_for_PC_v14.0-stable.img 1
1898 cgpt show FydeOS_for_PC_v14.0-stable.img
1903 cgpt show FydeOS_for_PC_v14.0-stable.img | grep "STATE"
1917 sudo losetup /dev/loop18 FydeOS_for_PC_v14.0-stable.img
1918 sudo partprobe /dev/loop18
1919 sudo cgpt show '/dev/loop18p1' && sudo resize2fs -p '/dev/loop18p1'
1920 sudo losetup --detach /dev/loop18
1733 unzip chromeos_14516.0.0_reven_recovery_dev-channel_mp-v2.bin.zip
1734 dd if=/dev/zero of=chromeos_14516.0.0_reven_recovery_dev-channel_mp-v2.bin seek=20971520 obs=1024 count=0
1735 mv chromeos_14516.0.0_reven_recovery_dev-channel_mp-v2.bin chromeos20g.bin
1736 ls -lh *.bin
1737 export start=$(cgpt show chromeos20g.bin | grep 'STATE' | awk '{ print $1 }')
1738 export size=$(expr $(cgpt show chromeos20g.bin | grep 'Sec GPT table' | awk '{ print $1 }') - $start )
1739 echo "start is " $start ", size is " $size ", new data partition size is " $( expr $size \* 512 / 1024 / 1024
/ 1024 ) "GB"
1740 cgpt show chromeos20g.bin | grep 'Sec GPT table'
1741 parted chromeos20g.bin
1742 export start=$(cgpt show chromeos20g.bin | grep 'STATE' | awk '{ print $1 }')
1743 export size=$(expr $(cgpt show chromeos20g.bin | grep 'Sec GPT table' | awk '{ print $1 }') - $start )
1744 echo "start is " $start ", size is " $size ", new data partition size is " $( expr $size \* 512 / 1024 / 1024
/ 1024 ) "GB"
1745 cgpt add -i 1 -t data -b $start -s $size -l STATE chromeos20g.bin
1746 cgpt show chromeos20g.bin | grep -B 5 STATE
1747 growpart chromeos20g.bin 1
1988 unxz -k FydeOS_for_PC_v14.0-stable.img.xz
1989 fdisk -l -u FydeOS_for_PC_v14.0-stable.img
1990 parted FydeOS_for_PC_v14.0-stable.img unit s print
1991 parted chromeos_14516.0.0_reven_recovery_dev-channel_mp-v2.bin unit s print
1992 dd if=/dev/zero bs=1M count=4096 >> FydeOS_for_PC_v14.0-stable.img
1993 cgpt show FydeOS_for_PC_v14.0-stable.img | grep -B 5 "STATE"
1994 sudo losetup --detach /dev/loop18
1995 sudo losetup /dev/loop18 FydeOS_for_PC_v14.0-stable.img
// not working for resizepart if shrink volume
sudo parted /media/kali/Ventoy/iso/ubuntu-mbp-20.04.img --script unit s resizepart 2 219679694s Yes
1996 sudo partprobe /dev/loop18
1998 sudo parted /dev/loop18 unit s print
1999 sudo parted /dev/loop18 --script rm 1
2001 sudo parted /dev/loop18 --script mkpart STATE 5898240s 100%
2002 sudo parted /dev/loop18 unit s print
2003 sudo e2fsck -f -y -v -C 0 '/dev/loop18p1'
2004 sudo resize2fs -p '/dev/loop18p1'
2005 sudo losetup --detach /dev/loop18
-->
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-60612550186941251782022-01-25T17:20:00.016+08:002022-01-27T06:10:19.947+08:00How to install vs code-server in Windows WSL2 and setup firewall rules to access from other LAN machines(1) Start Ubuntu 20.04 of WSL2 and install code-server<br/>
<code>curl -fsSL https://code-server.dev/install.sh | sh</code>
<br/><br/>
(2) Modify bind IP address port settings and password of the code-server<br/>
Get Ubuntu IP address<br/>
<code>ifconfig eth0 | grep 'inet '</code> <br/>
Edit bind address and password in <br/>
<code>~/.config/code-server/config.yaml</code>
<br/><br/>
(3) start code-server in Ubuntu<br/>
<code>code-server</code>
<br/><br/>
(4) Modify firewall rule and add forward port in Windows using PowerShell with Admin Right. Create the following file vscode_server_port_wsl2.ps1
and run in PowerShell with Admin Right<br/>
<code>.\vscode_server_port_wsl2.ps1</code> <br/>
<dl class="codebox">
<dt>vscode_server_port_wsl2.ps1 <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>
# Get network information
$network_information = bash.exe -c "ifconfig eth0 | grep 'inet '";
# Define ip address pattern
$ip_address_pattern = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}";
# Get ip address
$ip_address = $network_information -match $ip_address_pattern
# Proceed if ip address is found
if ($ip_address) {
# Get remote address
$remote_address = $matches[0];
}
# Define rule name
$rule_name = "VS Code Server (WSL2)";
# Define port for the VS Code Server - default is 8080
$port = 8080;
# Check if rule exists
$rule_exists = Get-NetFirewallRule -DisplayName $rule_name 2> $null;
# Proceed if rule doesn't exists
if (-Not $rule_exists) {
# Add new inbound rule
New-NetFirewallRule -DisplayName $rule_name -Direction Inbound -LocalPort $port -Protocol TCP -Action Allow
}
# Define listen address
$listen_address = "0.0.0.0";
# Update ip address
iex "netsh interface portproxy delete v4tov4 listenport = $port listenaddress = $listen_address";
iex "netsh interface portproxy add v4tov4 listenport = $port listenaddress = $listen_address connectport = $port connectaddress = $remote_address";
</code></dl><br/>
Do this in powershell with admin right.<br/>
<p><span style="color:blue">Set-ExecutionPolicy Unrestricted -Force</span></p><br/><br/>
<br/><br/>
(5) Test access of code-server from other machine in the LAN<br/>
Use browser to access this address and enter password as in <br/>
<code>http://<IP address of your windows machine>:8080/</code>
<br/><br/>
(6) Test access of code-server from VPN connection from Internet.<br/>
First use OpenVPN to connect to your home/office network<br/>
Then use browser to access<br/>
<code>http://<IP address of your windows machine>:8080/</code>
<br/><br/>
(7) If you have installed docker for Windows, this command will help you to install and run code-server in docker.
<br/>
<dl class="codebox">
<dt>command prompt shell <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code># Testing on local host machine
docker run --name code-server -p 127.0.0.1:8080:8080 -v "$HOME/.config:/home/coder/.config" -v "$HOME/:/home/coder/project" -e "USER=$env:UserName" -e "DOCKER_USER=$env:UserName" codercom/code-server:latest
#or publish to the host machine IP address with port no 8081, to allow access from other LAN machines
docker run --name code-server -p 8081:8080 -v "$HOME/.config:/home/coder/.config" -v "$HOME/:/home/coder/project" -e "USER=$env:UserName" -e "DOCKER_USER=$env:UserName" codercom/code-server:latest
# stop container
docker stop code-server
# start container
docker start code-server
</code></dl>
run this command to get the password in config.yaml and then edit it of wanted.<br/>
<code>docker exec -it code-server cat .config/code-server/config.yaml</code><br/>
or <br/>
<code>type $HOME\.config\code-server\config.yaml</code><br/>
.
.
.
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-213809145866824072022-01-13T12:27:00.040+08:002023-05-01T10:06:52.518+08:00Decompile and Recompile an Android APK using apktoolYou need these tools to do the jobs<br/>
<br/>
<a href="https://developer.android.com/studio" target="_blank">Android Studio</a> (with build tools such as keytool, jarsigner)<br/>
<a href="https://bitbucket.org/iBotPeaches/apktool/downloads" target="_blank">apktool</a> download from https://bitbucket.org/iBotPeaches/apktool/downloads/ and extract and rename to apktool.jar<br/>
<a href="https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/windows/apktool.bat" target="_blank">apktool wrapper script</a> https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/windows/apktool.bat<br/>
<a href="https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html" target="_blank">Java SE 8 JDK</a> download from https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html<br/>
<a href="https://sourceforge.net/projects/dex2jar" target="_blank">dex2jar</a> download from https://sourceforge.net/projects/dex2jar/<br/>
<a href="http://jd.benow.ca" target="_blank">JD_GUI</a> download from http://jd.benow.ca/<br/>
<a href="https://github.com/JesusFreke/smalidea" target="_blank">smalidea</a> download from https://github.com/JesusFreke/smalidea<br/>
Online Decompiler for apk <a href="https://appscms.com/apk-decompiler" target="_blank">https://appscms.com/apk-decompiler</a><br/>
<a href="https://github.com/skylot/jadx/releases" target="_blank">jadx download from https://github.com/skylot/jadx/releases</a>
<br/><br/>
apktool — tool for reverse engineering Android apk files. In this case we are using to extract files from apk and rebuild.<br/>
keytool — Java tool for creating keys/certs, that comes with the Java SE JDK.<br/>
jarsigner Java tool for signing JAR/APK files, that comes with the Java SE JDK.<br/>
zipalign — archive alignment tool, that comes with the Android SDK.<br/>
JD-GUI — To view java code<br/>
dex2jar — Converts Android dex files to class/jar files.<br/>
smalidea is a smali language plugin for AS and to edit the file in Android Studio<br/>
jadx — convert single smali file to java code to test the modification of smali<br/><br/>
For smali syntax, please refer to this doc <br/>
https://programmer.help/blogs/smali-introduction-manual.html<br/>
or http://source.android.com/devices/tech/dalvik/dalvik-bytecode.html
<br/><br/>
Instructions:<br/>
First, Take any apk file and unpack(decompile) it. This will create an “application” directory with assets, resources, compiled code, etc.<br/>
# To decompile an apk<br/>
<code>apktool d -r -s my_application.apk</code><br/>
or<br/>
<code>apktool d my_application.apk</code><br/>
<br/>
Then, you can use Android Studio to open the smali file and edit it. Use APKRepacker to test the single smali file conversion.<br/>
<br/>
# To recompile(build) the apk<br/>
<code>apktool b -f -d my_application -o my_application2.apk</code><br/>
<br/>
After recompiling (building) the apk the new apk (my_application2.apk) will be generated in directory.<br/>
<br/>
The APK must be signed before you run on your device. If you want an official key from google play signing key, you should register with https://play.google.com/console/u/0/signup first and pay $25 registration key<br/>
Before signing an apk, create a self-signing key if you don't have an existing one from google play. If prompted for a password, create your own password.<br/>
These tools are installed withn JDK e.g. in "c:\Program Files\Java\jdk1.8.0_301\bin\". Add this to the environment PATH.<br/>
<br/>
macOS binary are here
/Applications/Android Studio.app/Contents/jre/Contents/Home/bin
<br/>
<br/>
# To generate a key. And remember the store password<br/>
<code>keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000</code><br/>
<br/>
# if want to generate SHA256withRSA keystore (in order to get rid of the warning of security when signing with SHA1), use this command<br/>
<code>keytool -genkey -v -keystore my-release-key256.keystore -alias mykey256 -sigalg SHA256withRSA -keyalg RSA -keysize 2048 -validity 10000 -deststoretype pkcs12</code><br/>
<br/>
Now sign the APK with the key:<br/>
# Sign the apk<br/>
<code>jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application2.apk alias_name</code><br/>
<br/>
# if Sign with SHA256withRSA (in order to get rid of the warning of security when signing with SHA1)<br/>
<code>jarsigner -verbose -sigalg SHA256withRSA -keystore my-release-key256.keystore my_application2.apk mykey256</code><br/>
<br/>
# Verify apk<br/>
<code>jarsigner -verify -verbose -certs -keystore my-release-key.keystore my_application2.apk</code><br/>
<br/>
# Verify apk with SHA256withRSA<br/>
<code>jarsigner -verify -verbose -certs -keystore my-release-key256.keystore my_application2.apk</code><br/>
<br/>
# Finally, the apk must be aligned for optimal loading:<br/>
zipalign is installed with Android SDK e.g. in c:\Users\User\AppData\Local\Android\Sdk\build-tools\28.0.3\zipalign.exe Add this to the environment PATH.<br/>
<code>zipalign -v 4 my_application2.apk my_application2-aligned.apk</code><br/>
you have a my_application2-aligned.apk file, which you can install onto your device.<br/>
<br/><br/>
Other useful tools using command prompt under Windows<br/>
<code>
<i># Command Prompt to list android virtual devices</i>
%USERPROFILE%\AppData\Local\Android\Sdk\emulator\emulator -list-avds<br/>
<i># PowerShell command to list android virtual devices</i>
& $env:UserProfile\AppData\Local\Android\Sdk\emulator\emulator -list-avds<br/>
<i># Command Prompt to list android virtual device in background</i><br/>
start /b %USERPROFILE%\AppData\Local\Android\Sdk\emulator\emulator -avd Pixel_3a_API_30_x86 -netdelay none -netspeed full<br/>
<i># Command Prompt to show running emulator devices</i><br/>
%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb devices<br/>
<i># Command Prompt to attach to running emulator device shell</i><br/>
%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb -s emulator-5554 shell<br/>
<i># Command Prompt to install apk to running emulator device</i><br/>
%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb -s emulator-5554 install %USERPROFILE%\Downloads\my_application2-aligned.apk<br/>
export ANDROID_HOME="%USERPROFILE%\AppData\Local\Android\Sdk"
</code><br/><br/>
<br/><br/>
Other useful tools using Terminal under macOS<br/>
<code>
<i># macOS Terminal to list android virtual devices</i>
$HOME/Library/Android/sdk/emulator/emulator -list-avds<br/>
<i># macOS Terminal to show running emulator devices</i><br/>
$HOME/Library/Android/sdk/platform-tools/adb devices<br/>
<i># macOS Terminal to attach to running emulator device shell</i><br/>
$HOME/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell<br/>
<i># macOS Terminal to install apk to running emulator device</i><br/>
$HOME/Library/Android/sdk/platform-tools/adb -s emulator-5554 install ~/Downloads/my_application2-aligned.apk<br/>
export ANDROID_HOME="$HOME/Library/Android/sdk"
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
export PATH=$ANDROID_HOME/build-tools/30.0.3:$ANDROID_HOME/platform-tools:$JAVA_HOME/bin:$PATH
</code><br/><br/>
<dl class="codebox">
<dt>Setup sdk and decompile tools in WSL2 Ubuntu 20.04 <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>#!/bin/bash
sudo apt install -y libarchive-tools
export ANDROID_SDK_TOOLS_VERSION=6858069
export ANDROID_SDK_TOOLS_CHECKSUM=87f6dcf41d4e642e37ba03cb2e387a542aa0bd73cb689a9e7152aad40a6e7a08
export ANDROID_HOME="/opt/android-sdk-linux"
export ANDROID_SDK_ROOT="/opt/android-sdk-linux"
export ANDROID_DECOMPILE_TOOLS="$ANDROID_HOME/Decompile"
curl -s https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS_VERSION}_latest.zip > ./tools.zip && echo "$ANDROID_SDK_TOOLS_CHECKSUM ./tools.zip" | sha256sum -c && sudo mkdir -p $ANDROID_HOME && sudo chown $(id -u):$(id -g) $ANDROID_HOME && unzip -qq ./tools.zip -d $ANDROID_HOME && rm -v ./tools.zip
sudo mkdir -p $ANDROID_HOME/licenses/ && sudo chown $(id -u):$(id -g) $ANDROID_HOME/licenses && echo "8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > $ANDROID_HOME/licenses/android-sdk-license && echo "84831b9409646a918e30573bab4c9c91346d8abd\n504667f4c0de7af1a06de9f4b1727b84351f2910" > $ANDROID_HOME/licenses/android-sdk-preview-license --licenses && yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --licenses --sdk_root=${ANDROID_SDK_ROOT}
curl -OL https://raw.githubusercontent.com/MobileDevOps/android-sdk-image/master/packages.txt
$ANDROID_HOME/cmdline-tools/bin/sdkmanager --update --sdk_root=${ANDROID_SDK_ROOT} && while read -r pkg; do PKGS="${PKGS}${pkg} "; done < $HOME/packages.txt && $ANDROID_HOME/cmdline-tools/bin/sdkmanager $PKGS > /dev/null --sdk_root=${ANDROID_SDK_ROOT}
curl -OL https://nchc.dl.sourceforge.net/project/dex2jar/dex2jar-2.0.zip && unzip dex2jar-2.0.zip -d $ANDROID_HOME/Decompile && chmod +x $ANDROID_HOME/Decompile/dex2jar-2.0/*.sh && rm -v dex2jar-2.0.zip
mkdir -p $ANDROID_DECOMPILE_TOOLS/apktool && pushd $ANDROID_DECOMPILE_TOOLS/apktool && curl -OL https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.6.0.jar && ln -s apktool_2.6.0.jar apktool.jar && curl -OL https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool && chmod +x apktool && popd
curl -OL https://github.com/skylot/jadx/releases/download/v1.3.3/jadx-1.3.3.zip && unzip jadx-1.3.3.zip -d $ANDROID_DECOMPILE_TOOLS/jadx && rm -v jadx-1.3.3.zip
mkdir -p $ANDROID_DECOMPILE_TOOLS/java2smali && curl -OL https://github.com/izgzhen/java2smali/releases/download/1.1/dist.zip && bsdtar xvf dist.zip --strip-components=1 -C $ANDROID_DECOMPILE_TOOLS/java2smali/ && rm -v dist.zip
mkdir -p $ANDROID_DECOMPILE_TOOLS/java2smali && pushd $ANDROID_HOME/Decompile/java2smali && curl -OL https://github.com/JesusFreke/smali/releases/download/v2.0b6/smali-2.0b6.jar && curl -OL https://github.com/JesusFreke/smali/releases/download/v2.0b6/baksmali-2.0b6.jar && curl -OL https://raw.githubusercontent.com/JesusFreke/smali/master/scripts/smali && curl -OL https://raw.githubusercontent.com/JesusFreke/smali/master/scripts/baksmali && popd
pushd $ANDROID_DECOMPILE_TOOLS/java2smali && ln -s baksmali-2.0b6.jar baksmali.jar && ln -s smali-2.0b6.jar smali.jar && chmod +x baksmali && chmod +x smali && popd
# Then append these lines to ~/.profile
export ANDROID_HOME="/opt/android-sdk-linux"
export ANDROID_SDK_ROOT=$ANDROID_HOME
export ANDROID_DECOMPILE_TOOLS=="$ANDROID_HOME/Decompile"
export PATH=$ANDROID_HOME/cmdline-tools:$ANDROID_HOME/cmdline-tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools/30.0.3:$ANDROID_DECOMPILE_TOOLS/jadx/bin:$ANDROID_DECOMPILE_TOOLS/java2smali:$ANDROID_DECOMPILE_TOOLS/apktool:$ANDROID_DECOMPILE_TOOLS/dex2jar-2.0:$PATH
</code></dl><br/>
<br/><br/>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-36399756695009111852021-11-12T04:48:00.003+08:002021-11-12T04:48:25.688+08:00Termux pkg update error on Android devicesIf you have pkg update error on your old installation of Android devices<br/>
<br/>
pkg install termux-tools<br/>
termux-change-repoUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-66383296359085981872021-07-13T05:03:00.022+08:002021-07-27T14:01:49.627+08:00Personal Installation Guide for new Chromebook(1) For new chromebook, there is free Google One 100GB and DropBox 100GB both for 1 year. See here.
<a href="https://www.google.com/chromebook/perks/" target="_blank">https://www.google.com/chromebook/perks/</a><br/><br/>
(2) To enable google drive on Files app of Chrome OS, Bottom right clock -> Settings Icon -> Advanced -> Files -> Disconnect Google Drive account set to off.<br/><br/>
(3) To enable DropBox on Files app of Chrome OS, Install DropBox app from Android Play Store and login dropbox.<br/><br/>
(4) To enable smb share on Files app of Chrome OS, Open Files App and select the 3 dots menu on top right and Choose "Service" and then "SMB File Share".<br/><br/>
(5) To enable OneDrive (readonly) on Files app of Chrome OS, Install OneDrive App from Google Play Store.<br/><br/>
(5.1) How to share files or Google Drive with Linux apps on Chrome OS
<dl class="codebox">
<dt> <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>(a) Open the My Files app.
(b) From within that app, locate the directory housing the documents you want accessible by the installed Linux apps.
(c) Right-click the folder in question and then select Share With Linux. The sharing happens immediately.
(d) Google Drive is in /mnt/chromeos/GoogleDrive/MyDrive/
(e) MyFiles is in /mnt/chromeos/MyFiles/
</code></dl>
<br /><br /><br /><br />
(6) If you cannot install Chrome OS Linux Beta Crostini now, install Termux App as a temporary solution, Download the apk file from here <a href="https://f-droid.org/en/packages/com.termux/" target="_blank">https://f-droid.org/en/packages/com.termux/</a> (Google Play Version was outdated).<br/><br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6hcaAS11tDdDvjFOP2JGes9J4xgcddhwujApog6odjlRQKgGsxKWbDY4Bxfx1AKeNzpofhxa-g6GccWbc9jUKIZWBtIycaGk5Bb54YEb12IJLa2TgVjz3Hm8BNIk3VAvrX2NPAYKfBQ4/s423/Screenshot+2021-07-14+10.21.56+PM.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" height="400" data-original-height="423" data-original-width="369" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6hcaAS11tDdDvjFOP2JGes9J4xgcddhwujApog6odjlRQKgGsxKWbDY4Bxfx1AKeNzpofhxa-g6GccWbc9jUKIZWBtIycaGk5Bb54YEb12IJLa2TgVjz3Hm8BNIk3VAvrX2NPAYKfBQ4/s400/Screenshot+2021-07-14+10.21.56+PM.png"/></a></div>
(7) How to install Linux Web Development Environment on Chrome OS, see here <a href="https://www.youtube.com/watch?v=3CWUAisN-vo" target="_blank">https://www.youtube.com/watch?v=3CWUAisN-vo</a><br/><br/>
<dl class="codebox">
<dt>shellscript.sh <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>
# nodejs dependencies
sudo apt install gnupg2
# install nodejs v14 and npm v6
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt-get install -y nodejs
# try it out! Sweep for mines
sudo apt install libnss3
git clone https://github.com/GoogleChromeLabs/proxx.git
cd proxx
npm install
npm run build
npm run serve
# Install React
npm install create-react-app
# Create a React app
npx create-react-app hello-world-react
cd hello-world-react
npm start
# Install Angular
npm install @angular/cli
# Create an Angular app
ng new my-angular-project
cd my-angular-project
ng serve
# Docker Dependencies
sudo apt install ca-certificates software-properties-common
# Docker repository
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
# Install Docker-ce
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
# Install docker client only and connect to docker desktop of windows machine
cd $HOME
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.7.tgz
tar xzvf docker-20.10.7.tgz
./docker/docker -H tcp://10.0.1.78:2375 images
# Or simply add the corresponding variables to ~/.bashrc
export DOCKER_HOST=tcp://192.168.1.78:2375
export PATH=$PATH:~/docker
#
# To detach the docker tty without exiting the shell, use the escape sequence Ctrl-p + Ctrl-q + Ctrl-c
#
# for docker desktop on mac, see this solution to open tcp port
<a href="https://stackoverflow.com/questions/39411126/access-docker-daemon-remote-api-on-docker-for-mac" target="_blank">https://stackoverflow.com/questions/39411126/access-docker-daemon-remote-api-on-docker-for-mac</a>
# on Mac machine
brew install socat
socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &
</code></dl>
<br /><br /><br /><br />
(8) System requirement for Android Studio for Chrome OS is 8GB RAM and Intel i5 CPU or above. <br/><br/>
(9) Flatpak applications can be installed on Chrome OS with the Crostini Linux compatibility layer. See here <a href="https://flatpak.org/setup/Chrome%20OS/" target="_blank">https://flatpak.org/setup/Chrome%20OS/</a><br/><br/>
(10) Popular shortcuts <a href="https://support.google.com/chromebook/answer/183101?hl=en" target="_blank">https://support.google.com/chromebook/answer/183101?hl=en</a><br/><br/>
(11) How to access onedrive in linux partition<br/><br/>
<dl class="codebox">
<dt>shellscript.sh <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code># download latest deb package from <a href="https://launchpad.net/~jstaf/+archive/ubuntu/onedriver/+packages" target="_blank">https://launchpad.net/~jstaf/+archive/ubuntu/onedriver/+packages</a>
wget https://launchpad.net/~jstaf/+archive/ubuntu/onedriver/+files/onedriver_0.11.1-1_amd64.deb
# install the deb package in linux
sudo apt install ./onedriver_0.11.1-1_amd64.deb
# reference from https://github.com/jstaf/onedriver
# create mount point
mkdir -p ~/onedrive
# determine the service name
export SERVICE_NAME=$(systemd-escape --template onedriver@.service --path ~/onedrive)
# mount onedrive
systemctl --user daemon-reload
systemctl --user start $SERVICE_NAME
# automatically mount onedrive when you login
systemctl --user enable $SERVICE_NAME
# query the status of onedriver
systemctl --user status $SERVICE_NAME
# check onedriver's logs for the current day
journalctl --user -u $SERVICE_NAME --since today
</code></dl>
<br /><br /><br /><br />
P.S. if you cannot install Chrome OS Linux Beta Crostini, please refer to the reason in this article <a href="https://chromeunboxed.com/google-pauses-chrome-os-update-breaks-linux-container/" target="_blank">https://chromeunboxed.com/google-pauses-chrome-os-update-breaks-linux-container/</a><br/><br/><br/><br/>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-42582877997800543082021-07-03T01:04:00.008+08:002022-06-04T23:14:25.617+08:00How to install Windows 11 WSL2 GUI App(1) If you have unspported hardware, please follow this guide to install Dev Channel Preview of Windows 11 -> <a href="https://christitus.com/update-any-pc-to-windows11/" target="_blank">update-any-pc-to-windows11</a><br/><br/>
(2) After installed Windows 11 Preview, Start Windows Terminal (install from Microsoft Store) in Administrative Role. The following commands are entered using Windows Terminal with elevated admin rights.<br/><br/>
(3) wslconfig /u ubuntu # if wsl already installed previously in Windows 10 and want to remove old ubuntu distro<br/><br/>
(4.1) wsl --update # if wsl already installed previously in Windows 10 and needs update to WSLg<br/><br/>
(4.2) wsl --shutdown # wsl needs to be restarted after update<br/><br/>
(5) wsl --install -d Ubuntu # this will install WSLg on Windows 11 and the new Ubuntu 20.04 instance<br/><br/>
(6) sudo apt install audacity # this will install audacity linux gui app for ubuntu<br/><br/>
(7) Use Windows search function to search for <b>Audacity (Ubuntu)</b> App to start the linux GUI App under Windows 11.<br/><br/>
(8) You can even install and run Chrome, Edge, or Teams under Ubuntu on Windows 11 with WSLg.<br/><br/>
(9) To install flatpak for GUI App<br/><br/>
<dl class="codebox">
<dt>Shellscript <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd>
<code>sudo apt install flatpak
# add repo
flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
# search app and install
flatpak search gimp
flatpak install flathub org.gimp.GIMP
</code>
</dd></dl>
<br/><br/>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-83355097086425159222021-06-08T05:38:00.007+08:002021-06-08T11:07:18.609+08:00Hello swift async and await for Swift 5.5(1) This is to test the new async and await feature for Swift 5.5 dev on Linux. First Download and install packages in Ubuntu 20.04.
<dl class="codebox">
<dt>Shell script for setup Swift 5.5 <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd>
<code>
sudo apt-get install -y binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 libz3-dev pkg-config tzdata zlib1g-dev
cd ${HOME}
wget https://swift.org/builds/swift-5.5-branch/ubuntu2004/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-06-02-a/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-06-02-a-ubuntu20.04.tar.gz
tar xzvf swift-5.5-DEVELOPMENT-SNAPSHOT-2021-06-02-a-ubuntu20.04.tar.gz
export PATH=${HOME}/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-06-02-a-ubuntu20.04/usr/bin:$PATH
</code>
</dd></dl>
<br/><br/>
(2) Create swift package for executable
<dl class="codebox">
<dt>Shell script testing async and await <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd>
<code>cd ${HOME}
mkdir -p ${HOME}/AsyncSwift
cd ${HOME}/AsyncSwift
swift package init --type executable
</code>
</dd></dl>
<br/><br/>
(3) Amend ${HOME}/AsyncSwift/Package.swift to have swift setting flags
<dl class="codebox">
<dt>Package.swift <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd>
<code>// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "AsyncSwift",
products: [
.executable(name: "AsyncSwift", targets: ["AsyncSwift"])
],
dependencies: [
// none for now..
],
targets: [
.executableTarget(name: "AsyncSwift",
swiftSettings: [
.unsafeFlags([
"-parse-as-library",
"-Xfrontend", "-disable-availability-checking",
"-Xfrontend", "-enable-experimental-concurrency",
])
]
),
.testTarget(name: "AsyncSwiftTests", dependencies: ["AsyncSwift"]),
]
)
</code>
</dd></dl>
<br/><br/>
(4) Edit ${HOME}/AsyncSwift/Sources/AsyncSwift/main.swift
<dl class="codebox">
<dt>Sources/AsyncSwift/main.swift <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd>
<code>import Foundation
func calculateFirstNumber() async -> Int {
print("First number is now being calculated...")
return await withUnsafeContinuation { c in
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
print("First number is now ready.")
c.resume(returning: 42)
}
}
}
func calculateSecondNumber() async -> Int {
print("Second number is now being calculated...")
return await withUnsafeContinuation { c in
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
print("Second number is now ready.")
c.resume(returning: 6)
}
}
}
func calculateThirdNumber() async -> Int {
print("Third number is now being calculated...")
return await withUnsafeContinuation { c in
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
print("Third number is now ready.")
c.resume(returning: 69)
}
}
}
func trace(task: Int) async {
// Generates a random integer in the [0, task] range
print("Task \(task) started")
sleep( UInt32.random(in: 0...UInt32(task)) )
print("Task \(task) completed")
}
@main
struct MyProgram {
static func main() async {
print("Hello, swift async!\n")
print("\nSerial queue, asynchronous execution\n")
for i in 5...10 {
print("Submitting task \(i)")
async {
await trace(task: i)
}
}
async let x = calculateFirstNumber()
let y = await calculateSecondNumber()
let z = await calculateThirdNumber()
await print(x + y + z)
sleep(2)
await print("Program ended")
}
}
/*
[6/6] Build complete!
Hello, swift async!
First number is now being calculated...
First number is now ready.
Second number is now being calculated...
Second number is now ready.
Third number is now being calculated...
Third number is now ready.
117
*/
</code>
</dd></dl>
<br/><br/>
(5) build and run executable
<dl class="codebox">
<dt>Shell script for building and running <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd>
<code>cd ${HOME}/AsyncSwift
swift package clean
swift build
swift run
</code>
</dd></dl>
<br/><br/>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-10721465193920498852021-05-17T10:56:00.020+08:002021-05-23T17:32:14.408+08:00How to compile Quantlib-Python for Raspberry Pi 4B arm32 and arm64Raspberry Pi has default gcc-8 and Python 3.7 for its 32 bit / 64 bit buster image. And compiling QuantLib-Python on this machine could have out of memeory error. Cross compiling on docker might have different python version which is not compatible. The trick to compile on Raspberry Pi is to setup swap say 2G and 4G Ram and turn off debug -g flag when compiling as Python package.
<dl class="codebox">
<dt>Shell script for building arm32 version <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd>
<code># install necessary packages for building
sudo apt update
sudo apt install -y build-essential wget libbz2-dev libboost-test1.67.0 libboost-test-dev
# Get QuantLib-1.22 and build static library
cd ${HOME}
wget https://github.com/lballabio/QuantLib/releases/download/QuantLib-v1.22/QuantLib-1.22.tar.gz
tar xzf QuantLib-1.22.tar.gz
cd QuantLib-1.22/
./configure --prefix=/usr --disable-shared CXXFLAGS=-O3
make -j 4 && make install
sudo ldconfig
# Setup and enable swap and check it for at least 2GB.
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
free -mh
sudo apt install -y python3 python3-pip python-dev libgomp1
# Get QuantLib-SWIG-1.22 and compile it
cd ${HOME}
wget --no-check-certificate https://github.com/lballabio/QuantLib-SWIG/releases/download/QuantLib-SWIG-v1.22/QuantLib-SWIG-${quantlib_swig_version}.tar.gz
tar xfz QuantLib-SWIG-1.22.tar.gz
cd QuantLib-SWIG-1.22/
./configure CXXFLAGS="-O2 --param ggc-min-expand=1 --param ggc-min-heapsize=32768 -Wno-deprecated-declarations -Wno-misleading-indentation" PYTHON=/usr/bin/python3
# manual compile it and remove the -g flag
cd Python/
mkdir -p build/temp.linux-armv7l-3.7/QuantLib
export CXX="echo gcc"; python3 setup.py bdist_wheel
g++ -fwrapv -O2 -Wall -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DNDEBUG -I/usr/include/python3.7m -I/usr/include -c QuantLib/quantlib_wrap.cpp -o build/temp.linux-armv7l-3.7/QuantLib/quantlib_wrap.o -Wno-unused --param ggc-min-expand=1 --param ggc-min-heapsize=32768 -Wno-deprecated-declarations -Wno-misleading-indentation
mkdir -p build/lib.linux-armv7l-3.7/QuantLib/
g++ -shared -Wl,-z,relro -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-armv7l-3.7/QuantLib/quantlib_wrap.o -lQuantLib -o build/lib.linux-armv7l-3.7/QuantLib/_QuantLib.cpython-37m-arm-linux-gnueabihf.so
# create wheel file
python3 setup.py bdist_wheel
# Upgrade PIP and install the wheel file
/usr/bin/python3 -m pip install --upgrade pip
pip3 install dist/QuantLib-1.22-cp37-cp37m-linux_armv7l.whl
# Or alternatively install as site-package
sudo python3 setup.py install
# Test examples after installation
pip3 install pandas
python3 examples/bonds.py
.
.
.
.
</code>
</dd></dl>
<br/><br/>
Compiling for Rapberry Pi arm64 is very similar but has to add -fPIC flag for the QuantLib when building static library
<dl class="codebox">
<dt>Shell script for building arm64 version <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd><code>
# install necessary packages for building
sudo apt update
sudo apt install -y build-essential wget libbz2-dev
sudo apt install -y libboost-test1.67.0 libboost-test-dev
cd ${HOME}
wget https://github.com/lballabio/QuantLib/releases/download/1.22/QuantLib-1.22.tar.gz
tar xzf QuantLib-1.22.tar.gz
cd QuantLib-1.22/
# enable -fPIC flag for building static library
./configure --prefix=/usr --disable-shared CXXFLAGS="-O3 -fPIC"
make -j 4 && make install
sudo ldconfig
# If Raspbeery Pi has 8GB Ram, no need to setup and enable swap
sudo apt install -y python3 python3-pip python-dev libgomp1
# Get QuantLib-SWIG-1.22 and compile it
cd {HOME}
wget https://github.com/lballabio/QuantLib-SWIG/releases/download/QuantLib-SWIG-v1.22/QuantLib-SWIG-1.22.tar.gz
tar xzf QuantLib-SWIG-1.22.tar.gz
cd QuantLib-SWIG-1.22/
cd Python/
./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768 -fPIC -Wno-deprecated-declarations -Wno-misleading-indentation" PYTHON=/usr/bin/python3
# manual compile it and remove the -g flag
cd Python/
mkdir -p build/temp.linux-aarch64-3.7/QuantLib/
g++ -fwrapv -O2 -Wall -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.7m -I/usr/include -c QuantLib/quantlib_wrap.cpp -o build/temp.linux-aarch64-3.7/QuantLib/quantlib_wrap.o -Wno-unused --param ggc-min-expand=1 --param ggc-min-heapsize=32768 -fno-strict-aliasing -Wno-unused -Wno-uninitialized -Wno-sign-compare -Wno-write-strings -Wno-deprecated-declarations -Wno-misleading-indentation
mkdir -p build/lib.linux-aarch64-3.7/QuantLib/
g++ -shared -Wl,-z,relro -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-aarch64-3.7/QuantLib/quantlib_wrap.o -lQuantLib -o build/lib.linux-aarch64-3.7/QuantLib/_QuantLib.cpython-37m-aarch64-linux-gnu.so
# create wheel file
python3 setup.py bdist_wheel
# Upgrade PIP and install the wheel file
/usr/bin/python3 -m pip install --upgrade pip
pip3 install dist/QuantLib-1.22-cp37-cp37m-linux_aarch64.whl
# Or alternatively install as site-package
sudo python3 setup.py install
# Test examples after installation
pip3 install pandas
python3 examples/bonds.py
</code>
</dd></dl>
<br/><br/>
File Download
QuantLib-1.22-cp37-cp37m-linux_armv7l.whl
<a href="https://mega.nz/file/mtJSxZTT#fzDDHw0AIqz-2LIspBGNZLoyW4_MT9qjft_b-ITTA8w" target="_blank">https://mega.nz/file/mtJSxZTT#fzDDHw0AIqz-2LIspBGNZLoyW4_MT9qjft_b-ITTA8w</a>
<br/><br/>
File Download QuantLib-1.22-cp37-cp37m-linux_aarch64.whl
<a href="https://mega.nz/file/WlAEXJCZ#UKFnlTrfQfRNzFW-OJbXHLFIHwzCw_189HvMa_xU4Oo" target="_blank">https://mega.nz/file/WlAEXJCZ#UKFnlTrfQfRNzFW-OJbXHLFIHwzCw_189HvMa_xU4Oo</a>
<br/><br/>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-11978597738200099112021-05-12T03:48:00.018+08:002022-03-16T04:09:55.745+08:00How to install docker client and connect to docker desktop engine on another machine macOS or Windows.Use Docker Desktop for Windows 10 / macOS as engine and docker client for linux/macos/Android to connect.<br/>
Why use docker client ? Because don't want to / cannot install docker engine in the client environment and just want to connect to the docker engine on local LAN.
<br/>
(1) For Windows 10 Host, after installation of docker desktop <br/>
# C:\ProgramData\Docker\config\daemon.json and add<br/>
<pre>"hosts" : ["tcp://0.0.0.0:2375"],</pre>
# change port forwarding to docker wsl backend, run this in powershell admin mode <br/>
<pre>netsh interface portproxy add v4tov4 listenport=2375 listenaddress=192.168.64.1 connectaddress=127.0.0.1 connectport=2375</pre>
# change Windows defender firewall and add incoming rule to enable port 2375
# Refer to this for setting openssh server authorized_keys, with proper file permission https://superuser.com/questions/1445976/windows-ssh-server-refuses-key-based-authentication-from-client
<br/><br/>
(2) For macOS Host, after installation of docker desktop <br/>
# ssh-keygen in client and ssh-copy-id to host, e.g. remote host username with ip address of 192.168.64.1<br/>
<pre>ssh-keygen -t rsa
ssh-copy-id username@192.168.64.1</pre>
# edit sshd_config<br/>
<pre>sudo vi /private/etc/ssh/sshd_config</pre>
# and add<br/>
<pre>PermitUserEnvironment PATH,LANG</pre>
# edit ~/.docker/daemon.json and add<br/>
<pre>"hosts" : ["tcp://0.0.0.0:2375"],</pre>
# add .ssh/environment<br/>
<pre>PATH=$PATH:/usr/local/bin</pre>
# restarting sshd using macOS System Preferences -> Sharing -> File Sharing
<br/><br/>
(3) To install docker client for Linux using tcp<br/>
<pre>
cd ~/
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.6.tgz
tar -xzvf docker-20.10.6.tgz
cd docker
./docker -H tcp://<remote host ip address>:2375 images
</pre>
<br/><br/>
(3.1) To install docker client for Termux app of Android and using tcp<br/>
<pre>
wget https://download.docker.com/linux/static/stable/aarch64/docker-20.10.6.tgz
tar xzvf docker-20.10.6.tgz
mv docker/docker /data/data/com.termux/files/usr/bin/
./docker -H tcp://<remote host ip address>:2375 images
</pre>
<br/><br/>
(4) To install docker client for macOS using ssh<br/>
<pre>cd ~/
wget https://download.docker.com/mac/static/stable/x86_64/docker-20.10.6.tgz
#or curl -OL https://download.docker.com/mac/static/stable/x86_64/docker-20.10.6.tgz
#or curl -OL https://download.docker.com/mac/static/stable/aarch64/docker-20.10.6.tgz
tar xzvf docker-20.10.6.tgz
xattr -rc docker
cd docker
sudo mkdir -p /usr/local/bin
sudo mv * /usr/local/bin/
docker -H ssh://username@<remote host ip address> images
</pre>
<br/><br/>
(5) Or simply add the corresponding variables to ~/.bashrc<br/>
<pre>unset DOCKER_HOST
# for tcp connection to Windows 10 host
export DOCKER_HOST=tcp://192.168.64.1:2375
# for ssh connection to macOS host <span style="color:red">using SSH</span>
export DOCKER_HOST=ssh://user@192.168.64.1
</pre>
<br/><br/>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-24123682228436045552021-05-02T13:40:00.014+08:002021-05-18T16:14:53.149+08:00How to install openssh server in wsl2(1) This is the guide to install openssh server and connect to wsl2 shell when ssh login from other machines in LAN network.<br/>
<p><a href="https://www.hanselman.com/blog/the-easy-way-how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machine" target="_blank">https://www.hanselman.com/blog/the-easy-way-how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machine</a></p><br/><br/>
(2) However, if still cannot connect from external machines from LAN network after setting all the firewall rules. Do this in powershell with admin right.<br/>
<p><span style="color:blue">Set-ExecutionPolicy Unrestricted -Force</span></p><br/><br/>
(3) If want to setup jupyter-notebook server in wsl2 and connect from other machines in the LAN network. Follow this guide.<br/>
<a href="https://medium.com/swlh/how-to-set-up-a-jupiter-notebook-server-and-access-it-from-a-local-or-remote-network-on-windows-d335c5ba490d" target="_blank">https://medium.com/swlh/how-to-set-up-a-jupiter-notebook-server-and-access-it-from-a-local-or-remote-network-on-windows-d335c5ba490d</a><br/><br/>
(4) The important setup steps are to open the Windows firewall rule and the script to port forward to the vm of the wsl2 as in.
<pre><span style="color:blue">
wget https://gist.githubusercontent.com/david-littlefield/f45999c069e0b6b68bdae829d8616727/raw/80a60968f1bdda598eaf275bf1300bb3451d45ab/jupyter_notebook_port_wsl2.ps1
</span></pre><br/><br/>
(5) It is advised to login from external internet to local LAN machines via VPN Server only rather than exposing or forwarding the local ports directly via the router.<br/><br/>
(6) Refer to this for setting openssh server authorized_keys, with proper file permission
https://superuser.com/questions/1445976/windows-ssh-server-refuses-key-based-authentication-from-client
<br/><br/>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-1053172852118712012021-05-01T08:29:00.028+08:002021-05-29T21:32:37.725+08:00How to use Chrome browser to scrape website using javascript(1) This is to demo how to scrape website using Chrome Browser and save the json text results to local drive.<br><br>
(2) First launch Desktop version of Chrome Browser and goto this website <a href="http://aastocks.com/en/stocks/market/calendar.aspx?type=5&industrysymbol=&wctype=&s=0&searchsymbol=&page=1" target="_blank">"http://aastocks.com/en/stocks/market/calendar.aspx?type=5"</a><br><br>
(3) Install "JQuery Inject" as Chrome Extension and enable it in current browser session.<br><br>
(4) Open Chrome Developer tools (Ctrl-Shift-I) and select console tab to enter the following code. Enter the code in 3 steps.<br>
<dl class="codebox">
<dt>Chrome Browser console code : Step 1 <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>// Step 1
// define arrays for scraped objects and should be store as global variable
var scrapeResults = [];
</code></dl><br/>
<dl class="codebox">
<dt>Console Code : Step 2 <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>//Step 2
// function to scrape page
$("table.CalendarResultTable > tbody > .crtRow").each((index, element) => {
const tds = $(element).find("td");
if (index===0) {
previousDate = $(tds[0]).text();
}
if ($(tds[0]).text().trim()==='') {
}
else {
previousDate = $(tds[0]).text();
}
const date = previousDate;
const namecell = $(tds[1]).find("a");
const name = $(tds[1]).text().replace('\n','').split(/[0-9]+.HK/)[0].trim();
const stockcode = $(namecell).text();
const stockurl = $(namecell).attr("href");
const dividend = $(tds[2]).text().trim().split('D:')[1];
const dividenddate = $(tds[3]).text().trim().split(/Ex-Date: | Payable: | Book Close: /);
const exdate = dividenddate[1]
const payable = dividenddate[2]
const bookclose = dividenddate[3]
const scrapeResult = { date, name, stockcode, stockurl, dividend, exdate, payable, bookclose };
//console.log(scrapeResult);
if (!scrapeResults.find(({stockcode}) => stockcode === scrapeResult.stockcode)) {
scrapeResults.push(scrapeResult);
}
});
// copy to clipboard.
copy(scrapeResults);
</code></dl>
If there are more than 1 page, click to goto next page and Repeat Step 2 to scrape again. After finished with all the pages then run Step 3 code to download to local drive. scrapeResults should be stored as Global variable for this to work,
<br/><br/>
<dl class="codebox">
<dt>Console Code : Step 3 <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>// Step 3
// define download function for webAPI
function download(content, fileName, contentType) {
var a = document.createElement("a");
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
// download json to local folder
var jsonData = JSON.stringify(scrapeResults);
var currentdate = new Date();
download(jsonData, currentdate.getFullYear()
+ ('0'+(currentdate.getMonth()+1)).slice(-2)
+ ('0'+currentdate.getDate()).slice(-2) + '_'
+ ('0'+currentdate.getHours()).slice(-2)
+ ('0'+currentdate.getMinutes()).slice(-2)
+ ('0'+currentdate.getSeconds()).slice(-2)+'_stockjson.txt', 'text/plain');
</code></dl>
<br/><br/>
(5) The same jquery code function above can be used in nodejs script for automation. Just add "request request-promise cheerio" packages to the project<br><br>
(6) For nodejs, the save function should be
<dl class="codebox">
<dt>nodejs script <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>var fs = require('fs');
fs.writeFile("json.txt", jsonData, function(err) {
if (err) {
console.log(err);
}
});
</code></dl>
<br/><br/>
(7) For browser console code without jQuery inject or don't want to import the jQuery library, and have to use querySelectorAll() function and use Object.values to convert to object as demo below.
<dl class="codebox">
<dt>console code <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>// Goto http://www.aastocks.com/en/stocks/market/calendar.aspx?type=1 and then open Browser (Chrome, Firefox, Safari) developer tools using ( Cmd + Opt + I in mac or Ctrl + Shift + I in win) and enter the following console code to run.
var scrapeResults = '';
document.querySelectorAll('tr.crtRow').forEach(function(item) {
const first = Object.values(item.querySelectorAll('.first'))[0];
if (typeof first !== 'undefined' && first !== null) {
console.log(first.textContent??first.textContent.trim());
scrapeResults = scrapeResults.concat(first.textContent??first.textContent.trim(), ' ');
};
const second = Object.values(item.querySelectorAll('td.second'))[0];
if (typeof second !== 'undefined' && second !== null) {
console.log(second.textContent??second.textContent.trim());
scrapeResults = scrapeResults.concat(second.textContent??second.textContent.trim(), ' ');
};
const third = Object.values(item.querySelectorAll('td.minw4'))[0];
if (typeof third !== 'undefined' && third !== null) {
console.log(third.textContent??third.textContent.trim());
scrapeResults = scrapeResults.concat(third.textContent??third.textContent.trim(), ' ');
};
const last = Object.values(item.querySelectorAll('td.last.minw1'))[0];
if (typeof last !== 'undefined' && last !== null) {
console.log(last.textContent??last.textContent.trim());
scrapeResults = scrapeResults.concat(last.textContent??last.textContent.trim(), '\n');
};
});
// copy results to clipboard.
copy(scrapeResults);
</code></dl>
<br/><br/>
(7.1) For browser console code and use Array.from and map function to return json data.
<dl class="codebox">
<dt>console code <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>//
//// Goto http://www.aastocks.com/en/stocks/market/calendar.aspx?type=1 and then open Browser (Chrome, Firefox, Safari) developer tools using ( Cmd + Opt + I in mac or Ctrl + Shift + I in win) and enter the following console code to run.
var data = Array.from(
document.querySelectorAll('.crtRow')
).map(
row => Array.from(row.children).map(node => node.textContent.trim())
).map(
(row) => row[0].length === 0 ? [...row.slice(1)] : row
).map(
(row, idx, arr) => {
if (row.length === 1) return null;
const getLastMatch = (idx, arr) =>
arr[idx].length === 4 ? arr[idx] : getLastMatch(idx - 1, arr);
const match = getLastMatch(idx, arr);
const isSameDate = row.length === 3;
console.log(''.concat(match[0],' ',row[1 - isSameDate *1],' ',row[2 - isSameDate *1],' ',row[3 - isSameDate *1],'\n'));
return {
date:match[0],
stock:row[1- isSameDate *1],
code:row[1 - isSameDate *1].slice(-8).slice(0,5),
industry:row[2 - isSameDate *1],
period:row[3 - isSameDate *1 -3]
}
}).filter(Boolean);
console.log(data);
copy(data);
</code></dl>
<br/><br/>
(8) Another example for nodejs scrapping code as demo below.
<dl class="codebox">
<dt>ronaldo.js <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code>// need to install npm install request
// run with node ronaldo.js
const request = require("request-promise");
const url = "https://www.transfermarkt.com/cristiano-ronaldo/alletore/spieler/8198/plus/1"
headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36' } ;
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const options = {
url: url,
timeout: 300000,
headers:headers
};
async function scrape() {
try {
const htmlResult = await request.get(options);
const dom = new JSDOM(htmlResult);
const { document } = dom.window;
var data = Array.from(
document.querySelectorAll('.responsive-table table tbody tr')
).map(
row => Array.from(row.children).map(node => node.textContent.trim())
).map(
(row) => row.length === 15 ? [...row.slice(0, 5), ...row.slice(6)] : row
).map(
(row, idx, goals) => {
if (row.length === 1) return null;
const getLastMatch = (idx, goals) =>
goals[idx].length === 14 ? goals[idx] : getLastMatch(idx - 1, goals);
const match = getLastMatch(idx, goals);
const isSameMatch = row.length === 14;
return {
competition: match[1],
matchday: match[2],
date: match[3],
venue: match[4],
opponent: match[7],
result: match[8],
position: match[9],
minute: row[1 + isSameMatch * 9],
atScore: row[2 + isSameMatch * 9],
goalType: row[3 + isSameMatch * 9],
assist: row[4 + isSameMatch * 9],
}
}
).filter(Boolean) // filter null
.filter(x => (new Date(x.date)).getFullYear() >= 2021) // filter year
console.log(data);
} catch (err) { // try catch
console.error(err);
}
}
scrape();
</code></dl>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1136927038369577335.post-38041794062973886302021-04-24T01:01:00.016+08:002021-04-25T14:30:20.540+08:00Google colab - keras-learn and Logistic Regression example(1) Following the previous post, this demo the keras sample from
<a href="/2020/04/how-to-install-tensorflow-with-gpu.html" target="_blank">how-to-install-tensorflow-with-gpu.html</a><br/>
Please take note that google only allow one active session for the free service. If you need faster GPU, more RAM and sessions, please consider to subscribe colab pro.<br/><br/>
<dl class="codebox">
<dt>keraslearn.ipynb <a href="#" onclick="selectCode(this); return false;">Select all</a></dt>
<code># Step 1 mount google drive if data is from google drive
import os
from google.colab import drive
drive.mount('/content/drive')
# Step 2 if using tensorflow GPU
#%tensorflow_version 2.x
#import tensorflow as tf
#print('TensorFlow: {}'.format(tf.__version__))
#tf.test.gpu_device_name()
# Step 3
from keras.models import Sequential
from keras.layers import Dense
import numpy
import time
# fix random seed for reproducibility
numpy.random.seed(7)
# Step 4
# download pima indians dataset to google drive
!curl -L https://tinyurl.com/tensorflowwin | grep -A768 pima-indians-diabetes.data.nbsp | sed '1d' > 'drive/MyDrive/Colab Notebooks/pima-indians-diabetes.data'
# or download to local data directory
!mkdir -p ./data
!curl -L https://tinyurl.com/tensorflowwin | grep -A768 pima-indians-diabetes.data.nbsp | sed '1d' > './data/pima-indians-diabetes.data'
# Step 5 load dataset from google drive
dataset = numpy.loadtxt("drive/MyDrive/Colab Notebooks/pima-indians-diabetes.data", delimiter=",")
# or load data from local data directory
dataset = numpy.loadtxt("./data/pima-indians-diabetes.data", delimiter=",")
# Step 6
# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]
# Step 7
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# Step 8
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Step 9
start_time=time.time()
# Fit the model
model.fit(X, Y, batch_size=10, epochs=1500) # parameters for keras 1.2.2
# evaluate the model
scores = model.evaluate(X, Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
print("\nTraining took %.2f seconds\n" %(time.time()-start_time))
</code></dl>
<br/><br/>
(2) For large training data set, consider to zip them and upload to google drive. Mount the google drive, then unzip it in local session. e.g.<br/>
<pre>
!mkdir -p ./data
!unzip -o './drive/MyDrive/Colab Notebooks/mydata.zip' -d ./data/
</pre>
<br/><br/>
(3) To stop the running cell in Google Colab use Ctrl-M I
<br/><br/>
(4) How to quickly run an ipynb example from github ?<br/>
4.1) Go to <a href="https://colab.research.google.com/" target="_blank">https://colab.research.google.com/</a>, after login gmail and choose GitHub tab and enter search say "clareyan/From-Linear-to-Logistic-Regression-Explained-Step-by-Step"<br/>
4.2)
In Step 2 cell box change the importing of dataset to <br/>
df = pd.read_csv('https://raw.githubusercontent.com/clareyan/From-Linear-to-Logistic-Regression-Explained-Step-by-Step/master/Social_Network_Ads.csv')<br/>
4.3) Then choose menu -> Runtime -> Run All. After that, use menu -> File -> Save a copy in Drive.<br/><br/>
Unknownnoreply@blogger.com0