Skip to content

Commit

Permalink
Fix issues related to package the crate
Browse files Browse the repository at this point in the history
  • Loading branch information
yaa110 committed Oct 24, 2018
1 parent 9306f5b commit 3891cd6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
**/*.rs.bk
Cargo.lock
/libinjection
src/bindings.rs
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
clean:
rm -rf libinjection
rm -f src/bindings.rs
cargo clean

fix-python:
sed -i 's/python$$/python2/g' libinjection/src/*.py
sed -i 's/python$$/python2/g' $(OUT_DIR)/libinjection/src/*.py

.PHONY: clean fix-python
.PHONY: fix-python
20 changes: 7 additions & 13 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@ extern crate regex;
use git2::Repository;
use regex::Regex;
use std::env;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::process::Command;

const LIBINJECTION_URL: &'static str = "https://github.com/client9/libinjection";
const BUILD_DIR_NAME: &'static str = "libinjection";

fn clone_libinjection(build_dir: &Path, version: &str) -> Option<()> {
let repo = if build_dir.exists() {
Repository::open(build_dir).ok()?
} else {
Repository::clone(LIBINJECTION_URL, build_dir).ok()?
};
let repo = Repository::clone(LIBINJECTION_URL, build_dir).ok()?;
let rev = repo.revparse_single(version).ok()?;
repo.set_head_detached(rev.id()).ok()
}

fn run_make(rule: &str, cwd: &Path) -> Option<bool> {
let output = Command::new("make")
.arg(rule)
.env("OUT_DIR", env::var("OUT_DIR").unwrap())
.current_dir(cwd)
.output()
.ok()?;
Expand All @@ -50,8 +47,8 @@ fn fix_python_version() -> Option<()> {
}

fn main() {
let mut build_parent_dir = env::current_dir().unwrap();
build_parent_dir.push(BUILD_DIR_NAME);
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut build_parent_dir = out_path.join(BUILD_DIR_NAME);

if clone_libinjection(build_parent_dir.as_path(), "v3.10.0").is_none() {
panic!("unable to clone libinjection");
Expand Down Expand Up @@ -79,10 +76,7 @@ fn main() {
.generate()
.expect("Unable to generate bindings");

let mut out_path = env::current_dir().unwrap();
out_path.push("src");
out_path.push("bindings.rs");
bindings
.write_to_file(out_path)
.expect("Couldn't write bindings!");
.write_to_file(out_path.join("bindings.rs"))
.expect("unable to write bindings");
}
6 changes: 6 additions & 0 deletions src/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
//!
//! ```
//! extern crate libinjection;
//!
//!
//! use libinjection::{sqli, xss};
//!
//!
//! fn main() {
//! let (is_sqli, fingerprint) = sqli("' OR '1'='1' --").unwrap();
//! assert!(is_sqli);
//! assert_eq!("s&sos", fingerprint);
//!
//!
//! let is_xss = xss("<script type='text/javascript'>alert('xss');</script>").unwrap();
//! assert!(is_xss);
//! }
Expand Down
1 change: 1 addition & 0 deletions tests/lib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn test_sqli() {
assert!(fingerprint.is_empty());
}

#[test]
fn test_xss() {
let is_xss = xss("<script type='text/javascript'>alert('xss');</script>").unwrap();
assert!(is_xss);
Expand Down

0 comments on commit 3891cd6

Please sign in to comment.