Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

1.3 KB
Raw Blame
import { OwnedCommandFailure } from "../process/OwnedCommand.js";
import { DarwinProcessOwnershipInspectionError } from "../process/DarwinProcessRunTokenReader.js";
import type { AnalysisCapturedOutput } from "../domain/analysisErrorBase.js";
import type { ProviderProcessSnapshot } from "../process/ProviderProcess.js";

/** Project the command owner's bounded output without losing examined byte counts. */
const capturedApktoolCommandOutput = (
  output: ProviderProcessSnapshot,
): AnalysisCapturedOutput => ({
  stdout: output.stdout.text,
  stderr: output.stderr.text,
  truncated:
    output.diagnosticTruncated === true || output.outputIncomplete === true,
  stdout_bytes: output.stdout.observedBytes,
  stderr_bytes: output.stderr.observedBytes,
  exit_code: output.exitCode ?? null,
  signal: output.signal ?? null,
});

/** The command owner selects command output or preparation output, once. */
export const capturedApktoolFailureOutput = (
  cause: unknown,
): AnalysisCapturedOutput | undefined => {
  if (cause instanceof OwnedCommandFailure)
    return cause.snapshot === null
      ? cause.preparationFailure?.capturedOutput
      : capturedApktoolCommandOutput(cause.snapshot);
  return cause instanceof DarwinProcessOwnershipInspectionError
    ? cause.capturedOutput
    : undefined;
};