Skip to content

Commit

Permalink
Fix path issue on Windows for mitm patch
Browse files Browse the repository at this point in the history
  • Loading branch information
amsharma44 committed Dec 13, 2020
1 parent adfaf9b commit fd9dc9b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/mitm-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,29 @@ async function modifyNetworkSecurityConfig(nscPath: string) {
}

async function disableCertificatePinning(directoryPath: string) {
const smaliPath = directoryPath.split(path.sep).join(path.posix.sep);


const smaliFiles = await globby(path.posix.join(directoryPath, 'smali*/**/*.smali'));
const smaliFiles = await globby(path.posix.join(smaliPath, 'smali*/**/*.smali'));

let pinningFound = false;

outputChannel.appendLine(`Analyzing ${smaliFiles.length} smali files`);

for (const filePath of smaliFiles) {
// observer.next(`Scanning ${path.basename(filePath)}...`)
for (const smaliFile of smaliFiles) {

const filePath = smaliFile.split(path.posix.sep).join(path.sep);

const originalContent = await fs.promises.readFile(filePath, 'utf-8');
let originalContent = await fs.promises.readFile(filePath, 'utf-8');

// Don't scan classes that don't implement the interface
if (!originalContent.includes(INTERFACE_LINE)) {
continue;
}

if (process.platform.startsWith("win")) {
originalContent = originalContent.replace(/\r\n/g, "\n");
}

let patchedContent = originalContent;

for (const pattern of METHOD_PATTERNS) {
Expand All @@ -149,6 +154,9 @@ async function disableCertificatePinning(directoryPath: string) {
if (originalContent !== patchedContent) {
pinningFound = true;
outputChannel.appendLine(`Applying patch in ${filePath}`);
if(process.platform.startsWith("win")) {
patchedContent = patchedContent.replace(/\n/g, "\r\n");
}
await fs.promises.writeFile(filePath, patchedContent);
}

Expand Down

0 comments on commit fd9dc9b

Please sign in to comment.