備忘録

備忘録

git clone recursive のエラー対策方法

Ⅰ. はじめに

タイトルの通り「git clone recursive のエラー対策方法」です。

エラー例は以下のとおりです。

$ git clone --recursive https://github.com/user001/project001
(略)
Cloning into 'C:/project001/dependency001'...
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@github.com:user002/dependency001.git' into submodule path 'C:/project001/dependency001' failed
Failed to clone 'dependency001' a second time, aborting

Ⅱ. 対策方法1

1. git clone する
git clone --recursive https://github.com/user001/project001
2. .git/config を編集する

httpsから始まるURLに書き換える
※.gitディレクトリは隠しフォルダになっています。

[submodule "dependency001"]
#  url = git@github.com:user002/dependency001.git
   url = https://github.com/user002/dependency001
3. git submodule update する
git submodule update --recursive

Ⅲ. 対策方法2

SSH の公開鍵を登録する方法です。
https://stackoverflow.com/a/29475881/4771485

C#でDLLをInjectする方法

Ⅰ. はじめに

タイトルの通り「C#でDLLをInjectする方法」です。

2019/05/12時点で以下3つのインジェクト方法に対応してます。

  • CreateRemoteThread
  • ManualMap
  • ThreadHijack

Ⅱ. やり方

1. NuGetから Bleak をインストールする
dotnet add package Bleak --version 3.1.1
2. サンプルプログラムを書く

TestDll.cpp

#include <Windows.h>

BOOL WINAPI DllMain(HINSTANCE hinstModule, DWORD dwReason, LPVOID lpvReserved)
{
  if (dwReason == DLL_PROCESS_ATTACH)
  {
    MessageBox(NULL, L"Hello world", L"Info", NULL);

    DisableThreadLibraryCalls(hinstModule);
  }
  return TRUE;
}

Program.cs

using Bleak;

var injector = new Injector("notepad", "TestDLL.dll", InjectionMethod.ManualMap, InjectionFlags.RandomiseDllHeaders);
injector.InjectDll();

実行結果


Ubuntuでマウスのスクロール量を調整する方法

Ⅰ. はじめに

タイトルの通り「Ubuntuでマウスのスクロール量を調整する方法」です。

Ⅱ. 環境

Ⅱ. スクロール量を調整する方法

1. imwheel をインストールする
sudo apt install imwheel
2. .imwheelrc を作成する

スクロール量として3を設定しています。

$ vim ~/.imwheelrc
".*"
None,      Up,   Button4, 3
None,      Down, Button5, 3
3. imwheel を起動する

期待するスクロール量に変化したかを確認する

imwheel

# 終了する時
# killall imwheel

Ⅲ. imwheel を自動起動する方法

1. 自動起動のプロパティを開く
gnome-session-properties
2. imwheel を追加する

f:id:kagasu:20190512003239p:plain

Puppeteerでレスポンスを書き換える方法

Ⅰ. はじめに

タイトルの通り「Puppeteerでレスポンスを書き換える方法」です。

Ⅱ. やり方

1. テスト用のサンプルプログラムを書く

index.html

<html>
  <script>
    (async() => {
      let res = await fetch('/get_data.php')
      let json = await res.json()
      // console.log(json)
    })()
  </script>
</html>

get_data.php

<?php
$obj = [
  'name' => 'tanaka',
  'age' => 20
];

echo json_encode($obj);
2. Puppeteerのサンプルプログラムを書く

index.js

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    headless: false
  })
  const page = await browser.newPage()

  await page.setRequestInterception(true)
  page.on('request', req => {
    let url = req.url()
    if (url.includes('get_data.php')) {
      req.respond({
        status: 200,
        contentType: 'application/json',
        body: JSON.stringify({
          'name': 'yamada',
          'age': 21
        })
      })
    } else {
      req.continue()
    }
  })

  await page.goto('http://127.0.0.1')

  // browser.close()
})()

実行結果

before after
f:id:kagasu:20190511103114p:plain f:id:kagasu:20190511103119p:plain

Puppeteer で指定した要素だけスクリーンショットを撮る方法

Ⅰ. はじめに

タイトルの通り「Puppeteer で指定した要素だけスクリーンショットを撮る方法」です。

Ⅱ. やり方

1. サンプルプログラムを書く
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.goto('http://example.com')
  let element = await page.$('h1')
  // 指定した要素だけスクリーンショットを撮る
  await element.screenshot({ path: 'out1.png' })
  // 比較用にページ全体のスクリーンショットを撮る
  await page.screenshot( { path: 'out2.png' })

  await browser.close()
})()

実行結果

out1.png out2.png
f:id:kagasu:20190509135420p:plain f:id:kagasu:20190509135427p:plain